Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.114
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.114! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.113 2021/12/13 00:56:47 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.93 raeburn 271: col2 => 'Name displayed'}],
1.160.6.37 raeburn 272: print => \&print_defaults,
273: modify => \&modify_defaults,
1.43 raeburn 274: },
1.160.6.113 raeburn 275: 'wafproxy' =>
276: { text => 'Web Application Firewall/Reverse Proxy',
277: help => 'Domain_Configuration_WAF_Proxy',
278: header => [{col1 => 'Domain(s)',
279: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
280: },
281: {col1 => 'Domain(s)',
282: col2 => 'WAF Configuration',}],
283: print => \&print_wafproxy,
284: modify => \&modify_wafproxy,
285: },
1.160.6.98 raeburn 286: 'passwords' =>
287: { text => 'Passwords (Internal authentication)',
288: help => 'Domain_Configuration_Passwords',
289: header => [{col1 => 'Resetting Forgotten Password',
290: col2 => 'Settings'},
291: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
292: col2 => 'Settings'},
293: {col1 => 'Rules for LON-CAPA Passwords',
294: col2 => 'Settings'},
295: {col1 => 'Course Owner Changing Student Passwords',
296: col2 => 'Settings'}],
297: print => \&print_passwords,
298: modify => \&modify_passwords,
299: },
1.30 raeburn 300: 'quotas' =>
1.160.6.20 raeburn 301: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 302: help => 'Domain_Configuration_Quotas',
1.77 raeburn 303: header => [{col1 => 'User affiliation',
1.72 raeburn 304: col2 => 'Available tools',
1.160.6.28 raeburn 305: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 306: print => \&print_quotas,
307: modify => \&modify_quotas,
1.30 raeburn 308: },
309: 'autoenroll' =>
310: { text => 'Auto-enrollment settings',
1.67 raeburn 311: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 312: header => [{col1 => 'Configuration setting',
313: col2 => 'Value(s)'}],
1.160.6.37 raeburn 314: print => \&print_autoenroll,
315: modify => \&modify_autoenroll,
1.30 raeburn 316: },
317: 'autoupdate' =>
318: { text => 'Auto-update settings',
1.67 raeburn 319: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 320: header => [{col1 => 'Setting',
321: col2 => 'Value',},
1.131 raeburn 322: {col1 => 'Setting',
323: col2 => 'Affiliation'},
1.43 raeburn 324: {col1 => 'User population',
1.160.6.35 raeburn 325: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 326: print => \&print_autoupdate,
327: modify => \&modify_autoupdate,
1.30 raeburn 328: },
1.125 raeburn 329: 'autocreate' =>
330: { text => 'Auto-course creation settings',
331: help => 'Domain_Configuration_Auto_Creation',
332: header => [{col1 => 'Configuration Setting',
333: col2 => 'Value',}],
1.160.6.37 raeburn 334: print => \&print_autocreate,
335: modify => \&modify_autocreate,
1.125 raeburn 336: },
1.30 raeburn 337: 'directorysrch' =>
1.160.6.72 raeburn 338: { text => 'Directory searches',
1.67 raeburn 339: help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72 raeburn 340: header => [{col1 => 'Institutional Directory Setting',
341: col2 => 'Value',},
342: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 343: col2 => 'Value',}],
1.160.6.37 raeburn 344: print => \&print_directorysrch,
345: modify => \&modify_directorysrch,
1.30 raeburn 346: },
347: 'contacts' =>
1.160.6.78 raeburn 348: { text => 'E-mail addresses and helpform',
1.67 raeburn 349: help => 'Domain_Configuration_Contact_Info',
1.160.6.78 raeburn 350: header => [{col1 => 'Default e-mail addresses',
351: col2 => 'Value',},
352: {col1 => 'Recipient(s) for notifications',
353: col2 => 'Value',},
1.160.6.107 raeburn 354: {col1 => 'Nightly status check e-mail',
355: col2 => 'Settings',},
1.160.6.78 raeburn 356: {col1 => 'Ask helpdesk form settings',
357: col2 => 'Value',},],
1.160.6.37 raeburn 358: print => \&print_contacts,
359: modify => \&modify_contacts,
1.30 raeburn 360: },
361: 'usercreation' =>
362: { text => 'User creation',
1.67 raeburn 363: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 364: header => [{col1 => 'Format rule type',
365: col2 => 'Format rules in force'},
1.34 raeburn 366: {col1 => 'User account creation',
367: col2 => 'Usernames which may be created',},
1.30 raeburn 368: {col1 => 'Context',
1.43 raeburn 369: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 370: print => \&print_usercreation,
371: modify => \&modify_usercreation,
1.30 raeburn 372: },
1.160.6.34 raeburn 373: 'selfcreation' =>
374: { text => 'Users self-creating accounts',
375: help => 'Domain_Configuration_Self_Creation',
376: header => [{col1 => 'Self-creation with institutional username',
377: col2 => 'Enabled?'},
378: {col1 => 'Institutional user type (login/SSO self-creation)',
379: col2 => 'Information user can enter'},
1.160.6.93 raeburn 380: {col1 => 'Self-creation with e-mail verification',
1.160.6.34 raeburn 381: col2 => 'Settings'}],
1.160.6.37 raeburn 382: print => \&print_selfcreation,
383: modify => \&modify_selfcreation,
1.160.6.34 raeburn 384: },
1.69 raeburn 385: 'usermodification' =>
1.33 raeburn 386: { text => 'User modification',
1.67 raeburn 387: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 388: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 389: col2 => 'User information updatable in author context'},
1.33 raeburn 390: {col1 => 'Target user has role',
1.160.6.35 raeburn 391: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 392: print => \&print_usermodification,
393: modify => \&modify_usermodification,
1.33 raeburn 394: },
1.69 raeburn 395: 'scantron' =>
1.160.6.97 raeburn 396: { text => 'Bubblesheet format',
1.67 raeburn 397: help => 'Domain_Configuration_Scantron_Format',
1.160.6.97 raeburn 398: header => [ {col1 => 'Bubblesheet format file',
399: col2 => ''},
400: {col1 => 'Bubblesheet data upload formats',
401: col2 => 'Settings'}],
1.160.6.37 raeburn 402: print => \&print_scantron,
403: modify => \&modify_scantron,
1.46 raeburn 404: },
1.86 raeburn 405: 'requestcourses' =>
406: {text => 'Request creation of courses',
407: help => 'Domain_Configuration_Request_Courses',
408: header => [{col1 => 'User affiliation',
1.102 raeburn 409: col2 => 'Availability/Processing of requests',},
410: {col1 => 'Setting',
1.160.6.30 raeburn 411: col2 => 'Value'},
412: {col1 => 'Available textbooks',
1.160.6.39 raeburn 413: col2 => ''},
1.160.6.46 raeburn 414: {col1 => 'Available templates',
415: col2 => ''},
1.160.6.39 raeburn 416: {col1 => 'Validation (not official courses)',
417: col2 => 'Value'},],
1.160.6.37 raeburn 418: print => \&print_quotas,
419: modify => \&modify_quotas,
1.86 raeburn 420: },
1.160.6.5 raeburn 421: 'requestauthor' =>
1.160.6.34 raeburn 422: {text => 'Request Authoring Space',
1.160.6.5 raeburn 423: help => 'Domain_Configuration_Request_Author',
424: header => [{col1 => 'User affiliation',
425: col2 => 'Availability/Processing of requests',},
426: {col1 => 'Setting',
427: col2 => 'Value'}],
1.160.6.37 raeburn 428: print => \&print_quotas,
429: modify => \&modify_quotas,
1.160.6.5 raeburn 430: },
1.69 raeburn 431: 'coursecategories' =>
1.120 raeburn 432: { text => 'Cataloging of courses/communities',
1.67 raeburn 433: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 434: header => [{col1 => 'Catalog type/availability',
435: col2 => '',},
436: {col1 => 'Category settings for standard catalog',
1.57 raeburn 437: col2 => '',},
438: {col1 => 'Categories',
439: col2 => '',
440: }],
1.160.6.37 raeburn 441: print => \&print_coursecategories,
442: modify => \&modify_coursecategories,
1.69 raeburn 443: },
444: 'serverstatuses' =>
1.77 raeburn 445: {text => 'Access to server status pages',
1.69 raeburn 446: help => 'Domain_Configuration_Server_Status',
447: header => [{col1 => 'Status Page',
448: col2 => 'Other named users',
449: col3 => 'Specific IPs',
450: }],
1.160.6.37 raeburn 451: print => \&print_serverstatuses,
452: modify => \&modify_serverstatuses,
1.69 raeburn 453: },
1.160.6.73 raeburn 454: 'helpsettings' =>
455: {text => 'Support settings',
456: help => 'Domain_Configuration_Help_Settings',
457: header => [{col1 => 'Help Page Settings (logged-in users)',
458: col2 => 'Value'},
459: {col1 => 'Helpdesk Roles',
460: col2 => 'Settings'},],
461: print => \&print_helpsettings,
462: modify => \&modify_helpsettings,
463: },
1.160.6.39 raeburn 464: 'coursedefaults' =>
1.160.6.16 raeburn 465: {text => 'Course/Community defaults',
466: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 467: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
468: col2 => 'Value',},
469: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 470: col2 => 'Value',},],
1.160.6.37 raeburn 471: print => \&print_coursedefaults,
472: modify => \&modify_coursedefaults,
473: },
1.160.6.39 raeburn 474: 'selfenrollment' =>
1.160.6.37 raeburn 475: {text => 'Self-enrollment in Course/Community',
476: help => 'Domain_Configuration_Selfenrollment',
477: header => [{col1 => 'Configuration Rights',
478: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
479: {col1 => 'Defaults',
480: col2 => 'Value'},
481: {col1 => 'Self-enrollment validation (optional)',
482: col2 => 'Value'},],
483: print => \&print_selfenrollment,
484: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 485: },
1.141 raeburn 486: 'usersessions' =>
1.145 raeburn 487: {text => 'User session hosting/offloading',
1.137 raeburn 488: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 489: header => [{col1 => 'Domain server',
490: col2 => 'Servers to offload sessions to when busy'},
491: {col1 => 'Hosting of users from other domains',
1.137 raeburn 492: col2 => 'Rules'},
493: {col1 => "Hosting domain's own users elsewhere",
494: col2 => 'Rules'}],
1.160.6.37 raeburn 495: print => \&print_usersessions,
496: modify => \&modify_usersessions,
1.137 raeburn 497: },
1.160.6.78 raeburn 498: 'loadbalancing' =>
1.160.6.7 raeburn 499: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 500: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 501: header => [{col1 => 'Balancers',
1.150 raeburn 502: col2 => 'Default destinations',
1.160.6.13 raeburn 503: col3 => 'User affiliation',
1.150 raeburn 504: col4 => 'Overrides'},
505: ],
1.160.6.37 raeburn 506: print => \&print_loadbalancing,
507: modify => \&modify_loadbalancing,
1.150 raeburn 508: },
1.160.6.113 raeburn 509: 'ipaccess' =>
510: {text => 'IP-based access control',
511: help => 'Domain_Configuration_IP_Access',
512: header => [{col1 => 'Setting',
513: col2 => 'Value'},],
514: print => \&print_ipaccess,
515: modify => \&modify_ipaccess,
516: },
1.3 raeburn 517: );
1.110 raeburn 518: if (keys(%servers) > 1) {
519: $prefs{'login'} = { text => 'Log-in page options',
520: help => 'Domain_Configuration_Login_Page',
521: header => [{col1 => 'Log-in Service',
522: col2 => 'Server Setting',},
523: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 524: col2 => ''},
525: {col1 => 'Log-in Help',
1.160.6.56 raeburn 526: col2 => 'Value'},
527: {col1 => 'Custom HTML in document head',
1.160.6.113 raeburn 528: col2 => 'Value'},
529: {col1 => 'SSO',
530: col2 => 'Dual login: SSO and non-SSO options'},
531: ],
1.160.6.37 raeburn 532: print => \&print_login,
533: modify => \&modify_login,
1.110 raeburn 534: };
535: }
1.160.6.13 raeburn 536:
1.6 raeburn 537: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 538: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 539: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 540: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 541: text=>"Settings to display/modify"});
1.9 raeburn 542: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 543:
1.3 raeburn 544: if ($phase eq 'process') {
1.160.6.27 raeburn 545: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
546: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 547: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 548: $r->rflush();
1.160.6.27 raeburn 549: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 550: }
1.30 raeburn 551: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 552: my $js = &recaptcha_js().
1.160.6.40 raeburn 553: &toggle_display_js();
1.160.6.7 raeburn 554: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 555: my ($othertitle,$usertypes,$types) =
556: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 557: $js .= &lonbalance_targets_js($dom,$types,\%servers,
558: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 559: &new_spares_js().
560: &common_domprefs_js().
561: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 562: }
1.160.6.30 raeburn 563: if (grep(/^requestcourses$/,@actions)) {
564: my $javascript_validations;
565: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
566: $js .= <<END;
567: <script type="text/javascript">
568: $javascript_validations
569: </script>
570: $coursebrowserjs
571: END
1.160.6.113 raeburn 572: } elsif (grep(/^ipaccess$/,@actions)) {
573: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.160.6.30 raeburn 574: }
1.160.6.93 raeburn 575: if (grep(/^selfcreation$/,@actions)) {
576: $js .= &selfcreate_javascript();
577: }
1.160.6.78 raeburn 578: if (grep(/^contacts$/,@actions)) {
579: $js .= &contacts_javascript();
580: }
1.160.6.97 raeburn 581: if (grep(/^scantron$/,@actions)) {
582: $js .= &scantron_javascript();
583: }
1.150 raeburn 584: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 585: } else {
1.160.6.11 raeburn 586: # check if domconfig user exists for the domain.
587: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 588: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 589: &config_check($dom,$confname,$servadm);
590: unless ($configuserok eq 'ok') {
591: &Apache::lonconfigsettings::print_header($r,$phase,$context);
592: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
593: $confname).
594: '<br />'
595: );
596: if ($switchserver) {
597: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
598: '<br />'.
599: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
600: '<br />'.
601: &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).
602: '<br />'.
603: &mt('To do that now, use the following link: [_1]',$switchserver)
604: );
605: } else {
606: $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.').
607: '<br />'.
608: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
609: );
610: }
611: $r->print(&Apache::loncommon::end_page());
612: return OK;
613: }
1.21 raeburn 614: if (keys(%domconfig) == 0) {
615: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 616: my @ids=&Apache::lonnet::current_machine_ids();
617: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 618: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 619: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 620: my $custom_img_count = 0;
621: foreach my $img (@loginimages) {
622: if ($designhash{$dom.'.login.'.$img} ne '') {
623: $custom_img_count ++;
624: }
625: }
626: foreach my $role (@roles) {
627: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
628: $custom_img_count ++;
629: }
630: }
631: if ($custom_img_count > 0) {
1.94 raeburn 632: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 633: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 634: $r->print(
635: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
636: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
637: &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 />'.
638: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
639: if ($switch_server) {
1.30 raeburn 640: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 641: }
1.91 raeburn 642: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 643: return OK;
644: }
645: }
646: }
1.91 raeburn 647: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 648: }
649: return OK;
650: }
651:
652: sub process_changes {
1.160.6.24 raeburn 653: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 654: my %domconfig;
655: if (ref($values) eq 'HASH') {
656: %domconfig = %{$values};
657: }
1.3 raeburn 658: my $output;
659: if ($action eq 'login') {
1.160.6.24 raeburn 660: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 661: } elsif ($action eq 'rolecolors') {
1.9 raeburn 662: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 663: $lastactref,%domconfig);
1.3 raeburn 664: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 665: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 666: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 667: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 668: } elsif ($action eq 'autoupdate') {
669: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 670: } elsif ($action eq 'autocreate') {
671: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 672: } elsif ($action eq 'directorysrch') {
1.160.6.81 raeburn 673: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 674: } elsif ($action eq 'usercreation') {
1.28 raeburn 675: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 676: } elsif ($action eq 'selfcreation') {
1.160.6.93 raeburn 677: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 678: } elsif ($action eq 'usermodification') {
679: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 680: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 681: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 682: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 683: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 684: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 685: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 686: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 687: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 688: } elsif ($action eq 'serverstatuses') {
689: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 690: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 691: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 692: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 693: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 694: } elsif ($action eq 'helpsettings') {
1.160.6.77 raeburn 695: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16 raeburn 696: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 697: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 698: } elsif ($action eq 'selfenrollment') {
699: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 700: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 701: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 702: } elsif ($action eq 'loadbalancing') {
703: $output = &modify_loadbalancing($dom,%domconfig);
1.160.6.98 raeburn 704: } elsif ($action eq 'passwords') {
705: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.113 raeburn 706: } elsif ($action eq 'wafproxy') {
707: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
708: } elsif ($action eq 'ipaccess') {
709: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.3 raeburn 710: }
711: return $output;
712: }
713:
714: sub print_config_box {
1.9 raeburn 715: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 716: my $rowtotal = 0;
1.49 raeburn 717: my $output;
718: if ($action eq 'coursecategories') {
719: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 720: } elsif ($action eq 'defaults') {
721: $output = &defaults_javascript($settings);
1.160.6.98 raeburn 722: } elsif ($action eq 'passwords') {
723: $output = &passwords_javascript();
1.160.6.73 raeburn 724: } elsif ($action eq 'helpsettings') {
725: my (%privs,%levelscurrent);
726: my %full=();
727: my %levels=(
728: course => {},
729: domain => {},
730: system => {},
731: );
732: my $context = 'domain';
733: my $crstype = 'Course';
734: my $formname = 'display';
735: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
736: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
737: $output =
738: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
739: \@templateroles);
1.160.6.113 raeburn 740: } elsif ($action eq 'wafproxy') {
741: $output .= &wafproxy_javascript($dom);
742: } elsif ($action eq 'autoupdate') {
743: $output .= &autoupdate_javascript();
744: } elsif ($action eq 'login') {
745: $output .= &saml_javascript();
746: } elsif ($action eq 'ipaccess') {
747: $output .= &ipaccess_javascript($settings);
1.91 raeburn 748: }
1.160.6.40 raeburn 749: $output .=
1.30 raeburn 750: '<table class="LC_nested_outer">
1.3 raeburn 751: <tr>
1.160.6.113 raeburn 752: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 753: &mt($item->{text}).' '.
754: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
755: '</tr>';
1.30 raeburn 756: $rowtotal ++;
1.110 raeburn 757: my $numheaders = 1;
758: if (ref($item->{'header'}) eq 'ARRAY') {
759: $numheaders = scalar(@{$item->{'header'}});
760: }
761: if ($numheaders > 1) {
1.64 raeburn 762: my $colspan = '';
1.145 raeburn 763: my $rightcolspan = '';
1.160.6.104 raeburn 764: my $leftnobr = '';
1.160.6.42 raeburn 765: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 766: ($action eq 'directorysrch') ||
1.160.6.113 raeburn 767: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 768: $colspan = ' colspan="2"';
769: }
1.145 raeburn 770: if ($action eq 'usersessions') {
771: $rightcolspan = ' colspan="3"';
772: }
1.160.6.104 raeburn 773: if ($action eq 'passwords') {
774: $leftnobr = ' LC_nobreak';
775: }
1.30 raeburn 776: $output .= '
1.3 raeburn 777: <tr>
778: <td>
779: <table class="LC_nested">
780: <tr class="LC_info_row">
1.160.6.104 raeburn 781: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 782: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 783: </tr>';
1.69 raeburn 784: $rowtotal ++;
1.160.6.37 raeburn 785: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 786: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 787: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.113 raeburn 788: ($action eq 'helpsettings') || ($action eq 'contacts') || ($action eq 'wafproxy')) {
1.160.6.37 raeburn 789: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.160.6.98 raeburn 790: } elsif ($action eq 'passwords') {
791: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 792: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 793: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.160.6.97 raeburn 794: } elsif ($action eq 'scantron') {
795: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 796: } elsif ($action eq 'login') {
1.160.6.113 raeburn 797: if ($numheaders == 5) {
1.160.6.5 raeburn 798: $colspan = ' colspan="2"';
799: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
800: } else {
801: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
802: }
1.160.6.37 raeburn 803: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 804: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 805: } elsif ($action eq 'rolecolors') {
1.30 raeburn 806: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 807: }
1.30 raeburn 808: $output .= '
1.6 raeburn 809: </table>
810: </td>
811: </tr>
812: <tr>
813: <td>
814: <table class="LC_nested">
815: <tr class="LC_info_row">
1.160.6.37 raeburn 816: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 817: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 818: </tr>';
819: $rowtotal ++;
1.160.6.37 raeburn 820: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
821: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 822: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.98 raeburn 823: ($action eq 'contacts') || ($action eq 'passwords')) {
1.160.6.42 raeburn 824: if ($action eq 'coursecategories') {
825: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
826: $colspan = ' colspan="2"';
1.160.6.98 raeburn 827: } elsif ($action eq 'passwords') {
828: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.160.6.42 raeburn 829: } else {
830: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
831: }
832: $output .= '
1.63 raeburn 833: </table>
834: </td>
835: </tr>
836: <tr>
837: <td>
838: <table class="LC_nested">
839: <tr class="LC_info_row">
1.160.6.113 raeburn 840: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 841: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 842: </tr>'."\n";
843: if ($action eq 'coursecategories') {
844: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.160.6.108 raeburn 845: } elsif (($action eq 'contacts') || ($action eq 'passwords')) {
1.160.6.107 raeburn 846: if ($action eq 'passwords') {
847: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
848: } else {
849: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
850: }
851: $output .= '
1.160.6.98 raeburn 852: </tr>
853: </table>
854: </td>
855: </tr>
856: <tr>
857: <td>
858: <table class="LC_nested">
859: <tr class="LC_info_row">
1.160.6.113 raeburn 860: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.160.6.107 raeburn 861: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1.160.6.108 raeburn 862: if ($action eq 'passwords') {
863: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
864: } else {
865: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
866: }
867: $output .= '
1.160.6.98 raeburn 868: </table>
869: </td>
870: </tr>
871: <tr>';
1.160.6.42 raeburn 872: } else {
873: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
874: }
1.63 raeburn 875: $rowtotal ++;
1.160.6.57 raeburn 876: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 877: ($action eq 'defaults') || ($action eq 'directorysrch') ||
1.160.6.113 raeburn 878: ($action eq 'helpsettings') || ($action eq 'wafproxy')) {
1.160.6.37 raeburn 879: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.160.6.97 raeburn 880: } elsif ($action eq 'scantron') {
881: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 882: } elsif ($action eq 'login') {
1.160.6.113 raeburn 883: if ($numheaders == 5) {
1.160.6.5 raeburn 884: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
885: </table>
886: </td>
887: </tr>
888: <tr>
889: <td>
890: <table class="LC_nested">
891: <tr class="LC_info_row">
892: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 893: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 894: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
895: $rowtotal ++;
896: } else {
897: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
898: }
1.160.6.56 raeburn 899: $output .= '
900: </table>
901: </td>
902: </tr>
903: <tr>
904: <td>
905: <table class="LC_nested">
906: <tr class="LC_info_row">';
1.160.6.113 raeburn 907: if ($numheaders == 5) {
1.160.6.56 raeburn 908: $output .= '
909: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
910: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
911: </tr>';
912: } else {
913: $output .= '
914: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
915: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
916: </tr>';
917: }
918: $rowtotal ++;
1.160.6.113 raeburn 919: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
920: </table>
921: </td>
922: </tr>
923: <tr>
924: <td>
925: <table class="LC_nested">
926: <tr class="LC_info_row">';
927: if ($numheaders == 5) {
928: $output .= '
929: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
930: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
931: </tr>';
932: } else {
933: $output .= '
934: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
935: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
936: </tr>';
937: }
938: $rowtotal ++;
939: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 940: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 941: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
942: $rowtotal ++;
943: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 944: </table>
945: </td>
946: </tr>
947: <tr>
948: <td>
949: <table class="LC_nested">
950: <tr class="LC_info_row">
951: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
952: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 953: &textbookcourses_javascript($settings).
954: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
955: </table>
956: </td>
957: </tr>
958: <tr>
959: <td>
960: <table class="LC_nested">
961: <tr class="LC_info_row">
962: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
963: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
964: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 965: </table>
966: </td>
967: </tr>
968: <tr>
969: <td>
970: <table class="LC_nested">
971: <tr class="LC_info_row">
1.160.6.46 raeburn 972: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
973: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 974: </tr>'.
975: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 976: } elsif ($action eq 'requestauthor') {
977: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 978: $rowtotal ++;
1.122 jms 979: } elsif ($action eq 'rolecolors') {
1.30 raeburn 980: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 981: </table>
982: </td>
983: </tr>
984: <tr>
985: <td>
986: <table class="LC_nested">
987: <tr class="LC_info_row">
1.69 raeburn 988: <td class="LC_left_item"'.$colspan.' valign="top">'.
989: &mt($item->{'header'}->[2]->{'col1'}).'</td>
990: <td class="LC_right_item" valign="top">'.
991: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 992: </tr>'.
1.30 raeburn 993: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 994: </table>
995: </td>
996: </tr>
997: <tr>
998: <td>
999: <table class="LC_nested">
1000: <tr class="LC_info_row">
1.59 bisitz 1001: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1002: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1003: </tr>'.
1.30 raeburn 1004: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1005: $rowtotal += 2;
1.6 raeburn 1006: }
1.3 raeburn 1007: } else {
1.30 raeburn 1008: $output .= '
1.3 raeburn 1009: <tr>
1010: <td>
1011: <table class="LC_nested">
1.30 raeburn 1012: <tr class="LC_info_row">';
1.160.6.72 raeburn 1013: if ($action eq 'login') {
1.30 raeburn 1014: $output .= '
1.59 bisitz 1015: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1016: } elsif ($action eq 'serverstatuses') {
1017: $output .= '
1018: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
1019: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1020:
1.6 raeburn 1021: } else {
1.30 raeburn 1022: $output .= '
1.69 raeburn 1023: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1024: }
1.72 raeburn 1025: if (defined($item->{'header'}->[0]->{'col3'})) {
1026: $output .= '<td class="LC_left_item" valign="top">'.
1027: &mt($item->{'header'}->[0]->{'col2'});
1028: if ($action eq 'serverstatuses') {
1029: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1030: }
1.69 raeburn 1031: } else {
1032: $output .= '<td class="LC_right_item" valign="top">'.
1033: &mt($item->{'header'}->[0]->{'col2'});
1034: }
1035: $output .= '</td>';
1036: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1037: if (defined($item->{'header'}->[0]->{'col4'})) {
1038: $output .= '<td class="LC_left_item" valign="top">'.
1039: &mt($item->{'header'}->[0]->{'col3'});
1040: } else {
1041: $output .= '<td class="LC_right_item" valign="top">'.
1042: &mt($item->{'header'}->[0]->{'col3'});
1043: }
1.69 raeburn 1044: if ($action eq 'serverstatuses') {
1045: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1046: }
1047: $output .= '</td>';
1.6 raeburn 1048: }
1.150 raeburn 1049: if ($item->{'header'}->[0]->{'col4'}) {
1050: $output .= '<td class="LC_right_item" valign="top">'.
1051: &mt($item->{'header'}->[0]->{'col4'});
1052: }
1.69 raeburn 1053: $output .= '</tr>';
1.48 raeburn 1054: $rowtotal ++;
1.160.6.5 raeburn 1055: if ($action eq 'quotas') {
1.86 raeburn 1056: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 1057: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.113 raeburn 1058: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1059: ($action eq 'ipaccess')) {
1.160.6.37 raeburn 1060: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1061: }
1.3 raeburn 1062: }
1.30 raeburn 1063: $output .= '
1.3 raeburn 1064: </table>
1065: </td>
1066: </tr>
1.30 raeburn 1067: </table><br />';
1068: return ($output,$rowtotal);
1.1 raeburn 1069: }
1070:
1.3 raeburn 1071: sub print_login {
1.160.6.5 raeburn 1072: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 1073: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1074: my %choices = &login_choices();
1.160.6.113 raeburn 1075: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1076: %lt = &login_file_options();
1077: $switchserver = &check_switchserver($dom,$confname);
1078: }
1.110 raeburn 1079:
1.160.6.5 raeburn 1080: if ($caller eq 'service') {
1.149 raeburn 1081: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1082: my $choice = $choices{'disallowlogin'};
1083: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1084: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 1085: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1086: '<th>'.$choices{'server'}.'</th>'.
1087: '<th>'.$choices{'serverpath'}.'</th>'.
1088: '<th>'.$choices{'custompath'}.'</th>'.
1089: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1090: my %disallowed;
1091: if (ref($settings) eq 'HASH') {
1092: if (ref($settings->{'loginvia'}) eq 'HASH') {
1093: %disallowed = %{$settings->{'loginvia'}};
1094: }
1095: }
1096: foreach my $lonhost (sort(keys(%servers))) {
1097: my $direct = 'selected="selected"';
1.128 raeburn 1098: if (ref($disallowed{$lonhost}) eq 'HASH') {
1099: if ($disallowed{$lonhost}{'server'} ne '') {
1100: $direct = '';
1101: }
1.110 raeburn 1102: }
1.115 raeburn 1103: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1104: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1105: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1106: '</option>';
1.160.6.13 raeburn 1107: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1108: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1109: my $selected = '';
1.128 raeburn 1110: if (ref($disallowed{$lonhost}) eq 'HASH') {
1111: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1112: $selected = 'selected="selected"';
1113: }
1.110 raeburn 1114: }
1115: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1116: $servers{$hostid}.'</option>';
1117: }
1.128 raeburn 1118: $datatable .= '</select></td>'.
1119: '<td><select name="'.$lonhost.'_serverpath">';
1120: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1121: my $pathname = $path;
1122: if ($path eq 'custom') {
1123: $pathname = &mt('Custom Path').' ->';
1124: }
1125: my $selected = '';
1126: if (ref($disallowed{$lonhost}) eq 'HASH') {
1127: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1128: $selected = 'selected="selected"';
1129: }
1130: } elsif ($path eq '') {
1131: $selected = 'selected="selected"';
1132: }
1133: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1134: }
1135: $datatable .= '</select></td>';
1136: my ($custom,$exempt);
1137: if (ref($disallowed{$lonhost}) eq 'HASH') {
1138: $custom = $disallowed{$lonhost}{'custompath'};
1139: $exempt = $disallowed{$lonhost}{'exempt'};
1140: }
1141: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1142: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1143: '</tr>';
1.110 raeburn 1144: }
1145: $datatable .= '</table></td></tr>';
1146: return $datatable;
1.160.6.5 raeburn 1147: } elsif ($caller eq 'page') {
1148: my %defaultchecked = (
1149: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1150: 'helpdesk' => 'on',
1.160.6.5 raeburn 1151: 'adminmail' => 'off',
1152: 'newuser' => 'off',
1153: );
1.160.6.14 raeburn 1154: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1155: my (%checkedon,%checkedoff);
1.42 raeburn 1156: foreach my $item (@toggles) {
1.160.6.5 raeburn 1157: if ($defaultchecked{$item} eq 'on') {
1158: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1159: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1160: } elsif ($defaultchecked{$item} eq 'off') {
1161: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1162: $checkedon{$item} = ' ';
1163: }
1.1 raeburn 1164: }
1.160.6.5 raeburn 1165: my @images = ('img','logo','domlogo','login');
1166: my @logintext = ('textcol','bgcol');
1167: my @bgs = ('pgbg','mainbg','sidebg');
1168: my @links = ('link','alink','vlink');
1169: my %designhash = &Apache::loncommon::get_domainconf($dom);
1170: my %defaultdesign = %Apache::loncommon::defaultdesign;
1171: my (%is_custom,%designs);
1172: my %defaults = (
1173: font => $defaultdesign{'login.font'},
1174: );
1.6 raeburn 1175: foreach my $item (@images) {
1.160.6.5 raeburn 1176: $defaults{$item} = $defaultdesign{'login.'.$item};
1177: $defaults{'showlogo'}{$item} = 1;
1178: }
1179: foreach my $item (@bgs) {
1180: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1181: }
1.41 raeburn 1182: foreach my $item (@logintext) {
1.160.6.5 raeburn 1183: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1184: }
1.160.6.5 raeburn 1185: foreach my $item (@links) {
1186: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1187: }
1.160.6.5 raeburn 1188: if (ref($settings) eq 'HASH') {
1189: foreach my $item (@toggles) {
1190: if ($settings->{$item} eq '1') {
1191: $checkedon{$item} = ' checked="checked" ';
1192: $checkedoff{$item} = ' ';
1193: } elsif ($settings->{$item} eq '0') {
1194: $checkedoff{$item} = ' checked="checked" ';
1195: $checkedon{$item} = ' ';
1196: }
1.6 raeburn 1197: }
1.160.6.5 raeburn 1198: foreach my $item (@images) {
1199: if (defined($settings->{$item})) {
1200: $designs{$item} = $settings->{$item};
1201: $is_custom{$item} = 1;
1202: }
1203: if (defined($settings->{'showlogo'}{$item})) {
1204: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1205: }
1206: }
1207: foreach my $item (@logintext) {
1208: if ($settings->{$item} ne '') {
1209: $designs{'logintext'}{$item} = $settings->{$item};
1210: $is_custom{$item} = 1;
1211: }
1212: }
1213: if ($settings->{'font'} ne '') {
1214: $designs{'font'} = $settings->{'font'};
1215: $is_custom{'font'} = 1;
1216: }
1217: foreach my $item (@bgs) {
1218: if ($settings->{$item} ne '') {
1219: $designs{'bgs'}{$item} = $settings->{$item};
1220: $is_custom{$item} = 1;
1221: }
1222: }
1223: foreach my $item (@links) {
1224: if ($settings->{$item} ne '') {
1225: $designs{'links'}{$item} = $settings->{$item};
1226: $is_custom{$item} = 1;
1227: }
1228: }
1229: } else {
1230: if ($designhash{$dom.'.login.font'} ne '') {
1231: $designs{'font'} = $designhash{$dom.'.login.font'};
1232: $is_custom{'font'} = 1;
1233: }
1234: foreach my $item (@images) {
1235: if ($designhash{$dom.'.login.'.$item} ne '') {
1236: $designs{$item} = $designhash{$dom.'.login.'.$item};
1237: $is_custom{$item} = 1;
1238: }
1239: }
1240: foreach my $item (@bgs) {
1241: if ($designhash{$dom.'.login.'.$item} ne '') {
1242: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1243: $is_custom{$item} = 1;
1244: }
1245: }
1246: foreach my $item (@links) {
1247: if ($designhash{$dom.'.login.'.$item} ne '') {
1248: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1249: $is_custom{$item} = 1;
1250: }
1.6 raeburn 1251: }
1252: }
1.160.6.5 raeburn 1253: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1254: logo => 'Institution Logo',
1255: domlogo => 'Domain Logo',
1256: login => 'Login box');
1257: my $itemcount = 1;
1258: foreach my $item (@toggles) {
1259: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1260: $datatable .=
1261: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1262: '</td><td>'.
1263: '<span class="LC_nobreak"><label><input type="radio" name="'.
1264: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1265: '</label> <label><input type="radio" name="'.$item.'"'.
1266: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1267: '</tr>';
1268: $itemcount ++;
1.6 raeburn 1269: }
1.160.6.5 raeburn 1270: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1271: $datatable .= '</tr></table></td></tr>';
1272: } elsif ($caller eq 'help') {
1.160.6.113 raeburn 1273: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.160.6.5 raeburn 1274: my $itemcount = 1;
1275: $defaulturl = '/adm/loginproblems.html';
1276: $defaulttype = 'default';
1277: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1278: my @currlangs;
1279: if (ref($settings) eq 'HASH') {
1280: if (ref($settings->{'helpurl'}) eq 'HASH') {
1281: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1282: next if ($settings->{'helpurl'}{$key} eq '');
1283: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1284: $type{$key} = 'custom';
1285: unless ($key eq 'nolang') {
1286: push(@currlangs,$key);
1287: }
1288: }
1289: } elsif ($settings->{'helpurl'} ne '') {
1290: $type{'nolang'} = 'custom';
1291: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1292: }
1293: }
1.160.6.5 raeburn 1294: foreach my $lang ('nolang',sort(@currlangs)) {
1295: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1296: $datatable .= '<tr'.$css_class.'>';
1297: if ($url{$lang} eq '') {
1298: $url{$lang} = $defaulturl;
1299: }
1300: if ($type{$lang} eq '') {
1301: $type{$lang} = $defaulttype;
1302: }
1303: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1304: if ($lang eq 'nolang') {
1305: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1306: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1307: } else {
1308: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1309: $langchoices{$lang},
1310: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1311: }
1312: $datatable .= '</span></td>'."\n".
1313: '<td class="LC_left_item">';
1314: if ($type{$lang} eq 'custom') {
1315: $datatable .= '<span class="LC_nobreak"><label>'.
1316: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1317: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1318: } else {
1319: $datatable .= $lt{'upl'};
1320: }
1321: $datatable .='<br />';
1322: if ($switchserver) {
1323: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1324: } else {
1325: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1326: }
1.160.6.5 raeburn 1327: $datatable .= '</td></tr>';
1328: $itemcount ++;
1.6 raeburn 1329: }
1.160.6.5 raeburn 1330: my @addlangs;
1331: foreach my $lang (sort(keys(%langchoices))) {
1332: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1333: push(@addlangs,$lang);
1334: }
1335: if (@addlangs > 0) {
1336: my %toadd;
1337: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1338: $toadd{''} = &mt('Select');
1339: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1340: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1341: &mt('Add log-in help page for a specific language:').' '.
1342: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1343: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1344: if ($switchserver) {
1345: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1346: } else {
1347: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1348: }
1.160.6.5 raeburn 1349: $datatable .= '</td></tr>';
1350: $itemcount ++;
1.6 raeburn 1351: }
1.160.6.5 raeburn 1352: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1353: } elsif ($caller eq 'headtag') {
1354: my %domservers = &Apache::lonnet::get_servers($dom);
1355: my $choice = $choices{'headtag'};
1356: $css_class = ' class="LC_odd_row"';
1357: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1358: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1359: '<th>'.$choices{'current'}.'</th>'.
1360: '<th>'.$choices{'action'}.'</th>'.
1361: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1362: my (%currurls,%currexempt);
1363: if (ref($settings) eq 'HASH') {
1364: if (ref($settings->{'headtag'}) eq 'HASH') {
1365: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1366: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1367: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1368: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1369: }
1370: }
1371: }
1372: }
1373: foreach my $lonhost (sort(keys(%domservers))) {
1374: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1375: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1376: if ($currurls{$lonhost}) {
1377: $datatable .= '<td class="LC_right_item"><a href="'.
1378: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1379: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1380: '">'.$lt{'curr'}.'</a></td>'.
1381: '<td><span class="LC_nobreak"><label>'.
1382: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1383: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1384: } else {
1385: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1386: }
1387: $datatable .='<br />';
1388: if ($switchserver) {
1389: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1390: } else {
1391: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1392: }
1.160.6.87 raeburn 1393: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56 raeburn 1394: }
1395: $datatable .= '</table></td></tr>';
1.160.6.113 raeburn 1396: } elsif ($caller eq 'saml') {
1397: my %domservers = &Apache::lonnet::get_servers($dom);
1398: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1399: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1400: '<th>'.$choices{'samllanding'}.'</th>'.
1401: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1402: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso,%styleon,%styleoff);
1403: foreach my $lonhost (keys(%domservers)) {
1404: $samlurl{$lonhost} = '/adm/sso';
1405: $styleon{$lonhost} = 'display:none';
1406: $styleoff{$lonhost} = '';
1407: }
1408: if (ref($settings->{'saml'}) eq 'HASH') {
1409: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1410: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1411: $saml{$lonhost} = 1;
1412: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1413: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1414: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1415: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1416: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1417: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1418: $styleon{$lonhost} = '';
1419: $styleoff{$lonhost} = 'display:none';
1420: } else {
1421: $styleon{$lonhost} = 'display:none';
1422: $styleoff{$lonhost} = '';
1423: }
1424: }
1425: }
1426: my $itemcount = 1;
1427: foreach my $lonhost (sort(keys(%domservers))) {
1428: my $samlon = ' ';
1429: my $samloff = ' checked="checked" ';
1430: if ($saml{$lonhost}) {
1431: $samlon = $samloff;
1432: $samloff = ' ';
1433: }
1434: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1435: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1436: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1437: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1438: &mt('No').'</label>'.(' 'x2).
1439: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1440: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1441: &mt('Yes').'</label></span></td>'.
1442: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1443: '<table><tr><th colspan="5" align="center">'.&mt('SSO').'</th><th align="center">'.
1444: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1445: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1446: '<th>'.&mt('Alt Text').'</th><th>'.&mt('URL').'</th>'.
1447: '<th>'.&mt('Tool Tip').'</th><th>'.&mt('Text').'</th></tr>'.
1448: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="8" value="'.
1449: $samltext{$lonhost}.'" /></td><td>';
1450: if ($samlimg{$lonhost}) {
1451: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1452: '<span class="LC_nobreak"><label>'.
1453: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1454: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1455: } else {
1456: $datatable .= $lt{'upl'};
1457: }
1458: $datatable .='<br />';
1459: if ($switchserver) {
1460: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1461: } else {
1462: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1463: }
1464: $datatable .= '</td>'.
1465: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="20" '.
1466: 'value="'.$samlalt{$lonhost}.'" /></td>'.
1467: '<td><input type="text" name="saml_url_'.$lonhost.'" size="8" '.
1468: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1469: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="15">'.
1470: $samltitle{$lonhost}.'</textarea></td>'.
1471: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="8" '.
1472: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1473: '</table></td>'.
1474: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1475: $itemcount ++;
1476: }
1477: $datatable .= '</table></td></tr>';
1.1 raeburn 1478: }
1.6 raeburn 1479: return $datatable;
1480: }
1481:
1482: sub login_choices {
1483: my %choices =
1484: &Apache::lonlocal::texthash (
1.116 bisitz 1485: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1486: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1487: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1488: disallowlogin => "Login page requests redirected",
1489: hostid => "Server",
1.128 raeburn 1490: server => "Redirect to:",
1491: serverpath => "Path",
1492: custompath => "Custom",
1493: exempt => "Exempt IP(s)",
1.110 raeburn 1494: directlogin => "No redirect",
1495: newuser => "Link to create a user account",
1496: img => "Header",
1497: logo => "Main Logo",
1498: domlogo => "Domain Logo",
1499: login => "Log-in Header",
1500: textcol => "Text color",
1501: bgcol => "Box color",
1502: bgs => "Background colors",
1503: links => "Link colors",
1504: font => "Font color",
1505: pgbg => "Header",
1506: mainbg => "Page",
1507: sidebg => "Login box",
1508: link => "Link",
1509: alink => "Active link",
1510: vlink => "Visited link",
1.160.6.56 raeburn 1511: headtag => "Custom markup",
1512: action => "Action",
1513: current => "Current",
1.160.6.113 raeburn 1514: samllanding => "Dual login?",
1515: samloptions => "Options",
1.6 raeburn 1516: );
1517: return %choices;
1518: }
1519:
1.160.6.113 raeburn 1520: sub login_file_options {
1521: return &Apache::lonlocal::texthash(
1522: del => 'Delete?',
1523: rep => 'Replace:',
1524: upl => 'Upload:',
1525: curr => 'View contents',
1526: default => 'Default',
1527: custom => 'Custom',
1528: none => 'None',
1529: );
1530: }
1531:
1532: sub print_ipaccess {
1533: my ($dom,$settings,$rowtotal) = @_;
1534: my $css_class;
1535: my $itemcount = 0;
1536: my $datatable;
1537: my %ordered;
1538: if (ref($settings) eq 'HASH') {
1539: foreach my $item (keys(%{$settings})) {
1540: if (ref($settings->{$item}) eq 'HASH') {
1541: my $num = $settings->{$item}{'order'};
1542: if ($num eq '') {
1543: $num = scalar(keys(%{$settings}));
1544: }
1545: $ordered{$num} = $item;
1546: }
1547: }
1548: }
1549: my $maxnum = scalar(keys(%ordered));
1550: if (keys(%ordered)) {
1551: my @items = sort { $a <=> $b } keys(%ordered);
1552: for (my $i=0; $i<@items; $i++) {
1553: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1554: my $item = $ordered{$items[$i]};
1555: my ($name,$ipranges,%commblocks,%courses);
1556: if (ref($settings->{$item}) eq 'HASH') {
1557: $name = $settings->{$item}->{'name'};
1558: $ipranges = $settings->{$item}->{'ip'};
1559: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1560: %commblocks = %{$settings->{$item}->{'commblocks'}};
1561: }
1562: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1563: %courses = %{$settings->{$item}->{'courses'}};
1564: }
1565: }
1566: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1567: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1568: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1569: for (my $k=0; $k<=$maxnum; $k++) {
1570: my $vpos = $k+1;
1571: my $selstr;
1572: if ($k == $i) {
1573: $selstr = ' selected="selected" ';
1574: }
1575: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1576: }
1577: $datatable .= '</select>'.(' 'x2).
1578: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1579: &mt('Delete?').'</label></span></td>'.
1580: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1581: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1582: '</td></tr>';
1583: $itemcount ++;
1584: }
1585: }
1586: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1587: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1588: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1589: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1590: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1591: for (my $k=0; $k<$maxnum+1; $k++) {
1592: my $vpos = $k+1;
1593: my $selstr;
1594: if ($k == $maxnum) {
1595: $selstr = ' selected="selected" ';
1596: }
1597: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1598: }
1599: $datatable .= '</select> '."\n".
1600: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1601: '<td colspan="2">'.
1602: &ipaccess_options('add',$itemcount,$dom).
1603: '</td>'."\n".
1604: '</tr>'."\n";
1605: $$rowtotal ++;
1606: return $datatable;
1607: }
1608:
1609: sub ipaccess_options {
1610: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1611: my (%currblocks,%currcourses,$output);
1612: if (ref($blocksref) eq 'HASH') {
1613: %currblocks = %{$blocksref};
1614: }
1615: if (ref($coursesref) eq 'HASH') {
1616: %currcourses = %{$coursesref};
1617: }
1618: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1619: '<span class="LC_nobreak">'.&mt('Name').': '.
1620: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1621: '</span></fieldset>'.
1622: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1623: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1624: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1625: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1626: $ipranges.'</textarea></fieldset>'.
1627: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1628: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1629: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1630: '<table>';
1631: foreach my $cid (sort(keys(%currcourses))) {
1632: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1633: $output .= '<tr><td><span class="LC_nobreak">'.
1634: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1635: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1636: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1637: }
1638: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1639: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1640: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1641: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1642: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1643: '</span></td></tr></table>'."\n".
1644: '</fieldset>';
1645: return $output;
1646: }
1647:
1648: sub blocker_checkboxes {
1649: my ($num,$blocks) = @_;
1650: my ($typeorder,$types) = &commblocktype_text();
1651: my $numinrow = 6;
1652: my $output = '<table>';
1653: for (my $i=0; $i<@{$typeorder}; $i++) {
1654: my $block = $typeorder->[$i];
1655: my $blockstatus;
1656: if (ref($blocks) eq 'HASH') {
1657: if ($blocks->{$block} eq 'on') {
1658: $blockstatus = 'checked="checked"';
1659: }
1660: }
1661: my $rem = $i%($numinrow);
1662: if ($rem == 0) {
1663: if ($i > 0) {
1664: $output .= '</tr>';
1665: }
1666: $output .= '<tr>';
1667: }
1668: if ($i == scalar(@{$typeorder})-1) {
1669: my $colsleft = $numinrow-$rem;
1670: if ($colsleft > 1) {
1671: $output .= '<td colspan="'.$colsleft.'">';
1672: } else {
1673: $output .= '<td>';
1674: }
1675: } else {
1676: $output .= '<td>';
1677: }
1678: my $item = 'ipaccess_block_'.$num;
1679: if ($blockstatus) {
1680: $blockstatus = ' '.$blockstatus;
1681: }
1682: $output .= '<span class="LC_nobreak"><label>'."\n".
1683: '<input type="checkbox" name="'.$item.'"'.
1684: $blockstatus.' value="'.$block.'"'.' />'.
1685: $types->{$block}.'</label></span>'."\n".
1686: '<br /></td>';
1687: }
1688: $output .= '</tr></table>';
1689: return $output;
1690: }
1691:
1692: sub commblocktype_text {
1693: my %types = &Apache::lonlocal::texthash(
1694: 'com' => 'Messaging',
1695: 'chat' => 'Chat Room',
1696: 'boards' => 'Discussion',
1697: 'port' => 'Portfolio',
1698: 'groups' => 'Groups',
1699: 'blogs' => 'Blogs',
1700: 'about' => 'User Information',
1701: 'printout' => 'Printouts',
1702: 'passwd' => 'Change Password',
1703: 'grades' => 'Gradebook',
1704: );
1705: my $typeorder = ['com','chat','boards','port','groups','blogs','about','printout','grades','passwd'];
1706: return ($typeorder,\%types);
1707: }
1708:
1.6 raeburn 1709: sub print_rolecolors {
1.30 raeburn 1710: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1711: my %choices = &color_font_choices();
1712: my @bgs = ('pgbg','tabbg','sidebg');
1713: my @links = ('link','alink','vlink');
1714: my @images = ('img');
1715: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1716: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1717: my %defaultdesign = %Apache::loncommon::defaultdesign;
1718: my (%is_custom,%designs);
1.160.6.22 raeburn 1719: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1720: if (ref($settings) eq 'HASH') {
1721: if (ref($settings->{$role}) eq 'HASH') {
1722: if ($settings->{$role}->{'img'} ne '') {
1723: $designs{'img'} = $settings->{$role}->{'img'};
1724: $is_custom{'img'} = 1;
1725: }
1726: if ($settings->{$role}->{'font'} ne '') {
1727: $designs{'font'} = $settings->{$role}->{'font'};
1728: $is_custom{'font'} = 1;
1729: }
1.97 tempelho 1730: if ($settings->{$role}->{'fontmenu'} ne '') {
1731: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1732: $is_custom{'fontmenu'} = 1;
1733: }
1.6 raeburn 1734: foreach my $item (@bgs) {
1735: if ($settings->{$role}->{$item} ne '') {
1736: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1737: $is_custom{$item} = 1;
1738: }
1739: }
1740: foreach my $item (@links) {
1741: if ($settings->{$role}->{$item} ne '') {
1742: $designs{'links'}{$item} = $settings->{$role}->{$item};
1743: $is_custom{$item} = 1;
1744: }
1745: }
1746: }
1747: } else {
1748: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1749: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1750: $is_custom{'img'} = 1;
1751: }
1.97 tempelho 1752: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1753: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1754: $is_custom{'fontmenu'} = 1;
1755: }
1.6 raeburn 1756: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1757: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1758: $is_custom{'font'} = 1;
1759: }
1760: foreach my $item (@bgs) {
1761: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1762: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1763: $is_custom{$item} = 1;
1764:
1765: }
1766: }
1767: foreach my $item (@links) {
1768: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1769: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1770: $is_custom{$item} = 1;
1771: }
1772: }
1773: }
1774: my $itemcount = 1;
1.30 raeburn 1775: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1776: $datatable .= '</tr></table></td></tr>';
1777: return $datatable;
1778: }
1779:
1.160.6.22 raeburn 1780: sub role_defaults {
1781: my ($role,$bgs,$links,$images,$logintext) = @_;
1782: my %defaults;
1783: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1784: return %defaults;
1785: }
1786: my %defaultdesign = %Apache::loncommon::defaultdesign;
1787: if ($role eq 'login') {
1788: %defaults = (
1789: font => $defaultdesign{$role.'.font'},
1790: );
1791: if (ref($logintext) eq 'ARRAY') {
1792: foreach my $item (@{$logintext}) {
1793: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1794: }
1795: }
1796: foreach my $item (@{$images}) {
1797: $defaults{'showlogo'}{$item} = 1;
1798: }
1799: } else {
1800: %defaults = (
1801: img => $defaultdesign{$role.'.img'},
1802: font => $defaultdesign{$role.'.font'},
1803: fontmenu => $defaultdesign{$role.'.fontmenu'},
1804: );
1805: }
1806: foreach my $item (@{$bgs}) {
1807: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1808: }
1809: foreach my $item (@{$links}) {
1810: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1811: }
1812: foreach my $item (@{$images}) {
1813: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1814: }
1815: return %defaults;
1816: }
1817:
1.6 raeburn 1818: sub display_color_options {
1.9 raeburn 1819: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1820: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1821: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1822: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1823: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1824: '<td>'.$choices->{'font'}.'</td>';
1825: if (!$is_custom->{'font'}) {
1.160.6.87 raeburn 1826: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1827: } else {
1828: $datatable .= '<td> </td>';
1829: }
1.160.6.9 raeburn 1830: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1831:
1.8 raeburn 1832: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1833: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1834: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1835: ' </span></td></tr>';
1.107 raeburn 1836: unless ($role eq 'login') {
1837: $datatable .= '<tr'.$css_class.'>'.
1838: '<td>'.$choices->{'fontmenu'}.'</td>';
1839: if (!$is_custom->{'fontmenu'}) {
1.160.6.87 raeburn 1840: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1841: } else {
1842: $datatable .= '<td> </td>';
1843: }
1.160.6.22 raeburn 1844: $current_color = $designs->{'fontmenu'} ?
1845: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1846: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1847: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1848: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1849: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1850: ' </span></td></tr>';
1.97 tempelho 1851: }
1.9 raeburn 1852: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1853: foreach my $img (@{$images}) {
1.18 albertel 1854: $itemcount ++;
1.6 raeburn 1855: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1856: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1857: '<td>'.$choices->{$img};
1.41 raeburn 1858: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1859: if ($role eq 'login') {
1860: if ($img eq 'login') {
1861: $login_hdr_pick =
1.135 bisitz 1862: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1863: $logincolors =
1864: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1865: $designs,$defaults);
1.70 raeburn 1866: } elsif ($img ne 'domlogo') {
1867: $datatable.= &logo_display_options($img,$defaults,$designs);
1868: }
1869: }
1870: $datatable .= '</td>';
1.6 raeburn 1871: if ($designs->{$img} ne '') {
1872: $imgfile = $designs->{$img};
1.18 albertel 1873: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1874: } else {
1875: $imgfile = $defaults->{$img};
1876: }
1877: if ($imgfile) {
1.9 raeburn 1878: my ($showfile,$fullsize);
1879: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1880: my $urldir = $1;
1881: my $filename = $2;
1882: my @info = &Apache::lonnet::stat_file($designs->{$img});
1883: if (@info) {
1884: my $thumbfile = 'tn-'.$filename;
1885: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1886: if (@thumb) {
1887: $showfile = $urldir.'/'.$thumbfile;
1888: } else {
1889: $showfile = $imgfile;
1890: }
1891: } else {
1892: $showfile = '';
1893: }
1894: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1895: $showfile = $imgfile;
1.6 raeburn 1896: my $imgdir = $1;
1897: my $filename = $2;
1.159 raeburn 1898: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1899: $showfile = "/$imgdir/tn-".$filename;
1900: } else {
1.159 raeburn 1901: my $input = $londocroot.$imgfile;
1902: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1903: if (!-e $output) {
1.9 raeburn 1904: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1905: my ($fullwidth,$fullheight) = &check_dimensions($input);
1906: if ($fullwidth ne '' && $fullheight ne '') {
1907: if ($fullwidth > $width && $fullheight > $height) {
1908: my $size = $width.'x'.$height;
1.160.6.88 raeburn 1909: my @args = ('convert','-sample',$size,$input,$output);
1910: system({$args[0]} @args);
1.159 raeburn 1911: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1912: }
1913: }
1.6 raeburn 1914: }
1915: }
1.16 raeburn 1916: }
1.6 raeburn 1917: if ($showfile) {
1.40 raeburn 1918: if ($showfile =~ m{^/(adm|res)/}) {
1919: if ($showfile =~ m{^/res/}) {
1920: my $local_showfile =
1921: &Apache::lonnet::filelocation('',$showfile);
1922: &Apache::lonnet::repcopy($local_showfile);
1923: }
1924: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1925: }
1926: if ($imgfile) {
1927: if ($imgfile =~ m{^/(adm|res)/}) {
1928: if ($imgfile =~ m{^/res/}) {
1929: my $local_imgfile =
1930: &Apache::lonnet::filelocation('',$imgfile);
1931: &Apache::lonnet::repcopy($local_imgfile);
1932: }
1933: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1934: } else {
1935: $fullsize = $imgfile;
1936: }
1937: }
1.41 raeburn 1938: $datatable .= '<td>';
1939: if ($img eq 'login') {
1.135 bisitz 1940: $datatable .= $login_hdr_pick;
1941: }
1.41 raeburn 1942: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1943: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1944: } else {
1.160.6.22 raeburn 1945: $datatable .= '<td> </td><td class="LC_left_item">'.
1946: &mt('Upload:').'<br />';
1.6 raeburn 1947: }
1948: } else {
1.160.6.22 raeburn 1949: $datatable .= '<td> </td><td class="LC_left_item">'.
1950: &mt('Upload:').'<br />';
1.6 raeburn 1951: }
1.9 raeburn 1952: if ($switchserver) {
1953: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1954: } else {
1.135 bisitz 1955: if ($img ne 'login') { # suppress file selection for Log-in header
1956: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1957: }
1.9 raeburn 1958: }
1959: $datatable .= '</td></tr>';
1.6 raeburn 1960: }
1961: $itemcount ++;
1962: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1963: $datatable .= '<tr'.$css_class.'>'.
1964: '<td>'.$choices->{'bgs'}.'</td>';
1965: my $bgs_def;
1966: foreach my $item (@{$bgs}) {
1967: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1968: $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 1969: }
1970: }
1971: if ($bgs_def) {
1.8 raeburn 1972: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1973: } else {
1974: $datatable .= '<td> </td>';
1975: }
1976: $datatable .= '<td class="LC_right_item">'.
1977: '<table border="0"><tr>';
1.160.6.13 raeburn 1978:
1.6 raeburn 1979: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1980: $datatable .= '<td align="center">'.$choices->{$item};
1981: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1982: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1983: $datatable .= ' ';
1.6 raeburn 1984: }
1.160.6.9 raeburn 1985: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1986: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1987: }
1988: $datatable .= '</tr></table></td></tr>';
1989: $itemcount ++;
1990: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1991: $datatable .= '<tr'.$css_class.'>'.
1992: '<td>'.$choices->{'links'}.'</td>';
1993: my $links_def;
1994: foreach my $item (@{$links}) {
1995: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1996: $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 1997: }
1998: }
1999: if ($links_def) {
1.8 raeburn 2000: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2001: } else {
2002: $datatable .= '<td> </td>';
2003: }
2004: $datatable .= '<td class="LC_right_item">'.
2005: '<table border="0"><tr>';
2006: foreach my $item (@{$links}) {
1.160.6.39 raeburn 2007: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 2008: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 2009: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 2010: $datatable.=' ';
1.6 raeburn 2011: }
1.160.6.9 raeburn 2012: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2013: '" /></td>';
2014: }
1.30 raeburn 2015: $$rowtotal += $itemcount;
1.3 raeburn 2016: return $datatable;
2017: }
2018:
1.70 raeburn 2019: sub logo_display_options {
2020: my ($img,$defaults,$designs) = @_;
2021: my $checkedon;
2022: if (ref($defaults) eq 'HASH') {
2023: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2024: if ($defaults->{'showlogo'}{$img}) {
2025: $checkedon = 'checked="checked" ';
2026: }
2027: }
2028: }
2029: if (ref($designs) eq 'HASH') {
2030: if (ref($designs->{'showlogo'}) eq 'HASH') {
2031: if (defined($designs->{'showlogo'}{$img})) {
2032: if ($designs->{'showlogo'}{$img} == 0) {
2033: $checkedon = '';
2034: } elsif ($designs->{'showlogo'}{$img} == 1) {
2035: $checkedon = 'checked="checked" ';
2036: }
2037: }
2038: }
2039: }
2040: return '<br /><label> <input type="checkbox" name="'.
2041: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2042: &mt('show').'</label>'."\n";
2043: }
2044:
1.41 raeburn 2045: sub login_header_options {
1.135 bisitz 2046: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2047: my $output = '';
1.41 raeburn 2048: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2049: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2050: if (!$is_custom->{'textcol'}) {
2051: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2052: ' ';
2053: }
2054: if (!$is_custom->{'bgcol'}) {
2055: $output .= $choices->{'bgcol'}.': '.
2056: '<span id="css_'.$role.'_font" style="background-color: '.
2057: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2058: }
2059: $output .= '<br />';
2060: }
2061: $output .='<br />';
2062: return $output;
2063: }
2064:
2065: sub login_text_colors {
1.160.6.22 raeburn 2066: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2067: my $color_menu = '<table border="0"><tr>';
2068: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 2069: $color_menu .= '<td align="center">'.$choices->{$item};
2070: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2071: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2072: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2073: }
2074: $color_menu .= '</tr></table><br />';
2075: return $color_menu;
2076: }
2077:
2078: sub image_changes {
2079: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2080: my $output;
1.135 bisitz 2081: if ($img eq 'login') {
1.160.6.87 raeburn 2082: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2083: } elsif (!$is_custom) {
1.70 raeburn 2084: if ($img ne 'domlogo') {
1.160.6.87 raeburn 2085: $output = &mt('Default image:').'<br />';
1.41 raeburn 2086: } else {
1.160.6.87 raeburn 2087: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2088: }
2089: }
1.160.6.87 raeburn 2090: if ($img ne 'login') {
1.135 bisitz 2091: if ($img_import) {
2092: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2093: }
2094: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2095: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2096: if ($is_custom) {
2097: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2098: '<input type="checkbox" name="'.
2099: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2100: '</label> '.&mt('Replace:').'</span><br />';
2101: } else {
1.160.6.22 raeburn 2102: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2103: }
1.41 raeburn 2104: }
2105: return $output;
2106: }
2107:
1.3 raeburn 2108: sub print_quotas {
1.86 raeburn 2109: my ($dom,$settings,$rowtotal,$action) = @_;
2110: my $context;
2111: if ($action eq 'quotas') {
2112: $context = 'tools';
2113: } else {
2114: $context = $action;
2115: }
1.160.6.20 raeburn 2116: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2117: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2118: my $typecount = 0;
1.101 raeburn 2119: my ($css_class,%titles);
1.86 raeburn 2120: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 2121: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 2122: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2123: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2124: %titles = &courserequest_titles();
1.160.6.5 raeburn 2125: } elsif ($context eq 'requestauthor') {
2126: @usertools = ('author');
2127: @options = ('norequest','approval','automatic');
2128: %titles = &authorrequest_titles();
1.86 raeburn 2129: } else {
1.160.6.4 raeburn 2130: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 2131: %titles = &tool_titles();
1.86 raeburn 2132: }
1.26 raeburn 2133: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2134: foreach my $type (@{$types}) {
1.160.6.20 raeburn 2135: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 2136: unless (($context eq 'requestcourses') ||
2137: ($context eq 'requestauthor')) {
1.86 raeburn 2138: if (ref($settings) eq 'HASH') {
2139: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 2140: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2141: } else {
2142: $currdefquota = $settings->{$type};
2143: }
1.160.6.20 raeburn 2144: if (ref($settings->{authorquota}) eq 'HASH') {
2145: $currauthorquota = $settings->{authorquota}->{$type};
2146: }
1.78 raeburn 2147: }
1.72 raeburn 2148: }
1.3 raeburn 2149: if (defined($usertypes->{$type})) {
2150: $typecount ++;
2151: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2152: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2153: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2154: '<td class="LC_left_item">';
1.101 raeburn 2155: if ($context eq 'requestcourses') {
2156: $datatable .= '<table><tr>';
2157: }
2158: my %cell;
1.72 raeburn 2159: foreach my $item (@usertools) {
1.101 raeburn 2160: if ($context eq 'requestcourses') {
2161: my ($curroption,$currlimit);
2162: if (ref($settings) eq 'HASH') {
2163: if (ref($settings->{$item}) eq 'HASH') {
2164: $curroption = $settings->{$item}->{$type};
2165: if ($curroption =~ /^autolimit=(\d*)$/) {
2166: $currlimit = $1;
2167: }
2168: }
2169: }
2170: if (!$curroption) {
2171: $curroption = 'norequest';
2172: }
2173: $datatable .= '<th>'.$titles{$item}.'</th>';
2174: foreach my $option (@options) {
2175: my $val = $option;
2176: if ($option eq 'norequest') {
2177: $val = 0;
2178: }
2179: if ($option eq 'validate') {
2180: my $canvalidate = 0;
2181: if (ref($validations{$item}) eq 'HASH') {
2182: if ($validations{$item}{$type}) {
2183: $canvalidate = 1;
2184: }
2185: }
2186: next if (!$canvalidate);
2187: }
2188: my $checked = '';
2189: if ($option eq $curroption) {
2190: $checked = ' checked="checked"';
2191: } elsif ($option eq 'autolimit') {
2192: if ($curroption =~ /^autolimit/) {
2193: $checked = ' checked="checked"';
2194: }
2195: }
2196: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2197: '<input type="radio" name="crsreq_'.$item.
2198: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2199: $titles{$option}.'</label>';
1.101 raeburn 2200: if ($option eq 'autolimit') {
1.127 raeburn 2201: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2202: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2203: 'value="'.$currlimit.'" />';
1.101 raeburn 2204: }
1.127 raeburn 2205: $cell{$item} .= '</span> ';
1.103 raeburn 2206: if ($option eq 'autolimit') {
1.127 raeburn 2207: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2208: }
1.101 raeburn 2209: }
1.160.6.5 raeburn 2210: } elsif ($context eq 'requestauthor') {
2211: my $curroption;
2212: if (ref($settings) eq 'HASH') {
2213: $curroption = $settings->{$type};
2214: }
2215: if (!$curroption) {
2216: $curroption = 'norequest';
2217: }
2218: foreach my $option (@options) {
2219: my $val = $option;
2220: if ($option eq 'norequest') {
2221: $val = 0;
2222: }
2223: my $checked = '';
2224: if ($option eq $curroption) {
2225: $checked = ' checked="checked"';
2226: }
2227: $datatable .= '<span class="LC_nobreak"><label>'.
2228: '<input type="radio" name="authorreq_'.$type.
2229: '" value="'.$val.'"'.$checked.' />'.
2230: $titles{$option}.'</label></span> ';
2231: }
1.101 raeburn 2232: } else {
2233: my $checked = 'checked="checked" ';
2234: if (ref($settings) eq 'HASH') {
2235: if (ref($settings->{$item}) eq 'HASH') {
2236: if ($settings->{$item}->{$type} == 0) {
2237: $checked = '';
2238: } elsif ($settings->{$item}->{$type} == 1) {
2239: $checked = 'checked="checked" ';
2240: }
1.78 raeburn 2241: }
1.72 raeburn 2242: }
1.101 raeburn 2243: $datatable .= '<span class="LC_nobreak"><label>'.
2244: '<input type="checkbox" name="'.$context.'_'.$item.
2245: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2246: '</label></span> ';
1.72 raeburn 2247: }
1.101 raeburn 2248: }
2249: if ($context eq 'requestcourses') {
2250: $datatable .= '</tr><tr>';
2251: foreach my $item (@usertools) {
1.106 raeburn 2252: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2253: }
2254: $datatable .= '</tr></table>';
1.72 raeburn 2255: }
1.86 raeburn 2256: $datatable .= '</td>';
1.160.6.5 raeburn 2257: unless (($context eq 'requestcourses') ||
2258: ($context eq 'requestauthor')) {
1.86 raeburn 2259: $datatable .=
1.160.6.20 raeburn 2260: '<td class="LC_right_item">'.
2261: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2262: '<input type="text" name="quota_'.$type.
1.72 raeburn 2263: '" value="'.$currdefquota.
1.160.6.20 raeburn 2264: '" size="5" /></span>'.(' ' x 2).
2265: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2266: '<input type="text" name="authorquota_'.$type.
2267: '" value="'.$currauthorquota.
2268: '" size="5" /></span></td>';
1.86 raeburn 2269: }
2270: $datatable .= '</tr>';
1.3 raeburn 2271: }
2272: }
2273: }
1.160.6.5 raeburn 2274: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2275: $defaultquota = '20';
1.160.6.20 raeburn 2276: $authorquota = '500';
1.86 raeburn 2277: if (ref($settings) eq 'HASH') {
2278: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2279: $defaultquota = $settings->{'defaultquota'}->{'default'};
2280: } elsif (defined($settings->{'default'})) {
2281: $defaultquota = $settings->{'default'};
2282: }
1.160.6.20 raeburn 2283: if (ref($settings->{'authorquota'}) eq 'HASH') {
2284: $authorquota = $settings->{'authorquota'}->{'default'};
2285: }
1.3 raeburn 2286: }
2287: }
2288: $typecount ++;
2289: $css_class = $typecount%2?' class="LC_odd_row"':'';
2290: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2291: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2292: '<td class="LC_left_item">';
1.101 raeburn 2293: if ($context eq 'requestcourses') {
2294: $datatable .= '<table><tr>';
2295: }
2296: my %defcell;
1.72 raeburn 2297: foreach my $item (@usertools) {
1.101 raeburn 2298: if ($context eq 'requestcourses') {
2299: my ($curroption,$currlimit);
2300: if (ref($settings) eq 'HASH') {
2301: if (ref($settings->{$item}) eq 'HASH') {
2302: $curroption = $settings->{$item}->{'default'};
2303: if ($curroption =~ /^autolimit=(\d*)$/) {
2304: $currlimit = $1;
2305: }
2306: }
2307: }
2308: if (!$curroption) {
2309: $curroption = 'norequest';
2310: }
2311: $datatable .= '<th>'.$titles{$item}.'</th>';
2312: foreach my $option (@options) {
2313: my $val = $option;
2314: if ($option eq 'norequest') {
2315: $val = 0;
2316: }
2317: if ($option eq 'validate') {
2318: my $canvalidate = 0;
2319: if (ref($validations{$item}) eq 'HASH') {
2320: if ($validations{$item}{'default'}) {
2321: $canvalidate = 1;
2322: }
2323: }
2324: next if (!$canvalidate);
2325: }
2326: my $checked = '';
2327: if ($option eq $curroption) {
2328: $checked = ' checked="checked"';
2329: } elsif ($option eq 'autolimit') {
2330: if ($curroption =~ /^autolimit/) {
2331: $checked = ' checked="checked"';
2332: }
2333: }
2334: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2335: '<input type="radio" name="crsreq_'.$item.
2336: '_default" value="'.$val.'"'.$checked.' />'.
2337: $titles{$option}.'</label>';
2338: if ($option eq 'autolimit') {
1.127 raeburn 2339: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2340: $item.'_limit_default" size="1" '.
2341: 'value="'.$currlimit.'" />';
2342: }
1.127 raeburn 2343: $defcell{$item} .= '</span> ';
1.104 raeburn 2344: if ($option eq 'autolimit') {
1.127 raeburn 2345: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2346: }
1.101 raeburn 2347: }
1.160.6.5 raeburn 2348: } elsif ($context eq 'requestauthor') {
2349: my $curroption;
2350: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 2351: $curroption = $settings->{'default'};
1.160.6.5 raeburn 2352: }
2353: if (!$curroption) {
2354: $curroption = 'norequest';
2355: }
2356: foreach my $option (@options) {
2357: my $val = $option;
2358: if ($option eq 'norequest') {
2359: $val = 0;
2360: }
2361: my $checked = '';
2362: if ($option eq $curroption) {
2363: $checked = ' checked="checked"';
2364: }
2365: $datatable .= '<span class="LC_nobreak"><label>'.
2366: '<input type="radio" name="authorreq_default"'.
2367: ' value="'.$val.'"'.$checked.' />'.
2368: $titles{$option}.'</label></span> ';
2369: }
1.101 raeburn 2370: } else {
2371: my $checked = 'checked="checked" ';
2372: if (ref($settings) eq 'HASH') {
2373: if (ref($settings->{$item}) eq 'HASH') {
2374: if ($settings->{$item}->{'default'} == 0) {
2375: $checked = '';
2376: } elsif ($settings->{$item}->{'default'} == 1) {
2377: $checked = 'checked="checked" ';
2378: }
1.78 raeburn 2379: }
1.72 raeburn 2380: }
1.101 raeburn 2381: $datatable .= '<span class="LC_nobreak"><label>'.
2382: '<input type="checkbox" name="'.$context.'_'.$item.
2383: '" value="default" '.$checked.'/>'.$titles{$item}.
2384: '</label></span> ';
2385: }
2386: }
2387: if ($context eq 'requestcourses') {
2388: $datatable .= '</tr><tr>';
2389: foreach my $item (@usertools) {
1.106 raeburn 2390: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2391: }
1.101 raeburn 2392: $datatable .= '</tr></table>';
1.72 raeburn 2393: }
1.86 raeburn 2394: $datatable .= '</td>';
1.160.6.5 raeburn 2395: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2396: $datatable .= '<td class="LC_right_item">'.
2397: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2398: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2399: $defaultquota.'" size="5" /></span>'.(' ' x2).
2400: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2401: '<input type="text" name="authorquota" value="'.
2402: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2403: }
2404: $datatable .= '</tr>';
1.72 raeburn 2405: $typecount ++;
2406: $css_class = $typecount%2?' class="LC_odd_row"':'';
2407: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2408: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2409: if ($context eq 'requestcourses') {
1.109 raeburn 2410: $datatable .= &mt('(overrides affiliation, if set)').
2411: '</td>'.
2412: '<td class="LC_left_item">'.
2413: '<table><tr>';
1.101 raeburn 2414: } else {
1.109 raeburn 2415: $datatable .= &mt('(overrides affiliation, if checked)').
2416: '</td>'.
2417: '<td class="LC_left_item" colspan="2">'.
2418: '<br />';
1.101 raeburn 2419: }
2420: my %advcell;
1.72 raeburn 2421: foreach my $item (@usertools) {
1.101 raeburn 2422: if ($context eq 'requestcourses') {
2423: my ($curroption,$currlimit);
2424: if (ref($settings) eq 'HASH') {
2425: if (ref($settings->{$item}) eq 'HASH') {
2426: $curroption = $settings->{$item}->{'_LC_adv'};
2427: if ($curroption =~ /^autolimit=(\d*)$/) {
2428: $currlimit = $1;
2429: }
2430: }
2431: }
2432: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2433: my $checked = '';
2434: if ($curroption eq '') {
2435: $checked = ' checked="checked"';
2436: }
2437: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2438: '<input type="radio" name="crsreq_'.$item.
2439: '__LC_adv" value=""'.$checked.' />'.
2440: &mt('No override set').'</label></span> ';
1.101 raeburn 2441: foreach my $option (@options) {
2442: my $val = $option;
2443: if ($option eq 'norequest') {
2444: $val = 0;
2445: }
2446: if ($option eq 'validate') {
2447: my $canvalidate = 0;
2448: if (ref($validations{$item}) eq 'HASH') {
2449: if ($validations{$item}{'_LC_adv'}) {
2450: $canvalidate = 1;
2451: }
2452: }
2453: next if (!$canvalidate);
2454: }
2455: my $checked = '';
1.104 raeburn 2456: if ($val eq $curroption) {
1.101 raeburn 2457: $checked = ' checked="checked"';
2458: } elsif ($option eq 'autolimit') {
2459: if ($curroption =~ /^autolimit/) {
2460: $checked = ' checked="checked"';
2461: }
2462: }
2463: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2464: '<input type="radio" name="crsreq_'.$item.
2465: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2466: $titles{$option}.'</label>';
2467: if ($option eq 'autolimit') {
1.127 raeburn 2468: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2469: $item.'_limit__LC_adv" size="1" '.
2470: 'value="'.$currlimit.'" />';
2471: }
1.127 raeburn 2472: $advcell{$item} .= '</span> ';
1.104 raeburn 2473: if ($option eq 'autolimit') {
1.127 raeburn 2474: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2475: }
1.101 raeburn 2476: }
1.160.6.5 raeburn 2477: } elsif ($context eq 'requestauthor') {
2478: my $curroption;
2479: if (ref($settings) eq 'HASH') {
2480: $curroption = $settings->{'_LC_adv'};
2481: }
2482: my $checked = '';
2483: if ($curroption eq '') {
2484: $checked = ' checked="checked"';
2485: }
2486: $datatable .= '<span class="LC_nobreak"><label>'.
2487: '<input type="radio" name="authorreq__LC_adv"'.
2488: ' value=""'.$checked.' />'.
2489: &mt('No override set').'</label></span> ';
2490: foreach my $option (@options) {
2491: my $val = $option;
2492: if ($option eq 'norequest') {
2493: $val = 0;
2494: }
2495: my $checked = '';
2496: if ($val eq $curroption) {
2497: $checked = ' checked="checked"';
2498: }
2499: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2500: '<input type="radio" name="authorreq__LC_adv"'.
2501: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2502: $titles{$option}.'</label></span> ';
2503: }
1.101 raeburn 2504: } else {
2505: my $checked = 'checked="checked" ';
2506: if (ref($settings) eq 'HASH') {
2507: if (ref($settings->{$item}) eq 'HASH') {
2508: if ($settings->{$item}->{'_LC_adv'} == 0) {
2509: $checked = '';
2510: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2511: $checked = 'checked="checked" ';
2512: }
1.79 raeburn 2513: }
1.72 raeburn 2514: }
1.101 raeburn 2515: $datatable .= '<span class="LC_nobreak"><label>'.
2516: '<input type="checkbox" name="'.$context.'_'.$item.
2517: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2518: '</label></span> ';
2519: }
2520: }
2521: if ($context eq 'requestcourses') {
2522: $datatable .= '</tr><tr>';
2523: foreach my $item (@usertools) {
1.106 raeburn 2524: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2525: }
1.101 raeburn 2526: $datatable .= '</tr></table>';
1.72 raeburn 2527: }
1.98 raeburn 2528: $datatable .= '</td></tr>';
1.30 raeburn 2529: $$rowtotal += $typecount;
1.3 raeburn 2530: return $datatable;
2531: }
2532:
1.160.6.5 raeburn 2533: sub print_requestmail {
1.160.6.93 raeburn 2534: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25 raeburn 2535: my ($now,$datatable,%currapp);
1.102 raeburn 2536: $now = time;
2537: if (ref($settings) eq 'HASH') {
2538: if (ref($settings->{'notify'}) eq 'HASH') {
2539: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2540: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2541: }
2542: }
2543: }
1.160.6.16 raeburn 2544: my $numinrow = 2;
1.160.6.34 raeburn 2545: my $css_class;
1.160.6.93 raeburn 2546: if ($$rowtotal%2) {
2547: $css_class = 'LC_odd_row';
2548: }
2549: if ($customcss) {
2550: $css_class .= " $customcss";
2551: }
2552: $css_class =~ s/^\s+//;
2553: if ($css_class) {
2554: $css_class = ' class="'.$css_class.'"';
2555: }
2556: if ($rowstyle) {
2557: $css_class .= ' style="'.$rowstyle.'"';
2558: }
1.160.6.5 raeburn 2559: my $text;
2560: if ($action eq 'requestcourses') {
2561: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2562: } elsif ($action eq 'requestauthor') {
2563: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2564: } else {
1.160.6.34 raeburn 2565: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2566: }
1.160.6.34 raeburn 2567: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2568: ' <td>'.$text.'</td>'.
1.102 raeburn 2569: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2570: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2571: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2572: if ($numdc > 0) {
2573: $datatable .= $table;
1.102 raeburn 2574: } else {
2575: $datatable .= &mt('There are no active Domain Coordinators');
2576: }
2577: $datatable .='</td></tr>';
2578: return $datatable;
2579: }
2580:
1.160.6.30 raeburn 2581: sub print_studentcode {
2582: my ($settings,$rowtotal) = @_;
2583: my $rownum = 0;
2584: my ($output,%current);
2585: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2586: if (ref($settings) eq 'HASH') {
2587: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2588: foreach my $type (@crstypes) {
2589: $current{$type} = $settings->{'uniquecode'}{$type};
2590: }
1.160.6.30 raeburn 2591: }
2592: }
2593: $output .= '<tr>'.
2594: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2595: '<td class="LC_left_item">';
2596: foreach my $type (@crstypes) {
2597: my $check = ' ';
2598: if ($current{$type}) {
2599: $check = ' checked="checked" ';
2600: }
2601: $output .= '<span class="LC_nobreak"><label>'.
2602: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2603: &mt($type).'</label></span>'.(' 'x2).' ';
2604: }
2605: $output .= '</td></tr>';
2606: $$rowtotal ++;
2607: return $output;
2608: }
2609:
2610: sub print_textbookcourses {
1.160.6.46 raeburn 2611: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2612: my $rownum = 0;
2613: my $css_class;
2614: my $itemcount = 1;
2615: my $maxnum = 0;
2616: my $bookshash;
2617: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2618: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2619: }
2620: my %ordered;
2621: if (ref($bookshash) eq 'HASH') {
2622: foreach my $item (keys(%{$bookshash})) {
2623: if (ref($bookshash->{$item}) eq 'HASH') {
2624: my $num = $bookshash->{$item}{'order'};
2625: $ordered{$num} = $item;
2626: }
2627: }
2628: }
2629: my $confname = $dom.'-domainconfig';
2630: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2631: my $maxnum = scalar(keys(%ordered));
2632: my $datatable;
1.160.6.30 raeburn 2633: if (keys(%ordered)) {
2634: my @items = sort { $a <=> $b } keys(%ordered);
2635: for (my $i=0; $i<@items; $i++) {
2636: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2637: my $key = $ordered{$items[$i]};
2638: my %coursehash=&Apache::lonnet::coursedescription($key);
2639: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2640: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2641: if (ref($bookshash->{$key}) eq 'HASH') {
2642: $subject = $bookshash->{$key}->{'subject'};
2643: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2644: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2645: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2646: $author = $bookshash->{$key}->{'author'};
2647: $image = $bookshash->{$key}->{'image'};
2648: if ($image ne '') {
2649: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2650: my $imagethumb = "$path/tn-".$imagefile;
2651: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2652: }
1.160.6.30 raeburn 2653: }
2654: }
1.160.6.46 raeburn 2655: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2656: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2657: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2658: for (my $k=0; $k<=$maxnum; $k++) {
2659: my $vpos = $k+1;
2660: my $selstr;
2661: if ($k == $i) {
2662: $selstr = ' selected="selected" ';
2663: }
2664: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2665: }
2666: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2667: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2668: &mt('Delete?').'</label></span></td>'.
2669: '<td colspan="2">'.
1.160.6.46 raeburn 2670: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2671: (' 'x2).
1.160.6.46 raeburn 2672: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2673: if ($type eq 'textbooks') {
2674: $datatable .= (' 'x2).
1.160.6.47 raeburn 2675: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2676: (' 'x2).
1.160.6.46 raeburn 2677: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2678: (' 'x2).
2679: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2680: if ($image) {
1.160.6.114! raeburn 2681: $datatable .= $imgsrc.
1.160.6.46 raeburn 2682: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2683: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2684: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2685: }
2686: if ($switchserver) {
2687: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2688: } else {
2689: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2690: }
1.160.6.30 raeburn 2691: }
1.160.6.46 raeburn 2692: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2693: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2694: $coursetitle.'</span></td></tr>'."\n";
2695: $itemcount ++;
2696: }
2697: }
2698: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2699: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2700: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2701: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2702: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2703: for (my $k=0; $k<$maxnum+1; $k++) {
2704: my $vpos = $k+1;
2705: my $selstr;
2706: if ($k == $maxnum) {
2707: $selstr = ' selected="selected" ';
2708: }
2709: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2710: }
2711: $datatable .= '</select> '."\n".
1.160.6.87 raeburn 2712: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2713: '<td colspan="2">'.
1.160.6.46 raeburn 2714: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2715: (' 'x2).
1.160.6.46 raeburn 2716: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2717: (' 'x2);
2718: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2719: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2720: (' 'x2).
2721: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2722: (' 'x2).
2723: '<span class="LC_nobreak">'.&mt('Image:').' ';
2724: if ($switchserver) {
2725: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2726: } else {
2727: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2728: }
1.160.6.87 raeburn 2729: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2730: }
1.160.6.87 raeburn 2731: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2732: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2733: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2734: &Apache::loncommon::selectcourse_link
1.160.6.87 raeburn 2735: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2736: '</span></td>'."\n".
2737: '</tr>'."\n";
2738: $itemcount ++;
2739: return $datatable;
2740: }
2741:
2742: sub textbookcourses_javascript {
1.160.6.46 raeburn 2743: my ($settings) = @_;
2744: return unless(ref($settings) eq 'HASH');
2745: my (%ordered,%total,%jstext);
2746: foreach my $type ('textbooks','templates') {
2747: $total{$type} = 0;
2748: if (ref($settings->{$type}) eq 'HASH') {
2749: foreach my $item (keys(%{$settings->{$type}})) {
2750: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2751: my $num = $settings->{$type}->{$item}{'order'};
2752: $ordered{$type}{$num} = $item;
2753: }
2754: }
2755: $total{$type} = scalar(keys(%{$settings->{$type}}));
2756: }
2757: my @jsarray = ();
2758: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2759: push(@jsarray,$ordered{$type}{$item});
2760: }
2761: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2762: }
2763: return <<"ENDSCRIPT";
2764: <script type="text/javascript">
2765: // <![CDATA[
1.160.6.46 raeburn 2766: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2767: var changedVal;
1.160.6.46 raeburn 2768: $jstext{'textbooks'};
2769: $jstext{'templates'};
2770: var newpos;
2771: var maxh;
2772: if (caller == 'textbooks') {
2773: newpos = 'textbooks_addbook_pos';
2774: maxh = 1 + $total{'textbooks'};
2775: } else {
2776: newpos = 'templates_addbook_pos';
2777: maxh = 1 + $total{'templates'};
2778: }
1.160.6.30 raeburn 2779: var current = new Array;
2780: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2781: if (item == newpos) {
2782: changedVal = newitemVal;
2783: } else {
2784: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2785: current[newitemVal] = newpos;
2786: }
1.160.6.46 raeburn 2787: if (caller == 'textbooks') {
2788: for (var i=0; i<textbooks.length; i++) {
2789: var elementName = 'textbooks_'+textbooks[i];
2790: if (elementName != item) {
2791: if (form.elements[elementName]) {
2792: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2793: current[currVal] = elementName;
2794: }
2795: }
2796: }
2797: }
2798: if (caller == 'templates') {
2799: for (var i=0; i<templates.length; i++) {
2800: var elementName = 'templates_'+templates[i];
2801: if (elementName != item) {
2802: if (form.elements[elementName]) {
2803: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2804: current[currVal] = elementName;
2805: }
1.160.6.30 raeburn 2806: }
2807: }
2808: }
2809: var oldVal;
2810: for (var j=0; j<maxh; j++) {
2811: if (current[j] == undefined) {
2812: oldVal = j;
2813: }
2814: }
2815: if (oldVal < changedVal) {
2816: for (var k=oldVal+1; k<=changedVal ; k++) {
2817: var elementName = current[k];
2818: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2819: }
2820: } else {
2821: for (var k=changedVal; k<oldVal; k++) {
2822: var elementName = current[k];
2823: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2824: }
2825: }
2826: return;
2827: }
2828:
2829: // ]]>
2830: </script>
2831:
2832: ENDSCRIPT
2833: }
2834:
1.160.6.113 raeburn 2835: sub wafproxy_javascript {
2836: my ($dom) = @_;
2837: return <<"ENDSCRIPT";
2838: <script type="text/javascript">
2839: // <![CDATA[
2840: function updateWAF() {
2841: if (document.getElementById('wafproxy_remoteip')) {
2842: var wafremote = 0;
2843: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
2844: wafremote = 1;
2845: }
2846: var fields = new Array('header','trust');
2847: for (var i=0; i<fields.length; i++) {
2848: if (document.getElementById('wafproxy_'+fields[i])) {
2849: if (wafremote == 1) {
2850: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
2851: }
2852: else {
2853: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
2854: }
2855: }
2856: }
2857: if (document.getElementById('wafproxyranges_$dom')) {
2858: if (wafremote == 1) {
2859: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
2860: } else {
2861: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
2862: if (document.display.wafproxy_vpnaccess[i].checked) {
2863: if (document.display.wafproxy_vpnaccess[i].value == 0) {
2864: document.getElementById('wafproxyranges_$dom').style.display = 'none';
2865: }
2866: }
2867: }
2868: }
2869: }
2870: }
2871: return;
2872: }
2873:
2874: function checkWAF() {
2875: if (document.getElementById('wafproxy_remoteip')) {
2876: var wafvpn = 0;
2877: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
2878: if (document.display.wafproxy_vpnaccess[i].checked) {
2879: if (document.display.wafproxy_vpnaccess[i].value == 1) {
2880: wafvpn = 1;
2881: }
2882: break;
2883: }
2884: }
2885: var vpn = new Array('vpnint','vpnext');
2886: for (var i=0; i<vpn.length; i++) {
2887: if (document.getElementById('wafproxy_show_'+vpn[i])) {
2888: if (wafvpn == 1) {
2889: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
2890: }
2891: else {
2892: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
2893: }
2894: }
2895: }
2896: if (document.getElementById('wafproxyranges_$dom')) {
2897: if (wafvpn == 1) {
2898: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
2899: }
2900: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
2901: document.getElementById('wafproxyranges_$dom').style.display = 'none';
2902: }
2903: }
2904: }
2905: return;
2906: }
2907:
2908: function toggleWAF() {
2909: if (document.getElementById('wafproxy_table')) {
2910: var wafproxy = 0;
2911: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
2912: if (document.display.wafproxy_${dom}[i].checked) {
2913: if (document.display.wafproxy_${dom}[i].value == 1) {
2914: wafproxy = 1;
2915: break;
2916: }
2917: }
2918: }
2919: if (wafproxy == 1) {
2920: document.getElementById('wafproxy_table').style.display='inline';
2921: }
2922: else {
2923: document.getElementById('wafproxy_table').style.display='none';
2924: }
2925: if (document.getElementById('wafproxyrow_${dom}')) {
2926: if (wafproxy == 1) {
2927: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
2928: }
2929: else {
2930: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
2931: }
2932: }
2933: if (document.getElementById('nowafproxyrow_$dom')) {
2934: if (wafproxy == 1) {
2935: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
2936: }
2937: else {
2938: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
2939: }
2940: }
2941: }
2942: return;
2943: }
2944: // ]]>
2945: </script>
2946:
2947: ENDSCRIPT
2948: }
2949:
2950: sub autoupdate_javascript {
2951: return <<"ENDSCRIPT";
2952: <script type="text/javascript">
2953: // <![CDATA[
2954: function toggleLastActiveDays(form) {
2955: var radioname = 'lastactive';
2956: var divid = 'lastactive_div';
2957: var num = form.elements[radioname].length;
2958: if (num) {
2959: var setvis = '';
2960: for (var i=0; i<num; i++) {
2961: if (form.elements[radioname][i].checked) {
2962: if (form.elements[radioname][i].value == '1') {
2963: if (document.getElementById(divid)) {
2964: document.getElementById(divid).style.display = 'inline-block';
2965: }
2966: setvis = 1;
2967: }
2968: break;
2969: }
2970: }
2971: if (!setvis) {
2972: if (document.getElementById(divid)) {
2973: document.getElementById(divid).style.display = 'none';
2974: }
2975: }
2976: }
2977: return;
2978: }
2979: // ]]>
2980: </script>
2981:
2982: ENDSCRIPT
2983: }
2984:
2985: sub saml_javascript {
2986: return <<"ENDSCRIPT";
2987: <script type="text/javascript">
2988: // <![CDATA[
2989: function toggleSamlOptions(form,hostid) {
2990: var radioname = 'saml_'+hostid;
2991: var tablecellon = 'samloptionson_'+hostid;
2992: var tablecelloff = 'samloptionsoff_'+hostid;
2993: var num = form.elements[radioname].length;
2994: if (num) {
2995: var setvis = '';
2996: for (var i=0; i<num; i++) {
2997: if (form.elements[radioname][i].checked) {
2998: if (form.elements[radioname][i].value == '1') {
2999: if (document.getElementById(tablecellon)) {
3000: document.getElementById(tablecellon).style.display='';
3001: }
3002: if (document.getElementById(tablecelloff)) {
3003: document.getElementById(tablecelloff).style.display='none';
3004: }
3005: setvis = 1;
3006: }
3007: break;
3008: }
3009: }
3010: if (!setvis) {
3011: if (document.getElementById(tablecellon)) {
3012: document.getElementById(tablecellon).style.display='none';
3013: }
3014: if (document.getElementById(tablecelloff)) {
3015: document.getElementById(tablecelloff).style.display='';
3016: }
3017: }
3018: }
3019: return;
3020: }
3021: // ]]>
3022: </script>
3023:
3024: ENDSCRIPT
3025: }
3026:
3027: sub ipaccess_javascript {
3028: my ($settings) = @_;
3029: my (%ordered,$total,%jstext);
3030: $total = 0;
3031: if (ref($settings) eq 'HASH') {
3032: foreach my $item (keys(%{$settings})) {
3033: if (ref($settings->{$item}) eq 'HASH') {
3034: my $num = $settings->{$item}{'order'};
3035: $ordered{$num} = $item;
3036: }
3037: }
3038: $total = scalar(keys(%{$settings}));
3039: }
3040: my @jsarray = ();
3041: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3042: push(@jsarray,$ordered{$item});
3043: }
3044: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3045: return <<"ENDSCRIPT";
3046: <script type="text/javascript">
3047: // <![CDATA[
3048: function reorderIPaccess(form,item) {
3049: var changedVal;
3050: $jstext
3051: var newpos = 'ipaccess_pos_add';
3052: var maxh = 1 + $total;
3053: var current = new Array;
3054: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3055: if (item == newpos) {
3056: changedVal = newitemVal;
3057: } else {
3058: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3059: current[newitemVal] = newpos;
3060: }
3061: for (var i=0; i<ipaccess.length; i++) {
3062: var elementName = 'ipaccess_pos_'+ipaccess[i];
3063: if (elementName != item) {
3064: if (form.elements[elementName]) {
3065: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3066: current[currVal] = elementName;
3067: }
3068: }
3069: }
3070: var oldVal;
3071: for (var j=0; j<maxh; j++) {
3072: if (current[j] == undefined) {
3073: oldVal = j;
3074: }
3075: }
3076: if (oldVal < changedVal) {
3077: for (var k=oldVal+1; k<=changedVal ; k++) {
3078: var elementName = current[k];
3079: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3080: }
3081: } else {
3082: for (var k=changedVal; k<oldVal; k++) {
3083: var elementName = current[k];
3084: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3085: }
3086: }
3087: return;
3088: }
3089: // ]]>
3090: </script>
3091:
3092: ENDSCRIPT
3093: }
3094:
1.3 raeburn 3095: sub print_autoenroll {
1.30 raeburn 3096: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3097: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68 raeburn 3098: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 3099: if (ref($settings) eq 'HASH') {
3100: if (exists($settings->{'run'})) {
3101: if ($settings->{'run'} eq '0') {
3102: $runoff = ' checked="checked" ';
3103: $runon = ' ';
3104: } else {
3105: $runon = ' checked="checked" ';
3106: $runoff = ' ';
3107: }
3108: } else {
3109: if ($autorun) {
3110: $runon = ' checked="checked" ';
3111: $runoff = ' ';
3112: } else {
3113: $runoff = ' checked="checked" ';
3114: $runon = ' ';
3115: }
3116: }
1.129 raeburn 3117: if (exists($settings->{'co-owners'})) {
3118: if ($settings->{'co-owners'} eq '0') {
3119: $coownersoff = ' checked="checked" ';
3120: $coownerson = ' ';
3121: } else {
3122: $coownerson = ' checked="checked" ';
3123: $coownersoff = ' ';
3124: }
3125: } else {
3126: $coownersoff = ' checked="checked" ';
3127: $coownerson = ' ';
3128: }
1.3 raeburn 3129: if (exists($settings->{'sender_domain'})) {
3130: $defdom = $settings->{'sender_domain'};
3131: }
1.160.6.68 raeburn 3132: if (exists($settings->{'autofailsafe'})) {
3133: $failsafe = $settings->{'autofailsafe'};
3134: }
1.14 raeburn 3135: } else {
3136: if ($autorun) {
3137: $runon = ' checked="checked" ';
3138: $runoff = ' ';
3139: } else {
3140: $runoff = ' checked="checked" ';
3141: $runon = ' ';
3142: }
1.3 raeburn 3143: }
3144: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3145: my $notif_sender;
3146: if (ref($settings) eq 'HASH') {
3147: $notif_sender = $settings->{'sender_uname'};
3148: }
1.3 raeburn 3149: my $datatable='<tr class="LC_odd_row">'.
3150: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3151: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3152: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3153: $runon.' value="1" />'.&mt('Yes').'</label> '.
3154: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3155: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3156: '</tr><tr>'.
3157: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3158: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3159: &mt('username').': '.
3160: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3161: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3162: ': '.$domform.'</span></td></tr>'.
3163: '<tr class="LC_odd_row">'.
3164: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3165: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3166: '<input type="radio" name="autoassign_coowners"'.
3167: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3168: '<label><input type="radio" name="autoassign_coowners"'.
3169: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 3170: '</tr><tr>'.
3171: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3172: '<td class="LC_right_item"><span class="LC_nobreak">'.
3173: '<input type="text" name="autoenroll_failsafe"'.
1.160.6.87 raeburn 3174: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.160.6.68 raeburn 3175: $$rowtotal += 4;
1.3 raeburn 3176: return $datatable;
3177: }
3178:
3179: sub print_autoupdate {
1.30 raeburn 3180: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 3181: my ($enable,$datatable);
1.3 raeburn 3182: if ($position eq 'top') {
1.160.6.113 raeburn 3183: my %choices = &Apache::lonlocal::texthash (
3184: run => 'Auto-update active?',
3185: classlists => 'Update information in classlists?',
3186: unexpired => 'Skip updates for users without active or future roles?',
3187: lastactive => 'Skip updates for inactive users?',
3188: );
3189: my $itemcount = 0;
1.3 raeburn 3190: my $updateon = ' ';
3191: my $updateoff = ' checked="checked" ';
3192: if (ref($settings) eq 'HASH') {
3193: if ($settings->{'run'} eq '1') {
3194: $updateon = $updateoff;
3195: $updateoff = ' ';
3196: }
3197: }
1.160.6.113 raeburn 3198: $enable = '<tr class="LC_odd_row">'.
3199: '<td>'.&mt($choices{'run'}).'</td>'.
3200: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3201: '<input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3202: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 3203: '<label><input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3204: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 3205: '</tr>';
1.160.6.113 raeburn 3206: my @toggles = ('classlists','unexpired');
3207: my %defaultchecked = ('classlists' => 'off',
3208: 'unexpired' => 'off'
3209: );
3210: $$rowtotal ++;
3211: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3212: \%choices,$itemcount,'','','left','no');
3213: $datatable = $enable.$datatable;
3214: $$rowtotal += $itemcount;
3215: my $lastactiveon = ' ';
3216: my $lastactiveoff = ' checked="checked" ';
3217: my $lastactivestyle = 'none';
3218: my $lastactivedays;
3219: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
3220: if (ref($settings) eq 'HASH') {
3221: if ($settings->{'lastactive'} =~ /^\d+$/) {
3222: $lastactiveon = $lastactiveoff;
3223: $lastactiveoff = ' ';
3224: $lastactivestyle = 'inline-block';
3225: $lastactivedays = $settings->{'lastactive'};
3226: }
3227: }
3228: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3229: $datatable .= '<tr'.$css_class.'>'.
3230: '<td>'.$choices{'lastactive'}.'</td>'.
3231: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3232: '<input type="radio" name="lastactive"'.
3233: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
3234: ' <label>'.
3235: '<input type="radio" name="lastactive"'.
3236: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
3237: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
3238: ': '.&mt('inactive = no activity in last [_1] days',
3239: '<input type="text" size="5" name="lastactivedays" value="'.
3240: $lastactivedays.'" />').
3241: '</span></td>'.
3242: '</tr>';
3243: $$rowtotal ++;
1.131 raeburn 3244: } elsif ($position eq 'middle') {
3245: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3246: my $numinrow = 3;
3247: my $locknamesettings;
3248: $datatable .= &insttypes_row($settings,$types,$usertypes,
3249: $dom,$numinrow,$othertitle,
1.160.6.93 raeburn 3250: 'lockablenames',$rowtotal);
1.131 raeburn 3251: $$rowtotal ++;
1.3 raeburn 3252: } else {
1.44 raeburn 3253: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3254: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3255: 'permanentemail','id');
1.33 raeburn 3256: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3257: my $numrows = 0;
1.26 raeburn 3258: if (ref($types) eq 'ARRAY') {
3259: if (@{$types} > 0) {
3260: $datatable =
3261: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3262: \@fields,$types,\$numrows);
1.30 raeburn 3263: $$rowtotal += @{$types};
1.26 raeburn 3264: }
1.3 raeburn 3265: }
3266: $datatable .=
3267: &usertype_update_row($settings,{'default' => $othertitle},
3268: \%fieldtitles,\@fields,['default'],
3269: \$numrows);
1.30 raeburn 3270: $$rowtotal ++;
1.3 raeburn 3271: }
3272: return $datatable;
3273: }
3274:
1.125 raeburn 3275: sub print_autocreate {
3276: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3277: my (%createon,%createoff,%currhash);
1.125 raeburn 3278: my @types = ('xml','req');
3279: if (ref($settings) eq 'HASH') {
3280: foreach my $item (@types) {
3281: $createoff{$item} = ' checked="checked" ';
3282: $createon{$item} = ' ';
3283: if (exists($settings->{$item})) {
3284: if ($settings->{$item}) {
3285: $createon{$item} = ' checked="checked" ';
3286: $createoff{$item} = ' ';
3287: }
3288: }
3289: }
1.160.6.16 raeburn 3290: if ($settings->{'xmldc'} ne '') {
3291: $currhash{$settings->{'xmldc'}} = 1;
3292: }
1.125 raeburn 3293: } else {
3294: foreach my $item (@types) {
3295: $createoff{$item} = ' checked="checked" ';
3296: $createon{$item} = ' ';
3297: }
3298: }
3299: $$rowtotal += 2;
1.160.6.16 raeburn 3300: my $numinrow = 2;
1.125 raeburn 3301: my $datatable='<tr class="LC_odd_row">'.
3302: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3303: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3304: '<input type="radio" name="autocreate_xml"'.
3305: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3306: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3307: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3308: '</td></tr><tr>'.
3309: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3310: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3311: '<input type="radio" name="autocreate_req"'.
3312: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3313: '<label><input type="radio" name="autocreate_req"'.
3314: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 3315: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3316: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 3317: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3318: if ($numdc > 1) {
1.160.6.50 raeburn 3319: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3320: '</td><td class="LC_left_item">';
1.125 raeburn 3321: } else {
1.160.6.50 raeburn 3322: $datatable .= &mt('Course creation processed as:').
3323: '</td><td class="LC_right_item">';
1.125 raeburn 3324: }
1.160.6.50 raeburn 3325: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 3326: $$rowtotal += $rows;
1.125 raeburn 3327: return $datatable;
3328: }
3329:
1.23 raeburn 3330: sub print_directorysrch {
1.160.6.72 raeburn 3331: my ($position,$dom,$settings,$rowtotal) = @_;
3332: my $datatable;
3333: if ($position eq 'top') {
3334: my $instsrchon = ' ';
3335: my $instsrchoff = ' checked="checked" ';
3336: my ($exacton,$containson,$beginson);
3337: my $instlocalon = ' ';
3338: my $instlocaloff = ' checked="checked" ';
3339: if (ref($settings) eq 'HASH') {
3340: if ($settings->{'available'} eq '1') {
3341: $instsrchon = $instsrchoff;
3342: $instsrchoff = ' ';
3343: }
3344: if ($settings->{'localonly'} eq '1') {
3345: $instlocalon = $instlocaloff;
3346: $instlocaloff = ' ';
3347: }
3348: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3349: foreach my $type (@{$settings->{'searchtypes'}}) {
3350: if ($type eq 'exact') {
3351: $exacton = ' checked="checked" ';
3352: } elsif ($type eq 'contains') {
3353: $containson = ' checked="checked" ';
3354: } elsif ($type eq 'begins') {
3355: $beginson = ' checked="checked" ';
3356: }
3357: }
3358: } else {
3359: if ($settings->{'searchtypes'} eq 'exact') {
3360: $exacton = ' checked="checked" ';
3361: } elsif ($settings->{'searchtypes'} eq 'contains') {
3362: $containson = ' checked="checked" ';
3363: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3364: $exacton = ' checked="checked" ';
3365: $containson = ' checked="checked" ';
3366: }
3367: }
1.23 raeburn 3368: }
1.160.6.72 raeburn 3369: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3370: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 3371:
1.160.6.72 raeburn 3372: my $numinrow = 4;
3373: my $cansrchrow = 0;
3374: $datatable='<tr class="LC_odd_row">'.
3375: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3376: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3377: '<input type="radio" name="dirsrch_available"'.
3378: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3379: '<label><input type="radio" name="dirsrch_available"'.
3380: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3381: '</tr><tr>'.
3382: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3383: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3384: '<input type="radio" name="dirsrch_instlocalonly"'.
3385: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3386: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3387: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3388: '</tr>';
3389: $$rowtotal += 2;
3390: if (ref($usertypes) eq 'HASH') {
3391: if (keys(%{$usertypes}) > 0) {
3392: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93 raeburn 3393: $numinrow,$othertitle,'cansearch',
3394: $rowtotal);
1.160.6.72 raeburn 3395: $cansrchrow = 1;
3396: }
1.26 raeburn 3397: }
1.160.6.72 raeburn 3398: if ($cansrchrow) {
3399: $$rowtotal ++;
3400: $datatable .= '<tr>';
3401: } else {
3402: $datatable .= '<tr class="LC_odd_row">';
3403: }
3404: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3405: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3406: foreach my $title (@{$titleorder}) {
3407: if (defined($searchtitles->{$title})) {
3408: my $check = ' ';
3409: if (ref($settings) eq 'HASH') {
3410: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3411: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3412: $check = ' checked="checked" ';
3413: }
1.39 raeburn 3414: }
1.25 raeburn 3415: }
1.160.6.72 raeburn 3416: $datatable .= '<td class="LC_left_item">'.
3417: '<span class="LC_nobreak"><label>'.
3418: '<input type="checkbox" name="searchby" '.
3419: 'value="'.$title.'"'.$check.'/>'.
3420: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3421: }
3422: }
1.160.6.72 raeburn 3423: $datatable .= '</tr></table></td></tr>';
3424: $$rowtotal ++;
3425: if ($cansrchrow) {
3426: $datatable .= '<tr class="LC_odd_row">';
3427: } else {
3428: $datatable .= '<tr>';
3429: }
3430: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3431: '<td class="LC_left_item" colspan="2">'.
3432: '<span class="LC_nobreak"><label>'.
3433: '<input type="checkbox" name="searchtypes" '.
3434: $exacton.' value="exact" />'.&mt('Exact match').
3435: '</label> '.
3436: '<label><input type="checkbox" name="searchtypes" '.
3437: $beginson.' value="begins" />'.&mt('Begins with').
3438: '</label> '.
3439: '<label><input type="checkbox" name="searchtypes" '.
3440: $containson.' value="contains" />'.&mt('Contains').
3441: '</label></span></td></tr>';
3442: $$rowtotal ++;
1.26 raeburn 3443: } else {
1.160.6.72 raeburn 3444: my $domsrchon = ' checked="checked" ';
3445: my $domsrchoff = ' ';
3446: my $domlocalon = ' ';
3447: my $domlocaloff = ' checked="checked" ';
3448: if (ref($settings) eq 'HASH') {
3449: if ($settings->{'lclocalonly'} eq '1') {
3450: $domlocalon = $domlocaloff;
3451: $domlocaloff = ' ';
3452: }
3453: if ($settings->{'lcavailable'} eq '0') {
3454: $domsrchoff = $domsrchon;
3455: $domsrchon = ' ';
3456: }
3457: }
3458: $datatable='<tr class="LC_odd_row">'.
3459: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3460: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3461: '<input type="radio" name="dirsrch_domavailable"'.
3462: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3463: '<label><input type="radio" name="dirsrch_domavailable"'.
3464: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3465: '</tr><tr>'.
3466: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3467: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3468: '<input type="radio" name="dirsrch_domlocalonly"'.
3469: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3470: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3471: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3472: '</tr>';
3473: $$rowtotal += 2;
1.26 raeburn 3474: }
1.25 raeburn 3475: return $datatable;
3476: }
3477:
1.28 raeburn 3478: sub print_contacts {
1.160.6.78 raeburn 3479: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3480: my $datatable;
3481: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 3482: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.160.6.107 raeburn 3483: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.160.6.78 raeburn 3484: if ($position eq 'top') {
3485: if (ref($settings) eq 'HASH') {
3486: foreach my $item (@contacts) {
3487: if (exists($settings->{$item})) {
3488: $to{$item} = $settings->{$item};
3489: }
1.28 raeburn 3490: }
3491: }
1.160.6.78 raeburn 3492: } elsif ($position eq 'middle') {
3493: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91 raeburn 3494: 'updatesmail','idconflictsmail','hostipmail');
1.28 raeburn 3495: foreach my $type (@mailings) {
1.160.6.78 raeburn 3496: $otheremails{$type} = '';
3497: }
1.160.6.107 raeburn 3498: } elsif ($position eq 'lower') {
3499: if (ref($settings) eq 'HASH') {
3500: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3501: %lonstatus = %{$settings->{'lonstatus'}};
3502: }
3503: }
1.160.6.78 raeburn 3504: } else {
3505: @mailings = ('helpdeskmail','otherdomsmail');
3506: foreach my $type (@mailings) {
3507: $otheremails{$type} = '';
3508: }
3509: $bccemails{'helpdeskmail'} = '';
3510: $bccemails{'otherdomsmail'} = '';
3511: $includestr{'helpdeskmail'} = '';
3512: $includestr{'otherdomsmail'} = '';
3513: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3514: }
3515: if (ref($settings) eq 'HASH') {
1.160.6.107 raeburn 3516: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 3517: foreach my $type (@mailings) {
3518: if (exists($settings->{$type})) {
3519: if (ref($settings->{$type}) eq 'HASH') {
3520: foreach my $item (@contacts) {
3521: if ($settings->{$type}{$item}) {
3522: $checked{$type}{$item} = ' checked="checked" ';
3523: }
1.28 raeburn 3524: }
1.160.6.78 raeburn 3525: $otheremails{$type} = $settings->{$type}{'others'};
3526: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3527: $bccemails{$type} = $settings->{$type}{'bcc'};
3528: if ($settings->{$type}{'include'} ne '') {
3529: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3530: $includestr{$type} = &unescape($includestr{$type});
3531: }
3532: }
3533: }
3534: } elsif ($type eq 'lonstatusmail') {
3535: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3536: }
3537: }
3538: }
3539: if ($position eq 'bottom') {
3540: foreach my $type (@mailings) {
3541: $bccemails{$type} = $settings->{$type}{'bcc'};
3542: if ($settings->{$type}{'include'} ne '') {
3543: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3544: $includestr{$type} = &unescape($includestr{$type});
3545: }
3546: }
3547: if (ref($settings->{'helpform'}) eq 'HASH') {
3548: if (ref($fields) eq 'ARRAY') {
3549: foreach my $field (@{$fields}) {
3550: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3551: }
1.160.6.78 raeburn 3552: }
3553: if (exists($settings->{'helpform'}{'maxsize'})) {
3554: $maxsize = $settings->{'helpform'}{'maxsize'};
3555: } else {
3556: $maxsize = '1.0';
3557: }
3558: } else {
3559: if (ref($fields) eq 'ARRAY') {
3560: foreach my $field (@{$fields}) {
3561: $currfield{$field} = 'yes';
1.134 raeburn 3562: }
1.28 raeburn 3563: }
1.160.6.78 raeburn 3564: $maxsize = '1.0';
1.28 raeburn 3565: }
3566: }
3567: } else {
1.160.6.78 raeburn 3568: if ($position eq 'top') {
3569: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3570: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3571: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3572: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
3573: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3574: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3575: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3576: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91 raeburn 3577: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78 raeburn 3578: } elsif ($position eq 'bottom') {
3579: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3580: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3581: if (ref($fields) eq 'ARRAY') {
3582: foreach my $field (@{$fields}) {
3583: $currfield{$field} = 'yes';
3584: }
3585: }
3586: $maxsize = '1.0';
3587: }
1.28 raeburn 3588: }
3589: my ($titles,$short_titles) = &contact_titles();
3590: my $rownum = 0;
3591: my $css_class;
1.160.6.78 raeburn 3592: if ($position eq 'top') {
3593: foreach my $item (@contacts) {
3594: $css_class = $rownum%2?' class="LC_odd_row"':'';
3595: $datatable .= '<tr'.$css_class.'>'.
3596: '<td><span class="LC_nobreak">'.$titles->{$item}.
3597: '</span></td><td class="LC_right_item">'.
3598: '<input type="text" name="'.$item.'" value="'.
3599: $to{$item}.'" /></td></tr>';
3600: $rownum ++;
3601: }
1.160.6.101 raeburn 3602: } elsif ($position eq 'bottom') {
3603: $css_class = $rownum%2?' class="LC_odd_row"':'';
3604: $datatable .= '<tr'.$css_class.'>'.
3605: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3606: &mt('(e-mail, subject, and description always shown)').
3607: '</td><td class="LC_left_item">';
3608: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3609: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3610: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3611: foreach my $field (@{$fields}) {
3612: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3613: if (($field eq 'screenshot') || ($field eq 'cc')) {
3614: $datatable .= ' '.&mt('(logged-in users)');
3615: }
3616: $datatable .='</td><td>';
3617: my $clickaction;
3618: if ($field eq 'screenshot') {
3619: $clickaction = ' onclick="screenshotSize(this);"';
3620: }
3621: if (ref($possoptions->{$field}) eq 'ARRAY') {
3622: foreach my $option (@{$possoptions->{$field}}) {
3623: my $checked;
3624: if ($currfield{$field} eq $option) {
3625: $checked = ' checked="checked"';
3626: }
3627: $datatable .= '<span class="LC_nobreak"><label>'.
3628: '<input type="radio" name="helpform_'.$field.'" '.
3629: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3630: '</label></span>'.(' 'x2);
3631: }
3632: }
3633: if ($field eq 'screenshot') {
3634: my $display;
3635: if ($currfield{$field} eq 'no') {
3636: $display = ' style="display:none"';
3637: }
3638: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
3639: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3640: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3641: }
3642: $datatable .= '</td></tr>';
3643: }
3644: $datatable .= '</table>';
3645: }
3646: $datatable .= '</td></tr>'."\n";
3647: $rownum ++;
3648: }
1.160.6.107 raeburn 3649: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 3650: foreach my $type (@mailings) {
3651: $css_class = $rownum%2?' class="LC_odd_row"':'';
3652: $datatable .= '<tr'.$css_class.'>'.
3653: '<td><span class="LC_nobreak">'.
3654: $titles->{$type}.': </span></td>'.
3655: '<td class="LC_left_item">';
3656: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3657: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3658: }
3659: $datatable .= '<span class="LC_nobreak">';
3660: foreach my $item (@contacts) {
3661: $datatable .= '<label>'.
3662: '<input type="checkbox" name="'.$type.'"'.
3663: $checked{$type}{$item}.
3664: ' value="'.$item.'" />'.$short_titles->{$item}.
3665: '</label> ';
3666: }
3667: $datatable .= '</span><br />'.&mt('Others').': '.
3668: '<input type="text" name="'.$type.'_others" '.
3669: 'value="'.$otheremails{$type}.'" />';
3670: my %locchecked;
3671: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3672: foreach my $loc ('s','b') {
3673: if ($includeloc{$type} eq $loc) {
3674: $locchecked{$loc} = ' checked="checked"';
3675: last;
3676: }
3677: }
3678: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3679: '<input type="text" name="'.$type.'_bcc" '.
3680: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3681: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3682: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 3683: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 3684: '<span class="LC_nobreak">'.&mt('Location:').' '.
3685: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3686: (' 'x2).
3687: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3688: '</span></fieldset>';
3689: }
3690: $datatable .= '</td></tr>'."\n";
3691: $rownum ++;
3692: }
1.28 raeburn 3693: }
1.160.6.78 raeburn 3694: if ($position eq 'middle') {
3695: my %choices;
1.160.6.107 raeburn 3696: my $corelink = &core_link_msu();
3697: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.160.6.78 raeburn 3698: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.160.6.107 raeburn 3699: $corelink);
3700: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
3701: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.160.6.78 raeburn 3702: my %defaultchecked = ('reporterrors' => 'on',
1.160.6.107 raeburn 3703: 'reportupdates' => 'on',
3704: 'reportstatus' => 'on');
1.160.6.78 raeburn 3705: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3706: \%choices,$rownum);
3707: $datatable .= $reports;
1.160.6.107 raeburn 3708: } elsif ($position eq 'lower') {
1.160.6.109 raeburn 3709: my (%current,%excluded,%weights);
1.160.6.107 raeburn 3710: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
3711: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.160.6.109 raeburn 3712: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.160.6.107 raeburn 3713: } else {
1.160.6.109 raeburn 3714: $current{'errorthreshold'} = $defaults->{'threshold'};
1.160.6.107 raeburn 3715: }
3716: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.160.6.109 raeburn 3717: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.160.6.107 raeburn 3718: } else {
1.160.6.109 raeburn 3719: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.160.6.107 raeburn 3720: }
3721: if (ref($lonstatus{'weights'}) eq 'HASH') {
3722: foreach my $type ('E','W','N','U') {
3723: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
3724: $weights{$type} = $lonstatus{'weights'}{$type};
3725: } else {
3726: $weights{$type} = $defaults->{$type};
3727: }
3728: }
3729: } else {
3730: foreach my $type ('E','W','N','U') {
3731: $weights{$type} = $defaults->{$type};
3732: }
3733: }
3734: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
3735: if (@{$lonstatus{'excluded'}} > 0) {
3736: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
3737: }
3738: }
1.160.6.109 raeburn 3739: foreach my $item ('errorthreshold','errorsysmail') {
3740: $css_class = $rownum%2?' class="LC_odd_row"':'';
3741: $datatable .= '<tr'.$css_class.'>'.
3742: '<td class="LC_left_item"><span class="LC_nobreak">'.
3743: $titles->{$item}.
3744: '</span></td><td class="LC_left_item">'.
3745: '<input type="text" name="'.$item.'" value="'.
3746: $current{$item}.'" size="5" /></td></tr>';
3747: $rownum ++;
3748: }
1.160.6.107 raeburn 3749: $css_class = $rownum%2?' class="LC_odd_row"':'';
3750: $datatable .= '<tr'.$css_class.'>'.
3751: '<td class="LC_left_item">'.
3752: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
3753: '</span></td><td class="LC_left_item"><table><tr>';
3754: foreach my $type ('E','W','N','U') {
3755: $datatable .= '<td>'.$names->{$type}.'<br />'.
3756: '<input type="text" name="errorweights_'.$type.'" value="'.
3757: $weights{$type}.'" size="5" /></td>';
3758: }
3759: $datatable .= '</tr></table></tr>';
3760: $rownum ++;
3761: $css_class = $rownum%2?' class="LC_odd_row"':'';
3762: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
3763: $titles->{'errorexcluded'}.'</td>'.
3764: '<td class="LC_left_item"><table>';
3765: my $numinrow = 4;
3766: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
3767: for (my $i=0; $i<@ids; $i++) {
3768: my $rem = $i%($numinrow);
3769: if ($rem == 0) {
3770: if ($i > 0) {
3771: $datatable .= '</tr>';
3772: }
3773: $datatable .= '<tr>';
3774: }
3775: my $check;
3776: if ($excluded{$ids[$i]}) {
3777: $check = ' checked="checked" ';
3778: }
3779: $datatable .= '<td class="LC_left_item">'.
3780: '<span class="LC_nobreak"><label>'.
3781: '<input type="checkbox" name="errorexcluded" '.
3782: 'value="'.$ids[$i].'"'.$check.' />'.
3783: $ids[$i].'</label></span></td>';
3784: }
3785: my $colsleft = $numinrow - @ids%($numinrow);
3786: if ($colsleft > 1 ) {
3787: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3788: ' </td>';
3789: } elsif ($colsleft == 1) {
3790: $datatable .= '<td class="LC_left_item"> </td>';
3791: }
3792: $datatable .= '</tr></table></td></tr>';
3793: $rownum ++;
1.160.6.78 raeburn 3794: } elsif ($position eq 'bottom') {
1.160.6.101 raeburn 3795: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3796: my (@posstypes,%usertypeshash);
3797: if (ref($types) eq 'ARRAY') {
3798: @posstypes = @{$types};
3799: }
3800: if (@posstypes) {
3801: if (ref($usertypes) eq 'HASH') {
3802: %usertypeshash = %{$usertypes};
3803: }
3804: my @overridden;
3805: my $numinrow = 4;
3806: if (ref($settings) eq 'HASH') {
3807: if (ref($settings->{'overrides'}) eq 'HASH') {
3808: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3809: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3810: push(@overridden,$key);
3811: foreach my $item (@contacts) {
3812: if ($settings->{'overrides'}{$key}{$item}) {
3813: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3814: }
3815: }
3816: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3817: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3818: $includeloc{'override_'.$key} = '';
3819: $includestr{'override_'.$key} = '';
3820: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3821: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3822: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3823: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3824: }
1.160.6.78 raeburn 3825: }
3826: }
3827: }
1.160.6.101 raeburn 3828: }
3829: my $customclass = 'LC_helpdesk_override';
3830: my $optionsprefix = 'LC_options_helpdesk_';
3831:
3832: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3833:
3834: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3835: $numinrow,$othertitle,'overrides',
3836: \$rownum,$onclicktypes,$customclass);
3837: $rownum ++;
3838: $usertypeshash{'default'} = $othertitle;
3839: foreach my $status (@posstypes) {
3840: my $css_class;
3841: if ($rownum%2) {
3842: $css_class = 'LC_odd_row ';
3843: }
3844: $css_class .= $customclass;
3845: my $rowid = $optionsprefix.$status;
3846: my $hidden = 1;
3847: my $currstyle = 'display:none';
3848: if (grep(/^\Q$status\E$/,@overridden)) {
3849: $currstyle = 'display:table-row';
3850: $hidden = 0;
3851: }
3852: my $key = 'override_'.$status;
3853: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3854: $includeloc{$key},$includestr{$key},$status,$rowid,
3855: $usertypeshash{$status},$css_class,$currstyle,
3856: \@contacts,$short_titles);
3857: unless ($hidden) {
3858: $rownum ++;
1.160.6.78 raeburn 3859: }
3860: }
1.134 raeburn 3861: }
1.28 raeburn 3862: }
1.30 raeburn 3863: $$rowtotal += $rownum;
1.28 raeburn 3864: return $datatable;
3865: }
3866:
1.160.6.107 raeburn 3867: sub core_link_msu {
3868: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3869: &mt('LON-CAPA core group - MSU'),600,500);
3870: }
3871:
1.160.6.101 raeburn 3872: sub overridden_helpdesk {
3873: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3874: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3875: my $class = 'LC_left_item';
3876: if ($css_class) {
3877: $css_class = ' class="'.$css_class.'"';
3878: }
3879: if ($rowid) {
3880: $rowid = ' id="'.$rowid.'"';
3881: }
3882: if ($rowstyle) {
3883: $rowstyle = ' style="'.$rowstyle.'"';
3884: }
3885: my ($output,$description);
3886: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3887: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3888: "<td>$description</td>\n".
3889: '<td class="'.$class.'" colspan="2">'.
3890: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3891: '<span class="LC_nobreak">';
3892: if (ref($contacts) eq 'ARRAY') {
3893: foreach my $item (@{$contacts}) {
3894: my $check;
3895: if (ref($checked) eq 'HASH') {
3896: $check = $checked->{$item};
3897: }
3898: my $title;
3899: if (ref($short_titles) eq 'HASH') {
3900: $title = $short_titles->{$item};
3901: }
3902: $output .= '<label>'.
3903: '<input type="checkbox" name="override_'.$type.'"'.$check.
3904: ' value="'.$item.'" />'.$title.'</label> ';
3905: }
3906: }
3907: $output .= '</span><br />'.&mt('Others').': '.
3908: '<input type="text" name="override_'.$type.'_others" '.
3909: 'value="'.$otheremails.'" />';
3910: my %locchecked;
3911: foreach my $loc ('s','b') {
3912: if ($includeloc eq $loc) {
3913: $locchecked{$loc} = ' checked="checked"';
3914: last;
3915: }
3916: }
3917: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3918: '<input type="text" name="override_'.$type.'_bcc" '.
3919: 'value="'.$bccemails.'" /></fieldset>'.
3920: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3921: &mt('Text automatically added to e-mail:').' '.
3922: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
3923: '<span class="LC_nobreak">'.&mt('Location:').' '.
3924: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3925: (' 'x2).
3926: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3927: '</span></fieldset>'.
3928: '</td></tr>'."\n";
3929: return $output;
3930: }
3931:
1.160.6.78 raeburn 3932: sub contacts_javascript {
3933: return <<"ENDSCRIPT";
3934:
3935: <script type="text/javascript">
3936: // <![CDATA[
3937:
3938: function screenshotSize(field) {
3939: if (document.getElementById('help_screenshotsize')) {
3940: if (field.value == 'no') {
3941: document.getElementById('help_screenshotsize').style.display="none";
3942: } else {
3943: document.getElementById('help_screenshotsize').style.display="";
3944: }
3945: }
3946: return;
3947: }
3948:
1.160.6.101 raeburn 3949: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3950: if (form.elements[checkbox].length != undefined) {
3951: var count = 0;
3952: if (docount) {
3953: for (var i=0; i<form.elements[checkbox].length; i++) {
3954: if (form.elements[checkbox][i].checked) {
3955: count ++;
3956: }
3957: }
3958: }
3959: for (var i=0; i<form.elements[checkbox].length; i++) {
3960: var type = form.elements[checkbox][i].value;
3961: if (document.getElementById(prefix+type)) {
3962: if (form.elements[checkbox][i].checked) {
3963: document.getElementById(prefix+type).style.display = 'table-row';
3964: if (count % 2 == 1) {
3965: document.getElementById(prefix+type).className = target+' LC_odd_row';
3966: } else {
3967: document.getElementById(prefix+type).className = target;
3968: }
3969: count ++;
3970: } else {
3971: document.getElementById(prefix+type).style.display = 'none';
3972: }
3973: }
3974: }
3975: }
3976: return;
3977: }
3978:
1.160.6.78 raeburn 3979: // ]]>
3980: </script>
3981:
3982: ENDSCRIPT
3983: }
3984:
1.118 jms 3985: sub print_helpsettings {
1.160.6.73 raeburn 3986: my ($position,$dom,$settings,$rowtotal) = @_;
3987: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 3988: my $formname = 'display';
1.160.6.5 raeburn 3989: my ($datatable,$itemcount);
1.160.6.73 raeburn 3990: if ($position eq 'top') {
3991: $itemcount = 1;
3992: my (%choices,%defaultchecked,@toggles);
3993: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3994: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3995: &mt('LON-CAPA bug tracker'),600,500));
3996: %defaultchecked = ('submitbugs' => 'on');
3997: @toggles = ('submitbugs');
3998: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3999: \%choices,$itemcount);
4000: $$rowtotal ++;
4001: } else {
4002: my $css_class;
4003: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 4004: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 4005: if (ref($settings) eq 'HASH') {
4006: if (ref($settings->{'adhoc'}) eq 'HASH') {
4007: %current = %{$settings->{'adhoc'}};
4008: }
1.160.6.77 raeburn 4009: }
4010: my $count = 0;
4011: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 4012: if ($key=~/^rolesdef\_(\w+)$/) {
4013: my $rolename = $1;
1.160.6.77 raeburn 4014: my (%privs,$order);
1.160.6.73 raeburn 4015: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4016: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 4017: if (ref($current{$rolename}) eq 'HASH') {
4018: $order = $current{$rolename}{'order'};
4019: }
4020: if ($order eq '') {
4021: $order = $count;
4022: }
4023: $ordered{$order} = $rolename;
4024: $count++;
1.160.6.73 raeburn 4025: }
4026: }
1.160.6.77 raeburn 4027: my $maxnum = scalar(keys(%ordered));
4028: my @roles_by_num = ();
4029: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4030: push(@roles_by_num,$item);
4031: }
4032: my $context = 'domprefs';
4033: my $crstype = 'Course';
4034: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 4035: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 4036: my ($numstatustypes,@jsarray);
4037: if (ref($types) eq 'ARRAY') {
4038: if (@{$types} > 0) {
4039: $numstatustypes = scalar(@{$types});
4040: push(@accesstypes,'status');
4041: @jsarray = ('bystatus');
4042: }
4043: }
1.160.6.86 raeburn 4044: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 4045: if (keys(%domhelpdesk)) {
4046: push(@accesstypes,('inc','exc'));
4047: push(@jsarray,('notinc','notexc'));
4048: }
4049: my $hiddenstr = join("','",@jsarray);
4050: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 4051: my $context = 'domprefs';
4052: my $crstype = 'Course';
1.160.6.77 raeburn 4053: my $prefix = 'helproles_';
4054: my $add_class = 'LC_hidden';
4055: foreach my $num (@roles_by_num) {
4056: my $role = $ordered{$num};
4057: my ($desc,$access,@statuses);
4058: if (ref($current{$role}) eq 'HASH') {
4059: $desc = $current{$role}{'desc'};
4060: $access = $current{$role}{'access'};
4061: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4062: @statuses = @{$current{$role}{'insttypes'}};
4063: }
4064: }
4065: if ($desc eq '') {
4066: $desc = $role;
4067: }
4068: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 4069: my %full=();
4070: my %levels= (
4071: course => {},
4072: domain => {},
4073: system => {},
4074: );
4075: my %levelscurrent=(
4076: course => {},
4077: domain => {},
4078: system => {},
4079: );
4080: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4081: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4082: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 4083: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
4084: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
4085: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4086: for (my $k=0; $k<=$maxnum; $k++) {
4087: my $vpos = $k+1;
4088: my $selstr;
4089: if ($k == $num) {
4090: $selstr = ' selected="selected" ';
4091: }
4092: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4093: }
4094: $datatable .= '</select>'.(' 'x2).
4095: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4096: '</td>'.
4097: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4098: &mt('Name shown to users:').
4099: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4100: '</fieldset>'.
4101: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4102: $othertitle,$usertypes,$types,\%domhelpdesk).
4103: '<fieldset>'.
4104: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 4105: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 4106: \%levelscurrent,$identifier,
4107: 'LC_hidden',$prefix.$num.'_privs').
4108: '</fieldset></td>';
1.160.6.73 raeburn 4109: $itemcount ++;
4110: }
4111: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4112: my $newcust = 'custhelp'.$count;
4113: my (%privs,%levelscurrent);
4114: my %full=();
4115: my %levels= (
4116: course => {},
4117: domain => {},
4118: system => {},
4119: );
4120: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4121: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 4122: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
4123: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
4124: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4125: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4126: for (my $k=0; $k<$maxnum+1; $k++) {
4127: my $vpos = $k+1;
4128: my $selstr;
4129: if ($k == $maxnum) {
4130: $selstr = ' selected="selected" ';
4131: }
4132: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4133: }
4134: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 4135: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4136: '</label></span></td>'.
1.160.6.77 raeburn 4137: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4138: '<span class="LC_nobreak">'.
4139: &mt('Internal name:').
4140: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4141: '</span>'.(' 'x4).
4142: '<span class="LC_nobreak">'.
4143: &mt('Name shown to users:').
4144: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4145: '</span></fieldset>'.
4146: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4147: $usertypes,$types,\%domhelpdesk).
4148: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 4149: &Apache::lonuserutils::custom_role_header($context,$crstype,
4150: \@templateroles,$newcust).
4151: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4152: \%levelscurrent,$newcust).
1.160.6.87 raeburn 4153: '</fieldset>'.
4154: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4155: '</td></tr>';
1.160.6.73 raeburn 4156: $count ++;
4157: $$rowtotal += $count;
4158: }
1.160.6.5 raeburn 4159: return $datatable;
1.121 raeburn 4160: }
4161:
1.160.6.77 raeburn 4162: sub adhocbutton {
4163: my ($prefix,$num,$field,$visibility) = @_;
4164: my %lt = &Apache::lonlocal::texthash(
4165: show => 'Show details',
4166: hide => 'Hide details',
4167: );
4168: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4169: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4170: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4171: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4172: }
4173:
4174: sub helpsettings_javascript {
4175: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4176: return unless(ref($roles_by_num) eq 'ARRAY');
4177: my %html_js_lt = &Apache::lonlocal::texthash(
4178: show => 'Show details',
4179: hide => 'Hide details',
4180: );
4181: &html_escape(\%html_js_lt);
4182: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4183: return <<"ENDSCRIPT";
4184: <script type="text/javascript">
4185: // <![CDATA[
4186:
4187: function reorderHelpRoles(form,item) {
4188: var changedVal;
4189: $jstext
4190: var newpos = 'helproles_${total}_pos';
4191: var maxh = 1 + $total;
4192: var current = new Array();
4193: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4194: if (item == newpos) {
4195: changedVal = newitemVal;
4196: } else {
4197: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4198: current[newitemVal] = newpos;
4199: }
4200: for (var i=0; i<helproles.length; i++) {
4201: var elementName = 'helproles_'+helproles[i]+'_pos';
4202: if (elementName != item) {
4203: if (form.elements[elementName]) {
4204: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4205: current[currVal] = elementName;
4206: }
4207: }
4208: }
4209: var oldVal;
4210: for (var j=0; j<maxh; j++) {
4211: if (current[j] == undefined) {
4212: oldVal = j;
4213: }
4214: }
4215: if (oldVal < changedVal) {
4216: for (var k=oldVal+1; k<=changedVal ; k++) {
4217: var elementName = current[k];
4218: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4219: }
4220: } else {
4221: for (var k=changedVal; k<oldVal; k++) {
4222: var elementName = current[k];
4223: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4224: }
4225: }
4226: return;
4227: }
4228:
4229: function helpdeskAccess(num) {
4230: var curraccess = null;
4231: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4232: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4233: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4234: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4235: }
4236: }
4237: }
4238: var shown = Array();
4239: var hidden = Array();
4240: if (curraccess == 'none') {
4241: hidden = Array('$hiddenstr');
4242: } else {
4243: if (curraccess == 'status') {
4244: shown = Array('bystatus');
4245: hidden = Array('notinc','notexc');
4246: } else {
4247: if (curraccess == 'exc') {
4248: shown = Array('notexc');
4249: hidden = Array('notinc','bystatus');
4250: }
4251: if (curraccess == 'inc') {
4252: shown = Array('notinc');
4253: hidden = Array('notexc','bystatus');
4254: }
1.160.6.79 raeburn 4255: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 4256: hidden = Array('notinc','notexc','bystatus');
4257: }
4258: }
4259: }
4260: if (hidden.length > 0) {
4261: for (var i=0; i<hidden.length; i++) {
4262: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4263: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4264: }
4265: }
4266: }
4267: if (shown.length > 0) {
4268: for (var i=0; i<shown.length; i++) {
4269: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4270: if (shown[i] == 'privs') {
4271: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4272: } else {
4273: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4274: }
4275: }
4276: }
4277: }
4278: return;
4279: }
4280:
4281: function toggleHelpdeskItem(num,field) {
4282: if (document.getElementById('helproles_'+num+'_'+field)) {
4283: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
4284: document.getElementById('helproles_'+num+'_'+field).className =
4285: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4286: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4287: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4288: }
4289: } else {
4290: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4291: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4292: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4293: }
4294: }
4295: }
4296: return;
4297: }
4298:
4299: // ]]>
4300: </script>
4301:
4302: ENDSCRIPT
4303: }
4304:
4305: sub helpdeskroles_access {
4306: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4307: $usertypes,$types,$domhelpdesk) = @_;
4308: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4309: my %lt = &Apache::lonlocal::texthash(
4310: 'rou' => 'Role usage',
4311: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 4312: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4313: 'dh' => 'All with domain helpdesk role',
4314: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 4315: 'none' => 'None',
4316: 'status' => 'Determined based on institutional status',
4317: 'inc' => 'Include all, but exclude specific personnel',
4318: 'exc' => 'Exclude all, but include specific personnel',
4319: );
4320: my %usecheck = (
4321: all => ' checked="checked"',
4322: );
4323: my %displaydiv = (
4324: status => 'none',
4325: inc => 'none',
4326: exc => 'none',
4327: priv => 'block',
4328: );
4329: my $output;
4330: if (ref($current) eq 'HASH') {
4331: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4332: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4333: $usecheck{$current->{access}} = $usecheck{'all'};
4334: delete($usecheck{'all'});
4335: if ($current->{access} =~ /^(status|inc|exc)$/) {
4336: my $access = $1;
4337: $displaydiv{$access} = 'inline';
4338: } elsif ($current->{access} eq 'none') {
4339: $displaydiv{'priv'} = 'none';
4340: }
4341: }
4342: }
4343: }
4344: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4345: '<p>'.$lt{'whi'}.'</p>';
4346: foreach my $access (@{$accesstypes}) {
4347: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4348: ' onclick="helpdeskAccess('."'$num'".');" />'.
4349: $lt{$access}.'</label>';
4350: if ($access eq 'status') {
4351: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4352: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4353: $othertitle,$usertypes,$types).
4354: '</div>';
4355: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4356: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4357: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4358: '</div>';
4359: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4360: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4361: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4362: '</div>';
4363: }
4364: $output .= '</p>';
4365: }
4366: $output .= '</fieldset>';
4367: return $output;
4368: }
4369:
1.121 raeburn 4370: sub radiobutton_prefs {
1.160.6.16 raeburn 4371: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.113 raeburn 4372: $additional,$align,$firstval) = @_;
1.121 raeburn 4373: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4374: (ref($choices) eq 'HASH'));
4375:
4376: my (%checkedon,%checkedoff,$datatable,$css_class);
4377:
4378: foreach my $item (@{$toggles}) {
4379: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4380: $checkedon{$item} = ' checked="checked" ';
4381: $checkedoff{$item} = ' ';
1.121 raeburn 4382: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4383: $checkedoff{$item} = ' checked="checked" ';
4384: $checkedon{$item} = ' ';
4385: }
4386: }
4387: if (ref($settings) eq 'HASH') {
1.121 raeburn 4388: foreach my $item (@{$toggles}) {
1.118 jms 4389: if ($settings->{$item} eq '1') {
4390: $checkedon{$item} = ' checked="checked" ';
4391: $checkedoff{$item} = ' ';
4392: } elsif ($settings->{$item} eq '0') {
4393: $checkedoff{$item} = ' checked="checked" ';
4394: $checkedon{$item} = ' ';
4395: }
4396: }
1.121 raeburn 4397: }
1.160.6.16 raeburn 4398: if ($onclick) {
4399: $onclick = ' onclick="'.$onclick.'"';
4400: }
1.121 raeburn 4401: foreach my $item (@{$toggles}) {
1.118 jms 4402: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4403: $datatable .=
1.160.6.16 raeburn 4404: '<tr'.$css_class.'><td valign="top">'.
4405: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 4406: '</span></td>';
4407: if ($align eq 'left') {
4408: $datatable .= '<td class="LC_left_item">';
4409: } else {
4410: $datatable .= '<td class="LC_right_item">';
4411: }
1.160.6.113 raeburn 4412: $datatable .= '<span class="LC_nobreak">';
4413: if ($firstval eq 'no') {
4414: $datatable .=
4415: '<label><input type="radio" name="'.
4416: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
4417: '</label> <label><input type="radio" name="'.$item.'" '.
4418: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
4419: } else {
4420: $datatable .=
1.118 jms 4421: '<label><input type="radio" name="'.
1.160.6.16 raeburn 4422: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4423: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.113 raeburn 4424: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
4425: }
4426: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 4427: $itemcount ++;
1.121 raeburn 4428: }
4429: return ($datatable,$itemcount);
4430: }
4431:
4432: sub print_coursedefaults {
1.139 raeburn 4433: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 4434: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4435: my $itemcount = 1;
1.160.6.16 raeburn 4436: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 4437: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 4438: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4439: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 4440: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4441: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.90 raeburn 4442: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 4443: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 4444: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 4445: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 4446: );
1.160.6.21 raeburn 4447: my %staticdefaults = (
4448: anonsurvey_threshold => 10,
4449: uploadquota => 500,
1.160.6.57 raeburn 4450: postsubmit => 60,
1.160.6.70 raeburn 4451: mysqltables => 172800,
1.160.6.21 raeburn 4452: );
1.139 raeburn 4453: if ($position eq 'top') {
1.160.6.57 raeburn 4454: %defaultchecked = (
4455: 'uselcmath' => 'on',
4456: 'usejsme' => 'on',
1.160.6.64 raeburn 4457: 'canclone' => 'none',
1.160.6.57 raeburn 4458: );
4459: @toggles = ('uselcmath','usejsme');
1.160.6.90 raeburn 4460: my $deftex = $Apache::lonnet::deftex;
4461: if (ref($settings) eq 'HASH') {
4462: if ($settings->{'texengine'}) {
4463: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
4464: $deftex = $settings->{'texengine'};
4465: }
4466: }
4467: }
4468: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4469: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
4470: '<span class="LC_nobreak">'.$choices{'texengine'}.
4471: '</span></td><td class="LC_right_item">'.
4472: '<select name="texengine">'."\n";
4473: my %texoptions = (
4474: MathJax => 'MathJax',
4475: mimetex => &mt('Convert to Images'),
4476: tth => &mt('TeX to HTML'),
4477: );
4478: foreach my $renderer ('MathJax','mimetex','tth') {
4479: my $selected = '';
4480: if ($renderer eq $deftex) {
4481: $selected = ' selected="selected"';
4482: }
4483: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
4484: }
4485: $mathdisp .= '</select></td></tr>'."\n";
4486: $itemcount ++;
1.139 raeburn 4487: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4488: \%choices,$itemcount);
1.160.6.90 raeburn 4489: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 4490: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4491: $datatable .=
4492: '<tr'.$css_class.'><td valign="top">'.
4493: '<span class="LC_nobreak">'.$choices{'canclone'}.
4494: '</span></td><td class="LC_left_item">';
4495: my $currcanclone = 'none';
4496: my $onclick;
4497: my @cloneoptions = ('none','domain');
1.160.6.111 raeburn 4498: my %clonetitles = &Apache::lonlocal::texthash (
1.160.6.64 raeburn 4499: none => 'No additional course requesters',
4500: domain => "Any course requester in course's domain",
4501: instcode => 'Course requests for official courses ...',
4502: );
4503: my (%codedefaults,@code_order,@posscodes);
4504: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4505: \@code_order) eq 'ok') {
4506: if (@code_order > 0) {
4507: push(@cloneoptions,'instcode');
4508: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4509: }
4510: }
4511: if (ref($settings) eq 'HASH') {
4512: if ($settings->{'canclone'}) {
4513: if (ref($settings->{'canclone'}) eq 'HASH') {
4514: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4515: if (@code_order > 0) {
4516: $currcanclone = 'instcode';
4517: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4518: }
4519: }
4520: } elsif ($settings->{'canclone'} eq 'domain') {
4521: $currcanclone = $settings->{'canclone'};
4522: }
4523: }
4524: }
4525: foreach my $option (@cloneoptions) {
4526: my ($checked,$additional);
4527: if ($currcanclone eq $option) {
4528: $checked = ' checked="checked"';
4529: }
4530: if ($option eq 'instcode') {
4531: if (@code_order) {
4532: my $show = 'none';
4533: if ($checked) {
4534: $show = 'block';
4535: }
4536: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4537: &mt('Institutional codes for new and cloned course have identical:').
4538: '<br />';
4539: foreach my $item (@code_order) {
4540: my $codechk;
4541: if ($checked) {
4542: if (grep(/^\Q$item\E$/,@posscodes)) {
4543: $codechk = ' checked="checked"';
4544: }
4545: }
4546: $additional .= '<label>'.
4547: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4548: $item.'</label>';
4549: }
4550: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4551: }
4552: }
4553: $datatable .=
4554: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4555: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4556: '</label> '.$additional.'</span><br />';
4557: }
4558: $datatable .= '</td>'.
4559: '</tr>';
4560: $itemcount ++;
1.139 raeburn 4561: } else {
4562: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 4563: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 4564: my $currusecredits = 0;
1.160.6.57 raeburn 4565: my $postsubmitclient = 1;
1.160.6.30 raeburn 4566: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 4567: if (ref($settings) eq 'HASH') {
4568: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 4569: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4570: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4571: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4572: }
4573: }
1.160.6.16 raeburn 4574: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 4575: foreach my $type (@types) {
4576: next if ($type eq 'community');
4577: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4578: if ($defcredits{$type} ne '') {
4579: $currusecredits = 1;
4580: }
4581: }
4582: }
4583: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4584: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4585: $postsubmitclient = 0;
4586: foreach my $type (@types) {
4587: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4588: }
4589: } else {
4590: foreach my $type (@types) {
4591: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4592: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
4593: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
4594: } else {
4595: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4596: }
4597: } else {
4598: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4599: }
4600: }
4601: }
4602: } else {
4603: foreach my $type (@types) {
4604: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 4605: }
4606: }
1.160.6.70 raeburn 4607: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4608: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4609: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4610: }
4611: } else {
4612: foreach my $type (@types) {
4613: $currmysql{$type} = $staticdefaults{'mysqltables'};
4614: }
4615: }
1.160.6.58 raeburn 4616: } else {
4617: foreach my $type (@types) {
4618: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4619: }
1.139 raeburn 4620: }
4621: if (!$currdefresponder) {
1.160.6.21 raeburn 4622: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4623: } elsif ($currdefresponder < 1) {
4624: $currdefresponder = 1;
4625: }
1.160.6.21 raeburn 4626: foreach my $type (@types) {
4627: if ($curruploadquota{$type} eq '') {
4628: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4629: }
4630: }
1.139 raeburn 4631: $datatable .=
1.160.6.16 raeburn 4632: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4633: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4634: '</span></td>'.
4635: '<td class="LC_right_item"><span class="LC_nobreak">'.
4636: '<input type="text" name="anonsurvey_threshold"'.
4637: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 4638: '</td></tr>'."\n";
4639: $itemcount ++;
4640: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4641: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4642: $choices{'uploadquota'}.
4643: '</span></td>'.
4644: '<td align="right" class="LC_right_item">'.
4645: '<table><tr>';
1.160.6.21 raeburn 4646: foreach my $type (@types) {
4647: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4648: '<input type="text" name="uploadquota_'.$type.'"'.
4649: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4650: }
4651: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 4652: $itemcount ++;
1.160.6.40 raeburn 4653: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 4654: my $display = 'none';
4655: if ($currusecredits) {
4656: $display = 'block';
4657: }
4658: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 4659: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4660: foreach my $type (@types) {
4661: next if ($type eq 'community');
4662: $additional .= '<td align="center">'.&mt($type).'<br />'.
4663: '<input type="text" name="'.$type.'_credits"'.
4664: ' value="'.$defcredits{$type}.'" size="3" /></td>';
4665: }
4666: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 4667: %defaultchecked = ('coursecredits' => 'off');
4668: @toggles = ('coursecredits');
4669: my $current = {
4670: 'coursecredits' => $currusecredits,
4671: };
4672: (my $table,$itemcount) =
4673: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4674: \%choices,$itemcount,$onclick,$additional,'left');
4675: $datatable .= $table;
4676: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4677: my $display = 'none';
4678: if ($postsubmitclient) {
4679: $display = 'block';
4680: }
4681: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 4682: &mt('Number of seconds submit is disabled').'<br />'.
4683: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4684: '<table><tr>';
1.160.6.57 raeburn 4685: foreach my $type (@types) {
4686: $additional .= '<td align="center">'.&mt($type).'<br />'.
4687: '<input type="text" name="'.$type.'_timeout" value="'.
4688: $deftimeout{$type}.'" size="5" /></td>';
4689: }
4690: $additional .= '</tr></table></div>'."\n";
4691: %defaultchecked = ('postsubmit' => 'on');
4692: @toggles = ('postsubmit');
1.160.6.70 raeburn 4693: $current = {
4694: 'postsubmit' => $postsubmitclient,
4695: };
1.160.6.57 raeburn 4696: ($table,$itemcount) =
4697: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4698: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 4699: $datatable .= $table;
1.160.6.70 raeburn 4700: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4701: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4702: $choices{'mysqltables'}.
4703: '</span></td>'.
4704: '<td align="right" class="LC_right_item">'.
4705: '<table><tr>';
4706: foreach my $type (@types) {
4707: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4708: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 4709: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 4710: }
4711: $datatable .= '</tr></table></td></tr>'."\n";
4712: $itemcount ++;
4713:
1.160.6.37 raeburn 4714: }
4715: $$rowtotal += $itemcount;
4716: return $datatable;
4717: }
4718:
4719: sub print_selfenrollment {
4720: my ($position,$dom,$settings,$rowtotal) = @_;
4721: my ($css_class,$datatable);
4722: my $itemcount = 1;
4723: my @types = ('official','unofficial','community','textbook');
4724: if (($position eq 'top') || ($position eq 'middle')) {
4725: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4726: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
4727: my @rows;
4728: my $key;
4729: if ($position eq 'top') {
4730: $key = 'admin';
4731: if (ref($rowsref) eq 'ARRAY') {
4732: @rows = @{$rowsref};
4733: }
4734: } elsif ($position eq 'middle') {
4735: $key = 'default';
4736: @rows = ('types','registered','approval','limit');
4737: }
4738: foreach my $row (@rows) {
4739: if (defined($titlesref->{$row})) {
4740: $itemcount ++;
4741: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4742: $datatable .= '<tr'.$css_class.'>'.
4743: '<td>'.$titlesref->{$row}.'</td>'.
4744: '<td class="LC_left_item">'.
4745: '<table><tr>';
4746: my (%current,%currentcap);
4747: if (ref($settings) eq 'HASH') {
4748: if (ref($settings->{$key}) eq 'HASH') {
4749: foreach my $type (@types) {
4750: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4751: $current{$type} = $settings->{$key}->{$type}->{$row};
4752: }
4753: if (($row eq 'limit') && ($key eq 'default')) {
4754: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4755: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4756: }
4757: }
4758: }
4759: }
4760: }
4761: my %roles = (
4762: '0' => &Apache::lonnet::plaintext('dc'),
4763: );
4764:
4765: foreach my $type (@types) {
4766: unless (($row eq 'registered') && ($key eq 'default')) {
4767: $datatable .= '<th>'.&mt($type).'</th>';
4768: }
4769: }
4770: unless (($row eq 'registered') && ($key eq 'default')) {
4771: $datatable .= '</tr><tr>';
4772: }
4773: foreach my $type (@types) {
4774: if ($type eq 'community') {
4775: $roles{'1'} = &mt('Community personnel');
4776: } else {
4777: $roles{'1'} = &mt('Course personnel');
4778: }
4779: $datatable .= '<td style="vertical-align: top">';
4780: if ($position eq 'top') {
4781: my %checked;
4782: if ($current{$type} eq '0') {
4783: $checked{'0'} = ' checked="checked"';
4784: } else {
4785: $checked{'1'} = ' checked="checked"';
4786: }
4787: foreach my $role ('1','0') {
4788: $datatable .= '<span class="LC_nobreak"><label>'.
4789: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4790: 'value="'.$role.'"'.$checked{$role}.' />'.
4791: $roles{$role}.'</label></span> ';
4792: }
4793: } else {
4794: if ($row eq 'types') {
4795: my %checked;
4796: if ($current{$type} =~ /^(all|dom)$/) {
4797: $checked{$1} = ' checked="checked"';
4798: } else {
4799: $checked{''} = ' checked="checked"';
4800: }
4801: foreach my $val ('','dom','all') {
4802: $datatable .= '<span class="LC_nobreak"><label>'.
4803: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4804: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4805: }
4806: } elsif ($row eq 'registered') {
4807: my %checked;
4808: if ($current{$type} eq '1') {
4809: $checked{'1'} = ' checked="checked"';
4810: } else {
4811: $checked{'0'} = ' checked="checked"';
4812: }
4813: foreach my $val ('0','1') {
4814: $datatable .= '<span class="LC_nobreak"><label>'.
4815: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4816: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4817: }
4818: } elsif ($row eq 'approval') {
4819: my %checked;
4820: if ($current{$type} =~ /^([12])$/) {
4821: $checked{$1} = ' checked="checked"';
4822: } else {
4823: $checked{'0'} = ' checked="checked"';
4824: }
4825: for my $val (0..2) {
4826: $datatable .= '<span class="LC_nobreak"><label>'.
4827: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4828: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4829: }
4830: } elsif ($row eq 'limit') {
4831: my %checked;
4832: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4833: $checked{$1} = ' checked="checked"';
4834: } else {
4835: $checked{'none'} = ' checked="checked"';
4836: }
4837: my $cap;
4838: if ($currentcap{$type} =~ /^\d+$/) {
4839: $cap = $currentcap{$type};
4840: }
4841: foreach my $val ('none','allstudents','selfenrolled') {
4842: $datatable .= '<span class="LC_nobreak"><label>'.
4843: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4844: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4845: }
4846: $datatable .= '<br />'.
4847: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4848: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4849: '</span>';
4850: }
4851: }
4852: $datatable .= '</td>';
4853: }
4854: $datatable .= '</tr>';
4855: }
4856: $datatable .= '</table></td></tr>';
4857: }
4858: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 4859: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4860: }
4861: $$rowtotal += $itemcount;
4862: return $datatable;
4863: }
4864:
4865: sub print_validation_rows {
4866: my ($caller,$dom,$settings,$rowtotal) = @_;
4867: my ($itemsref,$namesref,$fieldsref);
4868: if ($caller eq 'selfenroll') {
4869: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4870: } elsif ($caller eq 'requestcourses') {
4871: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4872: }
4873: my %currvalidation;
4874: if (ref($settings) eq 'HASH') {
4875: if (ref($settings->{'validation'}) eq 'HASH') {
4876: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 4877: }
1.160.6.39 raeburn 4878: }
4879: my $datatable;
4880: my $itemcount = 0;
4881: foreach my $item (@{$itemsref}) {
4882: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4883: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4884: $namesref->{$item}.
4885: '</span></td>'.
4886: '<td class="LC_left_item">';
4887: if (($item eq 'url') || ($item eq 'button')) {
4888: $datatable .= '<span class="LC_nobreak">'.
4889: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4890: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4891: } elsif ($item eq 'fields') {
4892: my @currfields;
4893: if (ref($currvalidation{$item}) eq 'ARRAY') {
4894: @currfields = @{$currvalidation{$item}};
4895: }
4896: foreach my $field (@{$fieldsref}) {
4897: my $check = '';
4898: if (grep(/^\Q$field\E$/,@currfields)) {
4899: $check = ' checked="checked"';
4900: }
4901: $datatable .= '<span class="LC_nobreak"><label>'.
4902: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4903: ' value="'.$field.'"'.$check.' />'.$field.
4904: '</label></span> ';
4905: }
4906: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 4907: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 4908: $currvalidation{$item}.
1.160.6.37 raeburn 4909: '</textarea>';
1.160.6.39 raeburn 4910: }
4911: $datatable .= '</td></tr>'."\n";
4912: if (ref($rowtotal)) {
1.160.6.37 raeburn 4913: $itemcount ++;
4914: }
1.139 raeburn 4915: }
1.160.6.39 raeburn 4916: if ($caller eq 'requestcourses') {
4917: my %currhash;
1.160.6.51 raeburn 4918: if (ref($settings) eq 'HASH') {
4919: if (ref($settings->{'validation'}) eq 'HASH') {
4920: if ($settings->{'validation'}{'dc'} ne '') {
4921: $currhash{$settings->{'validation'}{'dc'}} = 1;
4922: }
1.160.6.39 raeburn 4923: }
4924: }
4925: my $numinrow = 2;
4926: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4927: 'validationdc',%currhash);
1.160.6.50 raeburn 4928: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 4929: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 4930: if ($numdc > 1) {
1.160.6.50 raeburn 4931: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 4932: } else {
1.160.6.50 raeburn 4933: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 4934: }
1.160.6.50 raeburn 4935: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 4936: $itemcount ++;
4937: }
4938: if (ref($rowtotal)) {
4939: $$rowtotal += $itemcount;
4940: }
1.121 raeburn 4941: return $datatable;
1.118 jms 4942: }
4943:
1.160.6.98 raeburn 4944: sub print_passwords {
4945: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
4946: my ($datatable,$css_class);
4947: my $itemcount = 0;
4948: my %titles = &Apache::lonlocal::texthash (
4949: captcha => '"Forgot Password" CAPTCHA validation',
4950: link => 'Reset link expiration (hours)',
4951: case => 'Case-sensitive usernames/e-mail',
4952: prelink => 'Information required (form 1)',
4953: postlink => 'Information required (form 2)',
4954: emailsrc => 'LON-CAPA e-mail address type(s)',
4955: customtext => 'Domain specific text (HTML)',
4956: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
4957: intauth_check => 'Check bcrypt cost if authenticated',
4958: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
4959: permanent => 'Permanent e-mail address',
4960: critical => 'Critical notification address',
4961: notify => 'Notification address',
4962: min => 'Minimum password length',
4963: max => 'Maximum password length',
4964: chars => 'Required characters',
4965: numsaved => 'Number of previous passwords to save and disallow reuse',
4966: );
4967: if ($position eq 'top') {
4968: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4969: my $shownlinklife = 2;
4970: my $prelink = 'both';
4971: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
4972: if (ref($settings) eq 'HASH') {
4973: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
4974: $shownlinklife = $settings->{resetlink};
4975: }
4976: if (ref($settings->{resetcase}) eq 'ARRAY') {
4977: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
4978: }
4979: if ($settings->{resetprelink} =~ /^(both|either)$/) {
4980: $prelink = $settings->{resetprelink};
4981: }
4982: if (ref($settings->{resetpostlink}) eq 'HASH') {
4983: %postlink = %{$settings->{resetpostlink}};
4984: }
4985: if (ref($settings->{resetemail}) eq 'ARRAY') {
4986: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
4987: }
4988: if ($settings->{resetremove}) {
4989: $nostdtext = 1;
4990: }
4991: if ($settings->{resetcustom}) {
4992: $customurl = $settings->{resetcustom};
4993: }
4994: } else {
4995: if (ref($types) eq 'ARRAY') {
4996: foreach my $item (@{$types}) {
4997: $casesens{$item} = 1;
4998: $postlink{$item} = ['username','email'];
4999: }
5000: }
5001: $casesens{'default'} = 1;
5002: $postlink{'default'} = ['username','email'];
5003: $prelink = 'both';
5004: %emailsrc = (
5005: permanent => 1,
5006: critical => 1,
5007: notify => 1,
5008: );
5009: }
5010: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
5011: $itemcount ++;
5012: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5013: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
5014: '<td class="LC_left_item">'.
5015: '<input type="textbox" value="'.$shownlinklife.'" '.
5016: 'name="passwords_link" size="3" /></td></tr>';
5017: $itemcount ++;
5018: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5019: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
5020: '<td class="LC_left_item">';
5021: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5022: foreach my $item (@{$types}) {
5023: my $checkedcase;
5024: if ($casesens{$item}) {
5025: $checkedcase = ' checked="checked"';
5026: }
5027: $datatable .= '<span class="LC_nobreak"><label>'.
5028: '<input type="checkbox" name="passwords_case_sensitive" value="'.
5029: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.160.6.104 raeburn 5030: '</span> ';
1.160.6.98 raeburn 5031: }
5032: }
5033: my $checkedcase;
5034: if ($casesens{'default'}) {
5035: $checkedcase = ' checked="checked"';
5036: }
5037: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5038: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
5039: $othertitle.'</label></span></td>';
5040: $itemcount ++;
5041: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5042: my %checkedpre = (
5043: both => ' checked="checked"',
5044: either => '',
5045: );
5046: if ($prelink eq 'either') {
5047: $checkedpre{either} = ' checked="checked"';
5048: $checkedpre{both} = '';
5049: }
5050: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
5051: '<td class="LC_left_item"><span class="LC_nobreak">'.
5052: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
5053: &mt('Both username and e-mail address').'</label></span> '.
5054: '<span class="LC_nobreak"><label>'.
5055: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
5056: &mt('Either username or e-mail address').'</label></span></td></tr>';
5057: $itemcount ++;
5058: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5059: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
5060: '<td class="LC_left_item">';
5061: my %postlinked;
5062: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5063: foreach my $item (@{$types}) {
5064: undef(%postlinked);
5065: $datatable .= '<fieldset style="display: inline-block;">'.
5066: '<legend>'.$usertypes->{$item}.'</legend>';
5067: if (ref($postlink{$item}) eq 'ARRAY') {
5068: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
5069: }
5070: foreach my $field ('email','username') {
5071: my $checked;
5072: if ($postlinked{$field}) {
5073: $checked = ' checked="checked"';
5074: }
5075: $datatable .= '<span class="LC_nobreak"><label>'.
5076: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
5077: $field.'"'.$checked.' />'.$field.'</label>'.
5078: '<span> ';
5079: }
5080: $datatable .= '</fieldset>';
5081: }
5082: }
5083: if (ref($postlink{'default'}) eq 'ARRAY') {
5084: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
5085: }
5086: $datatable .= '<fieldset style="display: inline-block;">'.
5087: '<legend>'.$othertitle.'</legend>';
5088: foreach my $field ('email','username') {
5089: my $checked;
5090: if ($postlinked{$field}) {
5091: $checked = ' checked="checked"';
5092: }
5093: $datatable .= '<span class="LC_nobreak"><label>'.
5094: '<input type="checkbox" name="passwords_postlink_default" value="'.
5095: $field.'"'.$checked.' />'.$field.'</label>'.
5096: '<span> ';
5097: }
5098: $datatable .= '</fieldset></td></tr>';
5099: $itemcount ++;
5100: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5101: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
5102: '<td class="LC_left_item">';
5103: foreach my $type ('permanent','critical','notify') {
5104: my $checkedemail;
5105: if ($emailsrc{$type}) {
5106: $checkedemail = ' checked="checked"';
5107: }
5108: $datatable .= '<span class="LC_nobreak"><label>'.
5109: '<input type="checkbox" name="passwords_emailsrc" value="'.
5110: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
5111: '<span> ';
5112: }
5113: $datatable .= '</td></tr>';
5114: $itemcount ++;
5115: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5116: my $switchserver = &check_switchserver($dom,$confname);
5117: my ($showstd,$noshowstd);
5118: if ($nostdtext) {
5119: $noshowstd = ' checked="checked"';
5120: } else {
5121: $showstd = ' checked="checked"';
5122: }
5123: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
5124: '<td class="LC_left_item"><span class="LC_nobreak">'.
5125: &mt('Retain standard text:').
5126: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
5127: &mt('Yes').'</label>'.' '.
5128: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
5129: &mt('No').'</label></span><br />'.
5130: '<span class="LC_fontsize_small">'.
5131: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
5132: &mt('Include custom text:');
5133: if ($customurl) {
1.160.6.104 raeburn 5134: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.160.6.98 raeburn 5135: undef,undef,undef,undef,'background-color:#ffffff');
5136: $datatable .= '<span class="LC_nobreak"> '.$link.
5137: '<label><input type="checkbox" name="passwords_custom_del"'.
5138: ' value="1" />'.&mt('Delete?').'</label></span>'.
5139: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
5140: }
5141: if ($switchserver) {
5142: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
5143: } else {
5144: $datatable .='<span class="LC_nobreak"> '.
5145: '<input type="file" name="passwords_customfile" /></span>';
5146: }
5147: $datatable .= '</td></tr>';
5148: } elsif ($position eq 'middle') {
5149: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
5150: my @items = ('intauth_cost','intauth_check','intauth_switch');
5151: my %defaults;
5152: if (ref($domconf{'defaults'}) eq 'HASH') {
5153: %defaults = %{$domconf{'defaults'}};
5154: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
5155: $defaults{'intauth_cost'} = 10;
5156: }
5157: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
5158: $defaults{'intauth_check'} = 0;
5159: }
5160: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
5161: $defaults{'intauth_switch'} = 0;
5162: }
5163: } else {
5164: %defaults = (
5165: 'intauth_cost' => 10,
5166: 'intauth_check' => 0,
5167: 'intauth_switch' => 0,
5168: );
5169: }
5170: foreach my $item (@items) {
5171: if ($itemcount%2) {
5172: $css_class = '';
5173: } else {
5174: $css_class = ' class="LC_odd_row" ';
5175: }
5176: $datatable .= '<tr'.$css_class.'>'.
5177: '<td><span class="LC_nobreak">'.$titles{$item}.
5178: '</span></td><td class="LC_left_item" colspan="3">';
5179: if ($item eq 'intauth_switch') {
5180: my @options = (0,1,2);
5181: my %optiondesc = &Apache::lonlocal::texthash (
5182: 0 => 'No',
5183: 1 => 'Yes',
5184: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
5185: );
5186: $datatable .= '<table width="100%">';
5187: foreach my $option (@options) {
5188: my $checked = ' ';
5189: if ($defaults{$item} eq $option) {
5190: $checked = ' checked="checked"';
5191: }
5192: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5193: '<label><input type="radio" name="'.$item.
5194: '" value="'.$option.'"'.$checked.' />'.
5195: $optiondesc{$option}.'</label></span></td></tr>';
5196: }
5197: $datatable .= '</table>';
5198: } elsif ($item eq 'intauth_check') {
5199: my @options = (0,1,2);
5200: my %optiondesc = &Apache::lonlocal::texthash (
5201: 0 => 'No',
5202: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
5203: 2 => 'Yes, disallow login if stored cost is less than domain default',
5204: );
5205: $datatable .= '<table width="100%">';
5206: foreach my $option (@options) {
5207: my $checked = ' ';
5208: my $onclick;
5209: if ($defaults{$item} eq $option) {
5210: $checked = ' checked="checked"';
5211: }
5212: if ($option == 2) {
5213: $onclick = ' onclick="javascript:warnIntAuth(this);"';
5214: }
5215: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5216: '<label><input type="radio" name="'.$item.
5217: '" value="'.$option.'"'.$checked.$onclick.' />'.
5218: $optiondesc{$option}.'</label></span></td></tr>';
5219: }
5220: $datatable .= '</table>';
5221: } else {
5222: $datatable .= '<input type="text" name="'.$item.'" value="'.
5223: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
5224: }
5225: $datatable .= '</td></tr>';
5226: $itemcount ++;
5227: }
5228: } elsif ($position eq 'lower') {
5229: my ($min,$max,%chars,$numsaved);
1.160.6.99 raeburn 5230: $min = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 5231: if (ref($settings) eq 'HASH') {
5232: if ($settings->{min}) {
5233: $min = $settings->{min};
5234: }
5235: if ($settings->{max}) {
5236: $max = $settings->{max};
5237: }
5238: if (ref($settings->{chars}) eq 'ARRAY') {
5239: map { $chars{$_} = 1; } (@{$settings->{chars}});
5240: }
5241: if ($settings->{numsaved}) {
5242: $numsaved = $settings->{numsaved};
5243: }
5244: }
5245: my %rulenames = &Apache::lonlocal::texthash(
5246: uc => 'At least one upper case letter',
5247: lc => 'At least one lower case letter',
5248: num => 'At least one number',
5249: spec => 'At least one non-alphanumeric',
5250: );
5251: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5252: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
5253: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 5254: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
5255: 'onblur="javascript:warnIntPass(this);" />'.
5256: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.160.6.98 raeburn 5257: '</span></td></tr>';
5258: $itemcount ++;
5259: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5260: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
5261: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 5262: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
5263: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 5264: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
5265: '</span></td></tr>';
5266: $itemcount ++;
5267: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5268: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
5269: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
5270: '</span></td>';
5271: my $numinrow = 2;
5272: my @possrules = ('uc','lc','num','spec');
5273: $datatable .= '<td class="LC_left_item"><table>';
5274: for (my $i=0; $i<@possrules; $i++) {
5275: my ($rem,$checked);
5276: if ($chars{$possrules[$i]}) {
5277: $checked = ' checked="checked"';
5278: }
5279: $rem = $i%($numinrow);
5280: if ($rem == 0) {
5281: if ($i > 0) {
5282: $datatable .= '</tr>';
5283: }
5284: $datatable .= '<tr>';
5285: }
5286: $datatable .= '<td><span class="LC_nobreak"><label>'.
5287: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
5288: $rulenames{$possrules[$i]}.'</label></span></td>';
5289: }
5290: my $rem = @possrules%($numinrow);
5291: my $colsleft = $numinrow - $rem;
5292: if ($colsleft > 1 ) {
5293: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5294: ' </td>';
5295: } elsif ($colsleft == 1) {
5296: $datatable .= '<td class="LC_left_item"> </td>';
5297: }
5298: $datatable .='</table></td></tr>';
5299: $itemcount ++;
5300: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5301: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
5302: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.100 raeburn 5303: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
1.160.6.99 raeburn 5304: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 5305: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
5306: '</span></td></tr>';
5307: } else {
5308: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5309: my %ownerchg = (
5310: by => {},
5311: for => {},
5312: );
5313: my %ownertitles = &Apache::lonlocal::texthash (
5314: by => 'Course owner status(es) allowed',
5315: for => 'Student status(es) allowed',
5316: );
5317: if (ref($settings) eq 'HASH') {
5318: if (ref($settings->{crsownerchg}) eq 'HASH') {
5319: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
5320: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
5321: }
5322: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
5323: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
5324: }
5325: }
5326: }
5327: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5328: $datatable .= '<tr '.$css_class.'>'.
5329: '<td>'.
5330: &mt('Requirements').'<ul>'.
5331: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
5332: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
5333: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
5334: '<li>'.&mt('User, course, and student share same domain').'</li>'.
5335: '</ul>'.
5336: '</td>'.
5337: '<td class="LC_left_item">';
5338: foreach my $item ('by','for') {
5339: $datatable .= '<fieldset style="display: inline-block;">'.
5340: '<legend>'.$ownertitles{$item}.'</legend>';
5341: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5342: foreach my $type (@{$types}) {
5343: my $checked;
5344: if ($ownerchg{$item}{$type}) {
5345: $checked = ' checked="checked"';
5346: }
5347: $datatable .= '<span class="LC_nobreak"><label>'.
5348: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
5349: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.160.6.104 raeburn 5350: '</span> ';
1.160.6.98 raeburn 5351: }
5352: }
5353: my $checked;
5354: if ($ownerchg{$item}{'default'}) {
5355: $checked = ' checked="checked"';
5356: }
5357: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5358: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
5359: $othertitle.'</label></span></fieldset>';
5360: }
5361: $datatable .= '</td></tr>';
5362: }
5363: return $datatable;
5364: }
5365:
1.160.6.113 raeburn 5366: sub print_wafproxy {
5367: my ($position,$dom,$settings,$rowtotal) = @_;
5368: my $css_class;
5369: my $itemcount = 0;
5370: my $datatable;
5371: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5372: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
5373: my %lt = &wafproxy_titles();
5374: foreach my $server (sort(keys(%servers))) {
5375: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
5376: next if ($serverhome eq '');
5377: my $serverdom;
5378: if ($serverhome ne $server) {
5379: $serverdom = &Apache::lonnet::host_domain($serverhome);
5380: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
5381: $othercontrol{$server} = $serverdom;
5382: }
5383: } else {
5384: $serverdom = &Apache::lonnet::host_domain($server);
5385: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
5386: if ($serverdom ne $dom) {
5387: $othercontrol{$server} = $serverdom;
5388: } else {
5389: $setdom = 1;
5390: if (ref($settings) eq 'HASH') {
5391: if (ref($settings->{'alias'}) eq 'HASH') {
5392: $aliases{$dom} = $settings->{'alias'};
5393: if ($aliases{$dom} ne '') {
5394: $showdom = 1;
5395: }
5396: }
5397: if (ref($settings->{'saml'}) eq 'HASH') {
5398: $saml{$dom} = $settings->{'saml'};
5399: }
5400: }
5401: }
5402: }
5403: }
5404: if ($setdom) {
5405: %{$values{$dom}} = ();
5406: if (ref($settings) eq 'HASH') {
5407: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
5408: $values{$dom}{$item} = $settings->{$item};
5409: }
5410: }
5411: }
5412: if (keys(%othercontrol)) {
5413: %otherdoms = reverse(%othercontrol);
5414: foreach my $domain (keys(%otherdoms)) {
5415: %{$values{$domain}} = ();
5416: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
5417: if (ref($config{'wafproxy'}) eq 'HASH') {
5418: $aliases{$domain} = $config{'wafproxy'}{'alias'};
5419: if (exists($config{'wafproxy'}{'saml'})) {
5420: $saml{$domain} = $config{'wafproxy'}{'saml'};
5421: }
5422: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
5423: $values{$domain}{$item} = $config{'wafproxy'}{$item};
5424: }
5425: }
5426: }
5427: }
5428: if ($position eq 'top') {
5429: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5430: my %aliasinfo;
5431: foreach my $server (sort(keys(%servers))) {
5432: $itemcount ++;
5433: my $dom_in_effect;
5434: my $aliasrows = '<tr>'.
5435: '<td class="LC_left_item" style="vertical-align: baseline;">'.
5436: &mt('Hostname').': '.
5437: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
5438: if ($othercontrol{$server}) {
5439: $dom_in_effect = $othercontrol{$server};
5440: my ($current,$forsaml);
5441: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
5442: $current = $aliases{$dom_in_effect}{$server};
5443: }
5444: if (ref($saml{$dom_in_effect}) eq 'HASH') {
5445: if ($saml{$dom_in_effect}{$server}) {
5446: $forsaml = 1;
5447: }
5448: }
5449: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
5450: &mt('Alias').': ';
5451: if ($current) {
5452: $aliasrows .= $current;
5453: if ($forsaml) {
5454: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
5455: }
5456: } else {
5457: $aliasrows .= &mt('None');
5458: }
5459: $aliasrows .= ' <span class="LC_small">('.
5460: &mt('controlled by domain: [_1]',
5461: '<b>'.$dom_in_effect.'</b>').')</span></td>';
5462: } else {
5463: $dom_in_effect = $dom;
5464: my ($current,$samlon,$samloff);
5465: $samloff = ' checked="checked"';
5466: if (ref($aliases{$dom}) eq 'HASH') {
5467: if ($aliases{$dom}{$server}) {
5468: $current = $aliases{$dom}{$server};
5469: }
5470: }
5471: if (ref($saml{$dom}) eq 'HASH') {
5472: if ($saml{$dom}{$server}) {
5473: $samlon = $samloff;
5474: undef($samloff);
5475: }
5476: }
5477: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
5478: &mt('Alias').': '.
5479: '<input type="text" name="wafproxy_alias_'.$server.'" '.
5480: 'value="'.$current.'" size="30" />'.
5481: (' 'x2).'<span class="LC_nobreak">'.
5482: &mt('Alias used for SSO Auth').': <label>'.
5483: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
5484: &mt('No').'</label> <label>'.
5485: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
5486: &mt('Yes').'</label></span>'.
5487: '</td>';
5488: }
5489: $aliasrows .= '</tr>';
5490: $aliasinfo{$dom_in_effect} .= $aliasrows;
5491: }
5492: if ($aliasinfo{$dom}) {
5493: my ($onclick,$wafon,$wafoff,$showtable);
5494: $onclick = ' onclick="javascript:toggleWAF();"';
5495: $wafoff = ' checked="checked"';
5496: $showtable = ' style="display:none";';
5497: if ($showdom) {
5498: $wafon = $wafoff;
5499: $wafoff = '';
5500: $showtable = ' style="display:inline;"';
5501: }
5502: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5503: $datatable = '<tr'.$css_class.'>'.
5504: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
5505: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
5506: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
5507: &mt('Yes').'</label>'.(' 'x2).'<label>'.
5508: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
5509: &mt('No').'</label></span></td>'.
5510: '<td class="LC_left_item">'.
5511: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
5512: '</table></td></tr>';
5513: $itemcount++;
5514: }
5515: if (keys(%otherdoms)) {
5516: foreach my $key (sort(keys(%otherdoms))) {
5517: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5518: $datatable .= '<tr'.$css_class.'>'.
5519: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
5520: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
5521: '</table></td></tr>';
5522: $itemcount++;
5523: }
5524: }
5525: } else {
5526: my %ip_methods = &remoteip_methods();
5527: if ($setdom) {
5528: $itemcount ++;
5529: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5530: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
5531: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
5532: $wafstyle = ' style="display:none;"';
5533: $nowafstyle = ' style="display:table-row;"';
5534: $currwafdisplay = ' style="display: none"';
5535: $wafrangestyle = ' style="display: none"';
5536: $curr_remotip = 'n';
5537: $ssltossl = ' checked="checked"';
5538: if ($showdom) {
5539: $wafstyle = ' style="display:table-row;"';
5540: $nowafstyle = ' style="display:none;"';
5541: if (keys(%{$values{$dom}})) {
5542: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
5543: $curr_remotip = $values{$dom}{remoteip};
5544: }
5545: if ($curr_remotip eq 'h') {
5546: $currwafdisplay = ' style="display:table-row"';
5547: $wafrangestyle = ' style="display:inline-block;"';
5548: }
5549: if ($values{$dom}{'sslopt'}) {
5550: $alltossl = ' checked="checked"';
5551: $ssltossl = '';
5552: }
5553: }
5554: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
5555: $vpndircheck = ' checked="checked"';
5556: $currwafvpn = ' style="display:table-row;"';
5557: $wafrangestyle = ' style="display:inline-block;"';
5558: } else {
5559: $vpnaliascheck = ' checked="checked"';
5560: $currwafvpn = ' style="display:none;"';
5561: }
5562: }
5563: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
5564: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
5565: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
5566: '</tr>'.
5567: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
5568: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
5569: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
5570: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
5571: &mt('Range(s) stored in CIDR notation').'</div></td>'.
5572: '<td class="LC_left_item"><table>'.
5573: '<tr>'.
5574: '<td valign="top">'.$lt{'remoteip'}.': '.
5575: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
5576: foreach my $option ('m','h','n') {
5577: my $sel;
1.160.6.114! raeburn 5578: if ($option eq $curr_remotip) {
! 5579: $sel = ' selected="selected"';
! 5580: }
! 5581: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
! 5582: $ip_methods{$option}.'</option>';
! 5583: }
! 5584: $datatable .= '</select></td></tr>'."\n".
! 5585: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
! 5586: $lt{'ipheader'}.': '.
! 5587: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
! 5588: 'name="wafproxy_ipheader" />'.
! 5589: '</td></tr>'."\n".
! 5590: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
! 5591: $lt{'trusted'}.':<br />'.
! 5592: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
! 5593: $values{$dom}{'trusted'}.'</textarea>'.
! 5594: '</td></tr>'."\n".
! 5595: '<tr><td><hr /></td></tr>'."\n".
! 5596: '<tr>'.
1.160.6.113 raeburn 5597: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
5598: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
5599: $lt{'vpndirect'}.'</label>'.(' 'x2).
5600: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
5601: $lt{'vpnaliased'}.'</label></span></td></tr>';
5602: foreach my $item ('vpnint','vpnext') {
5603: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
5604: '<td valign="top">'.$lt{$item}.':<br />'.
5605: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
5606: $values{$dom}{$item}.'</textarea>'.
5607: '</td></tr>'."\n";
5608: }
5609: $datatable .= '<tr><td><hr /></td></tr>'."\n".
5610: '<tr>'.
5611: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
5612: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
5613: $lt{'alltossl'}.'</label>'.(' 'x2).
5614: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
5615: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
5616: '</table></td></tr>';
5617: }
5618: if (keys(%otherdoms)) {
5619: foreach my $domain (sort(keys(%otherdoms))) {
5620: $itemcount ++;
5621: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5622: $datatable .= '<tr'.$css_class.'>'.
5623: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
5624: '<td class="LC_left_item"><table>';
5625: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
5626: my $showval = &mt('None');
5627: if ($item eq 'ssl') {
5628: $showval = $lt{'ssltossl'};
5629: }
5630: if ($values{$domain}{$item}) {
5631: $showval = $values{$domain}{$item};
5632: if ($item eq 'ssl') {
5633: $showval = $lt{'alltossl'};
5634: } elsif ($item eq 'remoteip') {
5635: $showval = $ip_methods{$values{$domain}{$item}};
5636: }
5637: }
5638: $datatable .= '<tr>'.
5639: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
5640: }
5641: $datatable .= '</table></td></tr>';
5642: }
5643: }
5644: }
5645: $$rowtotal += $itemcount;
5646: return $datatable;
5647: }
5648:
5649: sub wafproxy_titles {
5650: return &Apache::lonlocal::texthash(
5651: remoteip => "Method for determining user's IP",
5652: ipheader => 'Request header containing remote IP',
5653: trusted => 'Trusted IP range(s)',
5654: vpnaccess => 'Access from institutional VPN',
5655: vpndirect => 'via regular hostname (no WAF)',
5656: vpnaliased => 'via aliased hostname (WAF)',
5657: vpnint => 'Internal IP Range(s) for VPN sessions',
5658: vpnext => 'IP Range(s) for backend WAF connections',
5659: sslopt => 'Forwarding http/https',
5660: alltossl => 'WAF forwards both http and https requests to https',
5661: ssltossl => 'WAF forwards http requests to http and https to https',
5662: );
5663: }
5664:
5665: sub remoteip_methods {
5666: return &Apache::lonlocal::texthash(
5667: m => 'Use Apache mod_remoteip',
5668: h => 'Use headers parsed by LON-CAPA',
5669: n => 'Not in use',
5670: );
5671: }
5672:
1.137 raeburn 5673: sub print_usersessions {
5674: my ($position,$dom,$settings,$rowtotal) = @_;
5675: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 5676: my (%by_ip,%by_location,@intdoms);
5677: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 5678:
5679: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 5680: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 5681: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 5682: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 5683: my $itemcount = 1;
5684: if ($position eq 'top') {
1.152 raeburn 5685: if (keys(%serverhomes) > 1) {
1.145 raeburn 5686: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.105 raeburn 5687: my ($curroffloadnow,$curroffloadoth);
1.160.6.61 raeburn 5688: if (ref($settings) eq 'HASH') {
5689: if (ref($settings->{'offloadnow'}) eq 'HASH') {
5690: $curroffloadnow = $settings->{'offloadnow'};
5691: }
1.160.6.105 raeburn 5692: if (ref($settings->{'offloadoth'}) eq 'HASH') {
5693: $curroffloadoth = $settings->{'offloadoth'};
5694: }
1.160.6.61 raeburn 5695: }
1.160.6.105 raeburn 5696: my $other_insts = scalar(keys(%by_location));
5697: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
5698: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 5699: } else {
1.140 raeburn 5700: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 5701: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 5702: }
1.137 raeburn 5703: } else {
1.145 raeburn 5704: if (keys(%by_location) == 0) {
5705: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 5706: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 5707: } else {
5708: my %lt = &usersession_titles();
5709: my $numinrow = 5;
5710: my $prefix;
5711: my @types;
5712: if ($position eq 'bottom') {
5713: $prefix = 'remote';
5714: @types = ('version','excludedomain','includedomain');
5715: } else {
5716: $prefix = 'hosted';
5717: @types = ('excludedomain','includedomain');
5718: }
5719: my (%current,%checkedon,%checkedoff);
5720: my @lcversions = &Apache::lonnet::all_loncaparevs();
5721: my @locations = sort(keys(%by_location));
5722: foreach my $type (@types) {
5723: $checkedon{$type} = '';
5724: $checkedoff{$type} = ' checked="checked"';
5725: }
5726: if (ref($settings) eq 'HASH') {
5727: if (ref($settings->{$prefix}) eq 'HASH') {
5728: foreach my $key (keys(%{$settings->{$prefix}})) {
5729: $current{$key} = $settings->{$prefix}{$key};
5730: if ($key eq 'version') {
5731: if ($current{$key} ne '') {
5732: $checkedon{$key} = ' checked="checked"';
5733: $checkedoff{$key} = '';
5734: }
5735: } elsif (ref($current{$key}) eq 'ARRAY') {
5736: $checkedon{$key} = ' checked="checked"';
5737: $checkedoff{$key} = '';
5738: }
1.137 raeburn 5739: }
5740: }
5741: }
1.145 raeburn 5742: foreach my $type (@types) {
5743: next if ($type ne 'version' && !@locations);
5744: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5745: $datatable .= '<tr'.$css_class.'>
5746: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
5747: <span class="LC_nobreak">
5748: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
5749: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
5750: if ($type eq 'version') {
5751: my $selector = '<select name="'.$prefix.'_version">';
5752: foreach my $version (@lcversions) {
5753: my $selected = '';
5754: if ($current{'version'} eq $version) {
5755: $selected = ' selected="selected"';
5756: }
5757: $selector .= ' <option value="'.$version.'"'.
5758: $selected.'>'.$version.'</option>';
5759: }
5760: $selector .= '</select> ';
5761: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
5762: } else {
5763: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
5764: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
5765: ' />'.(' 'x2).
5766: '<input type="button" value="'.&mt('uncheck all').'" '.
5767: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
5768: "\n".
5769: '</div><div><table>';
5770: my $rem;
5771: for (my $i=0; $i<@locations; $i++) {
5772: my ($showloc,$value,$checkedtype);
5773: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
5774: my $ip = $by_location{$locations[$i]}->[0];
5775: if (ref($by_ip{$ip}) eq 'ARRAY') {
5776: $value = join(':',@{$by_ip{$ip}});
5777: $showloc = join(', ',@{$by_ip{$ip}});
5778: if (ref($current{$type}) eq 'ARRAY') {
5779: foreach my $loc (@{$by_ip{$ip}}) {
5780: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
5781: $checkedtype = ' checked="checked"';
5782: last;
5783: }
5784: }
1.138 raeburn 5785: }
5786: }
5787: }
1.145 raeburn 5788: $rem = $i%($numinrow);
5789: if ($rem == 0) {
5790: if ($i > 0) {
5791: $datatable .= '</tr>';
5792: }
5793: $datatable .= '<tr>';
5794: }
5795: $datatable .= '<td class="LC_left_item">'.
5796: '<span class="LC_nobreak"><label>'.
5797: '<input type="checkbox" name="'.$prefix.'_'.$type.
5798: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
5799: '</label></span></td>';
1.137 raeburn 5800: }
1.145 raeburn 5801: $rem = @locations%($numinrow);
5802: my $colsleft = $numinrow - $rem;
5803: if ($colsleft > 1 ) {
5804: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5805: ' </td>';
5806: } elsif ($colsleft == 1) {
5807: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 5808: }
1.145 raeburn 5809: $datatable .= '</tr></table>';
1.137 raeburn 5810: }
1.145 raeburn 5811: $datatable .= '</td></tr>';
5812: $itemcount ++;
1.137 raeburn 5813: }
5814: }
5815: }
5816: $$rowtotal += $itemcount;
5817: return $datatable;
5818: }
5819:
1.138 raeburn 5820: sub build_location_hashes {
5821: my ($intdoms,$by_ip,$by_location) = @_;
5822: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
5823: (ref($by_location) eq 'HASH'));
5824: my %iphost = &Apache::lonnet::get_iphost();
5825: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
5826: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
5827: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
5828: foreach my $id (@{$iphost{$primary_ip}}) {
5829: my $intdom = &Apache::lonnet::internet_dom($id);
5830: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
5831: push(@{$intdoms},$intdom);
5832: }
5833: }
5834: }
5835: foreach my $ip (keys(%iphost)) {
5836: if (ref($iphost{$ip}) eq 'ARRAY') {
5837: foreach my $id (@{$iphost{$ip}}) {
5838: my $location = &Apache::lonnet::internet_dom($id);
5839: if ($location) {
5840: next if (grep(/^\Q$location\E$/,@{$intdoms}));
5841: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5842: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
5843: push(@{$by_ip->{$ip}},$location);
5844: }
5845: } else {
5846: $by_ip->{$ip} = [$location];
5847: }
5848: }
5849: }
5850: }
5851: }
5852: foreach my $ip (sort(keys(%{$by_ip}))) {
5853: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5854: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
5855: my $first = $by_ip->{$ip}->[0];
5856: if (ref($by_location->{$first}) eq 'ARRAY') {
5857: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
5858: push(@{$by_location->{$first}},$ip);
5859: }
5860: } else {
5861: $by_location->{$first} = [$ip];
5862: }
5863: }
5864: }
5865: return;
5866: }
5867:
1.145 raeburn 5868: sub current_offloads_to {
5869: my ($dom,$settings,$servers) = @_;
5870: my (%spareid,%otherdomconfigs);
1.152 raeburn 5871: if (ref($servers) eq 'HASH') {
1.145 raeburn 5872: foreach my $lonhost (sort(keys(%{$servers}))) {
5873: my $gotspares;
1.152 raeburn 5874: if (ref($settings) eq 'HASH') {
5875: if (ref($settings->{'spares'}) eq 'HASH') {
5876: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
5877: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
5878: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
5879: $gotspares = 1;
5880: }
1.145 raeburn 5881: }
5882: }
5883: unless ($gotspares) {
5884: my $gotspares;
5885: my $serverhomeID =
5886: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
5887: my $serverhomedom =
5888: &Apache::lonnet::host_domain($serverhomeID);
5889: if ($serverhomedom ne $dom) {
5890: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
5891: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5892: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5893: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5894: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5895: $gotspares = 1;
5896: }
5897: }
5898: } else {
5899: $otherdomconfigs{$serverhomedom} =
5900: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
5901: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
5902: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5903: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5904: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
5905: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5906: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5907: $gotspares = 1;
5908: }
5909: }
5910: }
5911: }
5912: }
5913: }
5914: }
5915: unless ($gotspares) {
5916: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
5917: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5918: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5919: } else {
5920: my $server_hostname = &Apache::lonnet::hostname($lonhost);
5921: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
5922: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
5923: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5924: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5925: } else {
1.150 raeburn 5926: my %what = (
5927: spareid => 1,
5928: );
5929: my ($result,$returnhash) =
5930: &Apache::lonnet::get_remote_globals($lonhost,\%what);
5931: if ($result eq 'ok') {
5932: if (ref($returnhash) eq 'HASH') {
5933: if (ref($returnhash->{'spareid'}) eq 'HASH') {
5934: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
5935: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
5936: }
5937: }
1.145 raeburn 5938: }
5939: }
5940: }
5941: }
5942: }
5943: }
5944: return %spareid;
5945: }
5946:
5947: sub spares_row {
1.160.6.105 raeburn 5948: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
5949: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 5950: my $css_class;
5951: my $numinrow = 4;
5952: my $itemcount = 1;
5953: my $datatable;
1.152 raeburn 5954: my %typetitles = &sparestype_titles();
5955: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 5956: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 5957: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
5958: my ($othercontrol,$serverdom);
5959: if ($serverhome ne $server) {
5960: $serverdom = &Apache::lonnet::host_domain($serverhome);
5961: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5962: } else {
5963: $serverdom = &Apache::lonnet::host_domain($server);
5964: if ($serverdom ne $dom) {
5965: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5966: }
5967: }
5968: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.105 raeburn 5969: my ($checkednow,$checkedoth);
1.160.6.61 raeburn 5970: if (ref($curroffloadnow) eq 'HASH') {
5971: if ($curroffloadnow->{$server}) {
5972: $checkednow = ' checked="checked"';
5973: }
5974: }
1.160.6.105 raeburn 5975: if (ref($curroffloadoth) eq 'HASH') {
5976: if ($curroffloadoth->{$server}) {
5977: $checkedoth = ' checked="checked"';
5978: }
5979: }
1.145 raeburn 5980: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5981: $datatable .= '<tr'.$css_class.'>
5982: <td rowspan="2">
1.160.6.13 raeburn 5983: <span class="LC_nobreak">'.
5984: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 5985: ,'<b>'.$server.'</b>').'</span><br />'.
5986: '<span class="LC_nobreak">'."\n".
5987: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.160.6.105 raeburn 5988: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.160.6.13 raeburn 5989: "\n";
1.160.6.105 raeburn 5990: if ($other_insts) {
5991: $datatable .= '<br />'.
5992: '<span class="LC_nobreak">'."\n".
5993: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
5994: ' '.&mt('Switch other institutions on next access').'</label></span>'.
5995: "\n";
5996: }
1.145 raeburn 5997: my (%current,%canselect);
1.152 raeburn 5998: my @choices =
5999: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6000: foreach my $type ('primary','default') {
6001: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 6002: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6003: my @spares = @{$spareid->{$server}{$type}};
6004: if (@spares > 0) {
1.152 raeburn 6005: if ($othercontrol) {
6006: $current{$type} = join(', ',@spares);
6007: } else {
6008: $current{$type} .= '<table>';
6009: my $numspares = scalar(@spares);
6010: for (my $i=0; $i<@spares; $i++) {
6011: my $rem = $i%($numinrow);
6012: if ($rem == 0) {
6013: if ($i > 0) {
6014: $current{$type} .= '</tr>';
6015: }
6016: $current{$type} .= '<tr>';
1.145 raeburn 6017: }
1.152 raeburn 6018: $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'".');" /> '.
6019: $spareid->{$server}{$type}[$i].
6020: '</label></td>'."\n";
6021: }
6022: my $rem = @spares%($numinrow);
6023: my $colsleft = $numinrow - $rem;
6024: if ($colsleft > 1 ) {
6025: $current{$type} .= '<td colspan="'.$colsleft.
6026: '" class="LC_left_item">'.
6027: ' </td>';
6028: } elsif ($colsleft == 1) {
6029: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 6030: }
1.152 raeburn 6031: $current{$type} .= '</tr></table>';
1.150 raeburn 6032: }
1.145 raeburn 6033: }
6034: }
6035: if ($current{$type} eq '') {
6036: $current{$type} = &mt('None specified');
6037: }
1.152 raeburn 6038: if ($othercontrol) {
6039: if ($type eq 'primary') {
6040: $canselect{$type} = $othercontrol;
6041: }
6042: } else {
6043: $canselect{$type} =
6044: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
6045: '<select name="newspare_'.$type.'_'.$server.'" '.
6046: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
6047: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
6048: if (@choices > 0) {
6049: foreach my $lonhost (@choices) {
6050: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
6051: }
6052: }
6053: $canselect{$type} .= '</select>'."\n";
6054: }
6055: } else {
6056: $current{$type} = &mt('Could not be determined');
6057: if ($type eq 'primary') {
6058: $canselect{$type} = $othercontrol;
6059: }
1.145 raeburn 6060: }
1.152 raeburn 6061: if ($type eq 'default') {
6062: $datatable .= '<tr'.$css_class.'>';
6063: }
6064: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
6065: '<td>'.$current{$type}.'</td>'."\n".
6066: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 6067: }
6068: $itemcount ++;
6069: }
6070: }
6071: $$rowtotal += $itemcount;
6072: return $datatable;
6073: }
6074:
1.152 raeburn 6075: sub possible_newspares {
6076: my ($server,$currspares,$serverhomes,$altids) = @_;
6077: my $serverhostname = &Apache::lonnet::hostname($server);
6078: my %excluded;
6079: if ($serverhostname ne '') {
6080: %excluded = (
6081: $serverhostname => 1,
6082: );
6083: }
6084: if (ref($currspares) eq 'HASH') {
6085: foreach my $type (keys(%{$currspares})) {
6086: if (ref($currspares->{$type}) eq 'ARRAY') {
6087: if (@{$currspares->{$type}} > 0) {
6088: foreach my $curr (@{$currspares->{$type}}) {
6089: my $hostname = &Apache::lonnet::hostname($curr);
6090: $excluded{$hostname} = 1;
6091: }
6092: }
6093: }
6094: }
6095: }
6096: my @choices;
6097: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
6098: if (keys(%{$serverhomes}) > 1) {
6099: foreach my $name (sort(keys(%{$serverhomes}))) {
6100: unless ($excluded{$name}) {
6101: if (exists($altids->{$serverhomes->{$name}})) {
6102: push(@choices,$altids->{$serverhomes->{$name}});
6103: } else {
6104: push(@choices,$serverhomes->{$name});
1.145 raeburn 6105: }
6106: }
6107: }
6108: }
6109: }
1.152 raeburn 6110: return sort(@choices);
1.145 raeburn 6111: }
6112:
1.150 raeburn 6113: sub print_loadbalancing {
6114: my ($dom,$settings,$rowtotal) = @_;
6115: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6116: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6117: my $numinrow = 1;
6118: my $datatable;
6119: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 6120: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 6121: if (ref($settings) eq 'HASH') {
6122: %existing = %{$settings};
6123: }
6124: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
6125: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 6126: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 6127: } else {
6128: return;
6129: }
6130: my ($othertitle,$usertypes,$types) =
6131: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 6132: my $rownum = 8;
1.150 raeburn 6133: if (ref($types) eq 'ARRAY') {
6134: $rownum += scalar(@{$types});
6135: }
1.160.6.7 raeburn 6136: my @css_class = ('LC_odd_row','LC_even_row');
6137: my $balnum = 0;
6138: my $islast;
6139: my (@toshow,$disabledtext);
6140: if (keys(%currbalancer) > 0) {
6141: @toshow = sort(keys(%currbalancer));
6142: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
6143: push(@toshow,'');
6144: }
6145: } else {
6146: @toshow = ('');
6147: $disabledtext = &mt('No existing load balancer');
6148: }
6149: foreach my $lonhost (@toshow) {
6150: if ($balnum == scalar(@toshow)-1) {
6151: $islast = 1;
6152: } else {
6153: $islast = 0;
6154: }
6155: my $cssidx = $balnum%2;
6156: my $targets_div_style = 'display: none';
6157: my $disabled_div_style = 'display: block';
6158: my $homedom_div_style = 'display: none';
6159: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
6160: '<td rowspan="'.$rownum.'" valign="top">'.
6161: '<p>';
6162: if ($lonhost eq '') {
6163: $datatable .= '<span class="LC_nobreak">';
6164: if (keys(%currbalancer) > 0) {
6165: $datatable .= &mt('Add balancer:');
6166: } else {
6167: $datatable .= &mt('Enable balancer:');
6168: }
6169: $datatable .= ' '.
6170: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
6171: ' id="loadbalancing_lonhost_'.$balnum.'"'.
6172: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
6173: '<option value="" selected="selected">'.&mt('None').
6174: '</option>'."\n";
6175: foreach my $server (sort(keys(%servers))) {
6176: next if ($currbalancer{$server});
6177: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
6178: }
6179: $datatable .=
6180: '</select>'."\n".
6181: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
6182: } else {
6183: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
6184: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
6185: &mt('Stop balancing').'</label>'.
6186: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
6187: $targets_div_style = 'display: block';
6188: $disabled_div_style = 'display: none';
6189: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
6190: $homedom_div_style = 'display: block';
6191: }
6192: }
6193: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
6194: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
6195: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
6196: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
6197: my ($numspares,@spares) = &count_servers($lonhost,%servers);
6198: my @sparestypes = ('primary','default');
6199: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 6200: my %hostherechecked = (
6201: no => ' checked="checked"',
6202: );
1.160.6.94 raeburn 6203: my %balcookiechecked = (
6204: no => ' checked="checked"',
6205: );
1.160.6.7 raeburn 6206: foreach my $sparetype (@sparestypes) {
6207: my $targettable;
6208: for (my $i=0; $i<$numspares; $i++) {
6209: my $checked;
6210: if (ref($currtargets{$lonhost}) eq 'HASH') {
6211: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6212: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6213: $checked = ' checked="checked"';
6214: }
6215: }
6216: }
6217: my ($chkboxval,$disabled);
6218: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
6219: $chkboxval = $spares[$i];
6220: }
6221: if (exists($currbalancer{$spares[$i]})) {
6222: $disabled = ' disabled="disabled"';
6223: }
6224: $targettable .=
1.160.6.55 raeburn 6225: '<td><span class="LC_nobreak"><label>'.
6226: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 6227: $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 6228: '</span></label></span></td>';
1.160.6.7 raeburn 6229: my $rem = $i%($numinrow);
6230: if ($rem == 0) {
6231: if (($i > 0) && ($i < $numspares-1)) {
6232: $targettable .= '</tr>';
6233: }
6234: if ($i < $numspares-1) {
6235: $targettable .= '<tr>';
1.150 raeburn 6236: }
6237: }
6238: }
1.160.6.7 raeburn 6239: if ($targettable ne '') {
6240: my $rem = $numspares%($numinrow);
6241: my $colsleft = $numinrow - $rem;
6242: if ($colsleft > 1 ) {
6243: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6244: ' </td>';
6245: } elsif ($colsleft == 1) {
6246: $targettable .= '<td class="LC_left_item"> </td>';
6247: }
6248: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
6249: '<table><tr>'.$targettable.'</tr></table><br />';
6250: }
1.160.6.76 raeburn 6251: $hostherechecked{$sparetype} = '';
6252: if (ref($currtargets{$lonhost}) eq 'HASH') {
6253: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6254: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6255: $hostherechecked{$sparetype} = ' checked="checked"';
6256: $hostherechecked{'no'} = '';
6257: }
6258: }
6259: }
6260: }
1.160.6.94 raeburn 6261: if ($currcookies{$lonhost}) {
6262: %balcookiechecked = (
6263: yes => ' checked="checked"',
6264: );
6265: }
1.160.6.76 raeburn 6266: $datatable .= &mt('Hosting on balancer itself').'<br />'.
6267: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
6268: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
6269: foreach my $sparetype (@sparestypes) {
6270: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
6271: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
6272: '</i></label><br />';
1.160.6.7 raeburn 6273: }
1.160.6.94 raeburn 6274: $datatable .= &mt('Use balancer cookie').'<br />'.
6275: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
6276: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
6277: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
6278: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
6279: '</div></td></tr>'.
1.160.6.7 raeburn 6280: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
6281: $othertitle,$usertypes,$types,\%servers,
6282: \%currbalancer,$lonhost,
6283: $targets_div_style,$homedom_div_style,
6284: $css_class[$cssidx],$balnum,$islast);
6285: $$rowtotal += $rownum;
6286: $balnum ++;
6287: }
6288: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
6289: return $datatable;
6290: }
6291:
6292: sub get_loadbalancers_config {
1.160.6.94 raeburn 6293: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 6294: return unless ((ref($servers) eq 'HASH') &&
6295: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 6296: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
6297: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 6298: if (keys(%{$existing}) > 0) {
6299: my $oldlonhost;
6300: foreach my $key (sort(keys(%{$existing}))) {
6301: if ($key eq 'lonhost') {
6302: $oldlonhost = $existing->{'lonhost'};
6303: $currbalancer->{$oldlonhost} = 1;
6304: } elsif ($key eq 'targets') {
6305: if ($oldlonhost) {
6306: $currtargets->{$oldlonhost} = $existing->{'targets'};
6307: }
6308: } elsif ($key eq 'rules') {
6309: if ($oldlonhost) {
6310: $currrules->{$oldlonhost} = $existing->{'rules'};
6311: }
6312: } elsif (ref($existing->{$key}) eq 'HASH') {
6313: $currbalancer->{$key} = 1;
6314: $currtargets->{$key} = $existing->{$key}{'targets'};
6315: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 6316: if ($existing->{$key}{'cookie'}) {
6317: $currcookies->{$key} = 1;
6318: }
1.150 raeburn 6319: }
6320: }
1.160.6.7 raeburn 6321: } else {
6322: my ($balancerref,$targetsref) =
6323: &Apache::lonnet::get_lonbalancer_config($servers);
6324: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
6325: foreach my $server (sort(keys(%{$balancerref}))) {
6326: $currbalancer->{$server} = 1;
6327: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 6328: }
6329: }
6330: }
1.160.6.7 raeburn 6331: return;
1.150 raeburn 6332: }
6333:
6334: sub loadbalancing_rules {
6335: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 6336: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
6337: $css_class,$balnum,$islast) = @_;
1.150 raeburn 6338: my $output;
1.160.6.7 raeburn 6339: my $num = 0;
6340: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 6341: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
6342: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
6343: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 6344: $num ++;
1.150 raeburn 6345: my $current;
6346: if (ref($currrules) eq 'HASH') {
6347: $current = $currrules->{$type};
6348: }
1.160.6.55 raeburn 6349: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 6350: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 6351: $current = '';
6352: }
6353: }
6354: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 6355: $servers,$currbalancer,$lonhost,$dom,
6356: $targets_div_style,$homedom_div_style,
6357: $css_class,$balnum,$num,$islast);
1.150 raeburn 6358: }
6359: }
6360: return $output;
6361: }
6362:
6363: sub loadbalancing_titles {
6364: my ($dom,$intdom,$usertypes,$types) = @_;
6365: my %othertypes = (
6366: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
6367: '_LC_author' => &mt('Users from [_1] with author role',$dom),
6368: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
6369: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 6370: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
6371: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 6372: );
1.160.6.26 raeburn 6373: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 6374: my @available;
1.150 raeburn 6375: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 6376: @available = @{$types};
1.150 raeburn 6377: }
1.160.6.89 raeburn 6378: unless (grep(/^default$/,@available)) {
6379: push(@available,'default');
6380: }
6381: unshift(@alltypes,@available);
1.150 raeburn 6382: my %titles;
6383: foreach my $type (@alltypes) {
6384: if ($type =~ /^_LC_/) {
6385: $titles{$type} = $othertypes{$type};
6386: } elsif ($type eq 'default') {
6387: $titles{$type} = &mt('All users from [_1]',$dom);
6388: if (ref($types) eq 'ARRAY') {
6389: if (@{$types} > 0) {
6390: $titles{$type} = &mt('Other users from [_1]',$dom);
6391: }
6392: }
6393: } elsif (ref($usertypes) eq 'HASH') {
6394: $titles{$type} = $usertypes->{$type};
6395: }
6396: }
6397: return (\@alltypes,\%othertypes,\%titles);
6398: }
6399:
6400: sub loadbalance_rule_row {
1.160.6.7 raeburn 6401: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
6402: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 6403: my @rulenames;
1.150 raeburn 6404: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 6405: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 6406: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 6407: } else {
1.160.6.26 raeburn 6408: @rulenames = ('default','homeserver');
6409: if ($type eq '_LC_external') {
6410: push(@rulenames,'externalbalancer');
6411: } else {
6412: push(@rulenames,'specific');
6413: }
6414: push(@rulenames,'none');
1.150 raeburn 6415: }
6416: my $style = $targets_div_style;
1.160.6.55 raeburn 6417: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 6418: $style = $homedom_div_style;
6419: }
1.160.6.7 raeburn 6420: my $space;
6421: if ($islast && $num == 1) {
6422: $space = '<div display="inline-block"> </div>';
6423: }
6424: my $output =
6425: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
6426: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
6427: '<td valaign="top">'.$space.
6428: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 6429: for (my $i=0; $i<@rulenames; $i++) {
6430: my $rule = $rulenames[$i];
6431: my ($checked,$extra);
6432: if ($rulenames[$i] eq 'default') {
6433: $rule = '';
6434: }
6435: if ($rulenames[$i] eq 'specific') {
6436: if (ref($servers) eq 'HASH') {
6437: my $default;
6438: if (($current ne '') && (exists($servers->{$current}))) {
6439: $checked = ' checked="checked"';
6440: }
6441: unless ($checked) {
6442: $default = ' selected="selected"';
6443: }
1.160.6.7 raeburn 6444: $extra =
6445: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
6446: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
6447: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
6448: '<option value=""'.$default.'></option>'."\n";
6449: foreach my $server (sort(keys(%{$servers}))) {
6450: if (ref($currbalancer) eq 'HASH') {
6451: next if (exists($currbalancer->{$server}));
6452: }
1.150 raeburn 6453: my $selected;
1.160.6.7 raeburn 6454: if ($server eq $current) {
1.150 raeburn 6455: $selected = ' selected="selected"';
6456: }
1.160.6.7 raeburn 6457: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 6458: }
6459: $extra .= '</select>';
6460: }
6461: } elsif ($rule eq $current) {
6462: $checked = ' checked="checked"';
6463: }
6464: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 6465: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
6466: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
6467: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 6468: ')"'.$checked.' /> ';
1.160.6.56 raeburn 6469: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 6470: $output .= $ruletitles{'particular'};
6471: } else {
6472: $output .= $ruletitles{$rulenames[$i]};
6473: }
6474: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 6475: }
6476: $output .= '</div></td></tr>'."\n";
6477: return $output;
6478: }
6479:
6480: sub offloadtype_text {
6481: my %ruletitles = &Apache::lonlocal::texthash (
6482: 'default' => 'Offloads to default destinations',
6483: 'homeserver' => "Offloads to user's home server",
6484: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
6485: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 6486: 'none' => 'No offload',
1.160.6.26 raeburn 6487: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
6488: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 6489: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 6490: );
6491: return %ruletitles;
6492: }
6493:
6494: sub sparestype_titles {
6495: my %typestitles = &Apache::lonlocal::texthash (
6496: 'primary' => 'primary',
6497: 'default' => 'default',
6498: );
6499: return %typestitles;
6500: }
6501:
1.28 raeburn 6502: sub contact_titles {
6503: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 6504: 'supportemail' => 'Support E-mail address',
6505: 'adminemail' => 'Default Server Admin E-mail address',
6506: 'errormail' => 'Error reports to be e-mailed to',
6507: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.101 raeburn 6508: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
6509: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 6510: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
6511: 'requestsmail' => 'E-mail from course requests requiring approval',
6512: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 6513: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 6514: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.160.6.109 raeburn 6515: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
6516: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.160.6.107 raeburn 6517: 'errorweights' => 'Weights used to compute error count',
6518: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 6519: );
6520: my %short_titles = &Apache::lonlocal::texthash (
6521: adminemail => 'Admin E-mail address',
6522: supportemail => 'Support E-mail',
6523: );
6524: return (\%titles,\%short_titles);
6525: }
6526:
1.160.6.78 raeburn 6527: sub helpform_fields {
6528: my %titles = &Apache::lonlocal::texthash (
6529: 'username' => 'Name',
6530: 'user' => 'Username/domain',
6531: 'phone' => 'Phone',
6532: 'cc' => 'Cc e-mail',
6533: 'course' => 'Course Details',
6534: 'section' => 'Sections',
6535: 'screenshot' => 'File upload',
6536: );
6537: my @fields = ('username','phone','user','course','section','cc','screenshot');
6538: my %possoptions = (
6539: username => ['yes','no','req'],
6540: phone => ['yes','no','req'],
6541: user => ['yes','no'],
6542: cc => ['yes','no'],
6543: course => ['yes','no'],
6544: section => ['yes','no'],
6545: screenshot => ['yes','no'],
6546: );
6547: my %fieldoptions = &Apache::lonlocal::texthash (
6548: 'yes' => 'Optional',
6549: 'req' => 'Required',
6550: 'no' => "Not shown",
6551: );
6552: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
6553: }
6554:
1.72 raeburn 6555: sub tool_titles {
6556: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 6557: aboutme => 'Personal web page',
1.86 raeburn 6558: blog => 'Blog',
1.160.6.4 raeburn 6559: webdav => 'WebDAV',
1.86 raeburn 6560: portfolio => 'Portfolio',
1.88 bisitz 6561: official => 'Official courses (with institutional codes)',
6562: unofficial => 'Unofficial courses',
1.98 raeburn 6563: community => 'Communities',
1.160.6.30 raeburn 6564: textbook => 'Textbook courses',
1.86 raeburn 6565: );
1.72 raeburn 6566: return %titles;
6567: }
6568:
1.101 raeburn 6569: sub courserequest_titles {
6570: my %titles = &Apache::lonlocal::texthash (
6571: official => 'Official',
6572: unofficial => 'Unofficial',
6573: community => 'Communities',
1.160.6.30 raeburn 6574: textbook => 'Textbook',
1.101 raeburn 6575: norequest => 'Not allowed',
1.104 raeburn 6576: approval => 'Approval by Dom. Coord.',
1.101 raeburn 6577: validate => 'With validation',
6578: autolimit => 'Numerical limit',
1.103 raeburn 6579: unlimited => '(blank for unlimited)',
1.101 raeburn 6580: );
6581: return %titles;
6582: }
6583:
1.160.6.5 raeburn 6584: sub authorrequest_titles {
6585: my %titles = &Apache::lonlocal::texthash (
6586: norequest => 'Not allowed',
6587: approval => 'Approval by Dom. Coord.',
6588: automatic => 'Automatic approval',
6589: );
6590: return %titles;
6591: }
6592:
1.101 raeburn 6593: sub courserequest_conditions {
6594: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 6595: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 6596: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 6597: );
6598: return %conditions;
6599: }
6600:
6601:
1.27 raeburn 6602: sub print_usercreation {
1.30 raeburn 6603: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 6604: my $numinrow = 4;
1.28 raeburn 6605: my $datatable;
6606: if ($position eq 'top') {
1.30 raeburn 6607: $$rowtotal ++;
1.34 raeburn 6608: my $rowcount = 0;
1.32 raeburn 6609: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 6610: if (ref($rules) eq 'HASH') {
6611: if (keys(%{$rules}) > 0) {
1.32 raeburn 6612: $datatable .= &user_formats_row('username',$settings,$rules,
6613: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 6614: $$rowtotal ++;
1.32 raeburn 6615: $rowcount ++;
6616: }
6617: }
6618: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
6619: if (ref($idrules) eq 'HASH') {
6620: if (keys(%{$idrules}) > 0) {
6621: $datatable .= &user_formats_row('id',$settings,$idrules,
6622: $idruleorder,$numinrow,$rowcount);
6623: $$rowtotal ++;
6624: $rowcount ++;
1.28 raeburn 6625: }
6626: }
1.39 raeburn 6627: if ($rowcount == 0) {
6628: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
6629: $$rowtotal ++;
6630: $rowcount ++;
6631: }
1.34 raeburn 6632: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 6633: my @creators = ('author','course','requestcrs');
1.37 raeburn 6634: my ($rules,$ruleorder) =
6635: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 6636: my %lt = &usercreation_types();
6637: my %checked;
6638: if (ref($settings) eq 'HASH') {
6639: if (ref($settings->{'cancreate'}) eq 'HASH') {
6640: foreach my $item (@creators) {
6641: $checked{$item} = $settings->{'cancreate'}{$item};
6642: }
6643: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
6644: foreach my $item (@creators) {
6645: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
6646: $checked{$item} = 'none';
6647: }
6648: }
6649: }
6650: }
6651: my $rownum = 0;
6652: foreach my $item (@creators) {
6653: $rownum ++;
1.160.6.34 raeburn 6654: if ($checked{$item} eq '') {
6655: $checked{$item} = 'any';
1.34 raeburn 6656: }
6657: my $css_class;
6658: if ($rownum%2) {
6659: $css_class = '';
6660: } else {
6661: $css_class = ' class="LC_odd_row" ';
6662: }
6663: $datatable .= '<tr'.$css_class.'>'.
6664: '<td><span class="LC_nobreak">'.$lt{$item}.
6665: '</span></td><td align="right">';
1.160.6.34 raeburn 6666: my @options = ('any');
6667: if (ref($rules) eq 'HASH') {
6668: if (keys(%{$rules}) > 0) {
6669: push(@options,('official','unofficial'));
1.37 raeburn 6670: }
6671: }
1.160.6.34 raeburn 6672: push(@options,'none');
1.37 raeburn 6673: foreach my $option (@options) {
1.50 raeburn 6674: my $type = 'radio';
1.34 raeburn 6675: my $check = ' ';
1.160.6.34 raeburn 6676: if ($checked{$item} eq $option) {
6677: $check = ' checked="checked" ';
1.34 raeburn 6678: }
6679: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 6680: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 6681: $item.'" value="'.$option.'"'.$check.'/> '.
6682: $lt{$option}.'</label> </span>';
6683: }
6684: $datatable .= '</td></tr>';
6685: }
1.28 raeburn 6686: } else {
6687: my @contexts = ('author','course','domain');
6688: my @authtypes = ('int','krb4','krb5','loc');
6689: my %checked;
6690: if (ref($settings) eq 'HASH') {
6691: if (ref($settings->{'authtypes'}) eq 'HASH') {
6692: foreach my $item (@contexts) {
6693: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
6694: foreach my $auth (@authtypes) {
6695: if ($settings->{'authtypes'}{$item}{$auth}) {
6696: $checked{$item}{$auth} = ' checked="checked" ';
6697: }
6698: }
6699: }
6700: }
1.27 raeburn 6701: }
1.35 raeburn 6702: } else {
6703: foreach my $item (@contexts) {
1.36 raeburn 6704: foreach my $auth (@authtypes) {
1.35 raeburn 6705: $checked{$item}{$auth} = ' checked="checked" ';
6706: }
6707: }
1.27 raeburn 6708: }
1.28 raeburn 6709: my %title = &context_names();
6710: my %authname = &authtype_names();
6711: my $rownum = 0;
6712: my $css_class;
6713: foreach my $item (@contexts) {
6714: if ($rownum%2) {
6715: $css_class = '';
6716: } else {
6717: $css_class = ' class="LC_odd_row" ';
6718: }
1.30 raeburn 6719: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 6720: '<td>'.$title{$item}.
6721: '</td><td class="LC_left_item">'.
6722: '<span class="LC_nobreak">';
6723: foreach my $auth (@authtypes) {
6724: $datatable .= '<label>'.
6725: '<input type="checkbox" name="'.$item.'_auth" '.
6726: $checked{$item}{$auth}.' value="'.$auth.'" />'.
6727: $authname{$auth}.'</label> ';
6728: }
6729: $datatable .= '</span></td></tr>';
6730: $rownum ++;
1.27 raeburn 6731: }
1.30 raeburn 6732: $$rowtotal += $rownum;
1.27 raeburn 6733: }
6734: return $datatable;
6735: }
6736:
1.160.6.34 raeburn 6737: sub print_selfcreation {
6738: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 6739: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
6740: $emaildomain,$datatable);
1.160.6.34 raeburn 6741: if (ref($settings) eq 'HASH') {
6742: if (ref($settings->{'cancreate'}) eq 'HASH') {
6743: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 6744: if (ref($createsettings) eq 'HASH') {
6745: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
6746: @selfcreate = @{$createsettings->{'selfcreate'}};
6747: } elsif ($createsettings->{'selfcreate'} ne '') {
6748: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
6749: @selfcreate = ('email','login','sso');
6750: } elsif ($createsettings->{'selfcreate'} ne 'none') {
6751: @selfcreate = ($createsettings->{'selfcreate'});
6752: }
6753: }
6754: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
6755: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 6756: }
1.160.6.93 raeburn 6757: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
6758: $emailoptions = $createsettings->{'emailoptions'};
6759: }
6760: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
6761: $emailverified = $createsettings->{'emailverified'};
6762: }
6763: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
6764: $emaildomain = $createsettings->{'emaildomain'};
6765: }
1.160.6.34 raeburn 6766: }
6767: }
6768: }
6769: my %radiohash;
6770: my $numinrow = 4;
6771: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 6772: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 6773: if ($position eq 'top') {
6774: my %choices = &Apache::lonlocal::texthash (
6775: cancreate_login => 'Institutional Login',
6776: cancreate_sso => 'Institutional Single Sign On',
6777: );
6778: my @toggles = sort(keys(%choices));
6779: my %defaultchecked = (
6780: 'cancreate_login' => 'off',
6781: 'cancreate_sso' => 'off',
6782: );
1.160.6.35 raeburn 6783: my ($onclick,$itemcount);
1.160.6.34 raeburn 6784: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6785: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 6786: $$rowtotal += $itemcount;
1.160.6.34 raeburn 6787:
6788: if (ref($usertypes) eq 'HASH') {
6789: if (keys(%{$usertypes}) > 0) {
6790: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
6791: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 6792: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 6793: $$rowtotal ++;
6794: }
6795: }
1.160.6.44 raeburn 6796: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
6797: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6798: $fieldtitles{'inststatus'} = &mt('Institutional status');
6799: my $rem;
6800: my $numperrow = 2;
6801: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
6802: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 6803: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 6804: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 6805: '<table>'."\n";
1.160.6.44 raeburn 6806: for (my $i=0; $i<@fields; $i++) {
6807: $rem = $i%($numperrow);
6808: if ($rem == 0) {
6809: if ($i > 0) {
6810: $datatable .= '</tr>';
6811: }
6812: $datatable .= '<tr>';
6813: }
6814: my $currval;
1.160.6.51 raeburn 6815: if (ref($createsettings) eq 'HASH') {
6816: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
6817: $currval = $createsettings->{'shibenv'}{$fields[$i]};
6818: }
1.160.6.44 raeburn 6819: }
6820: $datatable .= '<td class="LC_left_item">'.
6821: '<span class="LC_nobreak">'.
6822: '<input type="text" name="shibenv_'.$fields[$i].'" '.
6823: 'value="'.$currval.'" size="10" /> '.
6824: $fieldtitles{$fields[$i]}.'</span></td>';
6825: }
6826: my $colsleft = $numperrow - $rem;
6827: if ($colsleft > 1 ) {
6828: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6829: ' </td>';
6830: } elsif ($colsleft == 1) {
6831: $datatable .= '<td class="LC_left_item"> </td>';
6832: }
6833: $datatable .= '</tr></table></td></tr>';
6834: $$rowtotal ++;
1.160.6.34 raeburn 6835: } elsif ($position eq 'middle') {
6836: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 6837: my @posstypes;
1.160.6.34 raeburn 6838: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 6839: @posstypes = @{$types};
6840: }
6841: unless (grep(/^default$/,@posstypes)) {
6842: push(@posstypes,'default');
6843: }
6844: my %usertypeshash;
6845: if (ref($usertypes) eq 'HASH') {
6846: %usertypeshash = %{$usertypes};
6847: }
6848: $usertypeshash{'default'} = $othertitle;
6849: foreach my $status (@posstypes) {
6850: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
6851: $numinrow,$$rowtotal,\%usertypeshash);
6852: $$rowtotal ++;
1.160.6.34 raeburn 6853: }
6854: } else {
1.160.6.40 raeburn 6855: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 6856: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 6857: );
6858: my @toggles = sort(keys(%choices));
6859: my %defaultchecked = (
6860: 'cancreate_email' => 'off',
6861: );
1.160.6.93 raeburn 6862: my $customclass = 'LC_selfcreate_email';
6863: my $classprefix = 'LC_canmodify_emailusername_';
6864: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 6865: my $display = 'none';
1.160.6.93 raeburn 6866: my $rowstyle = 'display:none';
1.160.6.40 raeburn 6867: if (grep(/^\Qemail\E$/,@selfcreate)) {
6868: $display = 'block';
1.160.6.93 raeburn 6869: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 6870: }
1.160.6.93 raeburn 6871: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
6872: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6873: \%choices,$$rowtotal,$onclick);
6874: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
6875: $rowstyle);
6876: $$rowtotal ++;
6877: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
6878: $rowstyle);
6879: $$rowtotal ++;
6880: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 6881: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 6882: my ($emailrules,$emailruleorder) =
6883: &Apache::lonnet::inst_userrules($dom,'email');
6884: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6885: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6886: if (ref($types) eq 'ARRAY') {
6887: @posstypes = @{$types};
6888: }
6889: if (@posstypes) {
6890: unless (grep(/^default$/,@posstypes)) {
6891: push(@posstypes,'default');
1.160.6.89 raeburn 6892: }
6893: if (ref($usertypes) eq 'HASH') {
6894: %usertypeshash = %{$usertypes};
6895: }
1.160.6.93 raeburn 6896: my $currassign;
6897: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
6898: $currassign = {
6899: selfassign => $domdefaults{'inststatusguest'},
6900: };
6901: @ordered = @{$domdefaults{'inststatusguest'}};
6902: } else {
6903: $currassign = { selfassign => [] };
6904: }
6905: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
6906: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
6907: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
6908: $numinrow,$othertitle,'selfassign',
6909: $rowtotal,$onclicktypes,$customclass,
6910: $rowstyle);
6911: $$rowtotal ++;
1.160.6.89 raeburn 6912: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 6913: foreach my $status (@posstypes) {
6914: my $css_class;
6915: if ($$rowtotal%2) {
6916: $css_class = 'LC_odd_row ';
6917: }
6918: $css_class .= $customclass;
6919: my $rowid = $optionsprefix.$status;
6920: my $hidden = 1;
6921: my $currstyle = 'display:none';
6922: if (grep(/^\Q$status\E$/,@ordered)) {
6923: $currstyle = $rowstyle;
6924: $hidden = 0;
6925: }
6926: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6927: $emailrules,$emailruleorder,$settings,$status,$rowid,
6928: $usertypeshash{$status},$css_class,$currstyle,$intdom);
6929: unless ($hidden) {
6930: $$rowtotal ++;
6931: }
1.160.6.89 raeburn 6932: }
6933: } else {
1.160.6.93 raeburn 6934: my $css_class;
6935: if ($$rowtotal%2) {
6936: $css_class = 'LC_odd_row ';
6937: }
6938: $css_class .= $customclass;
1.160.6.89 raeburn 6939: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 6940: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6941: $emailrules,$emailruleorder,$settings,'default','',
6942: $othertitle,$css_class,$rowstyle,$intdom);
6943: $$rowtotal ++;
1.160.6.34 raeburn 6944: }
1.160.6.35 raeburn 6945: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
6946: $numinrow = 1;
1.160.6.93 raeburn 6947: if (@posstypes) {
6948: foreach my $status (@posstypes) {
6949: my $rowid = $classprefix.$status;
6950: my $datarowstyle = 'display:none';
6951: if (grep(/^\Q$status\E$/,@ordered)) {
6952: $datarowstyle = $rowstyle;
6953: }
6954: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
6955: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6956: $infotitles,$rowid,$customclass,$datarowstyle);
6957: unless ($datarowstyle eq 'display:none') {
6958: $$rowtotal ++;
6959: }
1.160.6.34 raeburn 6960: }
1.160.6.93 raeburn 6961: } else {
6962: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
6963: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6964: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 6965: }
6966: }
6967: return $datatable;
6968: }
6969:
1.160.6.93 raeburn 6970: sub selfcreate_javascript {
6971: return <<"ENDSCRIPT";
6972:
6973: <script type="text/javascript">
6974: // <![CDATA[
6975:
6976: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
6977: var x = document.getElementsByClassName(target);
6978: var insttypes = 0;
6979: var insttypeRegExp = new RegExp(prefix);
6980: if ((x.length != undefined) && (x.length > 0)) {
6981: if (form.elements[radio].length != undefined) {
6982: for (var i=0; i<form.elements[radio].length; i++) {
6983: if (form.elements[radio][i].checked) {
6984: if (form.elements[radio][i].value == 1) {
6985: for (var j=0; j<x.length; j++) {
6986: if (x[j].id == 'undefined') {
6987: x[j].style.display = 'table-row';
6988: } else if (insttypeRegExp.test(x[j].id)) {
6989: insttypes ++;
6990: } else {
6991: x[j].style.display = 'table-row';
6992: }
6993: }
6994: } else {
6995: for (var j=0; j<x.length; j++) {
6996: x[j].style.display = 'none';
6997: }
1.160.6.40 raeburn 6998: }
1.160.6.93 raeburn 6999: break;
7000: }
7001: }
7002: if (insttypes > 0) {
7003: toggleDataRow(form,checkbox,target,altprefix);
7004: toggleDataRow(form,checkbox,target,prefix,1);
7005: }
7006: }
7007: }
7008: return;
7009: }
7010:
7011: function toggleDataRow(form,checkbox,target,prefix,docount) {
7012: if (form.elements[checkbox].length != undefined) {
7013: var count = 0;
7014: if (docount) {
7015: for (var i=0; i<form.elements[checkbox].length; i++) {
7016: if (form.elements[checkbox][i].checked) {
7017: count ++;
7018: }
7019: }
7020: }
7021: for (var i=0; i<form.elements[checkbox].length; i++) {
7022: var type = form.elements[checkbox][i].value;
7023: if (document.getElementById(prefix+type)) {
7024: if (form.elements[checkbox][i].checked) {
7025: document.getElementById(prefix+type).style.display = 'table-row';
7026: if (count % 2 == 1) {
7027: document.getElementById(prefix+type).className = target+' LC_odd_row';
7028: } else {
7029: document.getElementById(prefix+type).className = target;
7030: }
7031: count ++;
1.160.6.40 raeburn 7032: } else {
1.160.6.93 raeburn 7033: document.getElementById(prefix+type).style.display = 'none';
7034: }
7035: }
7036: }
7037: }
7038: return;
7039: }
7040:
7041: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
7042: var caller = radio+'_'+status;
7043: if (form.elements[caller].length != undefined) {
7044: for (var i=0; i<form.elements[caller].length; i++) {
7045: if (form.elements[caller][i].checked) {
7046: if (document.getElementById(altprefix+'_inst_'+status)) {
7047: var curr = form.elements[caller][i].value;
7048: if (prefix) {
7049: document.getElementById(prefix+'_'+status).style.display = 'none';
7050: }
7051: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
7052: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
7053: if (curr == 'custom') {
7054: if (prefix) {
7055: document.getElementById(prefix+'_'+status).style.display = 'inline';
7056: }
7057: } else if (curr == 'inst') {
7058: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
7059: } else if (curr == 'noninst') {
7060: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 7061: }
1.160.6.93 raeburn 7062: break;
1.160.6.40 raeburn 7063: }
1.160.6.93 raeburn 7064: }
7065: }
7066: }
7067: }
7068:
7069: // ]]>
7070: </script>
7071:
7072: ENDSCRIPT
7073: }
7074:
7075: sub noninst_users {
7076: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
7077: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
7078: my $class = 'LC_left_item';
7079: if ($css_class) {
7080: $css_class = ' class="'.$css_class.'"';
7081: }
7082: if ($rowid) {
7083: $rowid = ' id="'.$rowid.'"';
7084: }
7085: if ($rowstyle) {
7086: $rowstyle = ' style="'.$rowstyle.'"';
7087: }
7088: my ($output,$description);
7089: if ($type eq 'default') {
7090: $description = &mt('Requests for: [_1]',$typetitle);
7091: } else {
7092: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
7093: }
7094: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
7095: "<td>$description</td>\n".
7096: '<td class="'.$class.'" colspan="2">'.
7097: '<table><tr>';
7098: my %headers = &Apache::lonlocal::texthash(
7099: approve => 'Processing',
7100: email => 'E-mail',
7101: username => 'Username',
7102: );
7103: foreach my $item ('approve','email','username') {
7104: $output .= '<th>'.$headers{$item}.'</th>';
7105: }
7106: $output .= '</tr><tr>';
7107: foreach my $item ('approve','email','username') {
7108: $output .= '<td valign="top">';
7109: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
7110: if ($item eq 'approve') {
7111: %choices = &Apache::lonlocal::texthash (
7112: automatic => 'Automatically approved',
7113: approval => 'Queued for approval',
7114: );
7115: @options = ('automatic','approval');
7116: $hashref = $processing;
7117: $defoption = 'automatic';
7118: $name = 'cancreate_emailprocess_'.$type;
7119: } elsif ($item eq 'email') {
7120: %choices = &Apache::lonlocal::texthash (
7121: any => 'Any e-mail',
7122: inst => 'Institutional only',
7123: noninst => 'Non-institutional only',
7124: custom => 'Custom restrictions',
7125: );
7126: @options = ('any','inst','noninst');
7127: my $showcustom;
7128: if (ref($emailrules) eq 'HASH') {
7129: if (keys(%{$emailrules}) > 0) {
7130: push(@options,'custom');
7131: $showcustom = 'cancreate_emailrule';
7132: if (ref($settings) eq 'HASH') {
7133: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
7134: foreach my $rule (@{$settings->{'email_rule'}}) {
7135: if (exists($emailrules->{$rule})) {
7136: $hascustom ++;
7137: }
7138: }
7139: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
7140: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
7141: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
7142: if (exists($emailrules->{$rule})) {
7143: $hascustom ++;
7144: }
7145: }
7146: }
7147: }
7148: }
7149: }
7150: }
7151: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
7152: "'cancreate_emaildomain','$type'".');"';
7153: $hashref = $emailoptions;
7154: $defoption = 'any';
7155: $name = 'cancreate_emailoptions_'.$type;
7156: } elsif ($item eq 'username') {
7157: %choices = &Apache::lonlocal::texthash (
7158: all => 'Same as e-mail',
7159: first => 'Omit @domain',
7160: free => 'Free to choose',
7161: );
7162: @options = ('all','first','free');
7163: $hashref = $emailverified;
7164: $defoption = 'all';
7165: $name = 'cancreate_usernameoptions_'.$type;
7166: }
7167: foreach my $option (@options) {
7168: my $checked;
7169: if (ref($hashref) eq 'HASH') {
7170: if ($type eq '') {
7171: if (!exists($hashref->{'default'})) {
7172: if ($option eq $defoption) {
7173: $checked = ' checked="checked"';
7174: }
7175: } else {
7176: if ($hashref->{'default'} eq $option) {
7177: $checked = ' checked="checked"';
7178: }
1.160.6.40 raeburn 7179: }
7180: } else {
1.160.6.93 raeburn 7181: if (!exists($hashref->{$type})) {
7182: if ($option eq $defoption) {
7183: $checked = ' checked="checked"';
7184: }
7185: } else {
7186: if ($hashref->{$type} eq $option) {
7187: $checked = ' checked="checked"';
7188: }
1.160.6.40 raeburn 7189: }
7190: }
1.160.6.93 raeburn 7191: } elsif (($item eq 'email') && ($hascustom)) {
7192: if ($option eq 'custom') {
7193: $checked = ' checked="checked"';
7194: }
7195: } elsif ($option eq $defoption) {
7196: $checked = ' checked="checked"';
7197: }
7198: $output .= '<span class="LC_nobreak"><label>'.
7199: '<input type="radio" name="'.$name.'"'.
7200: $checked.' value="'.$option.'"'.$onclick.' />'.
7201: $choices{$option}.'</label></span><br />';
7202: if ($item eq 'email') {
7203: if ($option eq 'custom') {
7204: my $id = 'cancreate_emailrule_'.$type;
7205: my $display = 'none';
7206: if ($checked) {
7207: $display = 'inline';
7208: }
7209: my $numinrow = 2;
7210: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
7211: '<legend>'.&mt('Disallow').'</legend><table>'.
7212: &user_formats_row('email',$settings,$emailrules,
7213: $emailruleorder,$numinrow,'',$type);
7214: '</table></fieldset>';
7215: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
7216: my %text = &Apache::lonlocal::texthash (
7217: inst => 'must end:',
7218: noninst => 'cannot end:',
7219: );
7220: my $value;
7221: if (ref($emaildomain) eq 'HASH') {
7222: if (ref($emaildomain->{$type}) eq 'HASH') {
7223: $value = $emaildomain->{$type}->{$option};
7224: }
7225: }
7226: if ($value eq '') {
7227: $value = '@'.$intdom;
7228: }
7229: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
7230: my $display = 'none';
7231: if ($checked) {
7232: $display = 'inline';
7233: }
7234: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
7235: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
7236: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
7237: '</div>';
7238: }
1.160.6.40 raeburn 7239: }
7240: }
1.160.6.93 raeburn 7241: $output .= '</td>'."\n";
1.160.6.40 raeburn 7242: }
1.160.6.93 raeburn 7243: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 7244: return $output;
7245: }
7246:
1.160.6.5 raeburn 7247: sub captcha_choice {
1.160.6.93 raeburn 7248: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 7249: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
7250: $vertext,$currver);
1.160.6.5 raeburn 7251: my %lt = &captcha_phrases();
7252: $keyentry = 'hidden';
1.160.6.98 raeburn 7253: my $colspan=2;
1.160.6.5 raeburn 7254: if ($context eq 'cancreate') {
1.160.6.34 raeburn 7255: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 7256: } elsif ($context eq 'login') {
7257: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98 raeburn 7258: } elsif ($context eq 'passwords') {
7259: $rowname = &mt('"Forgot Password" CAPTCHA validation');
7260: $colspan=1;
1.160.6.5 raeburn 7261: }
7262: if (ref($settings) eq 'HASH') {
7263: if ($settings->{'captcha'}) {
7264: $checked{$settings->{'captcha'}} = ' checked="checked"';
7265: } else {
7266: $checked{'original'} = ' checked="checked"';
7267: }
7268: if ($settings->{'captcha'} eq 'recaptcha') {
7269: $pubtext = $lt{'pub'};
7270: $privtext = $lt{'priv'};
7271: $keyentry = 'text';
1.160.6.69 raeburn 7272: $vertext = $lt{'ver'};
7273: $currver = $settings->{'recaptchaversion'};
7274: if ($currver ne '2') {
7275: $currver = 1;
7276: }
1.160.6.5 raeburn 7277: }
7278: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
7279: $currpub = $settings->{'recaptchakeys'}{'public'};
7280: $currpriv = $settings->{'recaptchakeys'}{'private'};
7281: }
7282: } else {
7283: $checked{'original'} = ' checked="checked"';
7284: }
1.160.6.93 raeburn 7285: my $css_class;
7286: if ($itemcount%2) {
7287: $css_class = 'LC_odd_row';
7288: }
7289: if ($customcss) {
7290: $css_class .= " $customcss";
7291: }
7292: $css_class =~ s/^\s+//;
7293: if ($css_class) {
7294: $css_class = ' class="'.$css_class.'"';
7295: }
7296: if ($rowstyle) {
7297: $css_class .= ' style="'.$rowstyle.'"';
7298: }
1.160.6.5 raeburn 7299: my $output = '<tr'.$css_class.'>'.
1.160.6.98 raeburn 7300: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 7301: '<table><tr><td>'."\n";
7302: foreach my $option ('original','recaptcha','notused') {
7303: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
7304: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
7305: $lt{$option}.'</label></span>';
7306: unless ($option eq 'notused') {
7307: $output .= (' 'x2)."\n";
7308: }
7309: }
7310: #
7311: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
7312: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
7313: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
7314: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
7315: #
7316: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 7317: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 7318: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
7319: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
7320: $currpub.'" size="40" /></span><br />'."\n".
7321: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
7322: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 7323: $currpriv.'" size="40" /></span><br />'.
7324: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
7325: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
7326: $currver.'" size="3" /></span><br />'.
7327: '</td></tr></table>'."\n".
1.160.6.5 raeburn 7328: '</td></tr>';
7329: return $output;
7330: }
7331:
1.32 raeburn 7332: sub user_formats_row {
1.160.6.93 raeburn 7333: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 7334: my $output;
7335: my %text = (
7336: 'username' => 'new usernames',
7337: 'id' => 'IDs',
7338: );
1.160.6.93 raeburn 7339: unless ($type eq 'email') {
7340: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7341: $output = '<tr '.$css_class.'>'.
7342: '<td><span class="LC_nobreak">'.
7343: &mt("Format rules to check for $text{$type}: ").
7344: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 7345: }
1.27 raeburn 7346: my $rem;
7347: if (ref($ruleorder) eq 'ARRAY') {
7348: for (my $i=0; $i<@{$ruleorder}; $i++) {
7349: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
7350: my $rem = $i%($numinrow);
7351: if ($rem == 0) {
7352: if ($i > 0) {
7353: $output .= '</tr>';
7354: }
7355: $output .= '<tr>';
7356: }
7357: my $check = ' ';
1.39 raeburn 7358: if (ref($settings) eq 'HASH') {
7359: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
7360: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
7361: $check = ' checked="checked" ';
7362: }
1.160.6.93 raeburn 7363: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
7364: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
7365: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
7366: $check = ' checked="checked" ';
7367: }
7368: }
1.27 raeburn 7369: }
7370: }
1.160.6.93 raeburn 7371: my $name = $type.'_rule';
7372: if ($type eq 'email') {
7373: $name .= '_'.$status;
7374: }
1.27 raeburn 7375: $output .= '<td class="LC_left_item">'.
7376: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 7377: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 7378: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
7379: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
7380: }
7381: }
7382: $rem = @{$ruleorder}%($numinrow);
7383: }
1.160.6.93 raeburn 7384: my $colsleft;
7385: if ($rem) {
7386: $colsleft = $numinrow - $rem;
7387: }
1.27 raeburn 7388: if ($colsleft > 1 ) {
7389: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7390: ' </td>';
7391: } elsif ($colsleft == 1) {
7392: $output .= '<td class="LC_left_item"> </td>';
7393: }
1.160.6.93 raeburn 7394: $output .= '</tr></table>';
7395: unless ($type eq 'email') {
7396: $output .= '</td></tr>';
7397: }
1.27 raeburn 7398: return $output;
7399: }
7400:
1.34 raeburn 7401: sub usercreation_types {
7402: my %lt = &Apache::lonlocal::texthash (
7403: author => 'When adding a co-author',
7404: course => 'When adding a user to a course',
1.100 raeburn 7405: requestcrs => 'When requesting a course',
1.34 raeburn 7406: any => 'Any',
7407: official => 'Institutional only ',
7408: unofficial => 'Non-institutional only',
7409: none => 'None',
7410: );
7411: return %lt;
1.48 raeburn 7412: }
1.34 raeburn 7413:
1.160.6.34 raeburn 7414: sub selfcreation_types {
7415: my %lt = &Apache::lonlocal::texthash (
7416: selfcreate => 'User creates own account',
7417: any => 'Any',
7418: official => 'Institutional only ',
7419: unofficial => 'Non-institutional only',
7420: email => 'E-mail address',
7421: login => 'Institutional Login',
7422: sso => 'SSO',
7423: );
7424: }
7425:
1.28 raeburn 7426: sub authtype_names {
7427: my %lt = &Apache::lonlocal::texthash(
7428: int => 'Internal',
7429: krb4 => 'Kerberos 4',
7430: krb5 => 'Kerberos 5',
7431: loc => 'Local',
7432: );
7433: return %lt;
7434: }
7435:
7436: sub context_names {
7437: my %context_title = &Apache::lonlocal::texthash(
7438: author => 'Creating users when an Author',
7439: course => 'Creating users when in a course',
7440: domain => 'Creating users when a Domain Coordinator',
7441: );
7442: return %context_title;
7443: }
7444:
1.33 raeburn 7445: sub print_usermodification {
7446: my ($position,$dom,$settings,$rowtotal) = @_;
7447: my $numinrow = 4;
7448: my ($context,$datatable,$rowcount);
7449: if ($position eq 'top') {
7450: $rowcount = 0;
7451: $context = 'author';
7452: foreach my $role ('ca','aa') {
7453: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7454: $numinrow,$rowcount);
7455: $$rowtotal ++;
7456: $rowcount ++;
7457: }
1.160.6.37 raeburn 7458: } elsif ($position eq 'bottom') {
1.33 raeburn 7459: $context = 'course';
7460: $rowcount = 0;
7461: foreach my $role ('st','ep','ta','in','cr') {
7462: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7463: $numinrow,$rowcount);
7464: $$rowtotal ++;
7465: $rowcount ++;
7466: }
7467: }
7468: return $datatable;
7469: }
7470:
1.43 raeburn 7471: sub print_defaults {
1.160.6.40 raeburn 7472: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 7473: my $rownum = 0;
1.160.6.80 raeburn 7474: my ($datatable,$css_class,$titles);
7475: unless ($position eq 'bottom') {
7476: $titles = &defaults_titles($dom);
7477: }
1.160.6.40 raeburn 7478: if ($position eq 'top') {
7479: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
7480: 'datelocale_def','portal_def');
7481: my %defaults;
7482: if (ref($settings) eq 'HASH') {
7483: %defaults = %{$settings};
1.43 raeburn 7484: } else {
1.160.6.40 raeburn 7485: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7486: foreach my $item (@items) {
7487: $defaults{$item} = $domdefaults{$item};
7488: }
1.43 raeburn 7489: }
1.160.6.40 raeburn 7490: foreach my $item (@items) {
7491: if ($rownum%2) {
7492: $css_class = '';
7493: } else {
7494: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 7495: }
1.160.6.40 raeburn 7496: $datatable .= '<tr'.$css_class.'>'.
7497: '<td><span class="LC_nobreak">'.$titles->{$item}.
7498: '</span></td><td class="LC_right_item" colspan="3">';
7499: if ($item eq 'auth_def') {
7500: my @authtypes = ('internal','krb4','krb5','localauth');
7501: my %shortauth = (
7502: internal => 'int',
7503: krb4 => 'krb4',
7504: krb5 => 'krb5',
7505: localauth => 'loc'
7506: );
7507: my %authnames = &authtype_names();
7508: foreach my $auth (@authtypes) {
7509: my $checked = ' ';
7510: if ($defaults{$item} eq $auth) {
7511: $checked = ' checked="checked" ';
7512: }
7513: $datatable .= '<label><input type="radio" name="'.$item.
7514: '" value="'.$auth.'"'.$checked.'/>'.
7515: $authnames{$shortauth{$auth}}.'</label> ';
7516: }
7517: } elsif ($item eq 'timezone_def') {
7518: my $includeempty = 1;
7519: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
7520: } elsif ($item eq 'datelocale_def') {
1.160.6.98 raeburn 7521: my $includeempty = 1;
7522: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
7523: } elsif ($item eq 'lang_def') {
7524: my $includeempty = 1;
7525: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.80 raeburn 7526: } else {
1.160.6.98 raeburn 7527: my $size;
7528: if ($item eq 'portal_def') {
7529: $size = ' size="25"';
7530: }
1.160.6.80 raeburn 7531: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.98 raeburn 7532: $defaults{$item}.'"'.$size.' />';
1.160.6.80 raeburn 7533: }
7534: $datatable .= '</td></tr>';
7535: $rownum ++;
7536: }
1.160.6.40 raeburn 7537: } else {
1.160.6.80 raeburn 7538: my %defaults;
1.160.6.40 raeburn 7539: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 7540: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 7541: my $maxnum = @{$settings->{'inststatusorder'}};
7542: for (my $i=0; $i<$maxnum; $i++) {
7543: $css_class = $rownum%2?' class="LC_odd_row"':'';
7544: my $item = $settings->{'inststatusorder'}->[$i];
7545: my $title = $settings->{'inststatustypes'}->{$item};
7546: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
7547: $datatable .= '<tr'.$css_class.'>'.
7548: '<td><span class="LC_nobreak">'.
7549: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
7550: for (my $k=0; $k<=$maxnum; $k++) {
7551: my $vpos = $k+1;
7552: my $selstr;
7553: if ($k == $i) {
7554: $selstr = ' selected="selected" ';
7555: }
7556: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7557: }
7558: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
7559: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
7560: &mt('delete').'</span></td>'.
1.160.6.112 raeburn 7561: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.160.6.40 raeburn 7562: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 7563: '</span></td></tr>';
1.160.6.40 raeburn 7564: }
7565: $css_class = $rownum%2?' class="LC_odd_row"':'';
7566: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
7567: $datatable .= '<tr '.$css_class.'>'.
7568: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
7569: for (my $k=0; $k<=$maxnum; $k++) {
7570: my $vpos = $k+1;
7571: my $selstr;
7572: if ($k == $maxnum) {
7573: $selstr = ' selected="selected" ';
7574: }
7575: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7576: }
7577: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 7578: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 7579: ' '.&mt('(new)').
7580: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.112 raeburn 7581: &mt('Name displayed').':'.
1.160.6.40 raeburn 7582: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
7583: '</tr>'."\n";
7584: $rownum ++;
1.141 raeburn 7585: }
1.43 raeburn 7586: }
7587: }
7588: $$rowtotal += $rownum;
7589: return $datatable;
7590: }
7591:
1.160.6.5 raeburn 7592: sub get_languages_hash {
7593: my %langchoices;
7594: foreach my $id (&Apache::loncommon::languageids()) {
7595: my $code = &Apache::loncommon::supportedlanguagecode($id);
7596: if ($code ne '') {
7597: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
7598: }
7599: }
7600: return %langchoices;
7601: }
7602:
1.43 raeburn 7603: sub defaults_titles {
1.141 raeburn 7604: my ($dom) = @_;
1.43 raeburn 7605: my %titles = &Apache::lonlocal::texthash (
7606: 'auth_def' => 'Default authentication type',
7607: 'auth_arg_def' => 'Default authentication argument',
7608: 'lang_def' => 'Default language',
1.54 raeburn 7609: 'timezone_def' => 'Default timezone',
1.68 raeburn 7610: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 7611: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 7612: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
7613: 'intauth_check' => 'Check bcrypt cost if authenticated',
7614: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 7615: );
1.141 raeburn 7616: if ($dom) {
7617: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
7618: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
7619: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
7620: $protocol = 'http' if ($protocol ne 'https');
7621: if ($uint_dom) {
7622: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
7623: $uint_dom);
7624: }
7625: }
1.43 raeburn 7626: return (\%titles);
7627: }
7628:
1.160.6.97 raeburn 7629: sub print_scantron {
7630: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
7631: if ($position eq 'top') {
7632: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
7633: } else {
7634: return &print_scantronconfig($dom,$settings,\$rowtotal);
7635: }
7636: }
7637:
7638: sub scantron_javascript {
7639: return <<"ENDSCRIPT";
7640:
7641: <script type="text/javascript">
7642: // <![CDATA[
7643:
7644: function toggleScantron(form) {
7645: var csvfieldset = new Array();
7646: if (document.getElementById('scantroncsv_cols')) {
7647: csvfieldset.push(document.getElementById('scantroncsv_cols'));
7648: }
7649: if (document.getElementById('scantroncsv_options')) {
7650: csvfieldset.push(document.getElementById('scantroncsv_options'));
7651: }
7652: if (csvfieldset.length) {
7653: if (document.getElementById('scantronconfcsv')) {
7654: var scantroncsv = document.getElementById('scantronconfcsv');
7655: if (scantroncsv.checked) {
7656: for (var i=0; i<csvfieldset.length; i++) {
7657: csvfieldset[i].style.display = 'block';
7658: }
7659: } else {
7660: for (var i=0; i<csvfieldset.length; i++) {
7661: csvfieldset[i].style.display = 'none';
7662: }
7663: var csvselects = document.getElementsByClassName('scantronconfig_csv');
7664: if (csvselects.length) {
7665: for (var j=0; j<csvselects.length; j++) {
7666: csvselects[j].selectedIndex = 0;
7667: }
7668: }
7669: }
7670: }
7671: }
7672: return;
7673: }
7674: // ]]>
7675: </script>
7676:
7677: ENDSCRIPT
7678:
7679: }
7680:
1.46 raeburn 7681: sub print_scantronformat {
7682: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
7683: my $itemcount = 1;
1.60 raeburn 7684: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
7685: %confhash);
1.46 raeburn 7686: my $switchserver = &check_switchserver($dom,$confname);
7687: my %lt = &Apache::lonlocal::texthash (
1.95 www 7688: default => 'Default bubblesheet format file error',
7689: custom => 'Custom bubblesheet format file error',
1.46 raeburn 7690: );
7691: my %scantronfiles = (
7692: default => 'default.tab',
7693: custom => 'custom.tab',
7694: );
7695: foreach my $key (keys(%scantronfiles)) {
7696: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
7697: .$scantronfiles{$key};
7698: }
7699: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
7700: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
7701: if (!$switchserver) {
7702: my $servadm = $r->dir_config('lonAdmEMail');
7703: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
7704: if ($configuserok eq 'ok') {
7705: if ($author_ok eq 'ok') {
7706: my %legacyfile = (
1.160.6.97 raeburn 7707: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
7708: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 7709: );
7710: my %md5chk;
7711: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7712: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
7713: chomp($md5chk{$type});
1.46 raeburn 7714: }
7715: if ($md5chk{'default'} ne $md5chk{'custom'}) {
7716: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 7717: ($scantronurls{$type},my $error) =
1.46 raeburn 7718: &legacy_scantronformat($r,$dom,$confname,
7719: $type,$legacyfile{$type},
7720: $scantronurls{$type},
7721: $scantronfiles{$type});
1.60 raeburn 7722: if ($error ne '') {
7723: $error{$type} = $error;
7724: }
7725: }
7726: if (keys(%error) == 0) {
7727: $is_custom = 1;
1.160.6.97 raeburn 7728: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 7729: $scantronurls{'custom'};
1.160.6.97 raeburn 7730: my $putresult =
1.60 raeburn 7731: &Apache::lonnet::put_dom('configuration',
7732: \%confhash,$dom);
7733: if ($putresult ne 'ok') {
1.160.6.97 raeburn 7734: $error{'custom'} =
1.60 raeburn 7735: '<span class="LC_error">'.
7736: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7737: }
1.46 raeburn 7738: }
7739: } else {
1.60 raeburn 7740: ($scantronurls{'default'},my $error) =
1.46 raeburn 7741: &legacy_scantronformat($r,$dom,$confname,
7742: 'default',$legacyfile{'default'},
7743: $scantronurls{'default'},
7744: $scantronfiles{'default'});
1.60 raeburn 7745: if ($error eq '') {
7746: $confhash{'scantron'}{'scantronformat'} = '';
7747: my $putresult =
7748: &Apache::lonnet::put_dom('configuration',
7749: \%confhash,$dom);
7750: if ($putresult ne 'ok') {
7751: $error{'default'} =
7752: '<span class="LC_error">'.
7753: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7754: }
7755: } else {
7756: $error{'default'} = $error;
7757: }
1.46 raeburn 7758: }
7759: }
7760: }
7761: } else {
1.95 www 7762: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 7763: }
7764: }
7765: if (ref($settings) eq 'HASH') {
7766: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
7767: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
7768: if ((!@info) || ($info[0] eq 'no_such_dir')) {
7769: $scantronurl = '';
7770: } else {
7771: $scantronurl = $settings->{'scantronformat'};
7772: }
7773: $is_custom = 1;
7774: } else {
7775: $scantronurl = $scantronurls{'default'};
7776: }
7777: } else {
1.60 raeburn 7778: if ($is_custom) {
7779: $scantronurl = $scantronurls{'custom'};
7780: } else {
7781: $scantronurl = $scantronurls{'default'};
7782: }
1.46 raeburn 7783: }
7784: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7785: $datatable .= '<tr'.$css_class.'>';
7786: if (!$is_custom) {
1.65 raeburn 7787: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
7788: '<span class="LC_nobreak">';
1.46 raeburn 7789: if ($scantronurl) {
1.160.6.21 raeburn 7790: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
7791: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 7792: } else {
7793: $datatable = &mt('File unavailable for display');
7794: }
1.65 raeburn 7795: $datatable .= '</span></td>';
1.60 raeburn 7796: if (keys(%error) == 0) {
7797: $datatable .= '<td valign="bottom">';
7798: if (!$switchserver) {
7799: $datatable .= &mt('Upload:').'<br />';
7800: }
7801: } else {
7802: my $errorstr;
7803: foreach my $key (sort(keys(%error))) {
7804: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7805: }
7806: $datatable .= '<td>'.$errorstr;
7807: }
1.46 raeburn 7808: } else {
7809: if (keys(%error) > 0) {
7810: my $errorstr;
7811: foreach my $key (sort(keys(%error))) {
7812: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7813: }
1.60 raeburn 7814: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 7815: } elsif ($scantronurl) {
1.160.6.26 raeburn 7816: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 7817: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 7818: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 7819: $link.
7820: '<label><input type="checkbox" name="scantronformat_del"'.
7821: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 7822: '<td><span class="LC_nobreak"> '.
7823: &mt('Replace:').'</span><br />';
1.46 raeburn 7824: }
7825: }
7826: if (keys(%error) == 0) {
7827: if ($switchserver) {
7828: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
7829: } else {
1.65 raeburn 7830: $datatable .='<span class="LC_nobreak"> '.
7831: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 7832: }
7833: }
7834: $datatable .= '</td></tr>';
7835: $$rowtotal ++;
7836: return $datatable;
7837: }
7838:
7839: sub legacy_scantronformat {
7840: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
7841: my ($url,$error);
7842: my @statinfo = &Apache::lonnet::stat_file($newurl);
7843: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
7844: (my $result,$url) =
7845: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
7846: '','',$newfile);
7847: if ($result ne 'ok') {
1.130 raeburn 7848: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 7849: }
7850: }
7851: return ($url,$error);
7852: }
1.43 raeburn 7853:
1.160.6.97 raeburn 7854: sub print_scantronconfig {
7855: my ($dom,$settings,$rowtotal) = @_;
7856: my $itemcount = 2;
7857: my $is_checked = ' checked="checked"';
7858: my %optionson = (
7859: hdr => ' checked="checked"',
7860: pad => ' checked="checked"',
7861: rem => ' checked="checked"',
7862: );
7863: my %optionsoff = (
7864: hdr => '',
7865: pad => '',
7866: rem => '',
7867: );
7868: my $currcsvsty = 'none';
7869: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
7870: my @fields = &scantroncsv_fields();
7871: my %titles = &scantronconfig_titles();
7872: if (ref($settings) eq 'HASH') {
7873: if (ref($settings->{config}) eq 'HASH') {
7874: if ($settings->{config}->{dat}) {
7875: $checked{'dat'} = $is_checked;
7876: }
7877: if (ref($settings->{config}->{csv}) eq 'HASH') {
7878: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
7879: %csvfields = %{$settings->{config}->{csv}->{fields}};
7880: if (keys(%csvfields) > 0) {
7881: $checked{'csv'} = $is_checked;
7882: $currcsvsty = 'block';
7883: }
7884: }
7885: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
7886: %csvoptions = %{$settings->{config}->{csv}->{options}};
7887: foreach my $option (keys(%optionson)) {
7888: unless ($csvoptions{$option}) {
7889: $optionsoff{$option} = $optionson{$option};
7890: $optionson{$option} = '';
7891: }
7892: }
7893: }
7894: }
7895: } else {
7896: $checked{'dat'} = $is_checked;
7897: }
7898: } else {
7899: $checked{'dat'} = $is_checked;
7900: }
7901: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
7902: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7903: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
7904: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
7905: foreach my $item ('dat','csv') {
7906: my $id;
7907: if ($item eq 'csv') {
7908: $id = 'id="scantronconfcsv" ';
7909: }
7910: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
7911: $titles{$item}.'</label>'.(' 'x3);
7912: if ($item eq 'csv') {
7913: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
7914: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
7915: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
7916: foreach my $col (@fields) {
7917: my $selnone;
7918: if ($csvfields{$col} eq '') {
7919: $selnone = ' selected="selected"';
7920: }
7921: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
7922: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
7923: '<option value=""'.$selnone.'></option>';
7924: for (my $i=0; $i<20; $i++) {
7925: my $shown = $i+1;
7926: my $sel;
7927: unless ($selnone) {
7928: if (exists($csvfields{$col})) {
7929: if ($csvfields{$col} == $i) {
7930: $sel = ' selected="selected"';
7931: }
7932: }
7933: }
7934: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
7935: }
7936: $datatable .= '</select></td></tr>';
7937: }
7938: $datatable .= '</table></fieldset>'.
7939: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
7940: '<legend>'.&mt('CSV Options').'</legend>';
7941: foreach my $option ('hdr','pad','rem') {
7942: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
7943: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
7944: &mt('Yes').'</label>'.(' 'x2)."\n".
7945: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
7946: }
7947: $datatable .= '</fieldset>';
7948: $itemcount ++;
7949: }
7950: }
7951: $datatable .= '</td></tr>';
7952: $$rowtotal ++;
7953: return $datatable;
7954: }
7955:
7956: sub scantronconfig_titles {
7957: return &Apache::lonlocal::texthash(
7958: dat => 'Standard format (.dat)',
7959: csv => 'Comma separated values (.csv)',
7960: hdr => 'Remove first line in file (contains column titles)',
7961: pad => 'Prepend 0s to PaperID',
7962: rem => 'Remove leading spaces (except Question Response columns)',
7963: CODE => 'CODE',
7964: ID => 'Student ID',
7965: PaperID => 'Paper ID',
7966: FirstName => 'First Name',
7967: LastName => 'Last Name',
7968: FirstQuestion => 'First Question Response',
7969: Section => 'Section',
7970: );
7971: }
7972:
7973: sub scantroncsv_fields {
7974: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
7975: }
7976:
1.49 raeburn 7977: sub print_coursecategories {
1.57 raeburn 7978: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
7979: my $datatable;
7980: if ($position eq 'top') {
1.160.6.42 raeburn 7981: my (%checked);
7982: my @catitems = ('unauth','auth');
7983: my @cattypes = ('std','domonly','codesrch','none');
7984: $checked{'unauth'} = 'std';
7985: $checked{'auth'} = 'std';
7986: if (ref($settings) eq 'HASH') {
7987: foreach my $type (@cattypes) {
7988: if ($type eq $settings->{'unauth'}) {
7989: $checked{'unauth'} = $type;
7990: }
7991: if ($type eq $settings->{'auth'}) {
7992: $checked{'auth'} = $type;
7993: }
7994: }
7995: }
7996: my %lt = &Apache::lonlocal::texthash (
7997: unauth => 'Catalog type for unauthenticated users',
7998: auth => 'Catalog type for authenticated users',
7999: none => 'No catalog',
8000: std => 'Standard catalog',
8001: domonly => 'Domain-only catalog',
8002: codesrch => "Code search form",
8003: );
8004: my $itemcount = 0;
8005: foreach my $item (@catitems) {
8006: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8007: $datatable .= '<tr '.$css_class.'>'.
8008: '<td>'.$lt{$item}.'</td>'.
8009: '<td class="LC_right_item"><span class="LC_nobreak">';
8010: foreach my $type (@cattypes) {
8011: my $ischecked;
8012: if ($checked{$item} eq $type) {
8013: $ischecked=' checked="checked"';
8014: }
8015: $datatable .= '<label>'.
8016: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
8017: ' />'.$lt{$type}.'</label> ';
8018: }
1.160.6.87 raeburn 8019: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 8020: $itemcount ++;
8021: }
8022: $$rowtotal += $itemcount;
8023: } elsif ($position eq 'middle') {
1.57 raeburn 8024: my $toggle_cats_crs = ' ';
8025: my $toggle_cats_dom = ' checked="checked" ';
8026: my $can_cat_crs = ' ';
8027: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 8028: my $toggle_catscomm_comm = ' ';
8029: my $toggle_catscomm_dom = ' checked="checked" ';
8030: my $can_catcomm_comm = ' ';
8031: my $can_catcomm_dom = ' checked="checked" ';
8032:
1.57 raeburn 8033: if (ref($settings) eq 'HASH') {
8034: if ($settings->{'togglecats'} eq 'crs') {
8035: $toggle_cats_crs = $toggle_cats_dom;
8036: $toggle_cats_dom = ' ';
8037: }
8038: if ($settings->{'categorize'} eq 'crs') {
8039: $can_cat_crs = $can_cat_dom;
8040: $can_cat_dom = ' ';
8041: }
1.120 raeburn 8042: if ($settings->{'togglecatscomm'} eq 'comm') {
8043: $toggle_catscomm_comm = $toggle_catscomm_dom;
8044: $toggle_catscomm_dom = ' ';
8045: }
8046: if ($settings->{'categorizecomm'} eq 'comm') {
8047: $can_catcomm_comm = $can_catcomm_dom;
8048: $can_catcomm_dom = ' ';
8049: }
1.57 raeburn 8050: }
8051: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 8052: togglecats => 'Show/Hide a course in catalog',
8053: togglecatscomm => 'Show/Hide a community in catalog',
8054: categorize => 'Assign a category to a course',
8055: categorizecomm => 'Assign a category to a community',
1.57 raeburn 8056: );
8057: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 8058: dom => 'Set in Domain',
8059: crs => 'Set in Course',
8060: comm => 'Set in Community',
1.57 raeburn 8061: );
8062: $datatable = '<tr class="LC_odd_row">'.
8063: '<td>'.$title{'togglecats'}.'</td>'.
8064: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8065: '<input type="radio" name="togglecats"'.
8066: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8067: '<label><input type="radio" name="togglecats"'.
8068: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
8069: '</tr><tr>'.
8070: '<td>'.$title{'categorize'}.'</td>'.
8071: '<td class="LC_right_item"><span class="LC_nobreak">'.
8072: '<label><input type="radio" name="categorize"'.
8073: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8074: '<label><input type="radio" name="categorize"'.
8075: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 8076: '</tr><tr class="LC_odd_row">'.
8077: '<td>'.$title{'togglecatscomm'}.'</td>'.
8078: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8079: '<input type="radio" name="togglecatscomm"'.
8080: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8081: '<label><input type="radio" name="togglecatscomm"'.
8082: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
8083: '</tr><tr>'.
8084: '<td>'.$title{'categorizecomm'}.'</td>'.
8085: '<td class="LC_right_item"><span class="LC_nobreak">'.
8086: '<label><input type="radio" name="categorizecomm"'.
8087: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8088: '<label><input type="radio" name="categorizecomm"'.
8089: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 8090: '</tr>';
1.120 raeburn 8091: $$rowtotal += 4;
1.57 raeburn 8092: } else {
8093: my $css_class;
8094: my $itemcount = 1;
8095: my $cathash;
8096: if (ref($settings) eq 'HASH') {
8097: $cathash = $settings->{'cats'};
8098: }
8099: if (ref($cathash) eq 'HASH') {
8100: my (@cats,@trails,%allitems,%idx,@jsarray);
8101: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
8102: \%allitems,\%idx,\@jsarray);
8103: my $maxdepth = scalar(@cats);
8104: my $colattrib = '';
8105: if ($maxdepth > 2) {
8106: $colattrib = ' colspan="2" ';
8107: }
8108: my @path;
8109: if (@cats > 0) {
8110: if (ref($cats[0]) eq 'ARRAY') {
8111: my $numtop = @{$cats[0]};
8112: my $maxnum = $numtop;
1.120 raeburn 8113: my %default_names = (
8114: instcode => &mt('Official courses'),
8115: communities => &mt('Communities'),
8116: );
8117:
8118: if ((!grep(/^instcode$/,@{$cats[0]})) ||
8119: ($cathash->{'instcode::0'} eq '') ||
8120: (!grep(/^communities$/,@{$cats[0]})) ||
8121: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 8122: $maxnum ++;
8123: }
8124: my $lastidx;
8125: for (my $i=0; $i<$numtop; $i++) {
8126: my $parent = $cats[0][$i];
8127: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8128: my $item = &escape($parent).'::0';
8129: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
8130: $lastidx = $idx{$item};
8131: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8132: .'<select name="'.$item.'"'.$chgstr.'>';
8133: for (my $k=0; $k<=$maxnum; $k++) {
8134: my $vpos = $k+1;
8135: my $selstr;
8136: if ($k == $i) {
8137: $selstr = ' selected="selected" ';
8138: }
8139: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8140: }
1.160.6.29 raeburn 8141: $datatable .= '</select></span></td><td>';
1.120 raeburn 8142: if ($parent eq 'instcode' || $parent eq 'communities') {
8143: $datatable .= '<span class="LC_nobreak">'
8144: .$default_names{$parent}.'</span>';
8145: if ($parent eq 'instcode') {
8146: $datatable .= '<br /><span class="LC_nobreak">('
8147: .&mt('with institutional codes')
8148: .')</span></td><td'.$colattrib.'>';
8149: } else {
8150: $datatable .= '<table><tr><td>';
8151: }
8152: $datatable .= '<span class="LC_nobreak">'
8153: .'<label><input type="radio" name="'
8154: .$parent.'" value="1" checked="checked" />'
8155: .&mt('Display').'</label>';
8156: if ($parent eq 'instcode') {
8157: $datatable .= ' ';
8158: } else {
8159: $datatable .= '</span></td></tr><tr><td>'
8160: .'<span class="LC_nobreak">';
8161: }
8162: $datatable .= '<label><input type="radio" name="'
8163: .$parent.'" value="0" />'
8164: .&mt('Do not display').'</label></span>';
8165: if ($parent eq 'communities') {
8166: $datatable .= '</td></tr></table>';
8167: }
8168: $datatable .= '</td>';
1.57 raeburn 8169: } else {
8170: $datatable .= $parent
1.160.6.29 raeburn 8171: .' <span class="LC_nobreak"><label>'
8172: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 8173: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
8174: }
8175: my $depth = 1;
8176: push(@path,$parent);
8177: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
8178: pop(@path);
8179: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8180: $itemcount ++;
8181: }
1.48 raeburn 8182: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 8183: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
8184: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 8185: for (my $k=0; $k<=$maxnum; $k++) {
8186: my $vpos = $k+1;
8187: my $selstr;
1.57 raeburn 8188: if ($k == $numtop) {
1.48 raeburn 8189: $selstr = ' selected="selected" ';
8190: }
8191: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8192: }
1.59 bisitz 8193: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 8194: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
8195: .'</tr>'."\n";
1.48 raeburn 8196: $itemcount ++;
1.120 raeburn 8197: foreach my $default ('instcode','communities') {
8198: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
8199: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8200: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
8201: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
8202: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
8203: for (my $k=0; $k<=$maxnum; $k++) {
8204: my $vpos = $k+1;
8205: my $selstr;
8206: if ($k == $maxnum) {
8207: $selstr = ' selected="selected" ';
8208: }
8209: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 8210: }
1.120 raeburn 8211: $datatable .= '</select></span></td>'.
8212: '<td><span class="LC_nobreak">'.
8213: $default_names{$default}.'</span>';
8214: if ($default eq 'instcode') {
8215: $datatable .= '<br /><span class="LC_nobreak">('
8216: .&mt('with institutional codes').')</span>';
8217: }
8218: $datatable .= '</td>'
8219: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
8220: .&mt('Display').'</label> '
8221: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
8222: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 8223: }
8224: }
8225: }
1.57 raeburn 8226: } else {
8227: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 8228: }
8229: } else {
1.160.6.87 raeburn 8230: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 8231: .&initialize_categories($itemcount);
1.48 raeburn 8232: }
1.57 raeburn 8233: $$rowtotal += $itemcount;
1.48 raeburn 8234: }
8235: return $datatable;
8236: }
8237:
1.69 raeburn 8238: sub print_serverstatuses {
8239: my ($dom,$settings,$rowtotal) = @_;
8240: my $datatable;
8241: my @pages = &serverstatus_pages();
8242: my (%namedaccess,%machineaccess);
8243: foreach my $type (@pages) {
8244: $namedaccess{$type} = '';
8245: $machineaccess{$type}= '';
8246: }
8247: if (ref($settings) eq 'HASH') {
8248: foreach my $type (@pages) {
8249: if (exists($settings->{$type})) {
8250: if (ref($settings->{$type}) eq 'HASH') {
8251: foreach my $key (keys(%{$settings->{$type}})) {
8252: if ($key eq 'namedusers') {
8253: $namedaccess{$type} = $settings->{$type}->{$key};
8254: } elsif ($key eq 'machines') {
8255: $machineaccess{$type} = $settings->{$type}->{$key};
8256: }
8257: }
8258: }
8259: }
8260: }
8261: }
1.81 raeburn 8262: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8263: my $rownum = 0;
8264: my $css_class;
8265: foreach my $type (@pages) {
8266: $rownum ++;
8267: $css_class = $rownum%2?' class="LC_odd_row"':'';
8268: $datatable .= '<tr'.$css_class.'>'.
8269: '<td><span class="LC_nobreak">'.
8270: $titles->{$type}.'</span></td>'.
8271: '<td class="LC_left_item">'.
8272: '<input type="text" name="'.$type.'_namedusers" '.
8273: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
8274: '<td class="LC_right_item">'.
8275: '<span class="LC_nobreak">'.
8276: '<input type="text" name="'.$type.'_machines" '.
8277: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 8278: '</span></td></tr>'."\n";
1.69 raeburn 8279: }
8280: $$rowtotal += $rownum;
8281: return $datatable;
8282: }
8283:
8284: sub serverstatus_pages {
8285: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 8286: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 8287: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 8288: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 8289: }
8290:
1.160.6.40 raeburn 8291: sub defaults_javascript {
8292: my ($settings) = @_;
1.160.6.98 raeburn 8293: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 8294: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8295: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
8296: if ($maxnum eq '') {
8297: $maxnum = 0;
8298: }
8299: $maxnum ++;
1.160.6.51 raeburn 8300: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 8301: return <<"ENDSCRIPT";
8302: <script type="text/javascript">
8303: // <![CDATA[
8304: function reorderTypes(form,caller) {
8305: var changedVal;
8306: $jstext
8307: var newpos = 'addinststatus_pos';
8308: var current = new Array;
8309: var maxh = $maxnum;
8310: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8311: var oldVal;
8312: if (caller == newpos) {
8313: changedVal = newitemVal;
8314: } else {
8315: var curritem = 'inststatus_pos_'+caller;
8316: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
8317: current[newitemVal] = newpos;
8318: }
8319: for (var i=0; i<inststatuses.length; i++) {
8320: if (inststatuses[i] != caller) {
8321: var elementName = 'inststatus_pos_'+inststatuses[i];
8322: if (form.elements[elementName]) {
8323: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8324: current[currVal] = elementName;
8325: }
8326: }
8327: }
8328: for (var j=0; j<maxh; j++) {
8329: if (current[j] == undefined) {
8330: oldVal = j;
8331: }
8332: }
8333: if (oldVal < changedVal) {
8334: for (var k=oldVal+1; k<=changedVal ; k++) {
8335: var elementName = current[k];
8336: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8337: }
8338: } else {
8339: for (var k=changedVal; k<oldVal; k++) {
8340: var elementName = current[k];
8341: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8342: }
8343: }
8344: return;
8345: }
8346:
8347: // ]]>
8348: </script>
8349:
8350: ENDSCRIPT
8351: }
8352: }
8353:
1.160.6.98 raeburn 8354: sub passwords_javascript {
1.160.6.99 raeburn 8355: my %intalert = &Apache::lonlocal::texthash (
8356: 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.',
8357: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
8358: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
8359: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
8360: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
8361: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
8362: );
8363: &js_escape(\%intalert);
8364: my $defmin = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 8365: my $intauthjs = <<"ENDSCRIPT";
8366:
8367: function warnIntAuth(field) {
8368: if (field.name == 'intauth_check') {
8369: if (field.value == '2') {
1.160.6.99 raeburn 8370: alert('$intalert{authcheck}');
1.160.6.98 raeburn 8371: }
8372: }
8373: if (field.name == 'intauth_cost') {
8374: field.value.replace(/\s/g,'');
8375: if (field.value != '') {
8376: var regexdigit=/^\\d+\$/;
8377: if (!regexdigit.test(field.value)) {
1.160.6.99 raeburn 8378: alert('$intalert{authcost}');
8379: }
8380: }
8381: }
8382: return;
8383: }
8384:
8385: function warnIntPass(field) {
8386: field.value.replace(/^\s+/,'');
8387: field.value.replace(/\s+\$/,'');
8388: var regexdigit=/^\\d+\$/;
8389: if (field.name == 'passwords_min') {
8390: if (field.value == '') {
8391: alert('$intalert{passmin}');
8392: field.value = '$defmin';
8393: } else {
8394: if (!regexdigit.test(field.value)) {
8395: alert('$intalert{passmin}');
8396: field.value = '$defmin';
8397: }
8398: var minval = parseInt(field.value,10);
8399: if (minval < $defmin) {
8400: alert('$intalert{passmin}');
8401: field.value = '$defmin';
8402: }
8403: }
8404: } else {
8405: if (field.value == '0') {
8406: field.value = '';
8407: }
8408: if (field.value != '') {
8409: if (field.name == 'passwords_expire') {
8410: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
8411: if (!regexpposnum.test(field.value)) {
8412: alert('$intalert{passexp}');
8413: field.value = '';
8414: } else {
8415: var expval = parseFloat(field.value);
8416: if (expval == 0) {
8417: alert('$intalert{passexp}');
8418: field.value = '';
8419: }
8420: }
8421: } else {
8422: if (!regexdigit.test(field.value)) {
8423: if (field.name == 'passwords_max') {
8424: alert('$intalert{passmax}');
8425: } else {
8426: if (field.name == 'passwords_numsaved') {
8427: alert('$intalert{passnum}');
8428: }
8429: }
1.160.6.104 raeburn 8430: field.value = '';
1.160.6.99 raeburn 8431: }
1.160.6.98 raeburn 8432: }
8433: }
8434: }
8435: return;
8436: }
8437:
8438: ENDSCRIPT
8439: return &Apache::lonhtmlcommon::scripttag($intauthjs);
8440: }
8441:
1.49 raeburn 8442: sub coursecategories_javascript {
8443: my ($settings) = @_;
1.57 raeburn 8444: my ($output,$jstext,$cathash);
1.49 raeburn 8445: if (ref($settings) eq 'HASH') {
1.57 raeburn 8446: $cathash = $settings->{'cats'};
8447: }
8448: if (ref($cathash) eq 'HASH') {
1.49 raeburn 8449: my (@cats,@jsarray,%idx);
1.57 raeburn 8450: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 8451: if (@jsarray > 0) {
8452: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
8453: for (my $i=0; $i<@jsarray; $i++) {
8454: if (ref($jsarray[$i]) eq 'ARRAY') {
8455: my $catstr = join('","',@{$jsarray[$i]});
8456: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
8457: }
8458: }
8459: }
8460: } else {
8461: $jstext = ' var categories = Array(1);'."\n".
8462: ' categories[0] = Array("instcode_pos");'."\n";
8463: }
1.160.6.42 raeburn 8464: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
8465: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 8466: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
8467: &js_escape(\$instcode_reserved);
8468: &js_escape(\$communities_reserved);
8469: &js_escape(\$choose_again);
1.49 raeburn 8470: $output = <<"ENDSCRIPT";
8471: <script type="text/javascript">
1.109 raeburn 8472: // <![CDATA[
1.49 raeburn 8473: function reorderCats(form,parent,item,idx) {
8474: var changedVal;
8475: $jstext
8476: var newpos = 'addcategory_pos';
8477: if (parent == '') {
8478: var has_instcode = 0;
8479: var maxtop = categories[idx].length;
8480: for (var j=0; j<maxtop; j++) {
8481: if (categories[idx][j] == 'instcode::0') {
8482: has_instcode == 1;
8483: }
8484: }
8485: if (has_instcode == 0) {
8486: categories[idx][maxtop] = 'instcode_pos';
8487: }
8488: } else {
8489: newpos += '_'+parent;
8490: }
8491: var maxh = 1 + categories[idx].length;
8492: var current = new Array;
8493: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8494: if (item == newpos) {
8495: changedVal = newitemVal;
8496: } else {
8497: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
8498: current[newitemVal] = newpos;
8499: }
8500: for (var i=0; i<categories[idx].length; i++) {
8501: var elementName = categories[idx][i];
8502: if (elementName != item) {
8503: if (form.elements[elementName]) {
8504: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8505: current[currVal] = elementName;
8506: }
8507: }
8508: }
8509: var oldVal;
8510: for (var j=0; j<maxh; j++) {
8511: if (current[j] == undefined) {
8512: oldVal = j;
8513: }
8514: }
8515: if (oldVal < changedVal) {
8516: for (var k=oldVal+1; k<=changedVal ; k++) {
8517: var elementName = current[k];
8518: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8519: }
8520: } else {
8521: for (var k=changedVal; k<oldVal; k++) {
8522: var elementName = current[k];
8523: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8524: }
8525: }
8526: return;
8527: }
1.120 raeburn 8528:
8529: function categoryCheck(form) {
8530: if (form.elements['addcategory_name'].value == 'instcode') {
8531: alert('$instcode_reserved\\n$choose_again');
8532: return false;
8533: }
8534: if (form.elements['addcategory_name'].value == 'communities') {
8535: alert('$communities_reserved\\n$choose_again');
8536: return false;
8537: }
8538: return true;
8539: }
8540:
1.109 raeburn 8541: // ]]>
1.49 raeburn 8542: </script>
8543:
8544: ENDSCRIPT
8545: return $output;
8546: }
8547:
1.48 raeburn 8548: sub initialize_categories {
8549: my ($itemcount) = @_;
1.120 raeburn 8550: my ($datatable,$css_class,$chgstr);
1.160.6.111 raeburn 8551: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 8552: instcode => 'Official courses (with institutional codes)',
8553: communities => 'Communities',
8554: );
8555: my $select0 = ' selected="selected"';
8556: my $select1 = '';
8557: foreach my $default ('instcode','communities') {
8558: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 8559: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 8560: if ($default eq 'communities') {
8561: $select1 = $select0;
8562: $select0 = '';
8563: }
8564: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8565: .'<select name="'.$default.'_pos">'
8566: .'<option value="0"'.$select0.'>1</option>'
8567: .'<option value="1"'.$select1.'>2</option>'
8568: .'<option value="2">3</option></select> '
8569: .$default_names{$default}
8570: .'</span></td><td><span class="LC_nobreak">'
8571: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
8572: .&mt('Display').'</label> <label>'
8573: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 8574: .'</label></span></td></tr>';
1.120 raeburn 8575: $itemcount ++;
8576: }
1.48 raeburn 8577: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 8578: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 8579: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 8580: .'<select name="addcategory_pos"'.$chgstr.'>'
8581: .'<option value="0">1</option>'
8582: .'<option value="1">2</option>'
8583: .'<option value="2" selected="selected">3</option></select> '
1.160.6.103 raeburn 8584: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
1.160.6.87 raeburn 8585: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
8586: .'</td></tr>';
1.48 raeburn 8587: return $datatable;
8588: }
8589:
8590: sub build_category_rows {
1.49 raeburn 8591: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
8592: my ($text,$name,$item,$chgstr);
1.48 raeburn 8593: if (ref($cats) eq 'ARRAY') {
8594: my $maxdepth = scalar(@{$cats});
8595: if (ref($cats->[$depth]) eq 'HASH') {
8596: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8597: my $numchildren = @{$cats->[$depth]{$parent}};
8598: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 8599: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 8600: my ($idxnum,$parent_name,$parent_item);
8601: my $higher = $depth - 1;
8602: if ($higher == 0) {
8603: $parent_name = &escape($parent).'::'.$higher;
8604: } else {
8605: if (ref($path) eq 'ARRAY') {
8606: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8607: }
8608: }
8609: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 8610: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 8611: if ($j < $numchildren) {
1.48 raeburn 8612: $name = $cats->[$depth]{$parent}[$j];
8613: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 8614: $idxnum = $idx->{$item};
8615: } else {
8616: $name = $parent_name;
8617: $item = $parent_item;
1.48 raeburn 8618: }
1.49 raeburn 8619: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8620: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 8621: for (my $i=0; $i<=$numchildren; $i++) {
8622: my $vpos = $i+1;
8623: my $selstr;
8624: if ($j == $i) {
8625: $selstr = ' selected="selected" ';
8626: }
8627: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8628: }
8629: $text .= '</select> ';
8630: if ($j < $numchildren) {
8631: my $deeper = $depth+1;
8632: $text .= $name.' '
8633: .'<label><input type="checkbox" name="deletecategory" value="'
8634: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8635: if(ref($path) eq 'ARRAY') {
8636: push(@{$path},$name);
1.49 raeburn 8637: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 8638: pop(@{$path});
8639: }
8640: } else {
1.160.6.87 raeburn 8641: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 8642: if ($j == $numchildren) {
8643: $text .= $name;
8644: } else {
8645: $text .= $item;
8646: }
8647: $text .= '" value="" />';
8648: }
8649: $text .= '</td></tr>';
8650: }
8651: $text .= '</table></td>';
8652: } else {
8653: my $higher = $depth-1;
8654: if ($higher == 0) {
8655: $name = &escape($parent).'::'.$higher;
8656: } else {
8657: if (ref($path) eq 'ARRAY') {
8658: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8659: }
8660: }
8661: my $colspan;
8662: if ($parent ne 'instcode') {
8663: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 8664: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 8665: }
8666: }
8667: }
8668: }
8669: return $text;
8670: }
8671:
1.33 raeburn 8672: sub modifiable_userdata_row {
1.160.6.93 raeburn 8673: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
8674: $rowid,$customcss,$rowstyle) = @_;
1.160.6.35 raeburn 8675: my ($role,$rolename,$statustype);
8676: $role = $item;
1.160.6.34 raeburn 8677: if ($context eq 'cancreate') {
1.160.6.93 raeburn 8678: if ($item =~ /^(emailusername)_(.+)$/) {
8679: $role = $1;
8680: $statustype = $2;
1.160.6.35 raeburn 8681: if (ref($usertypes) eq 'HASH') {
8682: if ($usertypes->{$statustype}) {
8683: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
8684: } else {
8685: $rolename = &mt('Data provided by user');
8686: }
8687: }
1.160.6.34 raeburn 8688: }
8689: } elsif ($context eq 'selfcreate') {
1.63 raeburn 8690: if (ref($usertypes) eq 'HASH') {
8691: $rolename = $usertypes->{$role};
8692: } else {
8693: $rolename = $role;
8694: }
1.33 raeburn 8695: } else {
1.63 raeburn 8696: if ($role eq 'cr') {
8697: $rolename = &mt('Custom role');
8698: } else {
8699: $rolename = &Apache::lonnet::plaintext($role);
8700: }
1.33 raeburn 8701: }
1.160.6.34 raeburn 8702: my (@fields,%fieldtitles);
8703: if (ref($fieldsref) eq 'ARRAY') {
8704: @fields = @{$fieldsref};
8705: } else {
8706: @fields = ('lastname','firstname','middlename','generation',
8707: 'permanentemail','id');
8708: }
8709: if ((ref($titlesref) eq 'HASH')) {
8710: %fieldtitles = %{$titlesref};
8711: } else {
8712: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8713: }
1.33 raeburn 8714: my $output;
1.160.6.93 raeburn 8715: my $css_class;
8716: if ($rowcount%2) {
8717: $css_class = 'LC_odd_row';
8718: }
8719: if ($customcss) {
8720: $css_class .= " $customcss";
8721: }
8722: $css_class =~ s/^\s+//;
8723: if ($css_class) {
8724: $css_class = ' class="'.$css_class.'"';
8725: }
8726: if ($rowstyle) {
8727: $css_class .= ' style="'.$rowstyle.'"';
8728: }
8729: if ($rowid) {
8730: $rowid = ' id="'.$rowid.'"';
8731: }
8732:
8733: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 8734: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
8735: '<td class="LC_left_item" colspan="2"><table>';
8736: my $rem;
8737: my %checks;
8738: if (ref($settings) eq 'HASH') {
8739: if (ref($settings->{$context}) eq 'HASH') {
8740: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 8741: my $hashref = $settings->{$context}->{$role};
8742: if ($role eq 'emailusername') {
8743: if ($statustype) {
8744: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
8745: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 8746: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 8747: foreach my $field (@fields) {
8748: if ($hashref->{$field}) {
8749: $checks{$field} = $hashref->{$field};
8750: }
8751: }
8752: }
8753: }
8754: }
8755: } else {
8756: if (ref($hashref) eq 'HASH') {
8757: foreach my $field (@fields) {
8758: if ($hashref->{$field}) {
8759: $checks{$field} = ' checked="checked" ';
8760: }
8761: }
1.33 raeburn 8762: }
8763: }
8764: }
8765: }
8766: }
1.160.6.93 raeburn 8767:
8768: my $total = scalar(@fields);
8769: for (my $i=0; $i<$total; $i++) {
8770: $rem = $i%($numinrow);
1.33 raeburn 8771: if ($rem == 0) {
8772: if ($i > 0) {
8773: $output .= '</tr>';
8774: }
8775: $output .= '<tr>';
8776: }
8777: my $check = ' ';
1.160.6.35 raeburn 8778: unless ($role eq 'emailusername') {
8779: if (exists($checks{$fields[$i]})) {
1.160.6.98 raeburn 8780: $check = $checks{$fields[$i]};
1.160.6.35 raeburn 8781: } else {
8782: if ($role eq 'st') {
8783: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 8784: $check = ' checked="checked" ';
1.160.6.35 raeburn 8785: }
1.33 raeburn 8786: }
8787: }
8788: }
8789: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 8790: '<span class="LC_nobreak">';
8791: if ($role eq 'emailusername') {
8792: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
8793: $checks{$fields[$i]} = 'omit';
8794: }
8795: foreach my $option ('required','optional','omit') {
8796: my $checked='';
8797: if ($checks{$fields[$i]} eq $option) {
8798: $checked='checked="checked" ';
8799: }
8800: $output .= '<label>'.
8801: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
8802: &mt($option).'</label>'.(' ' x2);
8803: }
8804: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
8805: } else {
8806: $output .= '<label>'.
8807: '<input type="checkbox" name="canmodify_'.$role.'" '.
8808: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
8809: '</label>';
8810: }
8811: $output .= '</span></td>';
1.33 raeburn 8812: }
1.160.6.93 raeburn 8813: $rem = $total%$numinrow;
8814: my $colsleft;
8815: if ($rem) {
8816: $colsleft = $numinrow - $rem;
8817: }
8818: if ($colsleft > 1) {
1.33 raeburn 8819: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8820: ' </td>';
8821: } elsif ($colsleft == 1) {
8822: $output .= '<td class="LC_left_item"> </td>';
8823: }
8824: $output .= '</tr></table></td></tr>';
8825: return $output;
8826: }
1.28 raeburn 8827:
1.93 raeburn 8828: sub insttypes_row {
1.160.6.93 raeburn 8829: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
8830: $customcss,$rowstyle) = @_;
1.93 raeburn 8831: my %lt = &Apache::lonlocal::texthash (
8832: cansearch => 'Users allowed to search',
8833: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 8834: lockablenames => 'User preference to lock name',
1.160.6.93 raeburn 8835: selfassign => 'Self-reportable affiliations',
1.160.6.101 raeburn 8836: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 8837: );
8838: my $showdom;
8839: if ($context eq 'cansearch') {
8840: $showdom = ' ('.$dom.')';
8841: }
1.160.6.5 raeburn 8842: my $class = 'LC_left_item';
8843: if ($context eq 'statustocreate') {
8844: $class = 'LC_right_item';
8845: }
1.160.6.93 raeburn 8846: my $css_class;
8847: if ($$rowtotal%2) {
8848: $css_class = 'LC_odd_row';
8849: }
8850: if ($customcss) {
8851: $css_class .= ' '.$customcss;
8852: }
8853: $css_class =~ s/^\s+//;
8854: if ($css_class) {
8855: $css_class = ' class="'.$css_class.'"';
8856: }
8857: if ($rowstyle) {
8858: $css_class .= ' style="'.$rowstyle.'"';
8859: }
8860: if ($onclick) {
8861: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 8862: }
8863: my $output = '<tr'.$css_class.'>'.
8864: '<td>'.$lt{$context}.$showdom.
8865: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 8866: my $rem;
8867: if (ref($types) eq 'ARRAY') {
8868: for (my $i=0; $i<@{$types}; $i++) {
8869: if (defined($usertypes->{$types->[$i]})) {
8870: my $rem = $i%($numinrow);
8871: if ($rem == 0) {
8872: if ($i > 0) {
8873: $output .= '</tr>';
8874: }
8875: $output .= '<tr>';
1.23 raeburn 8876: }
1.26 raeburn 8877: my $check = ' ';
1.99 raeburn 8878: if (ref($settings) eq 'HASH') {
8879: if (ref($settings->{$context}) eq 'ARRAY') {
8880: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
8881: $check = ' checked="checked" ';
8882: }
1.160.6.101 raeburn 8883: } elsif (ref($settings->{$context}) eq 'HASH') {
8884: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
8885: $check = ' checked="checked" ';
8886: }
1.99 raeburn 8887: } elsif ($context eq 'statustocreate') {
1.26 raeburn 8888: $check = ' checked="checked" ';
8889: }
1.23 raeburn 8890: }
1.26 raeburn 8891: $output .= '<td class="LC_left_item">'.
8892: '<span class="LC_nobreak"><label>'.
1.93 raeburn 8893: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 8894: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
1.26 raeburn 8895: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 8896: }
8897: }
1.26 raeburn 8898: $rem = @{$types}%($numinrow);
1.23 raeburn 8899: }
8900: my $colsleft = $numinrow - $rem;
1.160.6.101 raeburn 8901: if ($context eq 'overrides') {
8902: if ($colsleft > 1) {
8903: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8904: } else {
8905: $output .= '<td class="LC_left_item">';
8906: }
8907: $output .= ' ';
1.23 raeburn 8908: } else {
1.160.6.101 raeburn 8909: if ($rem == 0) {
8910: $output .= '<tr>';
8911: }
8912: if ($colsleft > 1) {
8913: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8914: } else {
8915: $output .= '<td class="LC_left_item">';
8916: }
8917: my $defcheck = ' ';
8918: if (ref($settings) eq 'HASH') {
8919: if (ref($settings->{$context}) eq 'ARRAY') {
8920: if (grep(/^default$/,@{$settings->{$context}})) {
8921: $defcheck = ' checked="checked" ';
8922: }
8923: } elsif ($context eq 'statustocreate') {
1.99 raeburn 8924: $defcheck = ' checked="checked" ';
8925: }
1.26 raeburn 8926: }
1.160.6.101 raeburn 8927: $output .= '<span class="LC_nobreak"><label>'.
8928: '<input type="checkbox" name="'.$context.'" '.
8929: 'value="default"'.$defcheck.$onclick.' />'.
8930: $othertitle.'</label></span>';
1.23 raeburn 8931: }
1.160.6.101 raeburn 8932: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 8933: return $output;
1.23 raeburn 8934: }
8935:
8936: sub sorted_searchtitles {
8937: my %searchtitles = &Apache::lonlocal::texthash(
8938: 'uname' => 'username',
8939: 'lastname' => 'last name',
8940: 'lastfirst' => 'last name, first name',
8941: );
8942: my @titleorder = ('uname','lastname','lastfirst');
8943: return (\%searchtitles,\@titleorder);
8944: }
8945:
1.25 raeburn 8946: sub sorted_searchtypes {
8947: my %srchtypes_desc = (
8948: exact => 'is exact match',
8949: contains => 'contains ..',
8950: begins => 'begins with ..',
8951: );
8952: my @srchtypeorder = ('exact','begins','contains');
8953: return (\%srchtypes_desc,\@srchtypeorder);
8954: }
8955:
1.3 raeburn 8956: sub usertype_update_row {
8957: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
8958: my $datatable;
8959: my $numinrow = 4;
8960: foreach my $type (@{$types}) {
8961: if (defined($usertypes->{$type})) {
8962: $$rownums ++;
8963: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
8964: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
8965: '</td><td class="LC_left_item"><table>';
8966: for (my $i=0; $i<@{$fields}; $i++) {
8967: my $rem = $i%($numinrow);
8968: if ($rem == 0) {
8969: if ($i > 0) {
8970: $datatable .= '</tr>';
8971: }
8972: $datatable .= '<tr>';
8973: }
8974: my $check = ' ';
1.39 raeburn 8975: if (ref($settings) eq 'HASH') {
8976: if (ref($settings->{'fields'}) eq 'HASH') {
8977: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
8978: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
8979: $check = ' checked="checked" ';
8980: }
1.3 raeburn 8981: }
8982: }
8983: }
8984:
8985: if ($i == @{$fields}-1) {
8986: my $colsleft = $numinrow - $rem;
8987: if ($colsleft > 1) {
8988: $datatable .= '<td colspan="'.$colsleft.'">';
8989: } else {
8990: $datatable .= '<td>';
8991: }
8992: } else {
8993: $datatable .= '<td>';
8994: }
1.8 raeburn 8995: $datatable .= '<span class="LC_nobreak"><label>'.
8996: '<input type="checkbox" name="updateable_'.$type.
8997: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
8998: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 8999: }
9000: $datatable .= '</tr></table></td></tr>';
9001: }
9002: }
9003: return $datatable;
1.1 raeburn 9004: }
9005:
9006: sub modify_login {
1.160.6.24 raeburn 9007: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 9008: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.160.6.113 raeburn 9009: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
9010: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso);
1.160.6.5 raeburn 9011: %title = ( coursecatalog => 'Display course catalog',
9012: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 9013: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 9014: newuser => 'Link for visitors to create a user account',
1.160.6.113 raeburn 9015: loginheader => 'Log-in box header',
9016: saml => 'Dual SSO and non-SSO login');
1.160.6.5 raeburn 9017: @offon = ('off','on');
1.112 raeburn 9018: if (ref($domconfig{login}) eq 'HASH') {
9019: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
9020: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
9021: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
9022: }
9023: }
1.160.6.113 raeburn 9024: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
9025: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
9026: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
9027: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
9028: $saml{$lonhost} = 1;
9029: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
9030: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
9031: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
9032: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
9033: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
9034: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
9035: }
9036: }
9037: }
1.112 raeburn 9038: }
1.9 raeburn 9039: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
9040: \%domconfig,\%loginhash);
1.160.6.14 raeburn 9041: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9042: foreach my $item (@toggles) {
9043: $loginhash{login}{$item} = $env{'form.'.$item};
9044: }
1.41 raeburn 9045: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 9046: if (ref($colchanges{'login'}) eq 'HASH') {
9047: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
9048: \%loginhash);
9049: }
1.110 raeburn 9050:
1.149 raeburn 9051: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 9052: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 9053: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 9054: if (keys(%servers) > 1) {
9055: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 9056: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
9057: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
9058: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
9059: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
9060: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
9061: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9062: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9063: $changes{'loginvia'}{$lonhost} = 1;
9064: } else {
9065: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
9066: $changes{'loginvia'}{$lonhost} = 1;
9067: }
9068: } else {
9069: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9070: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9071: $changes{'loginvia'}{$lonhost} = 1;
9072: }
9073: }
9074: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
9075: foreach my $item (@loginvia_attribs) {
9076: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
9077: }
9078: } else {
9079: foreach my $item (@loginvia_attribs) {
9080: my $new = $env{'form.'.$lonhost.'_'.$item};
9081: if (($item eq 'serverpath') && ($new eq 'custom')) {
9082: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
9083: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9084: $new = '/';
9085: }
9086: }
9087: if (($item eq 'custompath') &&
9088: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9089: $new = '';
9090: }
9091: if ($new ne $curr_loginvia{$lonhost}{$item}) {
9092: $changes{'loginvia'}{$lonhost} = 1;
9093: }
9094: if ($item eq 'exempt') {
1.160.6.56 raeburn 9095: $new = &check_exempt_addresses($new);
1.128 raeburn 9096: }
9097: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9098: }
9099: }
1.112 raeburn 9100: } else {
1.128 raeburn 9101: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9102: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 9103: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 9104: foreach my $item (@loginvia_attribs) {
9105: my $new = $env{'form.'.$lonhost.'_'.$item};
9106: if (($item eq 'serverpath') && ($new eq 'custom')) {
9107: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9108: $new = '/';
9109: }
9110: }
9111: if (($item eq 'custompath') &&
9112: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9113: $new = '';
9114: }
9115: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9116: }
1.110 raeburn 9117: }
9118: }
9119: }
9120: }
1.119 raeburn 9121:
1.160.6.5 raeburn 9122: my $servadm = $r->dir_config('lonAdmEMail');
9123: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
9124: if (ref($domconfig{'login'}) eq 'HASH') {
9125: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
9126: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
9127: if ($lang eq 'nolang') {
9128: push(@currlangs,$lang);
9129: } elsif (defined($langchoices{$lang})) {
9130: push(@currlangs,$lang);
9131: } else {
9132: next;
9133: }
9134: }
9135: }
9136: }
9137: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
9138: if (@currlangs > 0) {
9139: foreach my $lang (@currlangs) {
9140: if (grep(/^\Q$lang\E$/,@delurls)) {
9141: $changes{'helpurl'}{$lang} = 1;
9142: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
9143: $changes{'helpurl'}{$lang} = 1;
9144: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
9145: push(@newlangs,$lang);
9146: } else {
9147: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9148: }
9149: }
9150: }
9151: unless (grep(/^nolang$/,@currlangs)) {
9152: if ($env{'form.loginhelpurl_nolang.filename'}) {
9153: $changes{'helpurl'}{'nolang'} = 1;
9154: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
9155: push(@newlangs,'nolang');
9156: }
9157: }
9158: if ($env{'form.loginhelpurl_add_lang'}) {
9159: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
9160: ($env{'form.loginhelpurl_add_file.filename'})) {
9161: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
9162: $addedfile = $env{'form.loginhelpurl_add_lang'};
9163: }
9164: }
9165: if ((@newlangs > 0) || ($addedfile)) {
9166: my $error;
9167: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9168: if ($configuserok eq 'ok') {
9169: if ($switchserver) {
9170: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
9171: } elsif ($author_ok eq 'ok') {
9172: my @allnew = @newlangs;
9173: if ($addedfile ne '') {
9174: push(@allnew,$addedfile);
9175: }
9176: foreach my $lang (@allnew) {
9177: my $formelem = 'loginhelpurl_'.$lang;
9178: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
9179: $formelem = 'loginhelpurl_add_file';
9180: }
9181: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9182: "help/$lang",'','',$newfile{$lang});
9183: if ($result eq 'ok') {
9184: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
9185: $changes{'helpurl'}{$lang} = 1;
9186: } else {
9187: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
9188: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9189: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
9190: (!grep(/^\Q$lang\E$/,@delurls))) {
9191: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9192: }
9193: }
9194: }
9195: } else {
9196: $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);
9197: }
9198: } else {
9199: $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);
9200: }
9201: if ($error) {
9202: &Apache::lonnet::logthis($error);
9203: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9204: }
9205: }
1.160.6.56 raeburn 9206:
9207: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
9208: if (ref($domconfig{'login'}) eq 'HASH') {
9209: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
9210: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
9211: if ($domservers{$lonhost}) {
9212: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9213: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 9214: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 9215: }
9216: }
9217: }
9218: }
9219: }
9220: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
9221: foreach my $lonhost (sort(keys(%domservers))) {
9222: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9223: $changes{'headtag'}{$lonhost} = 1;
9224: } else {
9225: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
9226: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
9227: }
9228: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
9229: push(@newhosts,$lonhost);
9230: } elsif ($currheadtagurls{$lonhost}) {
9231: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
9232: if ($currexempt{$lonhost}) {
9233: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
9234: $changes{'headtag'}{$lonhost} = 1;
9235: }
9236: } elsif ($possexempt{$lonhost}) {
9237: $changes{'headtag'}{$lonhost} = 1;
9238: }
9239: if ($possexempt{$lonhost}) {
9240: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9241: }
9242: }
9243: }
9244: }
9245: if (@newhosts) {
9246: my $error;
9247: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9248: if ($configuserok eq 'ok') {
9249: if ($switchserver) {
9250: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
9251: } elsif ($author_ok eq 'ok') {
9252: foreach my $lonhost (@newhosts) {
9253: my $formelem = 'loginheadtag_'.$lonhost;
9254: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9255: "login/headtag/$lonhost",'','',
9256: $env{'form.loginheadtag_'.$lonhost.'.filename'});
9257: if ($result eq 'ok') {
1.160.6.113 raeburn 9258: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
9259: $changes{'headtag'}{$lonhost} = 1;
9260: if ($possexempt{$lonhost}) {
9261: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9262: }
9263: } else {
9264: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
9265: $newheadtagurls{$lonhost},$result);
9266: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9267: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
9268: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
9269: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
9270: }
9271: }
9272: }
9273: } else {
9274: $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);
9275: }
9276: } else {
9277: $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);
9278: }
9279: if ($error) {
9280: &Apache::lonnet::logthis($error);
9281: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9282: }
9283: }
9284: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
9285: my @newsamlimgs;
9286: foreach my $lonhost (keys(%domservers)) {
9287: if ($env{'form.saml_'.$lonhost}) {
9288: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
9289: push(@newsamlimgs,$lonhost);
9290: }
9291: foreach my $item ('text','alt','url','title','notsso') {
9292: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
9293: }
9294: if ($saml{$lonhost}) {
9295: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
9296: #FIXME Need to obsolete published image
9297: delete($currsaml{$lonhost}{'img'});
9298: $changes{'saml'}{$lonhost} = 1;
9299: }
9300: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
9301: $changes{'saml'}{$lonhost} = 1;
9302: }
9303: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
9304: $changes{'saml'}{$lonhost} = 1;
9305: }
9306: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
9307: $changes{'saml'}{$lonhost} = 1;
9308: }
9309: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
9310: $changes{'saml'}{$lonhost} = 1;
9311: }
9312: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
9313: $changes{'saml'}{$lonhost} = 1;
9314: }
9315: } else {
9316: $changes{'saml'}{$lonhost} = 1;
9317: }
9318: foreach my $item ('text','alt','url','title','notsso') {
9319: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
9320: }
9321: } else {
9322: if ($saml{$lonhost}) {
9323: $changes{'saml'}{$lonhost} = 1;
9324: delete($currsaml{$lonhost});
9325: }
9326: }
9327: }
9328: foreach my $posshost (keys(%currsaml)) {
9329: unless (exists($domservers{$posshost})) {
9330: delete($currsaml{$posshost});
9331: }
9332: }
9333: %{$loginhash{'login'}{'saml'}} = %currsaml;
9334: if (@newsamlimgs) {
9335: my $error;
9336: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9337: if ($configuserok eq 'ok') {
9338: if ($switchserver) {
9339: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
9340: } elsif ($author_ok eq 'ok') {
9341: foreach my $lonhost (@newsamlimgs) {
9342: my $formelem = 'saml_img_'.$lonhost;
9343: my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9344: "login/saml/$lonhost",'','',
9345: $env{'form.saml_img_'.$lonhost.'.filename'});
9346: if ($result eq 'ok') {
9347: $currsaml{$lonhost}{'img'} = $imgurl;
9348: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
9349: $changes{'saml'}{$lonhost} = 1;
1.160.6.56 raeburn 9350: } else {
1.160.6.113 raeburn 9351: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
9352: $lonhost,$result);
1.160.6.56 raeburn 9353: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9354: }
9355: }
9356: } else {
1.160.6.113 raeburn 9357: $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 9358: }
9359: } else {
1.160.6.113 raeburn 9360: $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 9361: }
9362: if ($error) {
9363: &Apache::lonnet::logthis($error);
9364: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9365: }
9366: }
1.160.6.5 raeburn 9367: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
9368:
9369: my $defaulthelpfile = '/adm/loginproblems.html';
9370: my $defaulttext = &mt('Default in use');
9371:
1.1 raeburn 9372: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
9373: $dom);
9374: if ($putresult eq 'ok') {
1.160.6.14 raeburn 9375: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9376: my %defaultchecked = (
9377: 'coursecatalog' => 'on',
1.160.6.14 raeburn 9378: 'helpdesk' => 'on',
1.42 raeburn 9379: 'adminmail' => 'off',
1.43 raeburn 9380: 'newuser' => 'off',
1.42 raeburn 9381: );
1.55 raeburn 9382: if (ref($domconfig{'login'}) eq 'HASH') {
9383: foreach my $item (@toggles) {
9384: if ($defaultchecked{$item} eq 'on') {
9385: if (($domconfig{'login'}{$item} eq '0') &&
9386: ($env{'form.'.$item} eq '1')) {
9387: $changes{$item} = 1;
9388: } elsif (($domconfig{'login'}{$item} eq '' ||
9389: $domconfig{'login'}{$item} eq '1') &&
9390: ($env{'form.'.$item} eq '0')) {
9391: $changes{$item} = 1;
9392: }
9393: } elsif ($defaultchecked{$item} eq 'off') {
9394: if (($domconfig{'login'}{$item} eq '1') &&
9395: ($env{'form.'.$item} eq '0')) {
9396: $changes{$item} = 1;
9397: } elsif (($domconfig{'login'}{$item} eq '' ||
9398: $domconfig{'login'}{$item} eq '0') &&
9399: ($env{'form.'.$item} eq '1')) {
9400: $changes{$item} = 1;
9401: }
1.42 raeburn 9402: }
9403: }
1.41 raeburn 9404: }
1.6 raeburn 9405: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 9406: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.113 raeburn 9407: if (exists($changes{'saml'})) {
9408: my $hostid_in_use;
9409: my @hosts = &Apache::lonnet::current_machine_ids();
9410: if (@hosts > 1) {
9411: foreach my $hostid (@hosts) {
9412: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
9413: $hostid_in_use = $hostid;
9414: last;
9415: }
9416: }
9417: } else {
9418: $hostid_in_use = $r->dir_config('lonHostID');
9419: }
9420: if (($hostid_in_use) &&
9421: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
9422: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
9423: }
9424: if (ref($lastactref) eq 'HASH') {
9425: if (ref($changes{'saml'}) eq 'HASH') {
9426: my %updates;
9427: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
9428: $lastactref->{'samllanding'} = \%updates;
9429: }
9430: }
9431: }
1.160.6.27 raeburn 9432: if (ref($lastactref) eq 'HASH') {
9433: $lastactref->{'domainconfig'} = 1;
9434: }
1.1 raeburn 9435: $resulttext = &mt('Changes made:').'<ul>';
9436: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 9437: if ($item eq 'loginvia') {
1.112 raeburn 9438: if (ref($changes{$item}) eq 'HASH') {
9439: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
9440: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 9441: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
9442: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
9443: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
9444: $protocol = 'http' if ($protocol ne 'https');
9445: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
9446:
9447: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
9448: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
9449: } else {
9450: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
9451: }
9452: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
9453: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
9454: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
9455: }
9456: $resulttext .= '</li>';
9457: } else {
9458: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
9459: }
1.112 raeburn 9460: } else {
1.128 raeburn 9461: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 9462: }
9463: }
1.128 raeburn 9464: $resulttext .= '</ul></li>';
1.112 raeburn 9465: }
1.160.6.5 raeburn 9466: } elsif ($item eq 'helpurl') {
9467: if (ref($changes{$item}) eq 'HASH') {
9468: foreach my $lang (sort(keys(%{$changes{$item}}))) {
9469: if (grep(/^\Q$lang\E$/,@delurls)) {
9470: my ($chg,$link);
9471: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
9472: if ($lang eq 'nolang') {
9473: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
9474: } else {
9475: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
9476: }
9477: $resulttext .= '<li>'.$chg.'</li>';
9478: } else {
9479: my $chg;
9480: if ($lang eq 'nolang') {
9481: $chg = &mt('custom log-in help file for no preferred language');
9482: } else {
9483: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
9484: }
9485: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
9486: $loginhash{'login'}{'helpurl'}{$lang}.
9487: '?inhibitmenu=yes',$chg,600,500).
9488: '</li>';
9489: }
9490: }
9491: }
1.160.6.56 raeburn 9492: } elsif ($item eq 'headtag') {
9493: if (ref($changes{$item}) eq 'HASH') {
9494: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9495: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9496: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
9497: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9498: $resulttext .= '<li><a href="'.
9499: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
9500: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
9501: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
9502: if ($possexempt{$lonhost}) {
9503: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
9504: } else {
9505: $resulttext .= &mt('included for any client IP');
9506: }
9507: $resulttext .= '</li>';
9508: }
9509: }
9510: }
1.160.6.113 raeburn 9511: } elsif ($item eq 'saml') {
9512: if (ref($changes{$item}) eq 'HASH') {
9513: my %notlt = (
9514: text => 'Text for log-in by SSO',
9515: img => 'SSO button image',
9516: alt => 'Alt text for button image',
9517: url => 'SSO URL',
9518: title => 'Tooltip for SSO link',
9519: notsso => 'Text for non-SSO log-in',
9520: );
9521: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9522: if (ref($currsaml{$lonhost}) eq 'HASH') {
9523: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
9524: '<ul>';
9525: foreach my $key ('text','img','alt','url','title','notsso') {
9526: if ($currsaml{$lonhost}{$key} eq '') {
9527: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
9528: } else {
9529: my $value = "'$currsaml{$lonhost}{$key}'";
9530: if ($key eq 'img') {
9531: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
9532: }
9533: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
9534: $value).'</li>';
9535: }
9536: }
9537: $resulttext .= '</ul></li>';
9538: } else {
9539: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
9540: }
9541: }
9542: }
1.160.6.5 raeburn 9543: } elsif ($item eq 'captcha') {
9544: if (ref($loginhash{'login'}) eq 'HASH') {
9545: my $chgtxt;
9546: if ($loginhash{'login'}{$item} eq 'notused') {
9547: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
9548: } else {
9549: my %captchas = &captcha_phrases();
9550: if ($captchas{$loginhash{'login'}{$item}}) {
9551: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
9552: } else {
9553: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
9554: }
9555: }
9556: $resulttext .= '<li>'.$chgtxt.'</li>';
9557: }
9558: } elsif ($item eq 'recaptchakeys') {
9559: if (ref($loginhash{'login'}) eq 'HASH') {
9560: my ($privkey,$pubkey);
9561: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
9562: $pubkey = $loginhash{'login'}{$item}{'public'};
9563: $privkey = $loginhash{'login'}{$item}{'private'};
9564: }
9565: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
9566: if (!$pubkey) {
9567: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
9568: } else {
9569: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9570: }
9571: if (!$privkey) {
9572: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
9573: } else {
1.160.6.53 raeburn 9574: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 9575: }
9576: $chgtxt .= '</ul>';
9577: $resulttext .= '<li>'.$chgtxt.'</li>';
9578: }
1.160.6.69 raeburn 9579: } elsif ($item eq 'recaptchaversion') {
9580: if (ref($loginhash{'login'}) eq 'HASH') {
9581: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
9582: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
9583: '</li>';
9584: }
9585: }
1.41 raeburn 9586: } else {
9587: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
9588: }
1.1 raeburn 9589: }
1.6 raeburn 9590: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 9591: } else {
9592: $resulttext = &mt('No changes made to log-in page settings');
9593: }
9594: } else {
1.11 albertel 9595: $resulttext = '<span class="LC_error">'.
9596: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9597: }
1.6 raeburn 9598: if ($errors) {
1.9 raeburn 9599: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 9600: $errors.'</ul>';
9601: }
9602: return $resulttext;
9603: }
9604:
1.160.6.56 raeburn 9605: sub check_exempt_addresses {
9606: my ($iplist) = @_;
9607: $iplist =~ s/^\s+//;
9608: $iplist =~ s/\s+$//;
9609: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
9610: my (@okips,$new);
9611: foreach my $ip (@poss_ips) {
9612: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
9613: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
9614: push(@okips,$ip);
9615: }
9616: }
9617: }
9618: if (@okips > 0) {
9619: $new = join(',',@okips);
9620: } else {
9621: $new = '';
9622: }
9623: return $new;
9624: }
9625:
1.6 raeburn 9626: sub color_font_choices {
9627: my %choices =
9628: &Apache::lonlocal::texthash (
9629: img => "Header",
9630: bgs => "Background colors",
9631: links => "Link colors",
1.55 raeburn 9632: images => "Images",
1.6 raeburn 9633: font => "Font color",
1.160.6.22 raeburn 9634: fontmenu => "Font menu",
1.76 raeburn 9635: pgbg => "Page",
1.6 raeburn 9636: tabbg => "Header",
9637: sidebg => "Border",
9638: link => "Link",
9639: alink => "Active link",
9640: vlink => "Visited link",
9641: );
9642: return %choices;
9643: }
9644:
1.160.6.113 raeburn 9645: sub modify_ipaccess {
9646: my ($dom,$lastactref,%domconfig) = @_;
9647: my (@allpos,%changes,%confhash,$errors,$resulttext);
9648: my (@items,%deletions,%itemids,@warnings);
9649: my ($typeorder,$types) = &commblocktype_text();
9650: if ($env{'form.ipaccess_add'}) {
9651: my $name = $env{'form.ipaccess_name_add'};
9652: my ($newid,$error) = &get_ipaccess_id($dom,$name);
9653: if ($newid) {
9654: $itemids{'add'} = $newid;
9655: push(@items,'add');
9656: $changes{$newid} = 1;
9657: } else {
9658: $error = &mt('Failed to acquire unique ID for new IP access control item');
9659: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9660: }
9661: }
9662: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
9663: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
9664: if (@todelete) {
9665: map { $deletions{$_} = 1; } @todelete;
9666: }
9667: my $maxnum = $env{'form.ipaccess_maxnum'};
9668: for (my $i=0; $i<$maxnum; $i++) {
9669: my $itemid = $env{'form.ipaccess_id_'.$i};
9670: $itemid =~ s/\D+//g;
9671: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
9672: if ($deletions{$itemid}) {
9673: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
9674: } else {
9675: push(@items,$i);
9676: $itemids{$i} = $itemid;
9677: }
9678: }
9679: }
9680: }
9681: foreach my $idx (@items) {
9682: my $itemid = $itemids{$idx};
9683: next unless ($itemid);
9684: my %current;
9685: unless ($idx eq 'add') {
9686: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
9687: %current = %{$domconfig{'ipaccess'}{$itemid}};
9688: }
9689: }
9690: my $position = $env{'form.ipaccess_pos_'.$itemid};
9691: $position =~ s/\D+//g;
9692: if ($position ne '') {
9693: $allpos[$position] = $itemid;
9694: }
9695: my $name = $env{'form.ipaccess_name_'.$idx};
9696: $name =~ s/^\s+|\s+$//g;
9697: $confhash{$itemid}{'name'} = $name;
9698: my $possrange = $env{'form.ipaccess_range_'.$idx};
9699: $possrange =~ s/^\s+|\s+$//g;
9700: unless ($possrange eq '') {
9701: $possrange =~ s/[\r\n]+/\s/g;
9702: $possrange =~ s/\s*-\s*/-/g;
9703: $possrange =~ s/\s+/,/g;
9704: $possrange =~ s/,+/,/g;
9705: if ($possrange ne '') {
9706: my (@ok,$count);
9707: $count = 0;
9708: foreach my $poss (split(/\,/,$possrange)) {
9709: $count ++;
9710: $poss = &validate_ip_pattern($poss);
9711: if ($poss ne '') {
9712: push(@ok,$poss);
9713: }
9714: }
9715: my $diff = $count - scalar(@ok);
9716: if ($diff) {
9717: $errors .= '<li><span class="LC_error">'.
9718: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
9719: $diff,$name).
9720: '</span></li>';
9721: }
9722: if (@ok) {
9723: my @cidr_list;
9724: foreach my $item (@ok) {
9725: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
9726: }
9727: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
9728: }
9729: }
9730: }
9731: foreach my $field ('name','ip') {
9732: unless (($idx eq 'add') || ($changes{$itemid})) {
9733: if ($current{$field} ne $confhash{$itemid}{$field}) {
9734: $changes{$itemid} = 1;
9735: last;
9736: }
9737: }
9738: }
9739: $confhash{$itemid}{'commblocks'} = {};
9740:
9741: my %commblocks;
9742: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
9743: foreach my $type (@{$typeorder}) {
9744: if ($commblocks{$type}) {
9745: $confhash{$itemid}{'commblocks'}{$type} = 'on';
9746: }
9747: unless (($idx eq 'add') || ($changes{$itemid})) {
9748: if (ref($current{'commblocks'}) eq 'HASH') {
9749: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
9750: $changes{$itemid} = 1;
9751: }
9752: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
9753: $changes{$itemid} = 1;
9754: }
9755: }
9756: }
9757: $confhash{$itemid}{'courses'} = {};
9758: my %crsdeletions;
9759: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
9760: if (@delcrs) {
9761: map { $crsdeletions{$_} = 1; } @delcrs;
9762: }
9763: if (ref($current{'courses'}) eq 'HASH') {
9764: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
9765: if ($crsdeletions{$cid}) {
9766: $changes{$itemid} = 1;
9767: } else {
9768: $confhash{$itemid}{'courses'}{$cid} = 1;
9769: }
9770: }
9771: }
9772: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
9773: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
9774: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
9775: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
9776: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
9777: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
9778: $errors .= '<li><span class="LC_error">'.
9779: &mt('Invalid courseID [_1] omitted from list of allowed courses',
9780: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
9781: '</span></li>';
9782: } else {
9783: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
9784: $changes{$itemid} = 1;
9785: }
9786: }
9787: }
9788: if (@allpos > 0) {
9789: my $idx = 0;
9790: foreach my $itemid (@allpos) {
9791: if ($itemid ne '') {
9792: $confhash{$itemid}{'order'} = $idx;
9793: unless ($changes{$itemid}) {
9794: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
9795: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
9796: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
9797: $changes{$itemid} = 1;
9798: }
9799: }
9800: }
9801: }
9802: $idx ++;
9803: }
9804: }
9805: }
9806: if (keys(%changes)) {
9807: my %defaultshash = (
9808: ipaccess => \%confhash,
9809: );
9810: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
9811: $dom);
9812: if ($putresult eq 'ok') {
9813: my $cachetime = 1800;
9814: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
9815: if (ref($lastactref) eq 'HASH') {
9816: $lastactref->{'ipaccess'} = 1;
9817: }
9818: $resulttext = &mt('Changes made:').'<ul>';
9819: my %bynum;
9820: foreach my $itemid (sort(keys(%changes))) {
9821: if (ref($confhash{$itemid}) eq 'HASH') {
9822: my $position = $confhash{$itemid}{'order'};
9823: if ($position =~ /^\d+$/) {
9824: $bynum{$position} = $itemid;
9825: }
9826: }
9827: }
9828: if (keys(%deletions)) {
9829: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
9830: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
9831: }
9832: }
9833: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
9834: my $itemid = $bynum{$pos};
9835: if (ref($confhash{$itemid}) eq 'HASH') {
9836: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
9837: my $position = $pos + 1;
9838: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
9839: if ($confhash{$itemid}{'ip'} eq '') {
9840: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
9841: } else {
9842: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
9843: }
9844: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
9845: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
9846: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
9847: '</li>';
9848: } else {
9849: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
9850: }
9851: if (keys(%{$confhash{$itemid}{'courses'}})) {
9852: my @courses;
9853: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
9854: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
9855: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
9856: }
9857: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
9858: join('</li><li>',@courses).'</li></ul>';
9859: } else {
9860: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
9861: }
9862: $resulttext .= '</ul></li>';
9863: }
9864: }
9865: $resulttext .= '</ul>';
9866: } else {
9867: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9868: }
9869: } else {
9870: $resulttext = &mt('No changes made');
9871: }
9872: if ($errors) {
9873: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
9874: $errors.'</ul></p>';
9875: }
9876: return $resulttext;
9877: }
9878:
9879: sub get_ipaccess_id {
9880: my ($domain,$location) = @_;
9881: # get lock on ipaccess db
9882: my $lockhash = {
9883: lock => $env{'user.name'}.
9884: ':'.$env{'user.domain'},
9885: };
9886: my $tries = 0;
9887: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
9888: my ($id,$error);
9889:
9890: while (($gotlock ne 'ok') && ($tries<10)) {
9891: $tries ++;
9892: sleep (0.1);
9893: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
9894: }
9895: if ($gotlock eq 'ok') {
9896: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
9897: if ($currids{'lock'}) {
9898: delete($currids{'lock'});
9899: if (keys(%currids)) {
9900: my @curr = sort { $a <=> $b } keys(%currids);
9901: if ($curr[-1] =~ /^\d+$/) {
9902: $id = 1 + $curr[-1];
9903: }
9904: } else {
9905: $id = 1;
9906: }
9907: if ($id) {
9908: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
9909: $error = 'nostore';
9910: }
9911: } else {
9912: $error = 'nonumber';
9913: }
9914: }
9915: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
9916: } else {
9917: $error = 'nolock';
9918: }
9919: return ($id,$error);
9920: }
9921:
1.6 raeburn 9922: sub modify_rolecolors {
1.160.6.24 raeburn 9923: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 9924: my ($resulttext,%rolehash);
9925: $rolehash{'rolecolors'} = {};
1.55 raeburn 9926: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
9927: if ($domconfig{'rolecolors'} eq '') {
9928: $domconfig{'rolecolors'} = {};
9929: }
9930: }
1.9 raeburn 9931: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 9932: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
9933: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
9934: $dom);
9935: if ($putresult eq 'ok') {
9936: if (keys(%changes) > 0) {
1.41 raeburn 9937: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9938: if (ref($lastactref) eq 'HASH') {
9939: $lastactref->{'domainconfig'} = 1;
9940: }
1.6 raeburn 9941: $resulttext = &display_colorchgs($dom,\%changes,$roles,
9942: $rolehash{'rolecolors'});
9943: } else {
9944: $resulttext = &mt('No changes made to default color schemes');
9945: }
9946: } else {
1.11 albertel 9947: $resulttext = '<span class="LC_error">'.
9948: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 9949: }
9950: if ($errors) {
9951: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9952: $errors.'</ul>';
9953: }
9954: return $resulttext;
9955: }
9956:
9957: sub modify_colors {
1.9 raeburn 9958: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 9959: my (%changes,%choices);
1.51 raeburn 9960: my @bgs;
1.6 raeburn 9961: my @links = ('link','alink','vlink');
1.41 raeburn 9962: my @logintext;
1.6 raeburn 9963: my @images;
9964: my $servadm = $r->dir_config('lonAdmEMail');
9965: my $errors;
1.160.6.22 raeburn 9966: my %defaults;
1.6 raeburn 9967: foreach my $role (@{$roles}) {
9968: if ($role eq 'login') {
1.12 raeburn 9969: %choices = &login_choices();
1.41 raeburn 9970: @logintext = ('textcol','bgcol');
1.12 raeburn 9971: } else {
9972: %choices = &color_font_choices();
9973: }
9974: if ($role eq 'login') {
1.41 raeburn 9975: @images = ('img','logo','domlogo','login');
1.51 raeburn 9976: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 9977: } else {
9978: @images = ('img');
1.160.6.22 raeburn 9979: @bgs = ('pgbg','tabbg','sidebg');
9980: }
9981: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
9982: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
9983: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
9984: }
9985: if ($role eq 'login') {
9986: foreach my $item (@logintext) {
1.160.6.39 raeburn 9987: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9988: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9989: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9990: }
9991: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 9992: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9993: }
9994: }
9995: } else {
1.160.6.39 raeburn 9996: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
9997: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
9998: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
9999: }
10000: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 10001: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
10002: }
1.6 raeburn 10003: }
1.160.6.22 raeburn 10004: foreach my $item (@bgs) {
1.160.6.39 raeburn 10005: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10006: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10007: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10008: }
10009: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 10010: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10011: }
10012: }
10013: foreach my $item (@links) {
1.160.6.39 raeburn 10014: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10015: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10016: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10017: }
10018: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 10019: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10020: }
1.6 raeburn 10021: }
1.46 raeburn 10022: my ($configuserok,$author_ok,$switchserver) =
10023: &config_check($dom,$confname,$servadm);
1.9 raeburn 10024: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 10025: if (ref($domconfig->{$role}) ne 'HASH') {
10026: $domconfig->{$role} = {};
10027: }
1.8 raeburn 10028: foreach my $img (@images) {
1.70 raeburn 10029: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
10030: if (defined($env{'form.login_showlogo_'.$img})) {
10031: $confhash->{$role}{'showlogo'}{$img} = 1;
10032: } else {
10033: $confhash->{$role}{'showlogo'}{$img} = 0;
10034: }
10035: }
1.18 albertel 10036: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
10037: && !defined($domconfig->{$role}{$img})
10038: && !$env{'form.'.$role.'_del_'.$img}
10039: && $env{'form.'.$role.'_import_'.$img}) {
10040: # import the old configured image from the .tab setting
10041: # if they haven't provided a new one
10042: $domconfig->{$role}{$img} =
10043: $env{'form.'.$role.'_import_'.$img};
10044: }
1.6 raeburn 10045: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 10046: my $error;
1.6 raeburn 10047: if ($configuserok eq 'ok') {
1.9 raeburn 10048: if ($switchserver) {
1.12 raeburn 10049: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 10050: } else {
10051: if ($author_ok eq 'ok') {
10052: my ($result,$logourl) =
10053: &publishlogo($r,'upload',$role.'_'.$img,
10054: $dom,$confname,$img,$width,$height);
10055: if ($result eq 'ok') {
10056: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 10057: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10058: } else {
1.12 raeburn 10059: $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 10060: }
10061: } else {
1.46 raeburn 10062: $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 10063: }
10064: }
10065: } else {
1.46 raeburn 10066: $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 10067: }
10068: if ($error) {
1.8 raeburn 10069: &Apache::lonnet::logthis($error);
1.11 albertel 10070: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 10071: }
10072: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 10073: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
10074: my $error;
10075: if ($configuserok eq 'ok') {
10076: # is confname an author?
10077: if ($switchserver eq '') {
10078: if ($author_ok eq 'ok') {
10079: my ($result,$logourl) =
10080: &publishlogo($r,'copy',$domconfig->{$role}{$img},
10081: $dom,$confname,$img,$width,$height);
10082: if ($result eq 'ok') {
10083: $confhash->{$role}{$img} = $logourl;
1.18 albertel 10084: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10085: }
10086: }
10087: }
10088: }
1.6 raeburn 10089: }
10090: }
10091: }
10092: if (ref($domconfig) eq 'HASH') {
10093: if (ref($domconfig->{$role}) eq 'HASH') {
10094: foreach my $img (@images) {
10095: if ($domconfig->{$role}{$img} ne '') {
10096: if ($env{'form.'.$role.'_del_'.$img}) {
10097: $confhash->{$role}{$img} = '';
1.12 raeburn 10098: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10099: } else {
1.9 raeburn 10100: if ($confhash->{$role}{$img} eq '') {
10101: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
10102: }
1.6 raeburn 10103: }
10104: } else {
10105: if ($env{'form.'.$role.'_del_'.$img}) {
10106: $confhash->{$role}{$img} = '';
1.12 raeburn 10107: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10108: }
10109: }
1.70 raeburn 10110: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
10111: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
10112: if ($confhash->{$role}{'showlogo'}{$img} ne
10113: $domconfig->{$role}{'showlogo'}{$img}) {
10114: $changes{$role}{'showlogo'}{$img} = 1;
10115: }
10116: } else {
10117: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10118: $changes{$role}{'showlogo'}{$img} = 1;
10119: }
10120: }
10121: }
10122: }
1.6 raeburn 10123: if ($domconfig->{$role}{'font'} ne '') {
10124: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
10125: $changes{$role}{'font'} = 1;
10126: }
10127: } else {
10128: if ($confhash->{$role}{'font'}) {
10129: $changes{$role}{'font'} = 1;
10130: }
10131: }
1.107 raeburn 10132: if ($role ne 'login') {
10133: if ($domconfig->{$role}{'fontmenu'} ne '') {
10134: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
10135: $changes{$role}{'fontmenu'} = 1;
10136: }
10137: } else {
10138: if ($confhash->{$role}{'fontmenu'}) {
10139: $changes{$role}{'fontmenu'} = 1;
10140: }
1.97 tempelho 10141: }
10142: }
1.6 raeburn 10143: foreach my $item (@bgs) {
10144: if ($domconfig->{$role}{$item} ne '') {
10145: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10146: $changes{$role}{'bgs'}{$item} = 1;
10147: }
10148: } else {
10149: if ($confhash->{$role}{$item}) {
10150: $changes{$role}{'bgs'}{$item} = 1;
10151: }
10152: }
10153: }
10154: foreach my $item (@links) {
10155: if ($domconfig->{$role}{$item} ne '') {
10156: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10157: $changes{$role}{'links'}{$item} = 1;
10158: }
10159: } else {
10160: if ($confhash->{$role}{$item}) {
10161: $changes{$role}{'links'}{$item} = 1;
10162: }
10163: }
10164: }
1.41 raeburn 10165: foreach my $item (@logintext) {
10166: if ($domconfig->{$role}{$item} ne '') {
10167: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10168: $changes{$role}{'logintext'}{$item} = 1;
10169: }
10170: } else {
10171: if ($confhash->{$role}{$item}) {
10172: $changes{$role}{'logintext'}{$item} = 1;
10173: }
10174: }
10175: }
1.6 raeburn 10176: } else {
10177: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10178: \@logintext,$confhash,\%changes);
1.6 raeburn 10179: }
10180: } else {
10181: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10182: \@logintext,$confhash,\%changes);
1.6 raeburn 10183: }
10184: }
10185: return ($errors,%changes);
10186: }
10187:
1.46 raeburn 10188: sub config_check {
10189: my ($dom,$confname,$servadm) = @_;
10190: my ($configuserok,$author_ok,$switchserver,%currroles);
10191: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
10192: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
10193: $confname,$servadm);
10194: if ($configuserok eq 'ok') {
10195: $switchserver = &check_switchserver($dom,$confname);
10196: if ($switchserver eq '') {
10197: $author_ok = &check_authorstatus($dom,$confname,%currroles);
10198: }
10199: }
10200: return ($configuserok,$author_ok,$switchserver);
10201: }
10202:
1.6 raeburn 10203: sub default_change_checker {
1.41 raeburn 10204: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 10205: foreach my $item (@{$links}) {
10206: if ($confhash->{$role}{$item}) {
10207: $changes->{$role}{'links'}{$item} = 1;
10208: }
10209: }
10210: foreach my $item (@{$bgs}) {
10211: if ($confhash->{$role}{$item}) {
10212: $changes->{$role}{'bgs'}{$item} = 1;
10213: }
10214: }
1.41 raeburn 10215: foreach my $item (@{$logintext}) {
10216: if ($confhash->{$role}{$item}) {
10217: $changes->{$role}{'logintext'}{$item} = 1;
10218: }
10219: }
1.6 raeburn 10220: foreach my $img (@{$images}) {
10221: if ($env{'form.'.$role.'_del_'.$img}) {
10222: $confhash->{$role}{$img} = '';
1.12 raeburn 10223: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 10224: }
1.70 raeburn 10225: if ($role eq 'login') {
10226: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10227: $changes->{$role}{'showlogo'}{$img} = 1;
10228: }
10229: }
1.6 raeburn 10230: }
10231: if ($confhash->{$role}{'font'}) {
10232: $changes->{$role}{'font'} = 1;
10233: }
1.48 raeburn 10234: }
1.6 raeburn 10235:
10236: sub display_colorchgs {
10237: my ($dom,$changes,$roles,$confhash) = @_;
10238: my (%choices,$resulttext);
10239: if (!grep(/^login$/,@{$roles})) {
10240: $resulttext = &mt('Changes made:').'<br />';
10241: }
10242: foreach my $role (@{$roles}) {
10243: if ($role eq 'login') {
10244: %choices = &login_choices();
10245: } else {
10246: %choices = &color_font_choices();
10247: }
10248: if (ref($changes->{$role}) eq 'HASH') {
10249: if ($role ne 'login') {
10250: $resulttext .= '<h4>'.&mt($role).'</h4>';
10251: }
10252: foreach my $key (sort(keys(%{$changes->{$role}}))) {
10253: if ($role ne 'login') {
10254: $resulttext .= '<ul>';
10255: }
10256: if (ref($changes->{$role}{$key}) eq 'HASH') {
10257: if ($role ne 'login') {
10258: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
10259: }
10260: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 10261: if (($role eq 'login') && ($key eq 'showlogo')) {
10262: if ($confhash->{$role}{$key}{$item}) {
10263: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
10264: } else {
10265: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
10266: }
10267: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 10268: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
10269: } else {
1.12 raeburn 10270: my $newitem = $confhash->{$role}{$item};
10271: if ($key eq 'images') {
10272: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
10273: }
10274: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 10275: }
10276: }
10277: if ($role ne 'login') {
10278: $resulttext .= '</ul></li>';
10279: }
10280: } else {
10281: if ($confhash->{$role}{$key} eq '') {
10282: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
10283: } else {
10284: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
10285: }
10286: }
10287: if ($role ne 'login') {
10288: $resulttext .= '</ul>';
10289: }
10290: }
10291: }
10292: }
1.3 raeburn 10293: return $resulttext;
1.1 raeburn 10294: }
10295:
1.9 raeburn 10296: sub thumb_dimensions {
10297: return ('200','50');
10298: }
10299:
1.16 raeburn 10300: sub check_dimensions {
10301: my ($inputfile) = @_;
10302: my ($fullwidth,$fullheight);
10303: if ($inputfile =~ m|^[/\w.\-]+$|) {
10304: if (open(PIPE,"identify $inputfile 2>&1 |")) {
10305: my $imageinfo = <PIPE>;
10306: if (!close(PIPE)) {
10307: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
10308: }
10309: chomp($imageinfo);
10310: my ($fullsize) =
1.21 raeburn 10311: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 10312: if ($fullsize) {
10313: ($fullwidth,$fullheight) = split(/x/,$fullsize);
10314: }
10315: }
10316: }
10317: return ($fullwidth,$fullheight);
10318: }
10319:
1.9 raeburn 10320: sub check_configuser {
10321: my ($uhome,$dom,$confname,$servadm) = @_;
10322: my ($configuserok,%currroles);
10323: if ($uhome eq 'no_host') {
10324: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98 raeburn 10325: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 10326: $configuserok =
10327: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
10328: $configpass,'','','','','',undef,$servadm);
10329: } else {
10330: $configuserok = 'ok';
10331: %currroles =
10332: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
10333: }
10334: return ($configuserok,%currroles);
10335: }
10336:
10337: sub check_authorstatus {
10338: my ($dom,$confname,%currroles) = @_;
10339: my $author_ok;
1.40 raeburn 10340: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 10341: my $start = time;
10342: my $end = 0;
10343: $author_ok =
10344: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 10345: 'au',$end,$start,'','','domconfig');
1.9 raeburn 10346: } else {
10347: $author_ok = 'ok';
10348: }
10349: return $author_ok;
10350: }
10351:
10352: sub publishlogo {
1.46 raeburn 10353: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 10354: my ($output,$fname,$logourl);
10355: if ($action eq 'upload') {
10356: $fname=$env{'form.'.$formname.'.filename'};
10357: chop($env{'form.'.$formname});
10358: } else {
10359: ($fname) = ($formname =~ /([^\/]+)$/);
10360: }
1.46 raeburn 10361: if ($savefileas ne '') {
10362: $fname = $savefileas;
10363: }
1.9 raeburn 10364: $fname=&Apache::lonnet::clean_filename($fname);
10365: # See if there is anything left
10366: unless ($fname) { return ('error: no uploaded file'); }
10367: $fname="$subdir/$fname";
1.160.6.5 raeburn 10368: my $docroot=$r->dir_config('lonDocRoot');
10369: my $filepath="$docroot/priv";
10370: my $relpath = "$dom/$confname";
1.9 raeburn 10371: my ($fnamepath,$file,$fetchthumb);
10372: $file=$fname;
10373: if ($fname=~m|/|) {
10374: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
10375: }
1.160.6.26 raeburn 10376: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 10377: my $count;
1.160.6.5 raeburn 10378: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 10379: $filepath.="/$parts[$count]";
10380: if ((-e $filepath)!=1) {
10381: mkdir($filepath,02770);
10382: }
10383: }
10384: # Check for bad extension and disallow upload
10385: if ($file=~/\.(\w+)$/ &&
10386: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
10387: $output =
1.160.6.25 raeburn 10388: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 10389: } elsif ($file=~/\.(\w+)$/ &&
10390: !defined(&Apache::loncommon::fileembstyle($1))) {
10391: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
10392: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 10393: $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 10394: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 10395: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 10396: } else {
10397: my $source = $filepath.'/'.$file;
10398: my $logfile;
1.160.6.88 raeburn 10399: if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 10400: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 10401: }
10402: print $logfile
10403: "\n================= Publish ".localtime()." ================\n".
10404: $env{'user.name'}.':'.$env{'user.domain'}."\n";
10405: # Save the file
1.160.6.88 raeburn 10406: if (!open(FH,">",$source)) {
1.9 raeburn 10407: &Apache::lonnet::logthis('Failed to create '.$source);
10408: return (&mt('Failed to create file'));
10409: }
10410: if ($action eq 'upload') {
10411: if (!print FH ($env{'form.'.$formname})) {
10412: &Apache::lonnet::logthis('Failed to write to '.$source);
10413: return (&mt('Failed to write file'));
10414: }
10415: } else {
10416: my $original = &Apache::lonnet::filelocation('',$formname);
10417: if(!copy($original,$source)) {
10418: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
10419: return (&mt('Failed to write file'));
10420: }
10421: }
10422: close(FH);
10423: chmod(0660, $source); # Permissions to rw-rw---.
10424:
10425: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
10426: my $copyfile=$targetdir.'/'.$file;
10427:
10428: my @parts=split(/\//,$targetdir);
10429: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
10430: for (my $count=5;$count<=$#parts;$count++) {
10431: $path.="/$parts[$count]";
10432: if (!-e $path) {
10433: print $logfile "\nCreating directory ".$path;
10434: mkdir($path,02770);
10435: }
10436: }
10437: my $versionresult;
10438: if (-e $copyfile) {
10439: $versionresult = &logo_versioning($targetdir,$file,$logfile);
10440: } else {
10441: $versionresult = 'ok';
10442: }
10443: if ($versionresult eq 'ok') {
10444: if (copy($source,$copyfile)) {
10445: print $logfile "\nCopied original source to ".$copyfile."\n";
10446: $output = 'ok';
10447: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 10448: push(@{$modified_urls},[$copyfile,$source]);
10449: my $metaoutput =
10450: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
10451: unless ($registered_cleanup) {
10452: my $handlers = $r->get_handlers('PerlCleanupHandler');
10453: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10454: $registered_cleanup=1;
10455: }
1.9 raeburn 10456: } else {
10457: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
10458: $output = &mt('Failed to copy file to RES space').", $!";
10459: }
10460: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
10461: my $inputfile = $filepath.'/'.$file;
10462: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 10463: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
10464: if ($fullwidth ne '' && $fullheight ne '') {
10465: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
10466: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88 raeburn 10467: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
10468: system({$args[0]} @args);
1.16 raeburn 10469: chmod(0660, $filepath.'/tn-'.$file);
10470: if (-e $outfile) {
10471: my $copyfile=$targetdir.'/tn-'.$file;
10472: if (copy($outfile,$copyfile)) {
10473: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 10474: my $thumb_metaoutput =
10475: &write_metadata($dom,$confname,$formname,
10476: $targetdir,'tn-'.$file,$logfile);
10477: push(@{$modified_urls},[$copyfile,$outfile]);
10478: unless ($registered_cleanup) {
10479: my $handlers = $r->get_handlers('PerlCleanupHandler');
10480: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10481: $registered_cleanup=1;
10482: }
1.16 raeburn 10483: } else {
10484: print $logfile "\nUnable to write ".$copyfile.
10485: ':'.$!."\n";
10486: }
10487: }
1.9 raeburn 10488: }
10489: }
10490: }
10491: } else {
10492: $output = $versionresult;
10493: }
10494: }
10495: return ($output,$logourl);
10496: }
10497:
10498: sub logo_versioning {
10499: my ($targetdir,$file,$logfile) = @_;
10500: my $target = $targetdir.'/'.$file;
10501: my ($maxversion,$fn,$extn,$output);
10502: $maxversion = 0;
10503: if ($file =~ /^(.+)\.(\w+)$/) {
10504: $fn=$1;
10505: $extn=$2;
10506: }
10507: opendir(DIR,$targetdir);
10508: while (my $filename=readdir(DIR)) {
10509: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
10510: $maxversion=($1>$maxversion)?$1:$maxversion;
10511: }
10512: }
10513: $maxversion++;
10514: print $logfile "\nCreating old version ".$maxversion."\n";
10515: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
10516: if (copy($target,$copyfile)) {
10517: print $logfile "Copied old target to ".$copyfile."\n";
10518: $copyfile=$copyfile.'.meta';
10519: if (copy($target.'.meta',$copyfile)) {
10520: print $logfile "Copied old target metadata to ".$copyfile."\n";
10521: $output = 'ok';
10522: } else {
10523: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
10524: $output = &mt('Failed to copy old meta').", $!, ";
10525: }
10526: } else {
10527: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
10528: $output = &mt('Failed to copy old target').", $!, ";
10529: }
10530: return $output;
10531: }
10532:
10533: sub write_metadata {
10534: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
10535: my (%metadatafields,%metadatakeys,$output);
10536: $metadatafields{'title'}=$formname;
10537: $metadatafields{'creationdate'}=time;
10538: $metadatafields{'lastrevisiondate'}=time;
10539: $metadatafields{'copyright'}='public';
10540: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
10541: $env{'user.domain'};
10542: $metadatafields{'authorspace'}=$confname.':'.$dom;
10543: $metadatafields{'domain'}=$dom;
10544: {
10545: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
10546: my $mfh;
1.160.6.88 raeburn 10547: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 10548: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 10549: unless ($_=~/\./) {
10550: my $unikey=$_;
10551: $unikey=~/^([A-Za-z]+)/;
10552: my $tag=$1;
10553: $tag=~tr/A-Z/a-z/;
10554: print $mfh "\n\<$tag";
10555: foreach (split(/\,/,$metadatakeys{$unikey})) {
10556: my $value=$metadatafields{$unikey.'.'.$_};
10557: $value=~s/\"/\'\'/g;
10558: print $mfh ' '.$_.'="'.$value.'"';
10559: }
10560: print $mfh '>'.
10561: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
10562: .'</'.$tag.'>';
10563: }
10564: }
10565: $output = 'ok';
10566: print $logfile "\nWrote metadata";
10567: close($mfh);
10568: } else {
10569: print $logfile "\nFailed to open metadata file";
1.9 raeburn 10570: $output = &mt('Could not write metadata');
10571: }
10572: }
1.155 raeburn 10573: return $output;
10574: }
10575:
10576: sub notifysubscribed {
10577: foreach my $targetsource (@{$modified_urls}){
10578: next unless (ref($targetsource) eq 'ARRAY');
10579: my ($target,$source)=@{$targetsource};
10580: if ($source ne '') {
1.160.6.88 raeburn 10581: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 10582: print $logfh "\nCleanup phase: Notifications\n";
10583: my @subscribed=&subscribed_hosts($target);
10584: foreach my $subhost (@subscribed) {
10585: print $logfh "\nNotifying host ".$subhost.':';
10586: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
10587: print $logfh $reply;
10588: }
10589: my @subscribedmeta=&subscribed_hosts("$target.meta");
10590: foreach my $subhost (@subscribedmeta) {
10591: print $logfh "\nNotifying host for metadata only ".$subhost.':';
10592: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
10593: $subhost);
10594: print $logfh $reply;
10595: }
10596: print $logfh "\n============ Done ============\n";
1.160 raeburn 10597: close($logfh);
1.155 raeburn 10598: }
10599: }
10600: }
10601: return OK;
10602: }
10603:
10604: sub subscribed_hosts {
10605: my ($target) = @_;
10606: my @subscribed;
1.160.6.88 raeburn 10607: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 10608: while (my $subline=<$fh>) {
10609: if ($subline =~ /^($match_lonid):/) {
10610: my $host = $1;
10611: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
10612: unless (grep(/^\Q$host\E$/,@subscribed)) {
10613: push(@subscribed,$host);
10614: }
10615: }
10616: }
10617: }
10618: }
10619: return @subscribed;
1.9 raeburn 10620: }
10621:
10622: sub check_switchserver {
10623: my ($dom,$confname) = @_;
10624: my ($allowed,$switchserver);
10625: my $home = &Apache::lonnet::homeserver($confname,$dom);
10626: if ($home eq 'no_host') {
10627: $home = &Apache::lonnet::domain($dom,'primary');
10628: }
10629: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 10630: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
10631: if (!$allowed) {
1.160.6.11 raeburn 10632: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 10633: }
10634: return $switchserver;
10635: }
10636:
1.1 raeburn 10637: sub modify_quotas {
1.160.6.30 raeburn 10638: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 10639: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 10640: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 10641: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
10642: $validationfieldsref);
1.86 raeburn 10643: if ($action eq 'quotas') {
10644: $context = 'tools';
1.160.6.26 raeburn 10645: } else {
1.86 raeburn 10646: $context = $action;
10647: }
10648: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 10649: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 10650: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 10651: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
10652: %titles = &courserequest_titles();
10653: $toolregexp = join('|',@usertools);
10654: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 10655: $confname = $dom.'-domainconfig';
10656: my $servadm = $r->dir_config('lonAdmEMail');
10657: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 10658: ($validationitemsref,$validationnamesref,$validationfieldsref) =
10659: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 10660: } elsif ($context eq 'requestauthor') {
10661: @usertools = ('author');
10662: %titles = &authorrequest_titles();
1.86 raeburn 10663: } else {
1.160.6.4 raeburn 10664: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 10665: %titles = &tool_titles();
1.86 raeburn 10666: }
1.160.6.27 raeburn 10667: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 10668: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10669: foreach my $key (keys(%env)) {
1.101 raeburn 10670: if ($context eq 'requestcourses') {
10671: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
10672: my $item = $1;
10673: my $type = $2;
10674: if ($type =~ /^limit_(.+)/) {
10675: $limithash{$item}{$1} = $env{$key};
10676: } else {
10677: $confhash{$item}{$type} = $env{$key};
10678: }
10679: }
1.160.6.5 raeburn 10680: } elsif ($context eq 'requestauthor') {
10681: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
10682: $confhash{$1} = $env{$key};
10683: }
1.101 raeburn 10684: } else {
1.86 raeburn 10685: if ($key =~ /^form\.quota_(.+)$/) {
10686: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 10687: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
10688: $confhash{'authorquota'}{$1} = $env{$key};
10689: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 10690: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
10691: }
1.72 raeburn 10692: }
10693: }
1.160.6.5 raeburn 10694: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 10695: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 10696: @approvalnotify = sort(@approvalnotify);
10697: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 10698: my @crstypes = ('official','unofficial','community','textbook');
10699: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
10700: foreach my $type (@hasuniquecode) {
10701: if (grep(/^\Q$type\E$/,@crstypes)) {
10702: $confhash{'uniquecode'}{$type} = 1;
10703: }
10704: }
1.160.6.46 raeburn 10705: my (%newbook,%allpos);
1.160.6.30 raeburn 10706: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 10707: foreach my $type ('textbooks','templates') {
10708: @{$allpos{$type}} = ();
10709: my $invalid;
10710: if ($type eq 'textbooks') {
10711: $invalid = &mt('Invalid LON-CAPA course for textbook');
10712: } else {
10713: $invalid = &mt('Invalid LON-CAPA course for template');
10714: }
10715: if ($env{'form.'.$type.'_addbook'}) {
10716: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
10717: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
10718: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
10719: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
10720: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
10721: } else {
10722: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
10723: my $position = $env{'form.'.$type.'_addbook_pos'};
10724: $position =~ s/\D+//g;
10725: if ($position ne '') {
10726: $allpos{$type}[$position] = $newbook{$type};
10727: }
1.160.6.30 raeburn 10728: }
1.160.6.46 raeburn 10729: } else {
10730: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 10731: }
10732: }
1.160.6.46 raeburn 10733: }
1.160.6.30 raeburn 10734: }
1.102 raeburn 10735: if (ref($domconfig{$action}) eq 'HASH') {
10736: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
10737: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
10738: $changes{'notify'}{'approval'} = 1;
10739: }
10740: } else {
1.144 raeburn 10741: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10742: $changes{'notify'}{'approval'} = 1;
10743: }
10744: }
1.160.6.30 raeburn 10745: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
10746: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10747: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
10748: unless ($confhash{'uniquecode'}{$crstype}) {
10749: $changes{'uniquecode'} = 1;
10750: }
10751: }
10752: unless ($changes{'uniquecode'}) {
10753: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
10754: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
10755: $changes{'uniquecode'} = 1;
10756: }
10757: }
10758: }
10759: } else {
10760: $changes{'uniquecode'} = 1;
10761: }
10762: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
10763: $changes{'uniquecode'} = 1;
10764: }
10765: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 10766: foreach my $type ('textbooks','templates') {
10767: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10768: my %deletions;
10769: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
10770: if (@todelete) {
10771: map { $deletions{$_} = 1; } @todelete;
10772: }
10773: my %imgdeletions;
10774: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
10775: if (@todeleteimages) {
10776: map { $imgdeletions{$_} = 1; } @todeleteimages;
10777: }
10778: my $maxnum = $env{'form.'.$type.'_maxnum'};
10779: for (my $i=0; $i<=$maxnum; $i++) {
10780: my $itemid = $env{'form.'.$type.'_id_'.$i};
10781: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
10782: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
10783: if ($deletions{$key}) {
10784: if ($domconfig{$action}{$type}{$key}{'image'}) {
10785: #FIXME need to obsolete item in RES space
10786: }
10787: next;
10788: } else {
10789: my $newpos = $env{'form.'.$itemid};
10790: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 10791: foreach my $item ('subject','title','publisher','author') {
10792: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10793: ($type eq 'templates'));
1.160.6.46 raeburn 10794: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
10795: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
10796: $changes{$type}{$key} = 1;
10797: }
10798: }
10799: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 10800: }
1.160.6.46 raeburn 10801: if ($imgdeletions{$key}) {
10802: $changes{$type}{$key} = 1;
10803: #FIXME need to obsolete item in RES space
10804: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
10805: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 10806: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10807: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10808: } else {
10809: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
10810: $cdom,$cnum,$type,$configuserok,
10811: $switchserver,$author_ok);
10812: if ($imgurl) {
10813: $confhash{$type}{$key}{'image'} = $imgurl;
10814: $changes{$type}{$key} = 1;
10815: }
10816: if ($error) {
10817: &Apache::lonnet::logthis($error);
10818: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10819: }
1.160.6.46 raeburn 10820: }
10821: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
10822: $confhash{$type}{$key}{'image'} =
10823: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 10824: }
10825: }
10826: }
10827: }
10828: }
10829: }
1.102 raeburn 10830: } else {
1.144 raeburn 10831: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10832: $changes{'notify'}{'approval'} = 1;
10833: }
1.160.6.30 raeburn 10834: if (ref($confhash{'uniquecode'} eq 'HASH')) {
10835: $changes{'uniquecode'} = 1;
10836: }
10837: }
10838: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 10839: foreach my $type ('textbooks','templates') {
10840: if ($newbook{$type}) {
10841: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 10842: foreach my $item ('subject','title','publisher','author') {
10843: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10844: ($type eq 'template'));
1.160.6.46 raeburn 10845: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
10846: if ($env{'form.'.$type.'_addbook_'.$item}) {
10847: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
10848: }
10849: }
10850: if ($type eq 'textbooks') {
10851: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
10852: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 10853: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10854: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10855: } else {
10856: my ($imageurl,$error) =
10857: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
10858: $configuserok,$switchserver,$author_ok);
10859: if ($imageurl) {
10860: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
10861: }
10862: if ($error) {
10863: &Apache::lonnet::logthis($error);
10864: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10865: }
1.160.6.46 raeburn 10866: }
10867: }
1.160.6.30 raeburn 10868: }
10869: }
1.160.6.46 raeburn 10870: if (@{$allpos{$type}} > 0) {
10871: my $idx = 0;
10872: foreach my $item (@{$allpos{$type}}) {
10873: if ($item ne '') {
10874: $confhash{$type}{$item}{'order'} = $idx;
10875: if (ref($domconfig{$action}) eq 'HASH') {
10876: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10877: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
10878: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
10879: $changes{$type}{$item} = 1;
10880: }
1.160.6.30 raeburn 10881: }
10882: }
10883: }
1.160.6.46 raeburn 10884: $idx ++;
1.160.6.30 raeburn 10885: }
10886: }
10887: }
10888: }
1.160.6.39 raeburn 10889: if (ref($validationitemsref) eq 'ARRAY') {
10890: foreach my $item (@{$validationitemsref}) {
10891: if ($item eq 'fields') {
10892: my @changed;
10893: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
10894: if (@{$confhash{'validation'}{$item}} > 0) {
10895: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
10896: }
1.160.6.65 raeburn 10897: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10898: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10899: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
10900: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
10901: $domconfig{'requestcourses'}{'validation'}{$item});
10902: } else {
10903: @changed = @{$confhash{'validation'}{$item}};
10904: }
1.160.6.39 raeburn 10905: } else {
10906: @changed = @{$confhash{'validation'}{$item}};
10907: }
10908: } else {
10909: @changed = @{$confhash{'validation'}{$item}};
10910: }
10911: if (@changed) {
10912: if ($confhash{'validation'}{$item}) {
10913: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
10914: } else {
10915: $changes{'validation'}{$item} = &mt('None');
10916: }
10917: }
10918: } else {
10919: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
10920: if ($item eq 'markup') {
10921: if ($env{'form.requestcourses_validation_'.$item}) {
10922: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10923: }
10924: }
1.160.6.65 raeburn 10925: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10926: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10927: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
10928: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10929: }
10930: } else {
10931: if ($confhash{'validation'}{$item} ne '') {
10932: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10933: }
1.160.6.39 raeburn 10934: }
10935: } else {
10936: if ($confhash{'validation'}{$item} ne '') {
10937: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10938: }
10939: }
10940: }
10941: }
10942: }
10943: if ($env{'form.validationdc'}) {
10944: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 10945: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 10946: if (exists($domcoords{$newval})) {
10947: $confhash{'validation'}{'dc'} = $newval;
10948: }
10949: }
10950: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 10951: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10952: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10953: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10954: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
10955: if ($confhash{'validation'}{'dc'} eq '') {
10956: $changes{'validation'}{'dc'} = &mt('None');
10957: } else {
10958: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10959: }
1.160.6.39 raeburn 10960: }
1.160.6.65 raeburn 10961: } elsif ($confhash{'validation'}{'dc'} ne '') {
10962: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 10963: }
10964: } elsif ($confhash{'validation'}{'dc'} ne '') {
10965: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10966: }
10967: } elsif ($confhash{'validation'}{'dc'} ne '') {
10968: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10969: }
1.160.6.65 raeburn 10970: } else {
10971: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10972: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10973: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10974: $changes{'validation'}{'dc'} = &mt('None');
10975: }
10976: }
1.160.6.39 raeburn 10977: }
10978: }
1.102 raeburn 10979: }
10980: } else {
1.86 raeburn 10981: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 10982: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 10983: }
1.72 raeburn 10984: foreach my $item (@usertools) {
10985: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 10986: my $unset;
1.101 raeburn 10987: if ($context eq 'requestcourses') {
1.104 raeburn 10988: $unset = '0';
10989: if ($type eq '_LC_adv') {
10990: $unset = '';
10991: }
1.101 raeburn 10992: if ($confhash{$item}{$type} eq 'autolimit') {
10993: $confhash{$item}{$type} .= '=';
10994: unless ($limithash{$item}{$type} =~ /\D/) {
10995: $confhash{$item}{$type} .= $limithash{$item}{$type};
10996: }
10997: }
1.160.6.5 raeburn 10998: } elsif ($context eq 'requestauthor') {
10999: $unset = '0';
11000: if ($type eq '_LC_adv') {
11001: $unset = '';
11002: }
1.72 raeburn 11003: } else {
1.101 raeburn 11004: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
11005: $confhash{$item}{$type} = 1;
11006: } else {
11007: $confhash{$item}{$type} = 0;
11008: }
1.72 raeburn 11009: }
1.86 raeburn 11010: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 11011: if ($action eq 'requestauthor') {
11012: if ($domconfig{$action}{$type} ne $confhash{$type}) {
11013: $changes{$type} = 1;
11014: }
11015: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 11016: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
11017: $changes{$item}{$type} = 1;
11018: }
11019: } else {
11020: if ($context eq 'requestcourses') {
1.104 raeburn 11021: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 11022: $changes{$item}{$type} = 1;
11023: }
11024: } else {
11025: if (!$confhash{$item}{$type}) {
11026: $changes{$item}{$type} = 1;
11027: }
11028: }
11029: }
11030: } else {
11031: if ($context eq 'requestcourses') {
1.104 raeburn 11032: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 11033: $changes{$item}{$type} = 1;
11034: }
1.160.6.5 raeburn 11035: } elsif ($context eq 'requestauthor') {
11036: if ($confhash{$type} ne $unset) {
11037: $changes{$type} = 1;
11038: }
1.72 raeburn 11039: } else {
11040: if (!$confhash{$item}{$type}) {
11041: $changes{$item}{$type} = 1;
11042: }
11043: }
11044: }
1.1 raeburn 11045: }
11046: }
1.160.6.5 raeburn 11047: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 11048: if (ref($domconfig{'quotas'}) eq 'HASH') {
11049: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11050: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
11051: if (exists($confhash{'defaultquota'}{$key})) {
11052: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
11053: $changes{'defaultquota'}{$key} = 1;
11054: }
11055: } else {
11056: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 11057: }
11058: }
1.86 raeburn 11059: } else {
11060: foreach my $key (keys(%{$domconfig{'quotas'}})) {
11061: if (exists($confhash{'defaultquota'}{$key})) {
11062: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
11063: $changes{'defaultquota'}{$key} = 1;
11064: }
11065: } else {
11066: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 11067: }
1.1 raeburn 11068: }
11069: }
1.160.6.20 raeburn 11070: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11071: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
11072: if (exists($confhash{'authorquota'}{$key})) {
11073: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
11074: $changes{'authorquota'}{$key} = 1;
11075: }
11076: } else {
11077: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
11078: }
11079: }
11080: }
1.1 raeburn 11081: }
1.86 raeburn 11082: if (ref($confhash{'defaultquota'}) eq 'HASH') {
11083: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
11084: if (ref($domconfig{'quotas'}) eq 'HASH') {
11085: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11086: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
11087: $changes{'defaultquota'}{$key} = 1;
11088: }
11089: } else {
11090: if (!exists($domconfig{'quotas'}{$key})) {
11091: $changes{'defaultquota'}{$key} = 1;
11092: }
1.72 raeburn 11093: }
11094: } else {
1.86 raeburn 11095: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 11096: }
1.1 raeburn 11097: }
11098: }
1.160.6.20 raeburn 11099: if (ref($confhash{'authorquota'}) eq 'HASH') {
11100: foreach my $key (keys(%{$confhash{'authorquota'}})) {
11101: if (ref($domconfig{'quotas'}) eq 'HASH') {
11102: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11103: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
11104: $changes{'authorquota'}{$key} = 1;
11105: }
11106: } else {
11107: $changes{'authorquota'}{$key} = 1;
11108: }
11109: } else {
11110: $changes{'authorquota'}{$key} = 1;
11111: }
11112: }
11113: }
1.1 raeburn 11114: }
1.72 raeburn 11115:
1.160.6.5 raeburn 11116: if ($context eq 'requestauthor') {
11117: $domdefaults{'requestauthor'} = \%confhash;
11118: } else {
11119: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 11120: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 11121: $domdefaults{$key} = $confhash{$key};
11122: }
1.160.6.5 raeburn 11123: }
1.72 raeburn 11124: }
1.160.6.5 raeburn 11125:
1.1 raeburn 11126: my %quotahash = (
1.86 raeburn 11127: $action => { %confhash }
1.1 raeburn 11128: );
11129: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
11130: $dom);
11131: if ($putresult eq 'ok') {
11132: if (keys(%changes) > 0) {
1.72 raeburn 11133: my $cachetime = 24*60*60;
11134: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11135: if (ref($lastactref) eq 'HASH') {
11136: $lastactref->{'domdefaults'} = 1;
11137: }
1.1 raeburn 11138: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 11139: unless (($context eq 'requestcourses') ||
11140: ($context eq 'requestauthor')) {
1.86 raeburn 11141: if (ref($changes{'defaultquota'}) eq 'HASH') {
11142: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
11143: foreach my $type (@{$types},'default') {
11144: if (defined($changes{'defaultquota'}{$type})) {
11145: my $typetitle = $usertypes->{$type};
11146: if ($type eq 'default') {
11147: $typetitle = $othertitle;
11148: }
1.160.6.28 raeburn 11149: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 11150: }
11151: }
1.86 raeburn 11152: $resulttext .= '</ul></li>';
1.72 raeburn 11153: }
1.160.6.20 raeburn 11154: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 11155: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 11156: foreach my $type (@{$types},'default') {
11157: if (defined($changes{'authorquota'}{$type})) {
11158: my $typetitle = $usertypes->{$type};
11159: if ($type eq 'default') {
11160: $typetitle = $othertitle;
11161: }
1.160.6.28 raeburn 11162: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 11163: }
11164: }
11165: $resulttext .= '</ul></li>';
11166: }
1.72 raeburn 11167: }
1.80 raeburn 11168: my %newenv;
1.72 raeburn 11169: foreach my $item (@usertools) {
1.160.6.5 raeburn 11170: my (%haschgs,%inconf);
11171: if ($context eq 'requestauthor') {
11172: %haschgs = %changes;
11173: %inconf = %confhash;
11174: } else {
11175: if (ref($changes{$item}) eq 'HASH') {
11176: %haschgs = %{$changes{$item}};
11177: }
11178: if (ref($confhash{$item}) eq 'HASH') {
11179: %inconf = %{$confhash{$item}};
11180: }
11181: }
11182: if (keys(%haschgs) > 0) {
1.80 raeburn 11183: my $newacc =
11184: &Apache::lonnet::usertools_access($env{'user.name'},
11185: $env{'user.domain'},
1.86 raeburn 11186: $item,'reload',$context);
1.160.6.5 raeburn 11187: if (($context eq 'requestcourses') ||
11188: ($context eq 'requestauthor')) {
1.108 raeburn 11189: if ($env{'environment.canrequest.'.$item} ne $newacc) {
11190: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 11191: }
11192: } else {
11193: if ($env{'environment.availabletools.'.$item} ne $newacc) {
11194: $newenv{'environment.availabletools.'.$item} = $newacc;
11195: }
1.80 raeburn 11196: }
1.160.6.5 raeburn 11197: unless ($context eq 'requestauthor') {
11198: $resulttext .= '<li>'.$titles{$item}.'<ul>';
11199: }
1.72 raeburn 11200: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 11201: if ($haschgs{$type}) {
1.72 raeburn 11202: my $typetitle = $usertypes->{$type};
11203: if ($type eq 'default') {
11204: $typetitle = $othertitle;
11205: } elsif ($type eq '_LC_adv') {
11206: $typetitle = 'LON-CAPA Advanced Users';
11207: }
1.160.6.5 raeburn 11208: if ($inconf{$type}) {
1.101 raeburn 11209: if ($context eq 'requestcourses') {
11210: my $cond;
1.160.6.5 raeburn 11211: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 11212: if ($1 eq '') {
11213: $cond = &mt('(Automatic processing of any request).');
11214: } else {
11215: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
11216: }
11217: } else {
1.160.6.5 raeburn 11218: $cond = $conditions{$inconf{$type}};
1.101 raeburn 11219: }
11220: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 11221: } elsif ($context eq 'requestauthor') {
11222: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
11223: $titles{$inconf{$type}},$typetitle);
11224:
1.101 raeburn 11225: } else {
11226: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
11227: }
1.72 raeburn 11228: } else {
1.104 raeburn 11229: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 11230: if ($inconf{$type} eq '0') {
1.104 raeburn 11231: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11232: } else {
11233: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
11234: }
11235: } else {
11236: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11237: }
1.72 raeburn 11238: }
11239: }
1.26 raeburn 11240: }
1.160.6.5 raeburn 11241: unless ($context eq 'requestauthor') {
11242: $resulttext .= '</ul></li>';
11243: }
1.26 raeburn 11244: }
1.1 raeburn 11245: }
1.160.6.5 raeburn 11246: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 11247: if (ref($changes{'notify'}) eq 'HASH') {
11248: if ($changes{'notify'}{'approval'}) {
11249: if (ref($confhash{'notify'}) eq 'HASH') {
11250: if ($confhash{'notify'}{'approval'}) {
11251: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
11252: } else {
1.160.6.5 raeburn 11253: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 11254: }
11255: }
11256: }
11257: }
11258: }
1.160.6.30 raeburn 11259: if ($action eq 'requestcourses') {
11260: my @offon = ('off','on');
11261: if ($changes{'uniquecode'}) {
11262: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11263: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
11264: $resulttext .= '<li>'.
11265: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
11266: '</li>';
11267: } else {
11268: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
11269: '</li>';
11270: }
11271: }
1.160.6.46 raeburn 11272: foreach my $type ('textbooks','templates') {
11273: if (ref($changes{$type}) eq 'HASH') {
11274: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
11275: foreach my $key (sort(keys(%{$changes{$type}}))) {
11276: my %coursehash = &Apache::lonnet::coursedescription($key);
11277: my $coursetitle = $coursehash{'description'};
11278: my $position = $confhash{$type}{$key}{'order'} + 1;
11279: $resulttext .= '<li>';
1.160.6.47 raeburn 11280: foreach my $item ('subject','title','publisher','author') {
11281: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11282: ($type eq 'templates'));
1.160.6.46 raeburn 11283: my $name = $item.':';
11284: $name =~ s/^(\w)/\U$1/;
11285: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
11286: }
11287: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
11288: if ($type eq 'textbooks') {
11289: if ($confhash{$type}{$key}{'image'}) {
11290: $resulttext .= ' '.&mt('Image: [_1]',
11291: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
11292: ' alt="Textbook cover" />').'<br />';
11293: }
11294: }
11295: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 11296: }
1.160.6.46 raeburn 11297: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 11298: }
11299: }
1.160.6.39 raeburn 11300: if (ref($changes{'validation'}) eq 'HASH') {
11301: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
11302: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
11303: foreach my $item (@{$validationitemsref}) {
11304: if (exists($changes{'validation'}{$item})) {
11305: if ($item eq 'markup') {
11306: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11307: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
11308: } else {
11309: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11310: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
11311: }
11312: }
11313: }
11314: if (exists($changes{'validation'}{'dc'})) {
11315: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
11316: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
11317: }
11318: }
11319: }
1.160.6.30 raeburn 11320: }
1.1 raeburn 11321: $resulttext .= '</ul>';
1.80 raeburn 11322: if (keys(%newenv)) {
11323: &Apache::lonnet::appenv(\%newenv);
11324: }
1.1 raeburn 11325: } else {
1.86 raeburn 11326: if ($context eq 'requestcourses') {
11327: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 11328: } elsif ($context eq 'requestauthor') {
11329: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 11330: } else {
1.90 weissno 11331: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 11332: }
1.1 raeburn 11333: }
11334: } else {
1.11 albertel 11335: $resulttext = '<span class="LC_error">'.
11336: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11337: }
1.160.6.30 raeburn 11338: if ($errors) {
11339: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
11340: '<ul>'.$errors.'</ul></p>';
11341: }
1.3 raeburn 11342: return $resulttext;
1.1 raeburn 11343: }
11344:
1.160.6.30 raeburn 11345: sub process_textbook_image {
1.160.6.46 raeburn 11346: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 11347: my $filename = $env{'form.'.$caller.'.filename'};
11348: my ($error,$url);
11349: my ($width,$height) = (50,50);
11350: if ($configuserok eq 'ok') {
11351: if ($switchserver) {
11352: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
11353: $switchserver);
11354: } elsif ($author_ok eq 'ok') {
11355: my ($result,$imageurl) =
11356: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88 raeburn 11357: "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 11358: if ($result eq 'ok') {
11359: $url = $imageurl;
11360: } else {
11361: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11362: }
11363: } else {
11364: $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);
11365: }
11366: } else {
11367: $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);
11368: }
11369: return ($url,$error);
11370: }
11371:
1.3 raeburn 11372: sub modify_autoenroll {
1.160.6.24 raeburn 11373: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 11374: my ($resulttext,%changes);
11375: my %currautoenroll;
11376: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
11377: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
11378: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
11379: }
11380: }
11381: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
11382: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 11383: sender => 'Sender for notification messages',
1.160.6.68 raeburn 11384: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
11385: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 11386: my @offon = ('off','on');
1.17 raeburn 11387: my $sender_uname = $env{'form.sender_uname'};
11388: my $sender_domain = $env{'form.sender_domain'};
11389: if ($sender_domain eq '') {
11390: $sender_uname = '';
11391: } elsif ($sender_uname eq '') {
11392: $sender_domain = '';
11393: }
1.129 raeburn 11394: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 11395: my $failsafe = $env{'form.autoenroll_failsafe'};
11396: $failsafe =~ s{^\s+|\s+$}{}g;
11397: if ($failsafe =~ /\D/) {
11398: undef($failsafe);
11399: }
1.1 raeburn 11400: my %autoenrollhash = (
1.129 raeburn 11401: autoenroll => { 'run' => $env{'form.autoenroll_run'},
11402: 'sender_uname' => $sender_uname,
11403: 'sender_domain' => $sender_domain,
11404: 'co-owners' => $coowners,
1.160.6.68 raeburn 11405: 'autofailsafe' => $failsafe,
1.1 raeburn 11406: }
11407: );
1.4 raeburn 11408: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
11409: $dom);
1.1 raeburn 11410: if ($putresult eq 'ok') {
11411: if (exists($currautoenroll{'run'})) {
11412: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
11413: $changes{'run'} = 1;
11414: }
11415: } elsif ($autorun) {
11416: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 11417: $changes{'run'} = 1;
1.1 raeburn 11418: }
11419: }
1.17 raeburn 11420: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 11421: $changes{'sender'} = 1;
11422: }
1.17 raeburn 11423: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 11424: $changes{'sender'} = 1;
11425: }
1.129 raeburn 11426: if ($currautoenroll{'co-owners'} ne '') {
11427: if ($currautoenroll{'co-owners'} ne $coowners) {
11428: $changes{'coowners'} = 1;
11429: }
11430: } elsif ($coowners) {
11431: $changes{'coowners'} = 1;
1.160.6.68 raeburn 11432: }
11433: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
11434: $changes{'autofailsafe'} = 1;
11435: }
1.1 raeburn 11436: if (keys(%changes) > 0) {
11437: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 11438: if ($changes{'run'}) {
1.1 raeburn 11439: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
11440: }
11441: if ($changes{'sender'}) {
1.17 raeburn 11442: if ($sender_uname eq '' || $sender_domain eq '') {
11443: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
11444: } else {
11445: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
11446: }
1.1 raeburn 11447: }
1.129 raeburn 11448: if ($changes{'coowners'}) {
11449: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
11450: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 11451: if (ref($lastactref) eq 'HASH') {
11452: $lastactref->{'domainconfig'} = 1;
11453: }
1.129 raeburn 11454: }
1.160.6.68 raeburn 11455: if ($changes{'autofailsafe'}) {
11456: if ($failsafe ne '') {
1.160.6.82 raeburn 11457: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68 raeburn 11458: } else {
1.160.6.82 raeburn 11459: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68 raeburn 11460: }
11461: &Apache::lonnet::get_domain_defaults($dom,1);
11462: if (ref($lastactref) eq 'HASH') {
11463: $lastactref->{'domdefaults'} = 1;
11464: }
11465: }
1.1 raeburn 11466: $resulttext .= '</ul>';
11467: } else {
11468: $resulttext = &mt('No changes made to auto-enrollment settings');
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.3 raeburn 11474: return $resulttext;
1.1 raeburn 11475: }
11476:
11477: sub modify_autoupdate {
1.3 raeburn 11478: my ($dom,%domconfig) = @_;
1.1 raeburn 11479: my ($resulttext,%currautoupdate,%fields,%changes);
11480: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
11481: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
11482: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
11483: }
11484: }
11485: my @offon = ('off','on');
11486: my %title = &Apache::lonlocal::texthash (
1.160.6.113 raeburn 11487: run => 'Auto-update:',
11488: classlists => 'Updates to user information in classlists?',
11489: unexpired => 'Skip updates for users without active or future roles?',
11490: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 11491: );
1.44 raeburn 11492: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 11493: my %fieldtitles = &Apache::lonlocal::texthash (
11494: id => 'Student/Employee ID',
1.20 raeburn 11495: permanentemail => 'E-mail address',
1.1 raeburn 11496: lastname => 'Last Name',
11497: firstname => 'First Name',
11498: middlename => 'Middle Name',
1.132 raeburn 11499: generation => 'Generation',
1.1 raeburn 11500: );
1.142 raeburn 11501: $othertitle = &mt('All users');
1.1 raeburn 11502: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 11503: $othertitle = &mt('Other users');
1.1 raeburn 11504: }
11505: foreach my $key (keys(%env)) {
11506: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 11507: my ($usertype,$item) = ($1,$2);
11508: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
11509: if ($usertype eq 'default') {
11510: push(@{$fields{$1}},$2);
11511: } elsif (ref($types) eq 'ARRAY') {
11512: if (grep(/^\Q$usertype\E$/,@{$types})) {
11513: push(@{$fields{$1}},$2);
11514: }
11515: }
11516: }
1.1 raeburn 11517: }
11518: }
1.131 raeburn 11519: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
11520: @lockablenames = sort(@lockablenames);
11521: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
11522: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11523: if (@changed) {
11524: $changes{'lockablenames'} = 1;
11525: }
11526: } else {
11527: if (@lockablenames) {
11528: $changes{'lockablenames'} = 1;
11529: }
11530: }
1.1 raeburn 11531: my %updatehash = (
11532: autoupdate => { run => $env{'form.autoupdate_run'},
11533: classlists => $env{'form.classlists'},
1.160.6.113 raeburn 11534: unexpired => $env{'form.unexpired'},
1.1 raeburn 11535: fields => {%fields},
1.131 raeburn 11536: lockablenames => \@lockablenames,
1.1 raeburn 11537: }
11538: );
1.160.6.113 raeburn 11539: my $lastactivedays;
11540: if ($env{'form.lastactive'}) {
11541: $lastactivedays = $env{'form.lastactivedays'};
11542: $lastactivedays =~ s/^\s+|\s+$//g;
11543: unless ($lastactivedays =~ /^\d+$/) {
11544: undef($lastactivedays);
11545: $env{'form.lastactive'} = 0;
11546: }
11547: }
11548: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 11549: foreach my $key (keys(%currautoupdate)) {
1.160.6.113 raeburn 11550: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 11551: if (exists($updatehash{autoupdate}{$key})) {
11552: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
11553: $changes{$key} = 1;
11554: }
11555: }
11556: } elsif ($key eq 'fields') {
11557: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 11558: foreach my $item (@{$types},'default') {
1.1 raeburn 11559: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
11560: my $change = 0;
11561: foreach my $type (@{$currautoupdate{$key}{$item}}) {
11562: if (!exists($fields{$item})) {
11563: $change = 1;
1.132 raeburn 11564: last;
1.1 raeburn 11565: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 11566: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 11567: $change = 1;
1.132 raeburn 11568: last;
1.1 raeburn 11569: }
11570: }
11571: }
11572: if ($change) {
11573: push(@{$changes{$key}},$item);
11574: }
1.26 raeburn 11575: }
1.1 raeburn 11576: }
11577: }
1.131 raeburn 11578: } elsif ($key eq 'lockablenames') {
11579: if (ref($currautoupdate{$key}) eq 'ARRAY') {
11580: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11581: if (@changed) {
11582: $changes{'lockablenames'} = 1;
11583: }
11584: } else {
11585: if (@lockablenames) {
11586: $changes{'lockablenames'} = 1;
11587: }
11588: }
11589: }
11590: }
11591: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
11592: if (@lockablenames) {
11593: $changes{'lockablenames'} = 1;
1.1 raeburn 11594: }
11595: }
1.160.6.113 raeburn 11596: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
11597: if ($updatehash{'autoupdate'}{'unexpired'}) {
11598: $changes{'unexpired'} = 1;
11599: }
11600: }
11601: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
11602: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
11603: $changes{'lastactive'} = 1;
11604: }
11605: }
1.26 raeburn 11606: foreach my $item (@{$types},'default') {
11607: if (defined($fields{$item})) {
11608: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 11609: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
11610: my $change = 0;
11611: if (ref($fields{$item}) eq 'ARRAY') {
11612: foreach my $type (@{$fields{$item}}) {
11613: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
11614: $change = 1;
11615: last;
11616: }
11617: }
11618: }
11619: if ($change) {
11620: push(@{$changes{'fields'}},$item);
11621: }
11622: } else {
1.26 raeburn 11623: push(@{$changes{'fields'}},$item);
11624: }
11625: } else {
11626: push(@{$changes{'fields'}},$item);
1.1 raeburn 11627: }
11628: }
11629: }
11630: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
11631: $dom);
11632: if ($putresult eq 'ok') {
11633: if (keys(%changes) > 0) {
11634: $resulttext = &mt('Changes made:').'<ul>';
11635: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 11636: if ($key eq 'lockablenames') {
11637: $resulttext .= '<li>';
11638: if (@lockablenames) {
11639: $usertypes->{'default'} = $othertitle;
11640: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
11641: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
11642: } else {
11643: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
11644: }
11645: $resulttext .= '</li>';
11646: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 11647: foreach my $item (@{$changes{$key}}) {
11648: my @newvalues;
11649: foreach my $type (@{$fields{$item}}) {
11650: push(@newvalues,$fieldtitles{$type});
11651: }
1.3 raeburn 11652: my $newvaluestr;
11653: if (@newvalues > 0) {
11654: $newvaluestr = join(', ',@newvalues);
11655: } else {
11656: $newvaluestr = &mt('none');
1.6 raeburn 11657: }
1.1 raeburn 11658: if ($item eq 'default') {
1.26 raeburn 11659: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 11660: } else {
1.26 raeburn 11661: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 11662: }
11663: }
11664: } else {
11665: my $newvalue;
11666: if ($key eq 'run') {
11667: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.160.6.113 raeburn 11668: } elsif ($key eq 'lastactive') {
11669: $newvalue = $offon[$env{'form.lastactive'}];
11670: unless ($lastactivedays eq '') {
11671: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
11672: }
1.1 raeburn 11673: } else {
11674: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 11675: }
1.1 raeburn 11676: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
11677: }
11678: }
11679: $resulttext .= '</ul>';
11680: } else {
1.3 raeburn 11681: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 11682: }
11683: } else {
1.11 albertel 11684: $resulttext = '<span class="LC_error">'.
11685: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11686: }
1.3 raeburn 11687: return $resulttext;
1.1 raeburn 11688: }
11689:
1.125 raeburn 11690: sub modify_autocreate {
11691: my ($dom,%domconfig) = @_;
11692: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
11693: if (ref($domconfig{'autocreate'}) eq 'HASH') {
11694: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
11695: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
11696: }
11697: }
11698: my %title= ( xml => 'Auto-creation of courses in XML course description files',
11699: req => 'Auto-creation of validated requests for official courses',
11700: xmldc => 'Identity of course creator of courses from XML files',
11701: );
11702: my @types = ('xml','req');
11703: foreach my $item (@types) {
11704: $newvals{$item} = $env{'form.autocreate_'.$item};
11705: $newvals{$item} =~ s/\D//g;
11706: $newvals{$item} = 0 if ($newvals{$item} eq '');
11707: }
11708: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 11709: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 11710: unless (exists($domcoords{$newvals{'xmldc'}})) {
11711: $newvals{'xmldc'} = '';
11712: }
11713: %autocreatehash = (
11714: autocreate => { xml => $newvals{'xml'},
11715: req => $newvals{'req'},
11716: }
11717: );
11718: if ($newvals{'xmldc'} ne '') {
11719: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
11720: }
11721: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
11722: $dom);
11723: if ($putresult eq 'ok') {
11724: my @items = @types;
11725: if ($newvals{'xml'}) {
11726: push(@items,'xmldc');
11727: }
11728: foreach my $item (@items) {
11729: if (exists($currautocreate{$item})) {
11730: if ($currautocreate{$item} ne $newvals{$item}) {
11731: $changes{$item} = 1;
11732: }
11733: } elsif ($newvals{$item}) {
11734: $changes{$item} = 1;
11735: }
11736: }
11737: if (keys(%changes) > 0) {
11738: my @offon = ('off','on');
11739: $resulttext = &mt('Changes made:').'<ul>';
11740: foreach my $item (@types) {
11741: if ($changes{$item}) {
11742: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 11743: $resulttext .= '<li>'.
11744: &mt("$title{$item} set to [_1]$newtxt [_2]",
11745: '<b>','</b>').
11746: '</li>';
1.125 raeburn 11747: }
11748: }
11749: if ($changes{'xmldc'}) {
11750: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
11751: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 11752: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 11753: }
11754: $resulttext .= '</ul>';
11755: } else {
11756: $resulttext = &mt('No changes made to auto-creation settings');
11757: }
11758: } else {
11759: $resulttext = '<span class="LC_error">'.
11760: &mt('An error occurred: [_1]',$putresult).'</span>';
11761: }
11762: return $resulttext;
11763: }
11764:
1.23 raeburn 11765: sub modify_directorysrch {
1.160.6.81 raeburn 11766: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 11767: my ($resulttext,%changes);
11768: my %currdirsrch;
11769: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
11770: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
11771: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
11772: }
11773: }
1.160.6.72 raeburn 11774: my %title = ( available => 'Institutional directory search available',
11775: localonly => 'Other domains can search institution',
11776: lcavailable => 'LON-CAPA directory search available',
11777: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 11778: searchby => 'Search types',
11779: searchtypes => 'Search latitude');
11780: my @offon = ('off','on');
1.24 raeburn 11781: my @otherdoms = ('Yes','No');
1.23 raeburn 11782:
1.25 raeburn 11783: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 11784: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
11785: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
11786:
1.44 raeburn 11787: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 11788: if (keys(%{$usertypes}) == 0) {
11789: @cansearch = ('default');
11790: } else {
11791: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
11792: foreach my $type (@{$currdirsrch{'cansearch'}}) {
11793: if (!grep(/^\Q$type\E$/,@cansearch)) {
11794: push(@{$changes{'cansearch'}},$type);
11795: }
1.23 raeburn 11796: }
1.26 raeburn 11797: foreach my $type (@cansearch) {
11798: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
11799: push(@{$changes{'cansearch'}},$type);
11800: }
1.23 raeburn 11801: }
1.26 raeburn 11802: } else {
11803: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 11804: }
11805: }
11806:
11807: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
11808: foreach my $by (@{$currdirsrch{'searchby'}}) {
11809: if (!grep(/^\Q$by\E$/,@searchby)) {
11810: push(@{$changes{'searchby'}},$by);
11811: }
11812: }
11813: foreach my $by (@searchby) {
11814: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
11815: push(@{$changes{'searchby'}},$by);
11816: }
11817: }
11818: } else {
11819: push(@{$changes{'searchby'}},@searchby);
11820: }
1.25 raeburn 11821:
11822: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
11823: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
11824: if (!grep(/^\Q$type\E$/,@searchtypes)) {
11825: push(@{$changes{'searchtypes'}},$type);
11826: }
11827: }
11828: foreach my $type (@searchtypes) {
11829: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
11830: push(@{$changes{'searchtypes'}},$type);
11831: }
11832: }
11833: } else {
11834: if (exists($currdirsrch{'searchtypes'})) {
11835: foreach my $type (@searchtypes) {
11836: if ($type ne $currdirsrch{'searchtypes'}) {
11837: push(@{$changes{'searchtypes'}},$type);
11838: }
11839: }
11840: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
11841: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
11842: }
11843: } else {
11844: push(@{$changes{'searchtypes'}},@searchtypes);
11845: }
11846: }
11847:
1.23 raeburn 11848: my %dirsrch_hash = (
11849: directorysrch => { available => $env{'form.dirsrch_available'},
11850: cansearch => \@cansearch,
1.160.6.72 raeburn 11851: localonly => $env{'form.dirsrch_instlocalonly'},
11852: lclocalonly => $env{'form.dirsrch_domlocalonly'},
11853: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 11854: searchby => \@searchby,
1.25 raeburn 11855: searchtypes => \@searchtypes,
1.23 raeburn 11856: }
11857: );
11858: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
11859: $dom);
11860: if ($putresult eq 'ok') {
11861: if (exists($currdirsrch{'available'})) {
11862: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
11863: $changes{'available'} = 1;
11864: }
11865: } else {
11866: if ($env{'form.dirsrch_available'} eq '1') {
11867: $changes{'available'} = 1;
11868: }
11869: }
1.160.6.72 raeburn 11870: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 11871: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
11872: $changes{'lcavailable'} = 1;
11873: }
1.24 raeburn 11874: } else {
1.160.6.72 raeburn 11875: if ($env{'form.dirsrch_lcavailable'} eq '1') {
11876: $changes{'lcavailable'} = 1;
11877: }
11878: }
11879: if (exists($currdirsrch{'localonly'})) {
11880: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 11881: $changes{'localonly'} = 1;
11882: }
1.160.6.72 raeburn 11883: } else {
11884: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
11885: $changes{'localonly'} = 1;
11886: }
11887: }
11888: if (exists($currdirsrch{'lclocalonly'})) {
11889: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
11890: $changes{'lclocalonly'} = 1;
11891: }
11892: } else {
11893: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
11894: $changes{'lclocalonly'} = 1;
11895: }
1.24 raeburn 11896: }
1.23 raeburn 11897: if (keys(%changes) > 0) {
11898: $resulttext = &mt('Changes made:').'<ul>';
11899: if ($changes{'available'}) {
11900: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
11901: }
1.160.6.72 raeburn 11902: if ($changes{'lcavailable'}) {
11903: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
11904: }
1.24 raeburn 11905: if ($changes{'localonly'}) {
1.160.6.72 raeburn 11906: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
11907: }
11908: if ($changes{'lclocalonly'}) {
11909: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 11910: }
1.23 raeburn 11911: if (ref($changes{'cansearch'}) eq 'ARRAY') {
11912: my $chgtext;
1.26 raeburn 11913: if (ref($usertypes) eq 'HASH') {
11914: if (keys(%{$usertypes}) > 0) {
11915: foreach my $type (@{$types}) {
11916: if (grep(/^\Q$type\E$/,@cansearch)) {
11917: $chgtext .= $usertypes->{$type}.'; ';
11918: }
11919: }
11920: if (grep(/^default$/,@cansearch)) {
11921: $chgtext .= $othertitle;
11922: } else {
11923: $chgtext =~ s/\; $//;
11924: }
1.160.6.13 raeburn 11925: $resulttext .=
11926: '<li>'.
11927: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
11928: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
11929: '</li>';
1.23 raeburn 11930: }
11931: }
11932: }
11933: if (ref($changes{'searchby'}) eq 'ARRAY') {
11934: my ($searchtitles,$titleorder) = &sorted_searchtitles();
11935: my $chgtext;
11936: foreach my $type (@{$titleorder}) {
11937: if (grep(/^\Q$type\E$/,@searchby)) {
11938: if (defined($searchtitles->{$type})) {
11939: $chgtext .= $searchtitles->{$type}.'; ';
11940: }
11941: }
11942: }
11943: $chgtext =~ s/\; $//;
11944: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
11945: }
1.25 raeburn 11946: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
11947: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
11948: my $chgtext;
11949: foreach my $type (@{$srchtypeorder}) {
11950: if (grep(/^\Q$type\E$/,@searchtypes)) {
11951: if (defined($srchtypes_desc->{$type})) {
11952: $chgtext .= $srchtypes_desc->{$type}.'; ';
11953: }
11954: }
11955: }
11956: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 11957: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 11958: }
11959: $resulttext .= '</ul>';
1.160.6.81 raeburn 11960: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
11961: if (ref($lastactref) eq 'HASH') {
11962: $lastactref->{'directorysrch'} = 1;
11963: }
1.23 raeburn 11964: } else {
1.160.6.72 raeburn 11965: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 11966: }
11967: } else {
11968: $resulttext = '<span class="LC_error">'.
1.27 raeburn 11969: &mt('An error occurred: [_1]',$putresult).'</span>';
11970: }
11971: return $resulttext;
11972: }
11973:
1.28 raeburn 11974: sub modify_contacts {
1.160.6.24 raeburn 11975: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 11976: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
11977: if (ref($domconfig{'contacts'}) eq 'HASH') {
11978: foreach my $key (keys(%{$domconfig{'contacts'}})) {
11979: $currsetting{$key} = $domconfig{'contacts'}{$key};
11980: }
11981: }
1.160.6.78 raeburn 11982: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 11983: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 11984: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 11985: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.107 raeburn 11986: my @toggles = ('reporterrors','reportupdates','reportstatus');
11987: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.160.6.78 raeburn 11988: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 11989: foreach my $type (@mailings) {
11990: @{$newsetting{$type}} =
11991: &Apache::loncommon::get_env_multiple('form.'.$type);
11992: foreach my $item (@contacts) {
11993: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
11994: $contacts_hash{contacts}{$type}{$item} = 1;
11995: } else {
11996: $contacts_hash{contacts}{$type}{$item} = 0;
11997: }
1.160.6.78 raeburn 11998: }
1.28 raeburn 11999: $others{$type} = $env{'form.'.$type.'_others'};
12000: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 12001: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12002: $bcc{$type} = $env{'form.'.$type.'_bcc'};
12003: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 12004: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
12005: $includestr{$type} = $env{'form.'.$type.'_includestr'};
12006: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
12007: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12008: }
1.134 raeburn 12009: }
1.28 raeburn 12010: }
12011: foreach my $item (@contacts) {
12012: $to{$item} = $env{'form.'.$item};
12013: $contacts_hash{'contacts'}{$item} = $to{$item};
12014: }
1.160.6.23 raeburn 12015: foreach my $item (@toggles) {
12016: if ($env{'form.'.$item} =~ /^(0|1)$/) {
12017: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
12018: }
12019: }
1.160.6.107 raeburn 12020: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
12021: foreach my $item (@lonstatus) {
12022: if ($item eq 'excluded') {
12023: my (%serverhomes,@excluded);
12024: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
12025: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
12026: if (@possexcluded) {
12027: foreach my $id (sort(@possexcluded)) {
12028: if ($serverhomes{$id}) {
12029: push(@excluded,$id);
12030: }
12031: }
12032: }
12033: if (@excluded) {
12034: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
12035: }
12036: } elsif ($item eq 'weights') {
12037: foreach my $type ('E','W','N','U') {
12038: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
12039: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
12040: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
12041: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
12042: $env{'form.error'.$item.'_'.$type};
12043: }
12044: }
12045: }
12046: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
12047: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
12048: if ($env{'form.error'.$item} =~ /^\d+$/) {
12049: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
12050: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
12051: }
12052: }
12053: }
12054: }
1.160.6.78 raeburn 12055: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
12056: foreach my $field (@{$fields}) {
12057: if (ref($possoptions->{$field}) eq 'ARRAY') {
12058: my $value = $env{'form.helpform_'.$field};
12059: $value =~ s/^\s+|\s+$//g;
12060: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101 raeburn 12061: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 12062: if ($field eq 'screenshot') {
12063: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
12064: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101 raeburn 12065: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 12066: }
12067: }
12068: }
12069: }
12070: }
12071: }
1.160.6.101 raeburn 12072: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12073: my (@statuses,%usertypeshash,@overrides);
12074: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
12075: @statuses = @{$types};
12076: if (ref($usertypes) eq 'HASH') {
12077: %usertypeshash = %{$usertypes};
12078: }
12079: }
12080: if (@statuses) {
12081: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
12082: foreach my $type (@possoverrides) {
12083: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
12084: push(@overrides,$type);
12085: }
12086: }
12087: if (@overrides) {
12088: foreach my $type (@overrides) {
12089: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
12090: foreach my $item (@contacts) {
12091: if (grep(/^\Q$item\E$/,@standard)) {
12092: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
12093: $newsetting{'override_'.$type}{$item} = 1;
12094: } else {
12095: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
12096: $newsetting{'override_'.$type}{$item} = 0;
12097: }
12098: }
12099: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
12100: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12101: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
12102: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12103: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
12104: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
12105: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
12106: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12107: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
12108: }
12109: }
12110: }
12111: }
1.28 raeburn 12112: if (keys(%currsetting) > 0) {
12113: foreach my $item (@contacts) {
12114: if ($to{$item} ne $currsetting{$item}) {
12115: $changes{$item} = 1;
12116: }
12117: }
12118: foreach my $type (@mailings) {
12119: foreach my $item (@contacts) {
12120: if (ref($currsetting{$type}) eq 'HASH') {
12121: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
12122: push(@{$changes{$type}},$item);
12123: }
12124: } else {
12125: push(@{$changes{$type}},@{$newsetting{$type}});
12126: }
12127: }
12128: if ($others{$type} ne $currsetting{$type}{'others'}) {
12129: push(@{$changes{$type}},'others');
12130: }
1.160.6.78 raeburn 12131: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12132: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
12133: push(@{$changes{$type}},'bcc');
12134: }
1.160.6.78 raeburn 12135: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
12136: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
12137: push(@{$changes{$type}},'include');
12138: }
12139: }
12140: }
12141: if (ref($fields) eq 'ARRAY') {
12142: if (ref($currsetting{'helpform'}) eq 'HASH') {
12143: foreach my $field (@{$fields}) {
12144: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
12145: push(@{$changes{'helpform'}},$field);
12146: }
12147: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12148: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
12149: push(@{$changes{'helpform'}},'maxsize');
12150: }
12151: }
12152: }
12153: } else {
12154: foreach my $field (@{$fields}) {
12155: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12156: push(@{$changes{'helpform'}},$field);
12157: }
12158: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12159: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12160: push(@{$changes{'helpform'}},'maxsize');
12161: }
12162: }
12163: }
1.134 raeburn 12164: }
1.28 raeburn 12165: }
1.160.6.101 raeburn 12166: if (@statuses) {
12167: if (ref($currsetting{'overrides'}) eq 'HASH') {
12168: foreach my $key (keys(%{$currsetting{'overrides'}})) {
12169: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
12170: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
12171: foreach my $item (@contacts,'bcc','others','include') {
12172: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
12173: push(@{$changes{'overrides'}},$key);
12174: last;
12175: }
12176: }
12177: } else {
12178: push(@{$changes{'overrides'}},$key);
12179: }
12180: }
12181: }
12182: foreach my $key (@overrides) {
12183: unless (exists($currsetting{'overrides'}{$key})) {
12184: push(@{$changes{'overrides'}},$key);
12185: }
12186: }
12187: } else {
12188: foreach my $key (@overrides) {
12189: push(@{$changes{'overrides'}},$key);
12190: }
12191: }
12192: }
1.160.6.107 raeburn 12193: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
12194: foreach my $key ('excluded','weights','threshold','sysmail') {
12195: if ($key eq 'excluded') {
12196: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
12197: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
12198: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
12199: (@{$currsetting{'lonstatus'}{$key}})) {
12200: my @diffs =
12201: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
12202: $currsetting{'lonstatus'}{$key});
12203: if (@diffs) {
12204: push(@{$changes{'lonstatus'}},$key);
12205: }
12206: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
12207: push(@{$changes{'lonstatus'}},$key);
12208: }
12209: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
12210: (@{$currsetting{'lonstatus'}{$key}})) {
12211: push(@{$changes{'lonstatus'}},$key);
12212: }
12213: } elsif ($key eq 'weights') {
12214: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
12215: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
12216: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
12217: foreach my $type ('E','W','N','U') {
12218: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
12219: $currsetting{'lonstatus'}{$key}{$type}) {
12220: push(@{$changes{'lonstatus'}},$key);
12221: last;
12222: }
12223: }
12224: } else {
12225: foreach my $type ('E','W','N','U') {
12226: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
12227: push(@{$changes{'lonstatus'}},$key);
12228: last;
12229: }
12230: }
12231: }
12232: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
12233: foreach my $type ('E','W','N','U') {
12234: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
12235: push(@{$changes{'lonstatus'}},$key);
12236: last;
12237: }
12238: }
12239: }
12240: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
12241: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12242: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
12243: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
12244: push(@{$changes{'lonstatus'}},$key);
12245: }
12246: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
12247: push(@{$changes{'lonstatus'}},$key);
12248: }
12249: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
12250: push(@{$changes{'lonstatus'}},$key);
12251: }
12252: }
12253: }
12254: } else {
12255: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12256: foreach my $key ('excluded','weights','threshold','sysmail') {
12257: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
12258: push(@{$changes{'lonstatus'}},$key);
12259: }
12260: }
12261: }
12262: }
1.28 raeburn 12263: } else {
12264: my %default;
12265: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
12266: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
12267: $default{'errormail'} = 'adminemail';
12268: $default{'packagesmail'} = 'adminemail';
12269: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 12270: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 12271: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 12272: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 12273: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 12274: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 12275: foreach my $item (@contacts) {
12276: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 12277: $changes{$item} = 1;
1.160.6.23 raeburn 12278: }
1.28 raeburn 12279: }
12280: foreach my $type (@mailings) {
12281: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
12282: push(@{$changes{$type}},@{$newsetting{$type}});
12283: }
12284: if ($others{$type} ne '') {
12285: push(@{$changes{$type}},'others');
1.134 raeburn 12286: }
1.160.6.78 raeburn 12287: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12288: if ($bcc{$type} ne '') {
12289: push(@{$changes{$type}},'bcc');
12290: }
1.160.6.78 raeburn 12291: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
12292: push(@{$changes{$type}},'include');
12293: }
12294: }
12295: }
12296: if (ref($fields) eq 'ARRAY') {
12297: foreach my $field (@{$fields}) {
12298: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12299: push(@{$changes{'helpform'}},$field);
12300: }
12301: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12302: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12303: push(@{$changes{'helpform'}},'maxsize');
12304: }
12305: }
1.134 raeburn 12306: }
1.28 raeburn 12307: }
1.160.6.107 raeburn 12308: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12309: foreach my $key ('excluded','weights','threshold','sysmail') {
12310: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
12311: push(@{$changes{'lonstatus'}},$key);
12312: }
12313: }
12314: }
1.28 raeburn 12315: }
1.160.6.23 raeburn 12316: foreach my $item (@toggles) {
12317: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
12318: $changes{$item} = 1;
12319: } elsif ((!$env{'form.'.$item}) &&
12320: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
12321: $changes{$item} = 1;
12322: }
12323: }
1.28 raeburn 12324: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
12325: $dom);
12326: if ($putresult eq 'ok') {
12327: if (keys(%changes) > 0) {
1.160.6.24 raeburn 12328: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 12329: if (ref($lastactref) eq 'HASH') {
12330: $lastactref->{'domainconfig'} = 1;
12331: }
1.28 raeburn 12332: my ($titles,$short_titles) = &contact_titles();
12333: $resulttext = &mt('Changes made:').'<ul>';
12334: foreach my $item (@contacts) {
12335: if ($changes{$item}) {
12336: $resulttext .= '<li>'.$titles->{$item}.
12337: &mt(' set to: ').
12338: '<span class="LC_cusr_emph">'.
12339: $to{$item}.'</span></li>';
12340: }
12341: }
12342: foreach my $type (@mailings) {
12343: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 12344: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
12345: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
12346: } else {
12347: $resulttext .= '<li>'.$titles->{$type}.': ';
12348: }
1.28 raeburn 12349: my @text;
12350: foreach my $item (@{$newsetting{$type}}) {
12351: push(@text,$short_titles->{$item});
12352: }
12353: if ($others{$type} ne '') {
12354: push(@text,$others{$type});
12355: }
1.160.6.78 raeburn 12356: if (@text) {
12357: $resulttext .= '<span class="LC_cusr_emph">'.
12358: join(', ',@text).'</span>';
12359: }
12360: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12361: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 12362: my $bcctext;
12363: if (@text) {
12364: $bcctext = ' '.&mt('with Bcc to');
12365: } else {
12366: $bcctext = '(Bcc)';
12367: }
12368: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
12369: } elsif (!@text) {
12370: $resulttext .= &mt('No one');
1.134 raeburn 12371: }
1.160.6.78 raeburn 12372: if ($includestr{$type} ne '') {
12373: if ($includeloc{$type} eq 'b') {
12374: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
12375: } elsif ($includeloc{$type} eq 's') {
12376: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
12377: }
12378: }
12379: } elsif (!@text) {
12380: $resulttext .= &mt('No recipients');
1.134 raeburn 12381: }
12382: $resulttext .= '</li>';
1.28 raeburn 12383: }
12384: }
1.160.6.101 raeburn 12385: if (ref($changes{'overrides'}) eq 'ARRAY') {
12386: my @deletions;
12387: foreach my $type (@{$changes{'overrides'}}) {
12388: if ($usertypeshash{$type}) {
12389: if (grep(/^\Q$type\E/,@overrides)) {
12390: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
12391: $usertypeshash{$type}).'<ul><li>';
12392: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
12393: my @text;
12394: foreach my $item (@contacts) {
12395: if ($newsetting{'override_'.$type}{$item}) {
12396: push(@text,$short_titles->{$item});
12397: }
12398: }
12399: if ($newsetting{'override_'.$type}{'others'} ne '') {
12400: push(@text,$newsetting{'override_'.$type}{'others'});
12401: }
12402:
12403: if (@text) {
12404: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
12405: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
12406: }
12407: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
12408: my $bcctext;
12409: if (@text) {
12410: $bcctext = ' '.&mt('with Bcc to');
12411: } else {
12412: $bcctext = '(Bcc)';
12413: }
12414: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
12415: } elsif (!@text) {
12416: $resulttext .= &mt('Helpdesk e-mail sent to no one');
12417: }
12418: $resulttext .= '</li>';
12419: if ($newsetting{'override_'.$type}{'include'} ne '') {
12420: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
12421: if ($loc eq 'b') {
12422: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
12423: } elsif ($loc eq 's') {
12424: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
12425: }
12426: }
12427: }
12428: $resulttext .= '</li></ul></li>';
12429: } else {
12430: push(@deletions,$usertypeshash{$type});
12431: }
12432: }
12433: }
12434: if (@deletions) {
12435: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
12436: join(', ',@deletions)).'</li>';
12437: }
12438: }
1.160.6.23 raeburn 12439: my @offon = ('off','on');
1.160.6.107 raeburn 12440: my $corelink = &core_link_msu();
1.160.6.23 raeburn 12441: if ($changes{'reporterrors'}) {
12442: $resulttext .= '<li>'.
12443: &mt('E-mail error reports to [_1] set to "'.
12444: $offon[$env{'form.reporterrors'}].'".',
1.160.6.107 raeburn 12445: $corelink).
1.160.6.23 raeburn 12446: '</li>';
12447: }
12448: if ($changes{'reportupdates'}) {
12449: $resulttext .= '<li>'.
12450: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
12451: $offon[$env{'form.reportupdates'}].'".',
1.160.6.107 raeburn 12452: $corelink).
1.160.6.23 raeburn 12453: '</li>';
12454: }
1.160.6.107 raeburn 12455: if ($changes{'reportstatus'}) {
12456: $resulttext .= '<li>'.
12457: &mt('E-mail status if errors above threshold to [_1] set to "'.
12458: $offon[$env{'form.reportstatus'}].'".',
12459: $corelink).
12460: '</li>';
12461: }
12462: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
12463: $resulttext .= '<li>'.
12464: &mt('Nightly status check e-mail settings').':<ul>';
12465: my (%defval,%use_def,%shown);
12466: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
12467: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
12468: $defval{'weights'} =
12469: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
12470: $defval{'excluded'} = &mt('None');
12471: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
12472: foreach my $item ('threshold','sysmail','weights','excluded') {
12473: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
12474: if (($item eq 'threshold') || ($item eq 'sysmail')) {
12475: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
12476: } elsif ($item eq 'weights') {
12477: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
12478: foreach my $type ('E','W','N','U') {
12479: $shown{$item} .= $lonstatus_names->{$type}.'=';
12480: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
12481: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
12482: } else {
12483: $shown{$item} .= $lonstatus_defs->{$type};
12484: }
12485: $shown{$item} .= ', ';
12486: }
12487: $shown{$item} =~ s/, $//;
12488: } else {
12489: $shown{$item} = $defval{$item};
12490: }
12491: } elsif ($item eq 'excluded') {
12492: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
12493: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
12494: } else {
12495: $shown{$item} = $defval{$item};
12496: }
12497: }
12498: } else {
12499: $shown{$item} = $defval{$item};
12500: }
12501: }
12502: } else {
12503: foreach my $item ('threshold','weights','excluded','sysmail') {
12504: $shown{$item} = $defval{$item};
12505: }
12506: }
12507: foreach my $item ('threshold','weights','excluded','sysmail') {
12508: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
12509: $shown{$item}).'</li>';
12510: }
12511: $resulttext .= '</ul></li>';
12512: }
1.160.6.78 raeburn 12513: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
12514: my (@optional,@required,@unused,$maxsizechg);
12515: foreach my $field (@{$changes{'helpform'}}) {
12516: if ($field eq 'maxsize') {
12517: $maxsizechg = 1;
12518: next;
12519: }
12520: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
12521: push(@optional,$field);
12522: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
12523: push(@unused,$field);
12524: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
12525: push(@required,$field);
12526: }
12527: }
12528: if (@optional) {
12529: $resulttext .= '<li>'.
12530: &mt('Help form fields changed to "Optional": [_1].',
12531: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
12532: '</li>';
12533: }
12534: if (@required) {
12535: $resulttext .= '<li>'.
12536: &mt('Help form fields changed to "Required": [_1].',
12537: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
12538: '</li>';
12539: }
12540: if (@unused) {
12541: $resulttext .= '<li>'.
12542: &mt('Help form fields changed to "Not shown": [_1].',
12543: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
12544: '</li>';
12545: }
12546: if ($maxsizechg) {
12547: $resulttext .= '<li>'.
12548: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
12549: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
12550: '</li>';
12551: }
12552: }
1.28 raeburn 12553: $resulttext .= '</ul>';
12554: } else {
1.160.6.78 raeburn 12555: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 12556: }
12557: } else {
12558: $resulttext = '<span class="LC_error">'.
12559: &mt('An error occurred: [_1].',$putresult).'</span>';
12560: }
12561: return $resulttext;
12562: }
12563:
1.160.6.98 raeburn 12564: sub modify_passwords {
12565: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
12566: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
12567: $updatedefaults,$updateconf);
12568: my $customfn = 'resetpw.html';
12569: if (ref($domconfig{'passwords'}) eq 'HASH') {
12570: %current = %{$domconfig{'passwords'}};
12571: }
12572: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12573: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12574: if (ref($types) eq 'ARRAY') {
12575: @oktypes = @{$types};
12576: }
12577: push(@oktypes,'default');
12578:
12579: my %titles = &Apache::lonlocal::texthash (
12580: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
12581: intauth_check => 'Check bcrypt cost if authenticated',
12582: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
12583: permanent => 'Permanent e-mail address',
12584: critical => 'Critical notification address',
12585: notify => 'Notification address',
12586: min => 'Minimum password length',
12587: max => 'Maximum password length',
12588: chars => 'Required characters',
12589: numsaved => 'Number of previous passwords to save',
12590: reset => 'Resetting Forgotten Password',
12591: intauth => 'Encryption of Stored Passwords (Internal Auth)',
12592: rules => 'Rules for LON-CAPA Passwords',
12593: crsownerchg => 'Course Owner Changing Student Passwords',
12594: username => 'Username',
12595: email => 'E-mail address',
12596: );
12597:
12598: #
12599: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
12600: #
12601: my (%curr_defaults,%save_defaults);
12602: if (ref($domconfig{'defaults'}) eq 'HASH') {
12603: foreach my $key (keys(%{$domconfig{'defaults'}})) {
12604: if ($key =~ /^intauth_(cost|check|switch)$/) {
12605: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
12606: } else {
12607: $save_defaults{$key} = $domconfig{'defaults'}{$key};
12608: }
12609: }
12610: }
12611: my %staticdefaults = (
12612: 'resetlink' => 2,
12613: 'resetcase' => \@oktypes,
12614: 'resetprelink' => 'both',
12615: 'resetemail' => ['critical','notify','permanent'],
12616: 'intauth_cost' => 10,
12617: 'intauth_check' => 0,
12618: 'intauth_switch' => 0,
12619: );
1.160.6.99 raeburn 12620: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 12621: foreach my $type (@oktypes) {
12622: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
12623: }
12624: my $linklife = $env{'form.passwords_link'};
12625: $linklife =~ s/^\s+|\s+$//g;
12626: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
12627: $newvalues{'resetlink'} = $linklife;
12628: if ($current{'resetlink'}) {
12629: if ($current{'resetlink'} ne $linklife) {
12630: $changes{'reset'} = 1;
12631: }
1.160.6.102 raeburn 12632: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12633: if ($staticdefaults{'resetlink'} ne $linklife) {
12634: $changes{'reset'} = 1;
12635: }
12636: }
12637: } elsif ($current{'resetlink'}) {
12638: $changes{'reset'} = 1;
12639: }
12640: my @casesens;
12641: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
12642: foreach my $case (sort(@posscase)) {
12643: if (grep(/^\Q$case\E$/,@oktypes)) {
12644: push(@casesens,$case);
12645: }
12646: }
12647: $newvalues{'resetcase'} = \@casesens;
12648: if (ref($current{'resetcase'}) eq 'ARRAY') {
12649: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
12650: if (@diffs > 0) {
12651: $changes{'reset'} = 1;
12652: }
1.160.6.102 raeburn 12653: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12654: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
12655: if (@diffs > 0) {
12656: $changes{'reset'} = 1;
12657: }
12658: }
12659: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
12660: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
12661: if (exists($current{'resetprelink'})) {
12662: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
12663: $changes{'reset'} = 1;
12664: }
1.160.6.102 raeburn 12665: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12666: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
12667: $changes{'reset'} = 1;
12668: }
12669: }
12670: } elsif ($current{'resetprelink'}) {
12671: $changes{'reset'} = 1;
12672: }
12673: foreach my $type (@oktypes) {
12674: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
12675: my @postlink;
12676: foreach my $item (sort(@possplink)) {
12677: if ($item =~ /^(email|username)$/) {
12678: push(@postlink,$item);
12679: }
12680: }
12681: $newvalues{'resetpostlink'}{$type} = \@postlink;
12682: unless ($changes{'reset'}) {
12683: if (ref($current{'resetpostlink'}) eq 'HASH') {
12684: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
12685: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
12686: if (@diffs > 0) {
12687: $changes{'reset'} = 1;
12688: }
12689: } else {
12690: $changes{'reset'} = 1;
12691: }
1.160.6.102 raeburn 12692: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12693: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
12694: if (@diffs > 0) {
12695: $changes{'reset'} = 1;
12696: }
12697: }
12698: }
12699: }
12700: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
12701: my @resetemail;
12702: foreach my $item (sort(@possemailsrc)) {
12703: if ($item =~ /^(permanent|critical|notify)$/) {
12704: push(@resetemail,$item);
12705: }
12706: }
12707: $newvalues{'resetemail'} = \@resetemail;
12708: unless ($changes{'reset'}) {
12709: if (ref($current{'resetemail'}) eq 'ARRAY') {
12710: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
12711: if (@diffs > 0) {
12712: $changes{'reset'} = 1;
12713: }
1.160.6.102 raeburn 12714: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12715: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
12716: if (@diffs > 0) {
12717: $changes{'reset'} = 1;
12718: }
12719: }
12720: }
12721: if ($env{'form.passwords_stdtext'} == 0) {
12722: $newvalues{'resetremove'} = 1;
12723: unless ($current{'resetremove'}) {
12724: $changes{'reset'} = 1;
12725: }
12726: } elsif ($current{'resetremove'}) {
12727: $changes{'reset'} = 1;
12728: }
12729: if ($env{'form.passwords_customfile.filename'} ne '') {
12730: my $servadm = $r->dir_config('lonAdmEMail');
12731: my $servadm = $r->dir_config('lonAdmEMail');
12732: my ($configuserok,$author_ok,$switchserver) =
12733: &config_check($dom,$confname,$servadm);
12734: my $error;
12735: if ($configuserok eq 'ok') {
12736: if ($switchserver) {
12737: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
12738: } else {
12739: if ($author_ok eq 'ok') {
12740: my ($result,$customurl) =
12741: &publishlogo($r,'upload','passwords_customfile',$dom,
12742: $confname,'customtext/resetpw','','',$customfn);
12743: if ($result eq 'ok') {
12744: $newvalues{'resetcustom'} = $customurl;
12745: $changes{'reset'} = 1;
12746: } else {
12747: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
12748: }
12749: } else {
12750: $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);
12751: }
12752: }
12753: } else {
12754: $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);
12755: }
12756: if ($error) {
12757: &Apache::lonnet::logthis($error);
12758: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12759: }
12760: } elsif ($current{'resetcustom'}) {
12761: if ($env{'form.passwords_custom_del'}) {
12762: $changes{'reset'} = 1;
12763: } else {
12764: $newvalues{'resetcustom'} = $current{'resetcustom'};
12765: }
12766: }
12767: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
12768: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
12769: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
12770: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
12771: $changes{'intauth'} = 1;
12772: }
12773: } else {
12774: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
12775: }
12776: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
12777: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
12778: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
12779: $changes{'intauth'} = 1;
12780: }
12781: } else {
12782: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
12783: }
12784: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
12785: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
12786: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
12787: $changes{'intauth'} = 1;
12788: }
12789: } else {
12790: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
12791: }
12792: foreach my $item ('cost','check','switch') {
12793: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
12794: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
12795: $updatedefaults = 1;
12796: }
12797: }
12798: foreach my $rule ('min','max','numsaved') {
12799: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.160.6.99 raeburn 12800: my $ruleok;
12801: if ($rule eq 'min') {
12802: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
12803: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
12804: $ruleok = 1;
12805: }
12806: }
12807: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
12808: ($env{'form.passwords_'.$rule} ne '0')) {
12809: $ruleok = 1;
12810: }
12811: if ($ruleok) {
1.160.6.98 raeburn 12812: $newvalues{$rule} = $env{'form.passwords_'.$rule};
12813: if (exists($current{$rule})) {
12814: if ($newvalues{$rule} ne $current{$rule}) {
12815: $changes{'rules'} = 1;
12816: }
12817: } elsif ($rule eq 'min') {
12818: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
12819: $changes{'rules'} = 1;
12820: }
1.160.6.104 raeburn 12821: } else {
12822: $changes{'rules'} = 1;
1.160.6.98 raeburn 12823: }
12824: } elsif (exists($current{$rule})) {
12825: $changes{'rules'} = 1;
12826: }
12827: }
12828: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
12829: my @chars;
12830: foreach my $item (sort(@posschars)) {
12831: if ($item =~ /^(uc|lc|num|spec)$/) {
12832: push(@chars,$item);
12833: }
12834: }
12835: $newvalues{'chars'} = \@chars;
12836: unless ($changes{'rules'}) {
12837: if (ref($current{'chars'}) eq 'ARRAY') {
12838: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
12839: if (@diffs > 0) {
12840: $changes{'rules'} = 1;
12841: }
12842: } else {
12843: if (@chars > 0) {
12844: $changes{'rules'} = 1;
12845: }
12846: }
12847: }
12848: my %crsownerchg = (
12849: by => [],
12850: for => [],
12851: );
12852: foreach my $item ('by','for') {
12853: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
12854: foreach my $type (sort(@posstypes)) {
12855: if (grep(/^\Q$type\E$/,@oktypes)) {
12856: push(@{$crsownerchg{$item}},$type);
12857: }
12858: }
12859: }
12860: $newvalues{'crsownerchg'} = \%crsownerchg;
12861: if (ref($current{'crsownerchg'}) eq 'HASH') {
12862: foreach my $item ('by','for') {
12863: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
12864: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
12865: if (@diffs > 0) {
12866: $changes{'crsownerchg'} = 1;
12867: last;
12868: }
12869: }
12870: }
1.160.6.102 raeburn 12871: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98 raeburn 12872: foreach my $item ('by','for') {
12873: if (@{$crsownerchg{$item}} > 0) {
12874: $changes{'crsownerchg'} = 1;
12875: last;
12876: }
12877: }
12878: }
12879:
12880: my %confighash = (
12881: defaults => \%save_defaults,
12882: passwords => \%newvalues,
12883: );
12884: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
12885:
12886: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
12887: if ($putresult eq 'ok') {
12888: if (keys(%changes) > 0) {
12889: $resulttext = &mt('Changes made: ').'<ul>';
12890: foreach my $key ('reset','intauth','rules','crsownerchg') {
12891: if ($changes{$key}) {
12892: unless ($key eq 'intauth') {
12893: $updateconf = 1;
12894: }
12895: $resulttext .= '<li>'.$titles{$key}.':<ul>';
12896: if ($key eq 'reset') {
12897: if ($confighash{'passwords'}{'captcha'} eq 'original') {
12898: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
12899: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
12900: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.160.6.104 raeburn 12901: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
12902: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
12903: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
12904: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
12905: }
1.160.6.98 raeburn 12906: } else {
12907: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
12908: }
12909: if ($confighash{'passwords'}{'resetlink'}) {
12910: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
12911: } else {
12912: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
12913: &mt('Will default to 2 hours').'</li>';
12914: }
12915: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
12916: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
12917: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
12918: } else {
12919: my $casesens;
12920: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
12921: if ($type eq 'default') {
12922: $casesens .= $othertitle.', ';
12923: } elsif ($usertypes->{$type} ne '') {
12924: $casesens .= $usertypes->{$type}.', ';
12925: }
12926: }
12927: $casesens =~ s/\Q, \E$//;
12928: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
12929: }
12930: } else {
12931: $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>';
12932: }
12933: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
12934: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
12935: } else {
12936: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
12937: }
12938: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
12939: my $output;
12940: if (ref($types) eq 'ARRAY') {
12941: foreach my $type (@{$types}) {
12942: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
12943: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
12944: $output .= $usertypes->{$type}.' -- '.&mt('none');
12945: } else {
12946: $output .= $usertypes->{$type}.' -- '.
12947: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
12948: }
12949: }
12950: }
12951: }
12952: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
12953: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
12954: $output .= $othertitle.' -- '.&mt('none');
12955: } else {
12956: $output .= $othertitle.' -- '.
12957: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
12958: }
12959: }
12960: if ($output) {
12961: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
12962: } else {
12963: $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>';
12964: }
12965: } else {
12966: $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>';
12967: }
12968: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
12969: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
12970: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
12971: } else {
12972: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
12973: }
12974: } else {
1.160.6.110 raeburn 12975: $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 12976: }
12977: if ($confighash{'passwords'}{'resetremove'}) {
12978: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
12979: } else {
12980: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
12981: }
12982: if ($confighash{'passwords'}{'resetcustom'}) {
12983: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.160.6.104 raeburn 12984: &mt('custom text'),600,500,undef,undef,
12985: undef,undef,'background-color:#ffffff');
12986: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.160.6.98 raeburn 12987: } else {
12988: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
12989: }
12990: } elsif ($key eq 'intauth') {
12991: foreach my $item ('cost','switch','check') {
12992: my $value = $save_defaults{$key.'_'.$item};
12993: if ($item eq 'switch') {
12994: my %optiondesc = &Apache::lonlocal::texthash (
12995: 0 => 'No',
12996: 1 => 'Yes',
12997: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
12998: );
12999: if ($value =~ /^(0|1|2)$/) {
13000: $value = $optiondesc{$value};
13001: } else {
13002: $value = &mt('none -- defaults to No');
13003: }
13004: } elsif ($item eq 'check') {
13005: my %optiondesc = &Apache::lonlocal::texthash (
13006: 0 => 'No',
13007: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
13008: 2 => 'Yes, disallow login if stored cost is less than domain default',
13009: );
13010: if ($value =~ /^(0|1|2)$/) {
13011: $value = $optiondesc{$value};
13012: } else {
13013: $value = &mt('none -- defaults to No');
13014: }
13015: }
13016: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
13017: }
13018: } elsif ($key eq 'rules') {
13019: foreach my $rule ('min','max','numsaved') {
13020: if ($confighash{'passwords'}{$rule} eq '') {
13021: if ($rule eq 'min') {
13022: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99 raeburn 13023: ' '.&mt('Default of [_1] will be used',
13024: $Apache::lonnet::passwdmin).'</li>';
1.160.6.98 raeburn 13025: } else {
13026: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
13027: }
13028: } else {
13029: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
13030: }
13031: }
1.160.6.104 raeburn 13032: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
13033: if (@{$confighash{'passwords'}{'chars'}} > 0) {
13034: my %rulenames = &Apache::lonlocal::texthash(
13035: uc => 'At least one upper case letter',
13036: lc => 'At least one lower case letter',
13037: num => 'At least one number',
13038: spec => 'At least one non-alphanumeric',
13039: );
13040: my $needed = '<ul><li>'.
13041: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
13042: '</li></ul>';
13043: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
13044: } else {
13045: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13046: }
13047: } else {
13048: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13049: }
1.160.6.98 raeburn 13050: } elsif ($key eq 'crsownerchg') {
13051: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
13052: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
13053: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
13054: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
13055: } else {
13056: my %crsownerstr;
13057: foreach my $item ('by','for') {
13058: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
13059: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
13060: if ($type eq 'default') {
13061: $crsownerstr{$item} .= $othertitle.', ';
13062: } elsif ($usertypes->{$type} ne '') {
13063: $crsownerstr{$item} .= $usertypes->{$type}.', ';
13064: }
13065: }
13066: $crsownerstr{$item} =~ s/\Q, \E$//;
13067: }
13068: }
13069: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
13070: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
13071: }
13072: } else {
13073: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
13074: }
13075: }
13076: $resulttext .= '</ul></li>';
13077: }
13078: }
13079: $resulttext .= '</ul>';
13080: } else {
13081: $resulttext = &mt('No changes made to password settings');
13082: }
13083: my $cachetime = 24*60*60;
13084: if ($updatedefaults) {
13085: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13086: if (ref($lastactref) eq 'HASH') {
13087: $lastactref->{'domdefaults'} = 1;
13088: }
13089: }
13090: if ($updateconf) {
13091: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
13092: if (ref($lastactref) eq 'HASH') {
13093: $lastactref->{'passwdconf'} = 1;
13094: }
13095: }
13096: } else {
13097: $resulttext = '<span class="LC_error">'.
13098: &mt('An error occurred: [_1]',$putresult).'</span>';
13099: }
13100: if ($errors) {
13101: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13102: $errors.'</ul></p>';
13103: }
13104: return $resulttext;
13105: }
13106:
1.28 raeburn 13107: sub modify_usercreation {
1.27 raeburn 13108: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 13109: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 13110: my $warningmsg;
1.27 raeburn 13111: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13112: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 13113: if ($key eq 'cancreate') {
13114: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13115: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 13116: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 13117: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 13118: } else {
13119: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 13120: }
1.50 raeburn 13121: }
1.43 raeburn 13122: }
1.160.6.34 raeburn 13123: } elsif ($key eq 'email_rule') {
13124: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13125: } else {
13126: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 13127: }
13128: }
1.34 raeburn 13129: }
1.160.6.34 raeburn 13130: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
13131: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
13132: my @contexts = ('author','course','requestcrs');
13133: foreach my $item(@contexts) {
13134: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 13135: }
1.34 raeburn 13136: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13137: foreach my $item (@contexts) {
1.160.6.34 raeburn 13138: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
13139: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 13140: }
1.27 raeburn 13141: }
1.34 raeburn 13142: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
13143: foreach my $item (@contexts) {
1.43 raeburn 13144: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 13145: if ($cancreate{$item} ne 'any') {
13146: push(@{$changes{'cancreate'}},$item);
13147: }
13148: } else {
13149: if ($cancreate{$item} ne 'none') {
13150: push(@{$changes{'cancreate'}},$item);
13151: }
1.27 raeburn 13152: }
13153: }
13154: } else {
1.43 raeburn 13155: foreach my $item (@contexts) {
1.34 raeburn 13156: push(@{$changes{'cancreate'}},$item);
13157: }
1.27 raeburn 13158: }
1.34 raeburn 13159:
1.27 raeburn 13160: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
13161: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
13162: if (!grep(/^\Q$type\E$/,@username_rule)) {
13163: push(@{$changes{'username_rule'}},$type);
13164: }
13165: }
13166: foreach my $type (@username_rule) {
13167: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
13168: push(@{$changes{'username_rule'}},$type);
13169: }
13170: }
13171: } else {
13172: push(@{$changes{'username_rule'}},@username_rule);
13173: }
13174:
1.32 raeburn 13175: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
13176: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
13177: if (!grep(/^\Q$type\E$/,@id_rule)) {
13178: push(@{$changes{'id_rule'}},$type);
13179: }
13180: }
13181: foreach my $type (@id_rule) {
13182: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
13183: push(@{$changes{'id_rule'}},$type);
13184: }
13185: }
13186: } else {
13187: push(@{$changes{'id_rule'}},@id_rule);
13188: }
13189:
1.43 raeburn 13190: my @authen_contexts = ('author','course','domain');
1.28 raeburn 13191: my @authtypes = ('int','krb4','krb5','loc');
13192: my %authhash;
1.43 raeburn 13193: foreach my $item (@authen_contexts) {
1.28 raeburn 13194: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
13195: foreach my $auth (@authtypes) {
13196: if (grep(/^\Q$auth\E$/,@authallowed)) {
13197: $authhash{$item}{$auth} = 1;
13198: } else {
13199: $authhash{$item}{$auth} = 0;
13200: }
13201: }
13202: }
13203: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 13204: foreach my $item (@authen_contexts) {
1.28 raeburn 13205: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
13206: foreach my $auth (@authtypes) {
13207: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
13208: push(@{$changes{'authtypes'}},$item);
13209: last;
13210: }
13211: }
13212: }
13213: }
13214: } else {
1.43 raeburn 13215: foreach my $item (@authen_contexts) {
1.28 raeburn 13216: push(@{$changes{'authtypes'}},$item);
13217: }
13218: }
13219:
1.160.6.34 raeburn 13220: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
13221: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
13222: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
13223: $save_usercreate{'id_rule'} = \@id_rule;
13224: $save_usercreate{'username_rule'} = \@username_rule,
13225: $save_usercreate{'authtypes'} = \%authhash;
13226:
1.27 raeburn 13227: my %usercreation_hash = (
1.160.6.34 raeburn 13228: usercreation => \%save_usercreate,
13229: );
1.27 raeburn 13230:
13231: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
13232: $dom);
1.50 raeburn 13233:
1.160.6.34 raeburn 13234: if ($putresult eq 'ok') {
13235: if (keys(%changes) > 0) {
13236: $resulttext = &mt('Changes made:').'<ul>';
13237: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13238: my %lt = &usercreation_types();
13239: foreach my $type (@{$changes{'cancreate'}}) {
13240: my $chgtext = $lt{$type}.', ';
13241: if ($cancreate{$type} eq 'none') {
13242: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
13243: } elsif ($cancreate{$type} eq 'any') {
13244: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
13245: } elsif ($cancreate{$type} eq 'official') {
13246: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
13247: } elsif ($cancreate{$type} eq 'unofficial') {
13248: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
13249: }
13250: $resulttext .= '<li>'.$chgtext.'</li>';
13251: }
13252: }
13253: if (ref($changes{'username_rule'}) eq 'ARRAY') {
13254: my ($rules,$ruleorder) =
13255: &Apache::lonnet::inst_userrules($dom,'username');
13256: my $chgtext = '<ul>';
13257: foreach my $type (@username_rule) {
13258: if (ref($rules->{$type}) eq 'HASH') {
13259: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
13260: }
13261: }
13262: $chgtext .= '</ul>';
13263: if (@username_rule > 0) {
13264: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13265: } else {
13266: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
13267: }
13268: }
13269: if (ref($changes{'id_rule'}) eq 'ARRAY') {
13270: my ($idrules,$idruleorder) =
13271: &Apache::lonnet::inst_userrules($dom,'id');
13272: my $chgtext = '<ul>';
13273: foreach my $type (@id_rule) {
13274: if (ref($idrules->{$type}) eq 'HASH') {
13275: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
13276: }
13277: }
13278: $chgtext .= '</ul>';
13279: if (@id_rule > 0) {
13280: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13281: } else {
13282: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
13283: }
13284: }
13285: my %authname = &authtype_names();
13286: my %context_title = &context_names();
13287: if (ref($changes{'authtypes'}) eq 'ARRAY') {
13288: my $chgtext = '<ul>';
13289: foreach my $type (@{$changes{'authtypes'}}) {
13290: my @allowed;
13291: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
13292: foreach my $auth (@authtypes) {
13293: if ($authhash{$type}{$auth}) {
13294: push(@allowed,$authname{$auth});
13295: }
13296: }
13297: if (@allowed > 0) {
13298: $chgtext .= join(', ',@allowed).'</li>';
13299: } else {
13300: $chgtext .= &mt('none').'</li>';
13301: }
13302: }
13303: $chgtext .= '</ul>';
13304: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
13305: $resulttext .= '</li>';
13306: }
13307: $resulttext .= '</ul>';
13308: } else {
13309: $resulttext = &mt('No changes made to user creation settings');
13310: }
13311: } else {
13312: $resulttext = '<span class="LC_error">'.
13313: &mt('An error occurred: [_1]',$putresult).'</span>';
13314: }
13315: if ($warningmsg ne '') {
13316: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13317: }
13318: return $resulttext;
13319: }
13320:
13321: sub modify_selfcreation {
1.160.6.93 raeburn 13322: my ($dom,$lastactref,%domconfig) = @_;
13323: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
13324: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
13325: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13326: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
13327: if (ref($typesref) eq 'ARRAY') {
13328: @types = @{$typesref};
13329: }
13330: if (ref($usertypesref) eq 'HASH') {
13331: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 13332: }
1.160.6.93 raeburn 13333: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 13334: #
13335: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
13336: #
13337: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13338: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
13339: if ($key eq 'cancreate') {
13340: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13341: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
13342: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 13343: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
13344: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
13345: ($item eq 'emailusername') || ($item eq 'shibenv') ||
13346: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
13347: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 13348: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13349: } else {
13350: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13351: }
13352: }
13353: }
13354: } elsif ($key eq 'email_rule') {
13355: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13356: } else {
13357: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13358: }
13359: }
13360: }
13361: #
13362: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
13363: #
13364: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13365: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
13366: if ($key eq 'selfcreate') {
13367: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
13368: } else {
13369: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
13370: }
13371: }
13372: }
1.160.6.93 raeburn 13373: #
13374: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
13375: #
13376: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13377: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
13378: if ($key eq 'inststatusguest') {
13379: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
13380: } else {
13381: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
13382: }
13383: }
13384: }
1.160.6.34 raeburn 13385:
13386: my @contexts = ('selfcreate');
13387: @{$cancreate{'selfcreate'}} = ();
13388: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 13389: if (@types) {
13390: @{$cancreate{'statustocreate'}} = ();
13391: }
1.160.6.40 raeburn 13392: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 13393: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 13394: %{$cancreate{'emailverified'}} = ();
13395: %{$cancreate{'emailoptions'}} = ();
13396: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 13397: my %selfcreatetypes = (
13398: sso => 'users authenticated by institutional single sign on',
13399: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 13400: email => 'users verified by e-mail',
1.50 raeburn 13401: );
1.160.6.34 raeburn 13402: #
13403: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
13404: # is permitted.
13405: #
1.160.6.40 raeburn 13406:
1.160.6.93 raeburn 13407: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 13408:
1.160.6.93 raeburn 13409: my (@statuses,%email_rule);
1.160.6.35 raeburn 13410: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 13411: if ($item eq 'email') {
1.160.6.40 raeburn 13412: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 13413: if (@types) {
13414: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
13415: foreach my $status (@poss_statuses) {
13416: if (grep(/^\Q$status\E$/,(@types,'default'))) {
13417: push(@statuses,$status);
13418: }
13419: }
13420: $save_inststatus{'inststatusguest'} = \@statuses;
13421: } else {
13422: push(@statuses,'default');
13423: }
13424: if (@statuses) {
13425: my %curr_rule;
13426: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
13427: foreach my $type (@statuses) {
13428: $curr_rule{$type} = $curr_usercreation{'email_rule'};
13429: }
13430: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
13431: foreach my $type (@statuses) {
13432: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
13433: }
13434: }
13435: push(@{$cancreate{'selfcreate'}},'email');
13436: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
13437: my %curremaildom;
13438: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
13439: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
13440: }
13441: foreach my $type (@statuses) {
13442: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
13443: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
13444: }
13445: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
13446: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
13447: }
13448: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
13449: #
13450: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
13451: #
13452: my $chosen = $1;
13453: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
13454: my $emaildom;
13455: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
13456: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
13457: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
13458: if (ref($curremaildom{$type}) eq 'HASH') {
13459: if (exists($curremaildom{$type}{$chosen})) {
13460: if ($curremaildom{$type}{$chosen} ne $emaildom) {
13461: push(@{$changes{'cancreate'}},'emaildomain');
13462: }
13463: } elsif ($emaildom ne '') {
13464: push(@{$changes{'cancreate'}},'emaildomain');
13465: }
13466: } elsif ($emaildom ne '') {
13467: push(@{$changes{'cancreate'}},'emaildomain');
13468: }
13469: }
13470: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13471: } elsif ($chosen eq 'custom') {
13472: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
13473: $email_rule{$type} = [];
13474: if (ref($emailrules) eq 'HASH') {
13475: foreach my $rule (@possemail_rules) {
13476: if (exists($emailrules->{$rule})) {
13477: push(@{$email_rule{$type}},$rule);
13478: }
13479: }
13480: }
13481: if (@{$email_rule{$type}}) {
13482: $cancreate{'emailoptions'}{$type} = 'custom';
13483: if (ref($curr_rule{$type}) eq 'ARRAY') {
13484: if (@{$curr_rule{$type}} > 0) {
13485: foreach my $rule (@{$curr_rule{$type}}) {
13486: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
13487: push(@{$changes{'email_rule'}},$type);
13488: }
13489: }
13490: }
13491: foreach my $type (@{$email_rule{$type}}) {
13492: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
13493: push(@{$changes{'email_rule'}},$type);
13494: }
13495: }
13496: } else {
13497: push(@{$changes{'email_rule'}},$type);
13498: }
13499: }
13500: } else {
13501: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13502: }
13503: }
13504: }
13505: if (@types) {
13506: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13507: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
13508: if (@changed) {
13509: push(@{$changes{'inststatus'}},'inststatusguest');
13510: }
13511: } else {
13512: push(@{$changes{'inststatus'}},'inststatusguest');
13513: }
13514: }
13515: } else {
13516: delete($env{'form.cancreate_email'});
13517: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13518: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13519: push(@{$changes{'inststatus'}},'inststatusguest');
13520: }
13521: }
13522: }
13523: } else {
13524: $save_inststatus{'inststatusguest'} = [];
13525: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13526: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13527: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 13528: }
13529: }
1.160.6.34 raeburn 13530: }
13531: } else {
13532: if ($env{'form.cancreate_'.$item}) {
13533: push(@{$cancreate{'selfcreate'}},$item);
13534: }
13535: }
13536: }
1.160.6.93 raeburn 13537: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 13538: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
13539: #
1.160.6.35 raeburn 13540: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
13541: # 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 13542: #
1.160.6.40 raeburn 13543:
1.160.6.48 raeburn 13544: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 13545: push(@contexts,'emailusername');
1.160.6.93 raeburn 13546: if (@statuses) {
13547: foreach my $type (@statuses) {
1.160.6.35 raeburn 13548: if (ref($infofields) eq 'ARRAY') {
13549: foreach my $field (@{$infofields}) {
13550: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
13551: $cancreate{'emailusername'}{$type}{$field} = $1;
13552: }
13553: }
1.160.6.34 raeburn 13554: }
13555: }
13556: }
13557: #
13558: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 13559: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 13560: #
13561:
13562: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
13563: @approvalnotify = sort(@approvalnotify);
13564: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
13565: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13566: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
13567: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
13568: push(@{$changes{'cancreate'}},'notify');
13569: }
13570: } else {
13571: if ($cancreate{'notify'}{'approval'}) {
13572: push(@{$changes{'cancreate'}},'notify');
13573: }
13574: }
13575: } elsif ($cancreate{'notify'}{'approval'}) {
13576: push(@{$changes{'cancreate'}},'notify');
13577: }
13578:
13579: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
13580: }
13581: #
1.160.6.40 raeburn 13582: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 13583: # institutional log-in.
13584: #
13585: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
13586: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
13587: ($domdefaults{'auth_def'} eq 'localauth'))) {
13588: $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.').' '.
13589: &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.');
13590: }
13591: }
13592: my @fields = ('lastname','firstname','middlename','generation',
13593: 'permanentemail','id');
1.160.6.44 raeburn 13594: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 13595: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13596: #
13597: # Where usernames may created for institutional log-in and/or institutional single sign on:
13598: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
13599: # may self-create accounts
13600: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
13601: # which the user may supply, if institutional data is unavailable.
13602: #
13603: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 13604: if (@types) {
13605: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
13606: push(@contexts,'statustocreate');
13607: foreach my $type (@types) {
1.160.6.34 raeburn 13608: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
13609: foreach my $field (@fields) {
13610: if (grep(/^\Q$field\E$/,@modifiable)) {
13611: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
13612: } else {
13613: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
13614: }
13615: }
13616: }
13617: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 13618: foreach my $type (@types) {
1.160.6.34 raeburn 13619: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
13620: foreach my $field (@fields) {
13621: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
13622: $curr_usermodify{'selfcreate'}{$type}{$field}) {
13623: push(@{$changes{'selfcreate'}},$type);
13624: last;
13625: }
13626: }
13627: }
13628: }
13629: } else {
1.160.6.93 raeburn 13630: foreach my $type (@types) {
1.160.6.34 raeburn 13631: push(@{$changes{'selfcreate'}},$type);
13632: }
13633: }
13634: }
1.160.6.44 raeburn 13635: foreach my $field (@shibfields) {
13636: if ($env{'form.shibenv_'.$field} ne '') {
13637: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
13638: }
13639: }
13640: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13641: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
13642: foreach my $field (@shibfields) {
13643: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
13644: push(@{$changes{'cancreate'}},'shibenv');
13645: }
13646: }
13647: } else {
13648: foreach my $field (@shibfields) {
13649: if ($env{'form.shibenv_'.$field}) {
13650: push(@{$changes{'cancreate'}},'shibenv');
13651: last;
13652: }
13653: }
13654: }
13655: }
1.160.6.34 raeburn 13656: }
13657: foreach my $item (@contexts) {
13658: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
13659: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
13660: if (ref($cancreate{$item}) eq 'ARRAY') {
13661: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
13662: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13663: push(@{$changes{'cancreate'}},$item);
13664: }
13665: }
13666: }
13667: }
13668: if (ref($cancreate{$item}) eq 'ARRAY') {
13669: foreach my $type (@{$cancreate{$item}}) {
13670: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
13671: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13672: push(@{$changes{'cancreate'}},$item);
13673: }
13674: }
13675: }
13676: }
13677: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
13678: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 13679: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
13680: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13681: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
13682: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 13683: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13684: push(@{$changes{'cancreate'}},$item);
13685: }
13686: }
13687: }
1.160.6.93 raeburn 13688: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13689: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 13690: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13691: push(@{$changes{'cancreate'}},$item);
13692: }
1.160.6.34 raeburn 13693: }
13694: }
13695: }
1.160.6.93 raeburn 13696: foreach my $type (keys(%{$cancreate{$item}})) {
13697: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13698: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13699: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13700: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 13701: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13702: push(@{$changes{'cancreate'}},$item);
13703: }
13704: }
13705: } else {
13706: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13707: push(@{$changes{'cancreate'}},$item);
13708: }
13709: }
13710: }
1.160.6.93 raeburn 13711: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13712: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 13713: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13714: push(@{$changes{'cancreate'}},$item);
13715: }
1.160.6.34 raeburn 13716: }
13717: }
13718: }
13719: }
13720: } elsif ($curr_usercreation{'cancreate'}{$item}) {
13721: if (ref($cancreate{$item}) eq 'ARRAY') {
13722: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
13723: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13724: push(@{$changes{'cancreate'}},$item);
13725: }
13726: }
1.160.6.93 raeburn 13727: }
13728: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13729: if (ref($cancreate{$item}) eq 'HASH') {
13730: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13731: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 13732: }
13733: }
13734: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 13735: if (ref($cancreate{$item}) eq 'HASH') {
13736: foreach my $type (keys(%{$cancreate{$item}})) {
13737: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13738: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13739: if ($cancreate{$item}{$type}{$field}) {
13740: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13741: push(@{$changes{'cancreate'}},$item);
13742: }
13743: last;
13744: }
13745: }
13746: }
13747: }
1.160.6.34 raeburn 13748: }
13749: }
13750: }
13751: #
13752: # Populate %save_usercreate hash with updates to self-creation configuration.
13753: #
13754: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
13755: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 13756: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 13757: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
13758: if (ref($cancreate{'notify'}) eq 'HASH') {
13759: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
13760: }
1.160.6.40 raeburn 13761: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
13762: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
13763: }
1.160.6.93 raeburn 13764: if (ref($cancreate{'emailverified'}) eq 'HASH') {
13765: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
13766: }
13767: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
13768: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
13769: }
13770: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
13771: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
13772: }
1.160.6.34 raeburn 13773: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13774: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
13775: }
1.160.6.44 raeburn 13776: if (ref($cancreate{'shibenv'}) eq 'HASH') {
13777: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
13778: }
1.160.6.34 raeburn 13779: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 13780: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 13781:
13782: my %userconfig_hash = (
13783: usercreation => \%save_usercreate,
13784: usermodification => \%save_usermodify,
1.160.6.93 raeburn 13785: inststatus => \%save_inststatus,
1.160.6.34 raeburn 13786: );
1.160.6.93 raeburn 13787:
1.160.6.34 raeburn 13788: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
13789: $dom);
13790: #
1.160.6.93 raeburn 13791: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 13792: #
1.27 raeburn 13793: if ($putresult eq 'ok') {
13794: if (keys(%changes) > 0) {
13795: $resulttext = &mt('Changes made:').'<ul>';
13796: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 13797: my %lt = &selfcreation_types();
1.34 raeburn 13798: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 13799: my $chgtext = '';
1.45 raeburn 13800: if ($type eq 'selfcreate') {
1.50 raeburn 13801: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 13802: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 13803: } else {
1.160.6.34 raeburn 13804: $chgtext .= &mt('Self-creation of a new account is permitted for:').
13805: '<ul>';
1.50 raeburn 13806: foreach my $case (@{$cancreate{$type}}) {
13807: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
13808: }
13809: $chgtext .= '</ul>';
1.100 raeburn 13810: if (ref($cancreate{$type}) eq 'ARRAY') {
13811: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
13812: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13813: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 13814: $chgtext .= '<span class="LC_warning">'.
13815: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
13816: '</span><br />';
1.100 raeburn 13817: }
13818: }
13819: }
1.160.6.93 raeburn 13820: if (grep(/^email$/,@{$cancreate{$type}})) {
13821: if (!@statuses) {
13822: $chgtext .= '<span class="LC_warning">'.
13823: &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.").
13824: '</span><br />';
13825:
13826: }
13827: }
1.100 raeburn 13828: }
1.43 raeburn 13829: }
1.160.6.44 raeburn 13830: } elsif ($type eq 'shibenv') {
13831: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 13832: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 13833: } else {
13834: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
13835: '<ul>';
13836: foreach my $field (@shibfields) {
13837: next if ($cancreate{$type}{$field} eq '');
13838: if ($field eq 'inststatus') {
13839: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
13840: } else {
13841: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
13842: }
13843: }
13844: $chgtext .= '</ul>';
1.160.6.93 raeburn 13845: }
1.93 raeburn 13846: } elsif ($type eq 'statustocreate') {
1.96 raeburn 13847: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
13848: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
13849: if (@{$cancreate{'selfcreate'}} > 0) {
13850: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 13851: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 13852: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 13853: $chgtext .= '<br />'.
13854: '<span class="LC_warning">'.
13855: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
13856: '</span>';
13857: }
1.160.6.93 raeburn 13858: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 13859: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 13860: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
13861: } else {
13862: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
13863: }
13864: $chgtext .= '<ul>';
13865: foreach my $case (@{$cancreate{$type}}) {
13866: if ($case eq 'default') {
13867: $chgtext .= '<li>'.$othertitle.'</li>';
13868: } else {
1.160.6.93 raeburn 13869: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 13870: }
13871: }
1.100 raeburn 13872: $chgtext .= '</ul>';
13873: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 13874: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 13875: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
13876: '</span>';
1.100 raeburn 13877: }
13878: }
13879: } else {
13880: if (@{$cancreate{$type}} == 0) {
13881: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
13882: } else {
13883: $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 13884: }
13885: }
1.160.6.93 raeburn 13886: $chgtext .= '<br />';
1.93 raeburn 13887: }
1.160.6.40 raeburn 13888: } elsif ($type eq 'selfcreateprocessing') {
13889: my %choices = &Apache::lonlocal::texthash (
13890: automatic => 'Automatic approval',
13891: approval => 'Queued for approval',
13892: );
1.160.6.93 raeburn 13893: if (@types) {
13894: if (@statuses) {
13895: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
13896: '<ul>';
13897: foreach my $status (@statuses) {
13898: if ($status eq 'default') {
13899: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
13900: } else {
13901: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
13902: }
13903: }
13904: $chgtext .= '</ul>';
13905: }
13906: } else {
13907: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
13908: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
13909: }
13910: } elsif ($type eq 'emailverified') {
13911: my %options = &Apache::lonlocal::texthash (
13912: all => 'Same as e-mail',
13913: first => 'Omit @domain',
13914: free => 'Free to choose',
13915: );
13916: if (@types) {
13917: if (@statuses) {
13918: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
13919: '<ul>';
13920: foreach my $status (@statuses) {
13921: if ($status eq 'default') {
13922: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
13923: } else {
13924: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
13925: }
13926: }
13927: $chgtext .= '</ul>';
13928: }
1.160.6.40 raeburn 13929: } else {
1.160.6.93 raeburn 13930: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
13931: $options{$cancreate{'emailverified'}{'default'}});
13932: }
13933: } elsif ($type eq 'emailoptions') {
13934: my %options = &Apache::lonlocal::texthash (
13935: any => 'Any e-mail',
13936: inst => 'Institutional only',
13937: noninst => 'Non-institutional only',
13938: custom => 'Custom restrictions',
13939: );
13940: if (@types) {
13941: if (@statuses) {
13942: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
13943: '<ul>';
13944: foreach my $status (@statuses) {
13945: if ($type eq 'default') {
13946: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13947: } else {
13948: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13949: }
13950: }
13951: $chgtext .= '</ul>';
13952: }
13953: } else {
13954: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
13955: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
13956: } else {
13957: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
13958: $options{$cancreate{'emailoptions'}{'default'}});
13959: }
13960: }
13961: } elsif ($type eq 'emaildomain') {
13962: my $output;
13963: if (@statuses) {
13964: foreach my $type (@statuses) {
13965: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
13966: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
13967: if ($type eq 'default') {
13968: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13969: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13970: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13971: } else {
13972: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
13973: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13974: }
13975: } else {
13976: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13977: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13978: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13979: } else {
13980: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
13981: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13982: }
13983: }
13984: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
13985: if ($type eq 'default') {
13986: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13987: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13988: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13989: } else {
13990: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
13991: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13992: }
13993: } else {
13994: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13995: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13996: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13997: } else {
13998: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
13999: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
14000: }
14001: }
14002: }
14003: }
14004: }
14005: }
14006: if ($output ne '') {
14007: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
14008: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 14009: }
1.160.6.5 raeburn 14010: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 14011: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 14012: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
14013: } else {
14014: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 14015: if ($captchas{$savecaptcha{$type}}) {
14016: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 14017: } else {
14018: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
14019: }
14020: }
14021: } elsif ($type eq 'recaptchakeys') {
14022: my ($privkey,$pubkey);
1.160.6.34 raeburn 14023: if (ref($savecaptcha{$type}) eq 'HASH') {
14024: $pubkey = $savecaptcha{$type}{'public'};
14025: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 14026: }
14027: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
14028: if (!$pubkey) {
14029: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
14030: } else {
14031: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
14032: }
14033: if (!$privkey) {
14034: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
14035: } else {
14036: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
14037: }
14038: $chgtext .= '</ul>';
1.160.6.69 raeburn 14039: } elsif ($type eq 'recaptchaversion') {
14040: if ($savecaptcha{'captcha'} eq 'recaptcha') {
14041: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
14042: }
1.160.6.34 raeburn 14043: } elsif ($type eq 'emailusername') {
14044: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 14045: if (@statuses) {
14046: foreach my $type (@statuses) {
1.160.6.35 raeburn 14047: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
14048: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 14049: $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 14050: '<ul>';
14051: foreach my $field (@{$infofields}) {
14052: if ($cancreate{'emailusername'}{$type}{$field}) {
14053: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
14054: }
14055: }
1.160.6.50 raeburn 14056: $chgtext .= '</ul>';
14057: } else {
1.160.6.93 raeburn 14058: $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 14059: }
14060: } else {
1.160.6.93 raeburn 14061: $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 14062: }
14063: }
14064: }
14065: }
14066: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 14067: my $numapprove = 0;
1.160.6.34 raeburn 14068: if (ref($changes{'cancreate'}) eq 'ARRAY') {
14069: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
14070: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 14071: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
14072: $numapprove ++;
1.160.6.34 raeburn 14073: }
14074: }
1.43 raeburn 14075: }
1.160.6.93 raeburn 14076: unless ($numapprove) {
14077: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
14078: }
1.34 raeburn 14079: }
1.160.6.34 raeburn 14080: if ($chgtext) {
14081: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 14082: }
14083: }
14084: }
1.160.6.93 raeburn 14085: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 14086: my ($emailrules,$emailruleorder) =
14087: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 14088: foreach my $type (@{$changes{'email_rule'}}) {
14089: if (ref($email_rule{$type}) eq 'ARRAY') {
14090: my $chgtext = '<ul>';
14091: foreach my $rule (@{$email_rule{$type}}) {
14092: if (ref($emailrules->{$rule}) eq 'HASH') {
14093: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
14094: }
14095: }
14096: $chgtext .= '</ul>';
14097: my $typename;
14098: if (@types) {
14099: if ($type eq 'default') {
14100: $typename = $othertitle;
14101: } else {
14102: $typename = $usertypes{$type};
14103: }
14104: $chgtext .= &mt('(Affiliation: [_1])',$typename);
14105: }
14106: if (@{$email_rule{$type}} > 0) {
14107: $resulttext .= '<li>'.
14108: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
14109: $usertypes{$type}).
14110: $chgtext.
14111: '</li>';
14112: } else {
14113: $resulttext .= '<li>'.
14114: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
14115: '</li>'.
14116: &mt('(Affiliation: [_1])',$typename);
14117: }
1.43 raeburn 14118: }
14119: }
1.160.6.93 raeburn 14120: }
14121: if (ref($changes{'inststatus'}) eq 'ARRAY') {
14122: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
14123: if (@{$save_inststatus{'inststatusguest'}} > 0) {
14124: my $chgtext = '<ul>';
14125: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
14126: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
14127: }
14128: $chgtext .= '</ul>';
14129: $resulttext .= '<li>'.
14130: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
14131: $chgtext.
14132: '</li>';
14133: } else {
14134: $resulttext .= '<li>'.
14135: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
14136: '</li>';
14137: }
1.43 raeburn 14138: }
14139: }
1.160.6.34 raeburn 14140: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
14141: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
14142: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14143: foreach my $type (@{$changes{'selfcreate'}}) {
14144: my $typename = $type;
1.160.6.93 raeburn 14145: if (keys(%usertypes) > 0) {
14146: if ($usertypes{$type} ne '') {
14147: $typename = $usertypes{$type};
1.28 raeburn 14148: }
14149: }
1.160.6.34 raeburn 14150: my @modifiable;
14151: $resulttext .= '<li>'.
14152: &mt('Self-creation of account by users with status: [_1]',
14153: '<span class="LC_cusr_emph">'.$typename.'</span>').
14154: ' - '.&mt('modifiable fields (if institutional data blank): ');
14155: foreach my $field (@fields) {
14156: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
14157: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
14158: }
14159: }
14160: if (@modifiable > 0) {
14161: $resulttext .= join(', ',@modifiable);
1.43 raeburn 14162: } else {
1.160.6.34 raeburn 14163: $resulttext .= &mt('none');
1.43 raeburn 14164: }
1.160.6.34 raeburn 14165: $resulttext .= '</li>';
1.28 raeburn 14166: }
1.160.6.34 raeburn 14167: $resulttext .= '</ul></li>';
1.28 raeburn 14168: }
1.27 raeburn 14169: $resulttext .= '</ul>';
1.160.6.93 raeburn 14170: my $cachetime = 24*60*60;
14171: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
14172: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14173: if (ref($lastactref) eq 'HASH') {
14174: $lastactref->{'domdefaults'} = 1;
14175: }
1.27 raeburn 14176: } else {
1.160.6.34 raeburn 14177: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 14178: }
14179: } else {
14180: $resulttext = '<span class="LC_error">'.
1.23 raeburn 14181: &mt('An error occurred: [_1]',$putresult).'</span>';
14182: }
1.43 raeburn 14183: if ($warningmsg ne '') {
14184: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
14185: }
1.23 raeburn 14186: return $resulttext;
14187: }
14188:
1.160.6.5 raeburn 14189: sub process_captcha {
1.160.6.104 raeburn 14190: my ($container,$changes,$newsettings,$currsettings) = @_;
14191: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.160.6.5 raeburn 14192: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
14193: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
14194: $newsettings->{'captcha'} = 'original';
14195: }
1.160.6.104 raeburn 14196: my %current;
14197: if (ref($currsettings) eq 'HASH') {
14198: %current = %{$currsettings};
14199: }
14200: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.160.6.5 raeburn 14201: if ($container eq 'cancreate') {
14202: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14203: push(@{$changes->{'cancreate'}},'captcha');
14204: } elsif (!defined($changes->{'cancreate'})) {
14205: $changes->{'cancreate'} = ['captcha'];
14206: }
1.160.6.102 raeburn 14207: } elsif ($container eq 'passwords') {
14208: $changes->{'reset'} = 1;
1.160.6.5 raeburn 14209: } else {
14210: $changes->{'captcha'} = 1;
14211: }
14212: }
1.160.6.69 raeburn 14213: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 14214: if ($newsettings->{'captcha'} eq 'recaptcha') {
14215: $newpub = $env{'form.'.$container.'_recaptchapub'};
14216: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 14217: $newpub =~ s/[^\w\-]//g;
14218: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 14219: $newsettings->{'recaptchakeys'} = {
14220: public => $newpub,
14221: private => $newpriv,
14222: };
1.160.6.69 raeburn 14223: $newversion = $env{'form.'.$container.'_recaptchaversion'};
14224: $newversion =~ s/\D//g;
14225: if ($newversion ne '2') {
14226: $newversion = 1;
14227: }
14228: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 14229: }
1.160.6.104 raeburn 14230: if (ref($current{'recaptchakeys'}) eq 'HASH') {
14231: $currpub = $current{'recaptchakeys'}{'public'};
14232: $currpriv = $current{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 14233: unless ($newsettings->{'captcha'} eq 'recaptcha') {
14234: $newsettings->{'recaptchakeys'} = {
14235: public => '',
14236: private => '',
14237: }
14238: }
1.160.6.5 raeburn 14239: }
1.160.6.104 raeburn 14240: if ($current{'captcha'} eq 'recaptcha') {
14241: $currversion = $current{'recaptchaversion'};
1.160.6.69 raeburn 14242: if ($currversion ne '2') {
14243: $currversion = 1;
14244: }
14245: }
14246: if ($currversion ne $newversion) {
14247: if ($container eq 'cancreate') {
14248: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14249: push(@{$changes->{'cancreate'}},'recaptchaversion');
14250: } elsif (!defined($changes->{'cancreate'})) {
14251: $changes->{'cancreate'} = ['recaptchaversion'];
14252: }
1.160.6.102 raeburn 14253: } elsif ($container eq 'passwords') {
14254: $changes->{'reset'} = 1;
1.160.6.69 raeburn 14255: } else {
14256: $changes->{'recaptchaversion'} = 1;
14257: }
14258: }
1.160.6.5 raeburn 14259: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
14260: if ($container eq 'cancreate') {
14261: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14262: push(@{$changes->{'cancreate'}},'recaptchakeys');
14263: } elsif (!defined($changes->{'cancreate'})) {
14264: $changes->{'cancreate'} = ['recaptchakeys'];
14265: }
1.160.6.102 raeburn 14266: } elsif ($container eq 'passwords') {
14267: $changes->{'reset'} = 1;
1.160.6.5 raeburn 14268: } else {
14269: $changes->{'recaptchakeys'} = 1;
14270: }
14271: }
14272: return;
14273: }
14274:
1.33 raeburn 14275: sub modify_usermodification {
14276: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 14277: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 14278: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14279: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 14280: if ($key eq 'selfcreate') {
14281: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
14282: } else {
14283: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
14284: }
1.33 raeburn 14285: }
14286: }
1.160.6.34 raeburn 14287: my @contexts = ('author','course');
1.33 raeburn 14288: my %context_title = (
14289: author => 'In author context',
14290: course => 'In course context',
14291: );
14292: my @fields = ('lastname','firstname','middlename','generation',
14293: 'permanentemail','id');
14294: my %roles = (
14295: author => ['ca','aa'],
14296: course => ['st','ep','ta','in','cr'],
14297: );
14298: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14299: foreach my $context (@contexts) {
14300: foreach my $role (@{$roles{$context}}) {
14301: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
14302: foreach my $item (@fields) {
14303: if (grep(/^\Q$item\E$/,@modifiable)) {
14304: $modifyhash{$context}{$role}{$item} = 1;
14305: } else {
14306: $modifyhash{$context}{$role}{$item} = 0;
14307: }
14308: }
14309: }
14310: if (ref($curr_usermodification{$context}) eq 'HASH') {
14311: foreach my $role (@{$roles{$context}}) {
14312: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
14313: foreach my $field (@fields) {
14314: if ($modifyhash{$context}{$role}{$field} ne
14315: $curr_usermodification{$context}{$role}{$field}) {
14316: push(@{$changes{$context}},$role);
14317: last;
14318: }
14319: }
14320: }
14321: }
14322: } else {
14323: foreach my $context (@contexts) {
14324: foreach my $role (@{$roles{$context}}) {
14325: push(@{$changes{$context}},$role);
14326: }
14327: }
14328: }
14329: }
14330: my %usermodification_hash = (
14331: usermodification => \%modifyhash,
14332: );
14333: my $putresult = &Apache::lonnet::put_dom('configuration',
14334: \%usermodification_hash,$dom);
14335: if ($putresult eq 'ok') {
14336: if (keys(%changes) > 0) {
14337: $resulttext = &mt('Changes made: ').'<ul>';
14338: foreach my $context (@contexts) {
14339: if (ref($changes{$context}) eq 'ARRAY') {
14340: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
14341: if (ref($changes{$context}) eq 'ARRAY') {
14342: foreach my $role (@{$changes{$context}}) {
14343: my $rolename;
1.160.6.34 raeburn 14344: if ($role eq 'cr') {
14345: $rolename = &mt('Custom');
1.33 raeburn 14346: } else {
1.160.6.34 raeburn 14347: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 14348: }
14349: my @modifiable;
1.160.6.34 raeburn 14350: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 14351: foreach my $field (@fields) {
14352: if ($modifyhash{$context}{$role}{$field}) {
14353: push(@modifiable,$fieldtitles{$field});
14354: }
14355: }
14356: if (@modifiable > 0) {
14357: $resulttext .= join(', ',@modifiable);
14358: } else {
14359: $resulttext .= &mt('none');
14360: }
14361: $resulttext .= '</li>';
14362: }
14363: $resulttext .= '</ul></li>';
14364: }
14365: }
14366: }
14367: $resulttext .= '</ul>';
14368: } else {
14369: $resulttext = &mt('No changes made to user modification settings');
14370: }
14371: } else {
14372: $resulttext = '<span class="LC_error">'.
14373: &mt('An error occurred: [_1]',$putresult).'</span>';
14374: }
14375: return $resulttext;
14376: }
14377:
1.43 raeburn 14378: sub modify_defaults {
1.160.6.27 raeburn 14379: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 14380: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 14381: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 14382: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98 raeburn 14383: 'portal_def');
1.43 raeburn 14384: my @authtypes = ('internal','krb4','krb5','localauth');
14385: foreach my $item (@items) {
14386: $newvalues{$item} = $env{'form.'.$item};
14387: if ($item eq 'auth_def') {
14388: if ($newvalues{$item} ne '') {
14389: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
14390: push(@errors,$item);
14391: }
14392: }
14393: } elsif ($item eq 'lang_def') {
14394: if ($newvalues{$item} ne '') {
14395: if ($newvalues{$item} =~ /^(\w+)/) {
14396: my $langcode = $1;
1.103 raeburn 14397: if ($langcode ne 'x_chef') {
14398: if (code2language($langcode) eq '') {
14399: push(@errors,$item);
14400: }
1.43 raeburn 14401: }
14402: } else {
14403: push(@errors,$item);
14404: }
14405: }
1.54 raeburn 14406: } elsif ($item eq 'timezone_def') {
14407: if ($newvalues{$item} ne '') {
1.62 raeburn 14408: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 14409: push(@errors,$item);
14410: }
14411: }
1.68 raeburn 14412: } elsif ($item eq 'datelocale_def') {
14413: if ($newvalues{$item} ne '') {
14414: my @datelocale_ids = DateTime::Locale->ids();
14415: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
14416: push(@errors,$item);
14417: }
14418: }
1.141 raeburn 14419: } elsif ($item eq 'portal_def') {
14420: if ($newvalues{$item} ne '') {
14421: 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])\/?$/) {
14422: push(@errors,$item);
14423: }
14424: }
1.43 raeburn 14425: }
14426: if (grep(/^\Q$item\E$/,@errors)) {
14427: $newvalues{$item} = $domdefaults{$item};
14428: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
14429: $changes{$item} = 1;
14430: }
1.72 raeburn 14431: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 14432: }
1.160.6.98 raeburn 14433: my %staticdefaults = (
14434: 'intauth_cost' => 10,
14435: 'intauth_check' => 0,
14436: 'intauth_switch' => 0,
14437: );
14438: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
14439: if (exists($domdefaults{$item})) {
14440: $newvalues{$item} = $domdefaults{$item};
14441: } else {
14442: $newvalues{$item} = $staticdefaults{$item};
14443: }
14444: }
1.43 raeburn 14445: my %defaults_hash = (
1.72 raeburn 14446: defaults => \%newvalues,
14447: );
1.43 raeburn 14448: my $title = &defaults_titles();
1.160.6.40 raeburn 14449:
14450: my $currinststatus;
14451: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14452: $currinststatus = $domconfig{'inststatus'};
14453: } else {
14454: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14455: $currinststatus = {
14456: inststatustypes => $usertypes,
14457: inststatusorder => $types,
14458: inststatusguest => [],
14459: };
14460: }
14461: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
14462: my @allpos;
14463: my %alltypes;
1.160.6.93 raeburn 14464: my @inststatusguest;
14465: if (ref($currinststatus) eq 'HASH') {
14466: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
14467: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
14468: unless (grep(/^\Q$type\E$/,@todelete)) {
14469: push(@inststatusguest,$type);
14470: }
14471: }
14472: }
14473: }
14474: my ($currtitles,$currorder);
1.160.6.40 raeburn 14475: if (ref($currinststatus) eq 'HASH') {
14476: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
14477: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
14478: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
14479: if ($currinststatus->{inststatustypes}->{$type} ne '') {
14480: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
14481: }
14482: }
14483: unless (grep(/^\Q$type\E$/,@todelete)) {
14484: my $position = $env{'form.inststatus_pos_'.$type};
14485: $position =~ s/\D+//g;
14486: $allpos[$position] = $type;
14487: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
14488: $alltypes{$type} =~ s/`//g;
14489: }
14490: }
14491: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
14492: $currtitles =~ s/,$//;
14493: }
14494: }
14495: if ($env{'form.addinststatus'}) {
14496: my $newtype = $env{'form.addinststatus'};
14497: $newtype =~ s/\W//g;
14498: unless (exists($alltypes{$newtype})) {
14499: $alltypes{$newtype} = $env{'form.addinststatus_title'};
14500: $alltypes{$newtype} =~ s/`//g;
14501: my $position = $env{'form.addinststatus_pos'};
14502: $position =~ s/\D+//g;
14503: if ($position ne '') {
14504: $allpos[$position] = $newtype;
14505: }
14506: }
14507: }
1.160.6.93 raeburn 14508: my @orderedstatus;
1.160.6.40 raeburn 14509: foreach my $type (@allpos) {
14510: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
14511: push(@orderedstatus,$type);
14512: }
14513: }
14514: foreach my $type (keys(%alltypes)) {
14515: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
14516: delete($alltypes{$type});
14517: }
14518: }
14519: $defaults_hash{'inststatus'} = {
14520: inststatustypes => \%alltypes,
14521: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 14522: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 14523: };
14524: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
14525: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
14526: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
14527: }
14528: }
14529: if ($currorder ne join(',',@orderedstatus)) {
14530: $changes{'inststatus'}{'inststatusorder'} = 1;
14531: }
14532: my $newtitles;
14533: foreach my $item (@orderedstatus) {
14534: $newtitles .= $alltypes{$item}.',';
14535: }
14536: $newtitles =~ s/,$//;
14537: if ($currtitles ne $newtitles) {
14538: $changes{'inststatus'}{'inststatustypes'} = 1;
14539: }
1.43 raeburn 14540: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
14541: $dom);
14542: if ($putresult eq 'ok') {
14543: if (keys(%changes) > 0) {
14544: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 14545: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 14546: 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";
14547: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 14548: if ($item eq 'inststatus') {
14549: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 14550: if (@orderedstatus) {
1.160.6.40 raeburn 14551: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
14552: foreach my $type (@orderedstatus) {
14553: $resulttext .= $alltypes{$type}.', ';
14554: }
14555: $resulttext =~ s/, $//;
14556: $resulttext .= '</li>';
1.160.6.93 raeburn 14557: } else {
14558: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 14559: }
14560: }
14561: } else {
14562: my $value = $env{'form.'.$item};
14563: if ($value eq '') {
14564: $value = &mt('none');
14565: } elsif ($item eq 'auth_def') {
14566: my %authnames = &authtype_names();
14567: my %shortauth = (
14568: internal => 'int',
14569: krb4 => 'krb4',
14570: krb5 => 'krb5',
14571: localauth => 'loc',
14572: );
14573: $value = $authnames{$shortauth{$value}};
14574: }
14575: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
14576: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 14577: }
14578: }
14579: $resulttext .= '</ul>';
14580: $mailmsgtext .= "\n";
14581: my $cachetime = 24*60*60;
1.72 raeburn 14582: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 14583: if (ref($lastactref) eq 'HASH') {
14584: $lastactref->{'domdefaults'} = 1;
14585: }
1.68 raeburn 14586: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 14587: my $notify = 1;
14588: if (ref($domconfig{'contacts'}) eq 'HASH') {
14589: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
14590: $notify = 0;
14591: }
14592: }
14593: if ($notify) {
14594: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
14595: "LON-CAPA Domain Settings Change - $dom",
14596: $mailmsgtext);
14597: }
1.54 raeburn 14598: }
1.43 raeburn 14599: } else {
1.54 raeburn 14600: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 14601: }
14602: } else {
14603: $resulttext = '<span class="LC_error">'.
14604: &mt('An error occurred: [_1]',$putresult).'</span>';
14605: }
14606: if (@errors > 0) {
14607: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
14608: foreach my $item (@errors) {
14609: $resulttext .= ' "'.$title->{$item}.'",';
14610: }
14611: $resulttext =~ s/,$//;
14612: }
14613: return $resulttext;
14614: }
14615:
1.46 raeburn 14616: sub modify_scantron {
1.160.6.24 raeburn 14617: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 14618: my ($resulttext,%confhash,%changes,$errors);
14619: my $custom = 'custom.tab';
14620: my $default = 'default.tab';
14621: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 14622: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 14623: &config_check($dom,$confname,$servadm);
14624: if ($env{'form.scantronformat.filename'} ne '') {
14625: my $error;
14626: if ($configuserok eq 'ok') {
14627: if ($switchserver) {
1.130 raeburn 14628: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 14629: } else {
14630: if ($author_ok eq 'ok') {
14631: my ($result,$scantronurl) =
14632: &publishlogo($r,'upload','scantronformat',$dom,
14633: $confname,'scantron','','',$custom);
14634: if ($result eq 'ok') {
14635: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 14636: $changes{'scantronformat'} = 1;
1.46 raeburn 14637: } else {
14638: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
14639: }
14640: } else {
14641: $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);
14642: }
14643: }
14644: } else {
14645: $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);
14646: }
14647: if ($error) {
14648: &Apache::lonnet::logthis($error);
14649: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14650: }
14651: }
1.48 raeburn 14652: if (ref($domconfig{'scantron'}) eq 'HASH') {
14653: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
14654: if ($env{'form.scantronformat_del'}) {
14655: $confhash{'scantron'}{'scantronformat'} = '';
14656: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 14657: } else {
14658: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
14659: }
14660: }
14661: }
14662: my @options = ('hdr','pad','rem');
14663: my @fields = &scantroncsv_fields();
14664: my %titles = &scantronconfig_titles();
14665: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
14666: my ($newdat,$currdat,%newcol,%currcol);
14667: if (grep(/^dat$/,@formats)) {
14668: $confhash{'scantron'}{config}{dat} = 1;
14669: $newdat = 1;
14670: } else {
14671: $newdat = 0;
14672: }
14673: if (grep(/^csv$/,@formats)) {
14674: my %bynum;
14675: foreach my $field (@fields) {
14676: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
14677: my $posscol = $1;
14678: if (($posscol < 20) && (!$bynum{$posscol})) {
14679: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
14680: $bynum{$posscol} = $field;
14681: $newcol{$field} = $posscol;
14682: }
14683: }
14684: }
14685: if (keys(%newcol)) {
14686: foreach my $option (@options) {
14687: if ($env{'form.scantroncsv_'.$option}) {
14688: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
14689: }
14690: }
14691: }
14692: }
14693: $currdat = 1;
14694: if (ref($domconfig{'scantron'}) eq 'HASH') {
14695: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
14696: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
14697: $currdat = 0;
14698: }
14699: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
14700: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
14701: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
14702: }
14703: }
14704: }
14705: }
14706: if ($currdat != $newdat) {
14707: $changes{'config'} = 1;
14708: } else {
14709: foreach my $field (@fields) {
14710: if ($currcol{$field} ne '') {
14711: if ($currcol{$field} ne $newcol{$field}) {
14712: $changes{'config'} = 1;
14713: last;
14714: }
14715: } elsif ($newcol{$field} ne '') {
14716: $changes{'config'} = 1;
14717: last;
1.46 raeburn 14718: }
14719: }
14720: }
14721: if (keys(%confhash) > 0) {
14722: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
14723: $dom);
14724: if ($putresult eq 'ok') {
14725: if (keys(%changes) > 0) {
1.48 raeburn 14726: if (ref($confhash{'scantron'}) eq 'HASH') {
14727: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 14728: if ($changes{'scantronformat'}) {
14729: if ($confhash{'scantron'}{'scantronformat'} eq '') {
14730: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
14731: } else {
14732: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
14733: }
14734: }
14735: if ($changes{'config'}) {
14736: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
14737: if ($confhash{'scantron'}{'config'}{'dat'}) {
14738: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
14739: }
14740: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
14741: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
14742: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
14743: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
14744: foreach my $field (@fields) {
14745: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
14746: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
14747: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
14748: }
14749: }
14750: $resulttext .= '</ul></li>';
14751: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
14752: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
14753: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
14754: foreach my $option (@options) {
14755: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
14756: $resulttext .= '<li>'.$titles{$option}.'</li>';
14757: }
14758: }
14759: $resulttext .= '</ul></li>';
14760: }
14761: }
14762: }
14763: }
14764: }
14765: } else {
14766: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
14767: }
1.46 raeburn 14768: }
1.48 raeburn 14769: $resulttext .= '</ul>';
14770: } else {
1.130 raeburn 14771: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 14772: }
14773: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 14774: if (ref($lastactref) eq 'HASH') {
14775: $lastactref->{'domainconfig'} = 1;
14776: }
1.46 raeburn 14777: } else {
1.160.6.97 raeburn 14778: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 14779: }
14780: } else {
14781: $resulttext = '<span class="LC_error">'.
14782: &mt('An error occurred: [_1]',$putresult).'</span>';
14783: }
14784: } else {
1.160.6.97 raeburn 14785: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 14786: }
14787: if ($errors) {
14788: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14789: $errors.'</ul>';
14790: }
14791: return $resulttext;
14792: }
14793:
1.48 raeburn 14794: sub modify_coursecategories {
1.160.6.43 raeburn 14795: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 14796: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
14797: $cathash);
1.48 raeburn 14798: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 14799: my @catitems = ('unauth','auth');
14800: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 14801: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 14802: $cathash = $domconfig{'coursecategories'}{'cats'};
14803: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
14804: $changes{'togglecats'} = 1;
14805: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
14806: }
14807: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
14808: $changes{'categorize'} = 1;
14809: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
14810: }
1.120 raeburn 14811: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
14812: $changes{'togglecatscomm'} = 1;
14813: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
14814: }
14815: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
14816: $changes{'categorizecomm'} = 1;
14817: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
14818: }
1.160.6.42 raeburn 14819: foreach my $item (@catitems) {
14820: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14821: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
14822: $changes{$item} = 1;
14823: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14824: }
14825: }
14826: }
1.57 raeburn 14827: } else {
14828: $changes{'togglecats'} = 1;
14829: $changes{'categorize'} = 1;
1.124 raeburn 14830: $changes{'togglecatscomm'} = 1;
14831: $changes{'categorizecomm'} = 1;
1.87 raeburn 14832: $domconfig{'coursecategories'} = {
14833: togglecats => $env{'form.togglecats'},
14834: categorize => $env{'form.categorize'},
1.124 raeburn 14835: togglecatscomm => $env{'form.togglecatscomm'},
14836: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 14837: };
1.160.6.42 raeburn 14838: foreach my $item (@catitems) {
14839: if ($env{'form.coursecat_'.$item} ne 'std') {
14840: $changes{$item} = 1;
14841: }
14842: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14843: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14844: }
14845: }
1.57 raeburn 14846: }
14847: if (ref($cathash) eq 'HASH') {
14848: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 14849: push (@deletecategory,'instcode::0');
14850: }
1.120 raeburn 14851: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
14852: push(@deletecategory,'communities::0');
14853: }
1.48 raeburn 14854: }
1.57 raeburn 14855: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
14856: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14857: if (@deletecategory > 0) {
14858: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 14859: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 14860: foreach my $item (@deletecategory) {
1.57 raeburn 14861: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
14862: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 14863: $deletions{$item} = 1;
1.57 raeburn 14864: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 14865: }
14866: }
14867: }
1.57 raeburn 14868: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 14869: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 14870: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 14871: $reorderings{$item} = 1;
1.57 raeburn 14872: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 14873: }
14874: if ($env{'form.addcategory_name_'.$item} ne '') {
14875: my $newcat = $env{'form.addcategory_name_'.$item};
14876: my $newdepth = $depth+1;
14877: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14878: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 14879: $adds{$newitem} = 1;
14880: }
14881: if ($env{'form.subcat_'.$item} ne '') {
14882: my $newcat = $env{'form.subcat_'.$item};
14883: my $newdepth = $depth+1;
14884: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14885: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 14886: $adds{$newitem} = 1;
14887: }
14888: }
14889: }
14890: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 14891: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14892: my $newitem = 'instcode::0';
1.57 raeburn 14893: if ($cathash->{$newitem} eq '') {
14894: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14895: $adds{$newitem} = 1;
14896: }
14897: } else {
14898: my $newitem = 'instcode::0';
1.57 raeburn 14899: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14900: $adds{$newitem} = 1;
14901: }
14902: }
1.120 raeburn 14903: if ($env{'form.communities'} eq '1') {
14904: if (ref($cathash) eq 'HASH') {
14905: my $newitem = 'communities::0';
14906: if ($cathash->{$newitem} eq '') {
14907: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14908: $adds{$newitem} = 1;
14909: }
14910: } else {
14911: my $newitem = 'communities::0';
14912: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14913: $adds{$newitem} = 1;
14914: }
14915: }
1.48 raeburn 14916: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 14917: if (($env{'form.addcategory_name'} ne 'instcode') &&
14918: ($env{'form.addcategory_name'} ne 'communities')) {
14919: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
14920: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
14921: $adds{$newitem} = 1;
14922: }
1.48 raeburn 14923: }
1.57 raeburn 14924: my $putresult;
1.48 raeburn 14925: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14926: if (keys(%deletions) > 0) {
14927: foreach my $key (keys(%deletions)) {
14928: if ($predelallitems{$key} ne '') {
14929: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
14930: }
14931: }
14932: }
14933: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 14934: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 14935: if (ref($chkcats[0]) eq 'ARRAY') {
14936: my $depth = 0;
14937: my $chg = 0;
14938: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
14939: my $name = $chkcats[0][$i];
14940: my $item;
14941: if ($name eq '') {
14942: $chg ++;
14943: } else {
14944: $item = &escape($name).'::0';
14945: if ($chg) {
1.57 raeburn 14946: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 14947: }
14948: $depth ++;
1.57 raeburn 14949: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 14950: $depth --;
14951: }
14952: }
14953: }
1.57 raeburn 14954: }
14955: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14956: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 14957: if ($putresult eq 'ok') {
1.57 raeburn 14958: my %title = (
1.120 raeburn 14959: togglecats => 'Show/Hide a course in catalog',
14960: categorize => 'Assign a category to a course',
14961: togglecatscomm => 'Show/Hide a community in catalog',
14962: categorizecomm => 'Assign a category to a community',
1.57 raeburn 14963: );
14964: my %level = (
1.120 raeburn 14965: dom => 'set in Domain ("Modify Course/Community")',
14966: crs => 'set in Course ("Course Configuration")',
14967: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 14968: none => 'No catalog',
14969: std => 'Standard catalog',
14970: domonly => 'Domain-only catalog',
14971: codesrch => 'Code search form',
1.57 raeburn 14972: );
1.48 raeburn 14973: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 14974: if ($changes{'togglecats'}) {
14975: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
14976: }
14977: if ($changes{'categorize'}) {
14978: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 14979: }
1.120 raeburn 14980: if ($changes{'togglecatscomm'}) {
14981: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
14982: }
14983: if ($changes{'categorizecomm'}) {
14984: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
14985: }
1.160.6.42 raeburn 14986: if ($changes{'unauth'}) {
14987: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
14988: }
14989: if ($changes{'auth'}) {
14990: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
14991: }
1.57 raeburn 14992: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14993: my $cathash;
14994: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
14995: $cathash = $domconfig{'coursecategories'}{'cats'};
14996: } else {
14997: $cathash = {};
14998: }
14999: my (@cats,@trails,%allitems);
15000: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
15001: if (keys(%deletions) > 0) {
15002: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
15003: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
15004: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
15005: }
15006: $resulttext .= '</ul></li>';
15007: }
15008: if (keys(%reorderings) > 0) {
15009: my %sort_by_trail;
15010: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
15011: foreach my $key (keys(%reorderings)) {
15012: if ($allitems{$key} ne '') {
15013: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
15014: }
1.48 raeburn 15015: }
1.57 raeburn 15016: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
15017: $resulttext .= '<li>'.$trails[$trail].'</li>';
15018: }
15019: $resulttext .= '</ul></li>';
1.48 raeburn 15020: }
1.57 raeburn 15021: if (keys(%adds) > 0) {
15022: my %sort_by_trail;
15023: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
15024: foreach my $key (keys(%adds)) {
15025: if ($allitems{$key} ne '') {
15026: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
15027: }
15028: }
15029: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
15030: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 15031: }
1.57 raeburn 15032: $resulttext .= '</ul></li>';
1.48 raeburn 15033: }
1.160.6.92 raeburn 15034: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
15035: if (ref($lastactref) eq 'HASH') {
15036: $lastactref->{'cats'} = 1;
15037: }
1.48 raeburn 15038: }
15039: $resulttext .= '</ul>';
1.160.6.43 raeburn 15040: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 15041: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15042: if ($changes{'auth'}) {
15043: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
15044: }
15045: if ($changes{'unauth'}) {
15046: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
15047: }
15048: my $cachetime = 24*60*60;
15049: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 15050: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 15051: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 15052: }
15053: }
1.48 raeburn 15054: } else {
15055: $resulttext = '<span class="LC_error">'.
1.57 raeburn 15056: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 15057: }
15058: } else {
1.120 raeburn 15059: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 15060: }
15061: return $resulttext;
15062: }
15063:
1.69 raeburn 15064: sub modify_serverstatuses {
15065: my ($dom,%domconfig) = @_;
15066: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
15067: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
15068: %currserverstatus = %{$domconfig{'serverstatuses'}};
15069: }
15070: my @pages = &serverstatus_pages();
15071: foreach my $type (@pages) {
15072: $newserverstatus{$type}{'namedusers'} = '';
15073: $newserverstatus{$type}{'machines'} = '';
15074: if (defined($env{'form.'.$type.'_namedusers'})) {
15075: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
15076: my @okusers;
15077: foreach my $user (@users) {
15078: my ($uname,$udom) = split(/:/,$user);
15079: if (($udom =~ /^$match_domain$/) &&
15080: (&Apache::lonnet::domain($udom)) &&
15081: ($uname =~ /^$match_username$/)) {
15082: if (!grep(/^\Q$user\E/,@okusers)) {
15083: push(@okusers,$user);
15084: }
15085: }
15086: }
15087: if (@okusers > 0) {
15088: @okusers = sort(@okusers);
15089: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
15090: }
15091: }
15092: if (defined($env{'form.'.$type.'_machines'})) {
15093: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
15094: my @okmachines;
15095: foreach my $ip (@machines) {
15096: my @parts = split(/\./,$ip);
15097: next if (@parts < 4);
15098: my $badip = 0;
15099: for (my $i=0; $i<4; $i++) {
15100: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
15101: $badip = 1;
15102: last;
15103: }
15104: }
15105: if (!$badip) {
15106: push(@okmachines,$ip);
15107: }
15108: }
15109: @okmachines = sort(@okmachines);
15110: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
15111: }
15112: }
15113: my %serverstatushash = (
15114: serverstatuses => \%newserverstatus,
15115: );
15116: foreach my $type (@pages) {
1.83 raeburn 15117: foreach my $setting ('namedusers','machines') {
1.84 raeburn 15118: my (@current,@new);
1.83 raeburn 15119: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 15120: if ($currserverstatus{$type}{$setting} ne '') {
15121: @current = split(/,/,$currserverstatus{$type}{$setting});
15122: }
15123: }
15124: if ($newserverstatus{$type}{$setting} ne '') {
15125: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 15126: }
15127: if (@current > 0) {
15128: if (@new > 0) {
15129: foreach my $item (@current) {
15130: if (!grep(/^\Q$item\E$/,@new)) {
15131: $changes{$type}{$setting} = 1;
1.82 raeburn 15132: last;
15133: }
15134: }
1.84 raeburn 15135: foreach my $item (@new) {
15136: if (!grep(/^\Q$item\E$/,@current)) {
15137: $changes{$type}{$setting} = 1;
15138: last;
1.82 raeburn 15139: }
15140: }
15141: } else {
1.83 raeburn 15142: $changes{$type}{$setting} = 1;
1.69 raeburn 15143: }
1.83 raeburn 15144: } elsif (@new > 0) {
15145: $changes{$type}{$setting} = 1;
1.69 raeburn 15146: }
15147: }
15148: }
15149: if (keys(%changes) > 0) {
1.81 raeburn 15150: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 15151: my $putresult = &Apache::lonnet::put_dom('configuration',
15152: \%serverstatushash,$dom);
15153: if ($putresult eq 'ok') {
15154: $resulttext .= &mt('Changes made:').'<ul>';
15155: foreach my $type (@pages) {
1.84 raeburn 15156: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 15157: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 15158: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 15159: if ($newserverstatus{$type}{'namedusers'} eq '') {
15160: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
15161: } else {
15162: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
15163: }
1.84 raeburn 15164: }
15165: if ($changes{$type}{'machines'}) {
1.69 raeburn 15166: if ($newserverstatus{$type}{'machines'} eq '') {
15167: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
15168: } else {
15169: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
15170: }
15171:
15172: }
15173: $resulttext .= '</ul></li>';
15174: }
15175: }
15176: $resulttext .= '</ul>';
15177: } else {
15178: $resulttext = '<span class="LC_error">'.
15179: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
15180:
15181: }
15182: } else {
15183: $resulttext = &mt('No changes made to access to server status pages');
15184: }
15185: return $resulttext;
15186: }
15187:
1.118 jms 15188: sub modify_helpsettings {
1.160.6.77 raeburn 15189: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 15190: my ($resulttext,$errors,%changes,%helphash);
15191: my %defaultchecked = ('submitbugs' => 'on');
15192: my @offon = ('off','on');
1.118 jms 15193: my @toggles = ('submitbugs');
1.160.6.77 raeburn 15194: my %current = ('submitbugs' => '',
15195: 'adhoc' => {},
15196: );
1.118 jms 15197: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 15198: %current = %{$domconfig{'helpsettings'}};
15199: }
1.160.6.77 raeburn 15200: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 15201: foreach my $item (@toggles) {
15202: if ($defaultchecked{$item} eq 'on') {
15203: if ($current{$item} eq '') {
15204: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 15205: $changes{$item} = 1;
15206: }
1.160.6.73 raeburn 15207: } elsif ($current{$item} ne $env{'form.'.$item}) {
15208: $changes{$item} = 1;
15209: }
15210: } elsif ($defaultchecked{$item} eq 'off') {
15211: if ($current{$item} eq '') {
15212: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 15213: $changes{$item} = 1;
15214: }
1.160.6.73 raeburn 15215: } elsif ($current{$item} ne $env{'form.'.$item}) {
15216: $changes{$item} = 1;
15217: }
15218: }
15219: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
15220: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
15221: }
15222: }
1.160.6.77 raeburn 15223: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 15224: my $confname = $dom.'-domainconfig';
15225: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 15226: my (@allpos,%newsettings,%changedprivs,$newrole);
15227: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 15228: my @accesstypes = ('all','dh','da','none','status','inc','exc');
15229: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 15230: my %lt = &Apache::lonlocal::texthash(
15231: s => 'system',
15232: d => 'domain',
15233: order => 'Display order',
15234: access => 'Role usage',
1.160.6.79 raeburn 15235: all => 'All with domain helpdesk or helpdesk assistant role',
15236: dh => 'All with domain helpdesk role',
15237: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 15238: none => 'None',
15239: status => 'Determined based on institutional status',
15240: inc => 'Include all, but exclude specific personnel',
15241: exc => 'Exclude all, but include specific personnel',
15242: );
15243: for (my $num=0; $num<=$maxnum; $num++) {
15244: my ($prefix,$identifier,$rolename,%curr);
15245: if ($num == $maxnum) {
15246: next unless ($env{'form.newcusthelp'} == $maxnum);
15247: $identifier = 'custhelp'.$num;
15248: $prefix = 'helproles_'.$num;
15249: $rolename = $env{'form.custhelpname'.$num};
15250: $rolename=~s/[^A-Za-z0-9]//gs;
15251: next if ($rolename eq '');
15252: next if (exists($existing{'rolesdef_'.$rolename}));
15253: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15254: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15255: $newprivs{'c'},$confname,$dom);
15256: if ($result ne 'ok') {
15257: $errors .= '<li><span class="LC_error">'.
15258: &mt('An error occurred storing the new custom role: [_1]',
15259: $result).'</span></li>';
15260: next;
15261: } else {
15262: $changedprivs{$rolename} = \%newprivs;
15263: $newrole = $rolename;
15264: }
15265: } else {
15266: $prefix = 'helproles_'.$num;
15267: $rolename = $env{'form.'.$prefix};
15268: next if ($rolename eq '');
15269: next unless (exists($existing{'rolesdef_'.$rolename}));
15270: $identifier = 'custhelp'.$num;
15271: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15272: my %currprivs;
15273: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
15274: split(/\_/,$existing{'rolesdef_'.$rolename});
15275: foreach my $level ('c','d','s') {
15276: if ($newprivs{$level} ne $currprivs{$level}) {
15277: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15278: $newprivs{'c'},$confname,$dom);
15279: if ($result ne 'ok') {
15280: $errors .= '<li><span class="LC_error">'.
15281: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
15282: $rolename,$result).'</span></li>';
15283: } else {
15284: $changedprivs{$rolename} = \%newprivs;
15285: }
15286: last;
15287: }
15288: }
15289: if (ref($current{'adhoc'}) eq 'HASH') {
15290: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15291: %curr = %{$current{'adhoc'}{$rolename}};
15292: }
15293: }
15294: }
15295: my $newpos = $env{'form.'.$prefix.'_pos'};
15296: $newpos =~ s/\D+//g;
15297: $allpos[$newpos] = $rolename;
15298: my $newdesc = $env{'form.'.$prefix.'_desc'};
15299: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
15300: if ($curr{'desc'}) {
15301: if ($curr{'desc'} ne $newdesc) {
15302: $changes{'customrole'}{$rolename}{'desc'} = 1;
15303: $newsettings{$rolename}{'desc'} = $newdesc;
15304: }
15305: } elsif ($newdesc ne '') {
15306: $changes{'customrole'}{$rolename}{'desc'} = 1;
15307: $newsettings{$rolename}{'desc'} = $newdesc;
15308: }
15309: my $access = $env{'form.'.$prefix.'_access'};
15310: if (grep(/^\Q$access\E$/,@accesstypes)) {
15311: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
15312: if ($access eq 'status') {
15313: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
15314: if (scalar(@statuses) == 0) {
15315: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
15316: } else {
15317: my (@shownstatus,$numtypes);
15318: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15319: if (ref($types) eq 'ARRAY') {
15320: $numtypes = scalar(@{$types});
15321: foreach my $type (sort(@statuses)) {
15322: if ($type eq 'default') {
15323: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15324: } elsif (grep(/^\Q$type\E$/,@{$types})) {
15325: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15326: push(@shownstatus,$usertypes->{$type});
15327: }
1.160.6.73 raeburn 15328: }
15329: }
1.160.6.77 raeburn 15330: if (grep(/^default$/,@statuses)) {
15331: push(@shownstatus,$othertitle);
15332: }
15333: if (scalar(@shownstatus) == 1+$numtypes) {
15334: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
15335: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
15336: } else {
15337: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
15338: if (ref($curr{'status'}) eq 'ARRAY') {
15339: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15340: if (@diffs) {
15341: $changes{'customrole'}{$rolename}{$access} = 1;
15342: }
15343: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15344: $changes{'customrole'}{$rolename}{$access} = 1;
15345: }
15346: }
15347: }
15348: } elsif (($access eq 'inc') || ($access eq 'exc')) {
15349: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
15350: my @newspecstaff;
15351: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15352: foreach my $person (sort(@personnel)) {
15353: if ($domhelpdesk{$person}) {
15354: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
15355: }
15356: }
15357: if (ref($curr{$access}) eq 'ARRAY') {
15358: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15359: if (@diffs) {
15360: $changes{'customrole'}{$rolename}{$access} = 1;
15361: }
15362: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15363: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 15364: }
1.160.6.77 raeburn 15365: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15366: my ($uname,$udom) = split(/:/,$person);
15367: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
15368: }
15369: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 15370: }
1.160.6.77 raeburn 15371: } else {
15372: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
15373: }
15374: unless ($curr{'access'} eq $access) {
15375: $changes{'customrole'}{$rolename}{'access'} = 1;
15376: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 15377: }
15378: }
1.160.6.77 raeburn 15379: if (@allpos > 0) {
15380: my $idx = 0;
15381: foreach my $rolename (@allpos) {
15382: if ($rolename ne '') {
15383: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
15384: if (ref($current{'adhoc'}) eq 'HASH') {
15385: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15386: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
15387: $changes{'customrole'}{$rolename}{'order'} = 1;
15388: $newsettings{$rolename}{'order'} = $idx+1;
15389: }
15390: }
1.160.6.73 raeburn 15391: }
1.160.6.77 raeburn 15392: $idx ++;
1.122 jms 15393: }
15394: }
1.118 jms 15395: }
1.123 jms 15396: my $putresult;
15397: if (keys(%changes) > 0) {
1.160.6.5 raeburn 15398: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
15399: if ($putresult eq 'ok') {
1.160.6.77 raeburn 15400: if (ref($helphash{'helpsettings'}) eq 'HASH') {
15401: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
15402: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
15403: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
15404: }
15405: }
15406: my $cachetime = 24*60*60;
15407: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15408: if (ref($lastactref) eq 'HASH') {
15409: $lastactref->{'domdefaults'} = 1;
15410: }
15411: } else {
15412: $errors .= '<li><span class="LC_error">'.
15413: &mt('An error occurred storing the settings: [_1]',
15414: $putresult).'</span></li>';
15415: }
15416: }
15417: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
15418: $resulttext = &mt('Changes made:').'<ul>';
15419: my (%shownprivs,@levelorder);
15420: @levelorder = ('c','d','s');
15421: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 15422: foreach my $item (sort(keys(%changes))) {
15423: if ($item eq 'submitbugs') {
15424: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
15425: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
15426: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 15427: } elsif ($item eq 'customrole') {
15428: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 15429: my @keyorder = ('order','desc','access','status','exc','inc');
15430: my %keytext = &Apache::lonlocal::texthash(
15431: order => 'Order',
15432: desc => 'Role description',
15433: access => 'Role usage',
1.160.6.83 raeburn 15434: status => 'Allowed institutional types',
1.160.6.77 raeburn 15435: exc => 'Allowed personnel',
15436: inc => 'Disallowed personnel',
15437: );
1.160.6.73 raeburn 15438: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 15439: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
15440: if ($role eq $newrole) {
15441: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
15442: $role).'<ul>';
15443: } else {
15444: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15445: $role).'<ul>';
15446: }
15447: foreach my $key (@keyorder) {
15448: if ($changes{'customrole'}{$role}{$key}) {
15449: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
15450: $keytext{$key},$newsettings{$role}{$key}).
15451: '</li>';
15452: }
15453: }
15454: if (ref($changedprivs{$role}) eq 'HASH') {
15455: $shownprivs{$role} = 1;
15456: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
15457: foreach my $level (@levelorder) {
15458: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15459: next if ($item eq '');
15460: my ($priv) = split(/\&/,$item,2);
15461: if (&Apache::lonnet::plaintext($priv)) {
15462: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15463: unless ($level eq 'c') {
15464: $resulttext .= ' ('.$lt{$level}.')';
15465: }
15466: $resulttext .= '</li>';
15467: }
15468: }
15469: }
15470: $resulttext .= '</ul>';
15471: }
15472: $resulttext .= '</ul></li>';
15473: }
1.160.6.73 raeburn 15474: }
15475: }
1.160.6.5 raeburn 15476: }
15477: }
15478: }
1.160.6.77 raeburn 15479: if (keys(%changedprivs)) {
15480: foreach my $role (sort(keys(%changedprivs))) {
15481: unless ($shownprivs{$role}) {
15482: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15483: $role).'<ul>'.
15484: '<li>'.&mt('Privileges set to :').'<ul>';
15485: foreach my $level (@levelorder) {
15486: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15487: next if ($item eq '');
15488: my ($priv) = split(/\&/,$item,2);
15489: if (&Apache::lonnet::plaintext($priv)) {
15490: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15491: unless ($level eq 'c') {
15492: $resulttext .= ' ('.$lt{$level}.')';
15493: }
15494: $resulttext .= '</li>';
15495: }
15496: }
15497: }
15498: $resulttext .= '</ul></li></ul></li>';
15499: }
15500: }
15501: }
15502: $resulttext .= '</ul>';
15503: } else {
15504: $resulttext = &mt('No changes made to help settings');
1.118 jms 15505: }
15506: if ($errors) {
1.160.6.5 raeburn 15507: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 15508: $errors.'</ul>';
1.118 jms 15509: }
15510: return $resulttext;
15511: }
15512:
1.121 raeburn 15513: sub modify_coursedefaults {
1.160.6.27 raeburn 15514: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 15515: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 15516: my %defaultchecked = (
15517: 'uselcmath' => 'on',
15518: 'usejsme' => 'on'
15519: );
15520: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 15521: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 15522: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
15523: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 15524: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 15525: my %staticdefaults = (
15526: anonsurvey_threshold => 10,
15527: uploadquota => 500,
1.160.6.57 raeburn 15528: postsubmit => 60,
1.160.6.70 raeburn 15529: mysqltables => 172800,
1.160.6.21 raeburn 15530: );
1.160.6.90 raeburn 15531: my %texoptions = (
15532: MathJax => 'MathJax',
15533: mimetex => &mt('Convert to Images'),
15534: tth => &mt('TeX to HTML'),
15535: );
1.121 raeburn 15536: $defaultshash{'coursedefaults'} = {};
15537:
15538: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
15539: if ($domconfig{'coursedefaults'} eq '') {
15540: $domconfig{'coursedefaults'} = {};
15541: }
15542: }
15543:
15544: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
15545: foreach my $item (@toggles) {
15546: if ($defaultchecked{$item} eq 'on') {
15547: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15548: ($env{'form.'.$item} eq '0')) {
15549: $changes{$item} = 1;
1.160.6.16 raeburn 15550: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 15551: $changes{$item} = 1;
15552: }
15553: } elsif ($defaultchecked{$item} eq 'off') {
15554: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15555: ($env{'form.'.$item} eq '1')) {
15556: $changes{$item} = 1;
15557: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
15558: $changes{$item} = 1;
15559: }
15560: }
15561: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
15562: }
1.160.6.21 raeburn 15563: foreach my $item (@numbers) {
15564: my ($currdef,$newdef);
1.160.6.26 raeburn 15565: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 15566: if ($item eq 'anonsurvey_threshold') {
15567: $currdef = $domconfig{'coursedefaults'}{$item};
15568: $newdef =~ s/\D//g;
15569: if ($newdef eq '' || $newdef < 1) {
15570: $newdef = 1;
15571: }
15572: $defaultshash{'coursedefaults'}{$item} = $newdef;
15573: } else {
1.160.6.70 raeburn 15574: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
15575: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
15576: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 15577: }
15578: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 15579: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 15580: }
15581: if ($currdef ne $newdef) {
15582: if ($item eq 'anonsurvey_threshold') {
15583: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
15584: $changes{$item} = 1;
15585: }
1.160.6.70 raeburn 15586: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
15587: my $setting = $1;
15588: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
15589: $changes{$setting} = 1;
1.160.6.21 raeburn 15590: }
15591: }
1.139 raeburn 15592: }
15593: }
1.160.6.90 raeburn 15594: my $texengine;
15595: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
15596: $texengine = $env{'form.texengine'};
15597: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
15598: if ($currdef eq '') {
15599: unless ($texengine eq $Apache::lonnet::deftex) {
15600: $changes{'texengine'} = 1;
15601: }
15602: } elsif ($currdef ne $texengine) {
15603: $changes{'texengine'} = 1;
15604: }
15605: }
15606: if ($texengine ne '') {
15607: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
15608: }
1.160.6.64 raeburn 15609: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
15610: my @currclonecode;
15611: if (ref($currclone) eq 'HASH') {
15612: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
15613: @currclonecode = @{$currclone->{'instcode'}};
15614: }
15615: }
15616: my $newclone;
15617: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
15618: $newclone = $env{'form.canclone'};
15619: }
15620: if ($newclone eq 'instcode') {
15621: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
15622: my (%codedefaults,@code_order,@clonecode);
15623: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
15624: \@code_order);
15625: foreach my $item (@code_order) {
15626: if (grep(/^\Q$item\E$/,@newcodes)) {
15627: push(@clonecode,$item);
15628: }
15629: }
15630: if (@clonecode) {
15631: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
15632: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
15633: if (@diffs) {
15634: $changes{'canclone'} = 1;
15635: }
15636: } else {
15637: $newclone eq '';
15638: }
15639: } elsif ($newclone ne '') {
15640: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
15641: }
15642: if ($newclone ne $currclone) {
15643: $changes{'canclone'} = 1;
15644: }
1.160.6.57 raeburn 15645: my %credits;
15646: foreach my $type (@types) {
15647: unless ($type eq 'community') {
15648: $credits{$type} = $env{'form.'.$type.'_credits'};
15649: $credits{$type} =~ s/[^\d.]+//g;
15650: }
15651: }
15652: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
15653: ($env{'form.coursecredits'} eq '1')) {
15654: $changes{'coursecredits'} = 1;
15655: foreach my $type (keys(%credits)) {
15656: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15657: }
15658: } else {
15659: if ($env{'form.coursecredits'} eq '1') {
15660: foreach my $type (@types) {
15661: unless ($type eq 'community') {
15662: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
15663: $changes{'coursecredits'} = 1;
15664: }
15665: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15666: }
15667: }
15668: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15669: foreach my $type (@types) {
15670: unless ($type eq 'community') {
15671: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
15672: $changes{'coursecredits'} = 1;
15673: last;
15674: }
15675: }
15676: }
15677: }
15678: }
15679: if ($env{'form.postsubmit'} eq '1') {
15680: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
15681: my %currtimeout;
15682: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15683: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
15684: $changes{'postsubmit'} = 1;
15685: }
15686: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15687: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
15688: }
15689: } else {
15690: $changes{'postsubmit'} = 1;
15691: }
15692: foreach my $type (@types) {
15693: my $timeout = $env{'form.'.$type.'_timeout'};
15694: $timeout =~ s/\D//g;
15695: if ($timeout == $staticdefaults{'postsubmit'}) {
15696: $timeout = '';
15697: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
15698: $timeout = '0';
15699: }
15700: unless ($timeout eq '') {
15701: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
15702: }
15703: if (exists($currtimeout{$type})) {
15704: if ($timeout ne $currtimeout{$type}) {
15705: $changes{'postsubmit'} = 1;
15706: }
15707: } elsif ($timeout ne '') {
15708: $changes{'postsubmit'} = 1;
15709: }
15710: }
15711: } else {
15712: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
15713: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15714: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
15715: $changes{'postsubmit'} = 1;
15716: }
15717: } else {
15718: $changes{'postsubmit'} = 1;
15719: }
1.160.6.16 raeburn 15720: }
1.121 raeburn 15721: }
15722: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15723: $dom);
15724: if ($putresult eq 'ok') {
15725: if (keys(%changes) > 0) {
1.160.6.27 raeburn 15726: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 15727: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 15728: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.90 raeburn 15729: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
15730: foreach my $item ('uselcmath','usejsme','texengine') {
1.160.6.57 raeburn 15731: if ($changes{$item}) {
15732: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
15733: }
1.160.6.16 raeburn 15734: }
15735: if ($changes{'coursecredits'}) {
15736: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 15737: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
15738: $domdefaults{$type.'credits'} =
15739: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
15740: }
15741: }
15742: }
15743: if ($changes{'postsubmit'}) {
15744: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15745: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
15746: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15747: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
15748: $domdefaults{$type.'postsubtimeout'} =
15749: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15750: }
15751: }
1.160.6.16 raeburn 15752: }
15753: }
1.160.6.21 raeburn 15754: if ($changes{'uploadquota'}) {
15755: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15756: foreach my $type (@types) {
15757: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
15758: }
15759: }
15760: }
1.160.6.64 raeburn 15761: if ($changes{'canclone'}) {
15762: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15763: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15764: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
15765: if (@clonecodes) {
15766: $domdefaults{'canclone'} = join('+',@clonecodes);
15767: }
15768: }
15769: } else {
15770: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
15771: }
15772: }
1.121 raeburn 15773: my $cachetime = 24*60*60;
15774: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 15775: if (ref($lastactref) eq 'HASH') {
15776: $lastactref->{'domdefaults'} = 1;
15777: }
1.121 raeburn 15778: }
15779: $resulttext = &mt('Changes made:').'<ul>';
15780: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 15781: if ($item eq 'uselcmath') {
1.121 raeburn 15782: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 15783: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 15784: } else {
1.160.6.57 raeburn 15785: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
15786: }
15787: } elsif ($item eq 'usejsme') {
15788: if ($env{'form.'.$item} eq '1') {
15789: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
15790: } else {
15791: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 15792: }
1.160.6.90 raeburn 15793: } elsif ($item eq 'texengine') {
15794: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
15795: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
15796: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
15797: }
1.139 raeburn 15798: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 15799: $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 15800: } elsif ($item eq 'uploadquota') {
15801: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15802: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
15803: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
15804: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 15805: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
15806:
1.160.6.21 raeburn 15807: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
15808: '</ul>'.
15809: '</li>';
15810: } else {
15811: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
15812: }
1.160.6.70 raeburn 15813: } elsif ($item eq 'mysqltables') {
15814: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
15815: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
15816: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
15817: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
15818: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
15819: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
15820: '</ul>'.
15821: '</li>';
15822: } else {
15823: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
15824: }
1.160.6.57 raeburn 15825: } elsif ($item eq 'postsubmit') {
15826: if ($domdefaults{'postsubmit'} eq 'off') {
15827: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
15828: } else {
15829: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
15830: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15831: $resulttext .= &mt('durations:').'<ul>';
15832: foreach my $type (@types) {
15833: $resulttext .= '<li>';
15834: my $timeout;
15835: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15836: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15837: }
15838: my $display;
15839: if ($timeout eq '0') {
15840: $display = &mt('unlimited');
15841: } elsif ($timeout eq '') {
15842: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
15843: } else {
15844: $display = &mt('[quant,_1,second]',$timeout);
15845: }
15846: if ($type eq 'community') {
15847: $resulttext .= &mt('Communities');
15848: } elsif ($type eq 'official') {
15849: $resulttext .= &mt('Official courses');
15850: } elsif ($type eq 'unofficial') {
15851: $resulttext .= &mt('Unofficial courses');
15852: } elsif ($type eq 'textbook') {
15853: $resulttext .= &mt('Textbook courses');
15854: }
15855: $resulttext .= ' -- '.$display.'</li>';
15856: }
15857: $resulttext .= '</ul>';
15858: }
15859: $resulttext .= '</li>';
15860: }
1.160.6.16 raeburn 15861: } elsif ($item eq 'coursecredits') {
15862: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15863: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 15864: ($domdefaults{'unofficialcredits'} eq '') &&
15865: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 15866: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15867: } else {
15868: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
15869: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
15870: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 15871: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 15872: '</ul>'.
15873: '</li>';
15874: }
15875: } else {
15876: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15877: }
1.160.6.64 raeburn 15878: } elsif ($item eq 'canclone') {
15879: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15880: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15881: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
15882: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
15883: }
15884: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
15885: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
15886: } else {
15887: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
15888: }
1.140 raeburn 15889: }
1.121 raeburn 15890: }
15891: $resulttext .= '</ul>';
15892: } else {
15893: $resulttext = &mt('No changes made to course defaults');
15894: }
15895: } else {
15896: $resulttext = '<span class="LC_error">'.
15897: &mt('An error occurred: [_1]',$putresult).'</span>';
15898: }
15899: return $resulttext;
15900: }
15901:
1.160.6.37 raeburn 15902: sub modify_selfenrollment {
15903: my ($dom,$lastactref,%domconfig) = @_;
15904: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
15905: my @types = ('official','unofficial','community','textbook');
15906: my %titles = &tool_titles();
15907: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
15908: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
15909: $ordered{'default'} = ['types','registered','approval','limit'];
15910:
15911: my (%roles,%shown,%toplevel);
15912: $roles{'0'} = &Apache::lonnet::plaintext('dc');
15913:
15914: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
15915: if ($domconfig{'selfenrollment'} eq '') {
15916: $domconfig{'selfenrollment'} = {};
15917: }
15918: }
15919: %toplevel = (
15920: admin => 'Configuration Rights',
15921: default => 'Default settings',
15922: validation => 'Validation of self-enrollment requests',
15923: );
15924: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
15925:
15926: if (ref($ordered{'admin'}) eq 'ARRAY') {
15927: foreach my $item (@{$ordered{'admin'}}) {
15928: foreach my $type (@types) {
15929: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
15930: $selfenrollhash{'admin'}{$type}{$item} = 1;
15931: } else {
15932: $selfenrollhash{'admin'}{$type}{$item} = 0;
15933: }
15934: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
15935: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
15936: if ($selfenrollhash{'admin'}{$type}{$item} ne
15937: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
15938: push(@{$changes{'admin'}{$type}},$item);
15939: }
15940: } else {
15941: if (!$selfenrollhash{'admin'}{$type}{$item}) {
15942: push(@{$changes{'admin'}{$type}},$item);
15943: }
15944: }
15945: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
15946: push(@{$changes{'admin'}{$type}},$item);
15947: }
15948: }
15949: }
15950: }
15951:
15952: foreach my $item (@{$ordered{'default'}}) {
15953: foreach my $type (@types) {
15954: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
15955: if ($item eq 'types') {
15956: unless (($value eq 'all') || ($value eq 'dom')) {
15957: $value = '';
15958: }
15959: } elsif ($item eq 'registered') {
15960: unless ($value eq '1') {
15961: $value = 0;
15962: }
15963: } elsif ($item eq 'approval') {
15964: unless ($value =~ /^[012]$/) {
15965: $value = 0;
15966: }
15967: } else {
15968: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15969: $value = 'none';
15970: }
15971: }
15972: $selfenrollhash{'default'}{$type}{$item} = $value;
15973: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
15974: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15975: if ($selfenrollhash{'default'}{$type}{$item} ne
15976: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
15977: push(@{$changes{'default'}{$type}},$item);
15978: }
15979: } else {
15980: push(@{$changes{'default'}{$type}},$item);
15981: }
15982: } else {
15983: push(@{$changes{'default'}{$type}},$item);
15984: }
15985: if ($item eq 'limit') {
15986: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15987: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
15988: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
15989: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
15990: }
15991: } else {
15992: $selfenrollhash{'default'}{$type}{'cap'} = '';
15993: }
15994: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15995: if ($selfenrollhash{'default'}{$type}{'cap'} ne
15996: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
15997: push(@{$changes{'default'}{$type}},'cap');
15998: }
15999: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
16000: push(@{$changes{'default'}{$type}},'cap');
16001: }
16002: }
16003: }
16004: }
16005:
16006: foreach my $item (@{$itemsref}) {
16007: if ($item eq 'fields') {
16008: my @changed;
16009: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
16010: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
16011: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
16012: }
16013: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
16014: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
16015: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
16016: $domconfig{'selfenrollment'}{'validation'}{$item});
16017: } else {
16018: @changed = @{$selfenrollhash{'validation'}{$item}};
16019: }
16020: } else {
16021: @changed = @{$selfenrollhash{'validation'}{$item}};
16022: }
16023: if (@changed) {
16024: if ($selfenrollhash{'validation'}{$item}) {
16025: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
16026: } else {
16027: $changes{'validation'}{$item} = &mt('None');
16028: }
16029: }
16030: } else {
16031: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
16032: if ($item eq 'markup') {
16033: if ($env{'form.selfenroll_validation_'.$item}) {
16034: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
16035: }
16036: }
16037: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
16038: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
16039: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
16040: }
16041: }
16042: }
16043: }
16044:
16045: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
16046: $dom);
16047: if ($putresult eq 'ok') {
16048: if (keys(%changes) > 0) {
16049: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16050: $resulttext = &mt('Changes made:').'<ul>';
16051: foreach my $key ('admin','default','validation') {
16052: if (ref($changes{$key}) eq 'HASH') {
16053: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
16054: if ($key eq 'validation') {
16055: foreach my $item (@{$itemsref}) {
16056: if (exists($changes{$key}{$item})) {
16057: if ($item eq 'markup') {
16058: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
16059: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
16060: } else {
16061: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
16062: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
16063: }
16064: }
16065: }
16066: } else {
16067: foreach my $type (@types) {
16068: if ($type eq 'community') {
16069: $roles{'1'} = &mt('Community personnel');
16070: } else {
16071: $roles{'1'} = &mt('Course personnel');
16072: }
16073: if (ref($changes{$key}{$type}) eq 'ARRAY') {
16074: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
16075: if ($key eq 'admin') {
16076: my @mgrdc = ();
16077: if (ref($ordered{$key}) eq 'ARRAY') {
16078: foreach my $item (@{$ordered{'admin'}}) {
16079: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
16080: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
16081: push(@mgrdc,$item);
16082: }
16083: }
16084: }
16085: if (@mgrdc) {
16086: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
16087: } else {
16088: delete($domdefaults{$type.'selfenrolladmdc'});
16089: }
16090: }
16091: } else {
16092: if (ref($ordered{$key}) eq 'ARRAY') {
16093: foreach my $item (@{$ordered{$key}}) {
16094: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
16095: $domdefaults{$type.'selfenroll'.$item} =
16096: $selfenrollhash{$key}{$type}{$item};
16097: }
16098: }
16099: }
16100: }
16101: }
16102: $resulttext .= '<li>'.$titles{$type}.'<ul>';
16103: foreach my $item (@{$ordered{$key}}) {
16104: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
16105: $resulttext .= '<li>';
16106: if ($key eq 'admin') {
16107: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
16108: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
16109: } else {
16110: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
16111: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
16112: }
16113: $resulttext .= '</li>';
16114: }
16115: }
16116: $resulttext .= '</ul></li>';
16117: }
16118: }
16119: $resulttext .= '</ul></li>';
16120: }
16121: }
1.160.6.93 raeburn 16122: }
16123: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
16124: my $cachetime = 24*60*60;
16125: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16126: if (ref($lastactref) eq 'HASH') {
16127: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 16128: }
16129: }
16130: $resulttext .= '</ul>';
16131: } else {
16132: $resulttext = &mt('No changes made to self-enrollment settings');
16133: }
16134: } else {
16135: $resulttext = '<span class="LC_error">'.
16136: &mt('An error occurred: [_1]',$putresult).'</span>';
16137: }
16138: return $resulttext;
16139: }
16140:
1.160.6.113 raeburn 16141: sub modify_wafproxy {
16142: my ($dom,$action,$lastactref,%domconfig) = @_;
16143: my %servers = &Apache::lonnet::internet_dom_servers($dom);
16144: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
16145: %wafproxy,%changes,%expirecache,%expiresaml);
16146: foreach my $server (sort(keys(%servers))) {
16147: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
16148: if ($serverhome eq $server) {
16149: my $serverdom = &Apache::lonnet::host_domain($server);
16150: if ($serverdom eq $dom) {
16151: $canset{$server} = 1;
16152: }
16153: }
16154: }
16155: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
16156: %{$values{$dom}} = ();
16157: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
16158: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
16159: }
16160: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
16161: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
16162: }
16163: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
16164: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
16165: }
16166: }
16167: my $output;
16168: if (keys(%canset)) {
16169: %{$wafproxy{'alias'}} = ();
16170: %{$wafproxy{'saml'}} = ();
16171: foreach my $key (sort(keys(%canset))) {
16172: if ($env{'form.wafproxy_'.$dom}) {
16173: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
16174: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
16175: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
16176: $changes{'alias'} = 1;
16177: }
16178: if ($env{'form.wafproxy_alias_saml_'.$key}) {
16179: $wafproxy{'saml'}{$key} = 1;
16180: }
16181: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
16182: $changes{'saml'} = 1;
16183: }
16184: } else {
16185: $wafproxy{'alias'}{$key} = '';
16186: $wafproxy{'saml'}{$key} = '';
16187: if ($curralias{$key}) {
16188: $changes{'alias'} = 1;
16189: }
16190: if ($currsaml{$key}) {
16191: $changes{'saml'} = 1;
16192: }
16193: }
16194: if ($wafproxy{'alias'}{$key} eq '') {
16195: if ($curralias{$key}) {
16196: $expirecache{$key} = 1;
16197: }
16198: delete($wafproxy{'alias'}{$key});
16199: }
16200: if ($wafproxy{'saml'}{$key} eq '') {
16201: if ($currsaml{$key}) {
16202: $expiresaml{$key} = 1;
16203: }
16204: delete($wafproxy{'saml'}{$key});
16205: }
16206: }
16207: unless (keys(%{$wafproxy{'alias'}})) {
16208: delete($wafproxy{'alias'});
16209: }
16210: unless (keys(%{$wafproxy{'saml'}})) {
16211: delete($wafproxy{'saml'});
16212: }
16213: # Localization for values in %warn occurs in &mt() calls separately.
16214: my %warn = (
16215: trusted => 'trusted IP range(s)',
16216: vpnint => 'internal IP range(s) for VPN sessions(s)',
16217: vpnext => 'IP range(s) for backend WAF connections',
16218: );
16219: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
16220: my $possible = $env{'form.wafproxy_'.$item};
16221: $possible =~ s/^\s+|\s+$//g;
16222: if ($possible ne '') {
16223: if ($item eq 'remoteip') {
16224: if ($possible =~ /^[mhn]$/) {
16225: $wafproxy{$item} = $possible;
16226: }
16227: } elsif ($item eq 'ipheader') {
16228: if ($wafproxy{'remoteip'} eq 'h') {
16229: $wafproxy{$item} = $possible;
16230: }
16231: } elsif ($item eq 'sslopt') {
16232: if ($possible =~ /^0|1$/) {
16233: $wafproxy{$item} = $possible;
16234: }
16235: } else {
16236: my (@ok,$count);
16237: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
16238: unless ($env{'form.wafproxy_vpnaccess'}) {
16239: $possible = '';
16240: }
16241: } elsif ($item eq 'trusted') {
16242: unless ($wafproxy{'remoteip'} eq 'h') {
16243: $possible = '';
16244: }
16245: }
16246: unless ($possible eq '') {
16247: $possible =~ s/[\r\n]+/\s/g;
16248: $possible =~ s/\s*-\s*/-/g;
16249: $possible =~ s/\s+/,/g;
16250: $possible =~ s/,+/,/g;
16251: }
16252: $count = 0;
16253: if ($possible ne '') {
16254: foreach my $poss (split(/\,/,$possible)) {
16255: $count ++;
16256: $poss = &validate_ip_pattern($poss);
16257: if ($poss ne '') {
16258: push(@ok,$poss);
16259: }
16260: }
16261: my $diff = $count - scalar(@ok);
16262: if ($diff) {
16263: push(@warnings,'<li>'.
16264: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
16265: $diff,$warn{$item}).
16266: '</li>');
16267: }
16268: if (@ok) {
16269: my @cidr_list;
16270: foreach my $item (@ok) {
16271: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
16272: }
16273: $wafproxy{$item} = join(',',@cidr_list);
16274: }
16275: }
16276: }
16277: if ($wafproxy{$item} ne $currvalue{$item}) {
16278: $changes{$item} = 1;
16279: }
16280: } elsif ($currvalue{$item}) {
16281: $changes{$item} = 1;
16282: }
16283: }
16284: } else {
16285: if (keys(%curralias)) {
16286: $changes{'alias'} = 1;
16287: }
16288: if (keys(%currsaml)) {
16289: $changes{'saml'} = 1;
16290: }
16291: if (keys(%currvalue)) {
16292: foreach my $key (keys(%currvalue)) {
16293: $changes{$key} = 1;
16294: }
16295: }
16296: }
16297: if (keys(%changes)) {
16298: my %defaultshash = (
16299: wafproxy => \%wafproxy,
16300: );
16301: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16302: $dom);
16303: if ($putresult eq 'ok') {
16304: my $cachetime = 24*60*60;
16305: my (%domdefaults,$updatedomdefs);
16306: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
16307: if ($changes{$item}) {
16308: unless ($updatedomdefs) {
16309: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
16310: $updatedomdefs = 1;
16311: }
16312: if ($wafproxy{$item}) {
16313: $domdefaults{'waf_'.$item} = $wafproxy{$item};
16314: } elsif (exists($domdefaults{'waf_'.$item})) {
16315: delete($domdefaults{'waf_'.$item});
16316: }
16317: }
16318: }
16319: if ($updatedomdefs) {
16320: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16321: if (ref($lastactref) eq 'HASH') {
16322: $lastactref->{'domdefaults'} = 1;
16323: }
16324: }
16325: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
16326: my %updates = %expirecache;
16327: foreach my $key (keys(%expirecache)) {
16328: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
16329: }
16330: if (ref($wafproxy{'alias'}) eq 'HASH') {
16331: my $cachetime = 24*60*60;
16332: foreach my $key (keys(%{$wafproxy{'alias'}})) {
16333: $updates{$key} = 1;
16334: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
16335: $cachetime);
16336: }
16337: }
16338: if (ref($lastactref) eq 'HASH') {
16339: $lastactref->{'proxyalias'} = \%updates;
16340: }
16341: }
16342: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
16343: my %samlupdates = %expiresaml;
16344: foreach my $key (keys(%expiresaml)) {
16345: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
16346: }
16347: if (ref($wafproxy{'saml'}) eq 'HASH') {
16348: my $cachetime = 24*60*60;
16349: foreach my $key (keys(%{$wafproxy{'saml'}})) {
16350: $samlupdates{$key} = 1;
16351: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
16352: $cachetime);
16353: }
16354: }
16355: if (ref($lastactref) eq 'HASH') {
16356: $lastactref->{'proxysaml'} = \%samlupdates;
16357: }
16358: }
16359: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
16360: foreach my $item ('alias','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
16361: if ($changes{$item}) {
16362: if ($item eq 'alias') {
16363: my $numaliased = 0;
16364: if (ref($wafproxy{'alias'}) eq 'HASH') {
16365: my $shown;
16366: if (keys(%{$wafproxy{'alias'}})) {
16367: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
16368: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
16369: &Apache::lonnet::hostname($server),
16370: $wafproxy{'alias'}{$server}).'</li>';
16371: $numaliased ++;
16372: }
16373: if ($numaliased) {
16374: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
16375: '<ul>'.$shown.'</ul>').'</li>';
16376: }
16377: }
16378: }
16379: unless ($numaliased) {
16380: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
16381: }
16382: } elsif ($item eq 'saml') {
16383: my $shown;
16384: if (ref($wafproxy{'saml'}) eq 'HASH') {
16385: if (keys(%{$wafproxy{'saml'}})) {
16386: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
16387: }
16388: }
16389: if ($shown) {
16390: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
16391: $shown).'</li>';
16392: } else {
16393: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
16394: }
16395: } else {
16396: if ($item eq 'remoteip') {
16397: my %ip_methods = &remoteip_methods();
16398: if ($wafproxy{$item} =~ /^[mh]$/) {
16399: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
16400: $ip_methods{$wafproxy{$item}}).'</li>';
16401: } else {
16402: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
16403: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
16404: '</li>';
16405: } else {
16406: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
16407: }
16408: }
16409: } elsif ($item eq 'ipheader') {
16410: if ($wafproxy{$item}) {
16411: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
16412: $wafproxy{$item}).'</li>';
16413: } else {
16414: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
16415: }
16416: } elsif ($item eq 'trusted') {
16417: if ($wafproxy{$item}) {
16418: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
16419: $wafproxy{$item}).'</li>';
16420: } else {
16421: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
16422: }
16423: } elsif ($item eq 'vpnint') {
16424: if ($wafproxy{$item}) {
16425: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
16426: $wafproxy{$item}).'</li>';
16427: } else {
16428: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
16429: }
16430: } elsif ($item eq 'vpnext') {
16431: if ($wafproxy{$item}) {
16432: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
16433: $wafproxy{$item}).'</li>';
16434: } else {
16435: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
16436: }
16437: } elsif ($item eq 'sslopt') {
16438: if ($wafproxy{$item}) {
16439: $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>';
16440: } else {
16441: $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>';
16442: }
16443: }
16444: }
16445: }
16446: }
16447: } else {
16448: $output = '<span class="LC_error">'.
16449: &mt('An error occurred: [_1]',$putresult).'</span>';
16450: }
16451: } elsif (keys(%canset)) {
16452: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
16453: }
16454: if (@warnings) {
16455: $output .= '<br />'.&mt('Warnings:').'<ul>'.
16456: join("\n",@warnings).'</ul>';
16457: }
16458: return $output;
16459: }
16460:
16461: sub validate_ip_pattern {
16462: my ($pattern) = @_;
16463: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
16464: my ($start,$end) = ($1,$2);
16465: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
16466: if (($start !~ m{/}) && ($end !~ m{/})) {
16467: return $start.'-'.$end;
16468: }
16469: }
16470: } elsif ($pattern ne '') {
16471: $pattern = &Net::CIDR::cidrvalidate($pattern);
16472: if ($pattern ne '') {
16473: return $pattern;
16474: }
16475: }
16476: return;
16477: }
16478:
1.137 raeburn 16479: sub modify_usersessions {
1.160.6.27 raeburn 16480: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 16481: my @hostingtypes = ('version','excludedomain','includedomain');
16482: my @offloadtypes = ('primary','default');
16483: my %types = (
16484: remote => \@hostingtypes,
16485: hosted => \@hostingtypes,
16486: spares => \@offloadtypes,
16487: );
16488: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 16489: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 16490: my (%by_ip,%by_location,@intdoms);
16491: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
16492: my @locations = sort(keys(%by_location));
1.137 raeburn 16493: my (%defaultshash,%changes);
16494: foreach my $prefix (@prefixes) {
16495: $defaultshash{'usersessions'}{$prefix} = {};
16496: }
1.160.6.27 raeburn 16497: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 16498: my $resulttext;
1.138 raeburn 16499: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 16500: foreach my $prefix (@prefixes) {
1.145 raeburn 16501: next if ($prefix eq 'spares');
16502: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 16503: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16504: if ($type eq 'version') {
16505: my $value = $env{'form.'.$prefix.'_'.$type};
16506: my $okvalue;
16507: if ($value ne '') {
16508: if (grep(/^\Q$value\E$/,@lcversions)) {
16509: $okvalue = $value;
16510: }
16511: }
16512: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16513: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16514: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
16515: if ($inuse == 0) {
16516: $changes{$prefix}{$type} = 1;
16517: } else {
16518: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
16519: $changes{$prefix}{$type} = 1;
16520: }
16521: if ($okvalue ne '') {
16522: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16523: }
16524: }
16525: } else {
16526: if (($inuse == 1) && ($okvalue ne '')) {
16527: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16528: $changes{$prefix}{$type} = 1;
16529: }
16530: }
16531: } else {
16532: if (($inuse == 1) && ($okvalue ne '')) {
16533: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16534: $changes{$prefix}{$type} = 1;
16535: }
16536: }
16537: } else {
16538: if (($inuse == 1) && ($okvalue ne '')) {
16539: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16540: $changes{$prefix}{$type} = 1;
16541: }
16542: }
16543: } else {
16544: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16545: my @okvals;
16546: foreach my $val (@vals) {
1.138 raeburn 16547: if ($val =~ /:/) {
16548: my @items = split(/:/,$val);
16549: foreach my $item (@items) {
16550: if (ref($by_location{$item}) eq 'ARRAY') {
16551: push(@okvals,$item);
16552: }
16553: }
16554: } else {
16555: if (ref($by_location{$val}) eq 'ARRAY') {
16556: push(@okvals,$val);
16557: }
1.137 raeburn 16558: }
16559: }
16560: @okvals = sort(@okvals);
16561: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16562: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16563: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16564: if ($inuse == 0) {
16565: $changes{$prefix}{$type} = 1;
16566: } else {
16567: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16568: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
16569: if (@changed > 0) {
16570: $changes{$prefix}{$type} = 1;
16571: }
16572: }
16573: } else {
16574: if ($inuse == 1) {
16575: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16576: $changes{$prefix}{$type} = 1;
16577: }
16578: }
16579: } else {
16580: if ($inuse == 1) {
16581: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16582: $changes{$prefix}{$type} = 1;
16583: }
16584: }
16585: } else {
16586: if ($inuse == 1) {
16587: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16588: $changes{$prefix}{$type} = 1;
16589: }
16590: }
16591: }
16592: }
16593: }
1.145 raeburn 16594:
16595: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 16596: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 16597: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
16598: my $savespares;
16599:
16600: foreach my $lonhost (sort(keys(%servers))) {
16601: my $serverhomeID =
16602: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 16603: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 16604: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
16605: my %spareschg;
16606: foreach my $type (@{$types{'spares'}}) {
16607: my @okspares;
16608: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
16609: foreach my $server (@checked) {
1.152 raeburn 16610: if (&Apache::lonnet::hostname($server) ne '') {
16611: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
16612: unless (grep(/^\Q$server\E$/,@okspares)) {
16613: push(@okspares,$server);
16614: }
1.145 raeburn 16615: }
16616: }
16617: }
16618: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
16619: my $newspare;
1.152 raeburn 16620: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
16621: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 16622: $newspare = $new;
16623: }
16624: }
1.152 raeburn 16625: my @spares;
16626: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
16627: @spares = sort(@okspares,$newspare);
16628: } else {
16629: @spares = sort(@okspares);
16630: }
16631: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 16632: if (ref($spareid{$lonhost}) eq 'HASH') {
16633: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 16634: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 16635: if (@diffs > 0) {
16636: $spareschg{$type} = 1;
16637: }
16638: }
16639: }
16640: }
16641: if (keys(%spareschg) > 0) {
16642: $changes{'spares'}{$lonhost} = \%spareschg;
16643: }
16644: }
1.160.6.61 raeburn 16645: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.160.6.105 raeburn 16646: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.160.6.61 raeburn 16647: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
16648: my @okoffload;
16649: if (@offloadnow) {
16650: foreach my $server (@offloadnow) {
16651: if (&Apache::lonnet::hostname($server) ne '') {
16652: unless (grep(/^\Q$server\E$/,@okoffload)) {
16653: push(@okoffload,$server);
16654: }
16655: }
16656: }
16657: if (@okoffload) {
16658: foreach my $lonhost (@okoffload) {
16659: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
16660: }
16661: }
16662: }
1.160.6.105 raeburn 16663: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
16664: my @okoffloadoth;
16665: if (@offloadoth) {
16666: foreach my $server (@offloadoth) {
16667: if (&Apache::lonnet::hostname($server) ne '') {
16668: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
16669: push(@okoffloadoth,$server);
16670: }
16671: }
16672: }
16673: if (@okoffloadoth) {
16674: foreach my $lonhost (@okoffloadoth) {
16675: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
16676: }
16677: }
16678: }
1.145 raeburn 16679: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16680: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
16681: if (ref($changes{'spares'}) eq 'HASH') {
16682: if (keys(%{$changes{'spares'}}) > 0) {
16683: $savespares = 1;
16684: }
16685: }
16686: } else {
16687: $savespares = 1;
16688: }
1.160.6.105 raeburn 16689: foreach my $offload ('offloadnow','offloadoth') {
16690: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
16691: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
16692: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
16693: $changes{$offload} = 1;
1.160.6.61 raeburn 16694: last;
16695: }
16696: }
1.160.6.105 raeburn 16697: unless ($changes{$offload}) {
16698: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
16699: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
16700: $changes{$offload} = 1;
16701: last;
16702: }
16703: }
16704: }
16705: } else {
16706: if (($offload eq 'offloadnow') && (@okoffload)) {
16707: $changes{'offloadnow'} = 1;
16708: }
16709: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
16710: $changes{'offloadoth'} = 1;
16711: }
1.160.6.61 raeburn 16712: }
1.160.6.105 raeburn 16713: }
16714: } else {
16715: if (@okoffload) {
1.160.6.61 raeburn 16716: $changes{'offloadnow'} = 1;
16717: }
1.160.6.105 raeburn 16718: if (@okoffloadoth) {
16719: $changes{'offloadoth'} = 1;
16720: }
1.145 raeburn 16721: }
1.147 raeburn 16722: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
16723: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 16724: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16725: $dom);
16726: if ($putresult eq 'ok') {
16727: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16728: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
16729: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
16730: }
16731: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
16732: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
16733: }
1.160.6.61 raeburn 16734: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16735: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
16736: }
1.160.6.105 raeburn 16737: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
16738: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
16739: }
1.137 raeburn 16740: }
16741: my $cachetime = 24*60*60;
16742: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 16743: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 16744: if (ref($lastactref) eq 'HASH') {
16745: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 16746: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 16747: }
1.147 raeburn 16748: if (keys(%changes) > 0) {
16749: my %lt = &usersession_titles();
16750: $resulttext = &mt('Changes made:').'<ul>';
16751: foreach my $prefix (@prefixes) {
16752: if (ref($changes{$prefix}) eq 'HASH') {
16753: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16754: if ($prefix eq 'spares') {
16755: if (ref($changes{$prefix}) eq 'HASH') {
16756: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
16757: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 16758: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 16759: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
16760: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 16761: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
16762: foreach my $type (@{$types{$prefix}}) {
16763: if ($changes{$prefix}{$lonhost}{$type}) {
16764: my $offloadto = &mt('None');
16765: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
16766: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
16767: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
16768: }
1.145 raeburn 16769: }
1.147 raeburn 16770: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 16771: }
1.137 raeburn 16772: }
16773: }
1.147 raeburn 16774: $resulttext .= '</li>';
1.137 raeburn 16775: }
16776: }
1.147 raeburn 16777: } else {
16778: foreach my $type (@{$types{$prefix}}) {
16779: if (defined($changes{$prefix}{$type})) {
16780: my $newvalue;
16781: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16782: if (ref($defaultshash{'usersessions'}{$prefix})) {
16783: if ($type eq 'version') {
16784: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
16785: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16786: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
16787: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
16788: }
1.145 raeburn 16789: }
16790: }
16791: }
1.147 raeburn 16792: if ($newvalue eq '') {
16793: if ($type eq 'version') {
16794: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
16795: } else {
16796: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16797: }
1.145 raeburn 16798: } else {
1.147 raeburn 16799: if ($type eq 'version') {
16800: $newvalue .= ' '.&mt('(or later)');
16801: }
16802: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 16803: }
1.137 raeburn 16804: }
16805: }
16806: }
1.147 raeburn 16807: $resulttext .= '</ul>';
1.137 raeburn 16808: }
16809: }
1.160.6.61 raeburn 16810: if ($changes{'offloadnow'}) {
16811: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16812: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.160.6.105 raeburn 16813: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.160.6.61 raeburn 16814: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
16815: $resulttext .= '<li>'.$lonhost.'</li>';
16816: }
16817: $resulttext .= '</ul>';
16818: } else {
1.160.6.105 raeburn 16819: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
16820: }
16821: } else {
16822: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
16823: }
16824: }
16825: if ($changes{'offloadoth'}) {
16826: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
16827: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
16828: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
16829: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
16830: $resulttext .= '<li>'.$lonhost.'</li>';
16831: }
16832: $resulttext .= '</ul>';
16833: } else {
16834: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.160.6.61 raeburn 16835: }
16836: } else {
1.160.6.105 raeburn 16837: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.160.6.61 raeburn 16838: }
16839: }
1.147 raeburn 16840: $resulttext .= '</ul>';
16841: } else {
16842: $resulttext = $nochgmsg;
1.137 raeburn 16843: }
16844: } else {
16845: $resulttext = '<span class="LC_error">'.
16846: &mt('An error occurred: [_1]',$putresult).'</span>';
16847: }
16848: } else {
1.147 raeburn 16849: $resulttext = $nochgmsg;
1.137 raeburn 16850: }
16851: return $resulttext;
16852: }
16853:
1.150 raeburn 16854: sub modify_loadbalancing {
16855: my ($dom,%domconfig) = @_;
16856: my $primary_id = &Apache::lonnet::domain($dom,'primary');
16857: my $intdom = &Apache::lonnet::internet_dom($primary_id);
16858: my ($othertitle,$usertypes,$types) =
16859: &Apache::loncommon::sorted_inst_types($dom);
16860: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 16861: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 16862: my @sparestypes = ('primary','default');
16863: my %typetitles = &sparestype_titles();
16864: my $resulttext;
1.160.6.94 raeburn 16865: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 16866: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16867: %existing = %{$domconfig{'loadbalancing'}};
16868: }
16869: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 16870: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 16871: my ($saveloadbalancing,%defaultshash,%changes);
16872: my ($alltypes,$othertypes,$titles) =
16873: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
16874: my %ruletitles = &offloadtype_text();
16875: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
16876: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
16877: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
16878: if ($balancer eq '') {
16879: next;
16880: }
16881: if (!exists($servers{$balancer})) {
16882: if (exists($currbalancer{$balancer})) {
16883: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 16884: }
1.160.6.7 raeburn 16885: next;
16886: }
16887: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
16888: push(@{$changes{'delete'}},$balancer);
16889: next;
16890: }
16891: if (!exists($currbalancer{$balancer})) {
16892: push(@{$changes{'add'}},$balancer);
16893: }
16894: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
16895: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
16896: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
16897: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16898: $saveloadbalancing = 1;
16899: }
16900: foreach my $sparetype (@sparestypes) {
16901: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
16902: my @offloadto;
16903: foreach my $target (@targets) {
16904: if (($servers{$target}) && ($target ne $balancer)) {
16905: if ($sparetype eq 'default') {
16906: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
16907: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 16908: }
16909: }
1.160.6.7 raeburn 16910: unless(grep(/^\Q$target\E$/,@offloadto)) {
16911: push(@offloadto,$target);
16912: }
1.150 raeburn 16913: }
16914: }
1.160.6.76 raeburn 16915: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
16916: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
16917: push(@offloadto,$balancer);
16918: }
16919: }
16920: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 16921: }
1.160.6.94 raeburn 16922: if ($env{'form.loadbalancing_cookie_'.$i}) {
16923: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
16924: if (exists($currbalancer{$balancer})) {
16925: unless ($currcookies{$balancer}) {
16926: $changes{'curr'}{$balancer}{'cookie'} = 1;
16927: }
16928: }
16929: } elsif (exists($currbalancer{$balancer})) {
16930: if ($currcookies{$balancer}) {
16931: $changes{'curr'}{$balancer}{'cookie'} = 1;
16932: }
16933: }
1.160.6.7 raeburn 16934: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 16935: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 16936: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
16937: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 16938: if (@targetdiffs > 0) {
1.160.6.7 raeburn 16939: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16940: }
1.160.6.7 raeburn 16941: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16942: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16943: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16944: }
16945: }
16946: }
16947: } else {
1.160.6.7 raeburn 16948: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
16949: foreach my $sparetype (@sparestypes) {
16950: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16951: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16952: $changes{'curr'}{$balancer}{'targets'} = 1;
16953: }
1.150 raeburn 16954: }
16955: }
1.160.6.7 raeburn 16956: }
1.150 raeburn 16957: }
16958: my $ishomedom;
1.160.6.7 raeburn 16959: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
16960: $ishomedom = 1;
1.150 raeburn 16961: }
16962: if (ref($alltypes) eq 'ARRAY') {
16963: foreach my $type (@{$alltypes}) {
16964: my $rule;
1.160.6.7 raeburn 16965: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 16966: (!$ishomedom)) {
1.160.6.7 raeburn 16967: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
16968: }
16969: if ($rule eq 'specific') {
1.160.6.55 raeburn 16970: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
16971: if (exists($servers{$specifiedhost})) {
16972: $rule = $specifiedhost;
16973: }
1.150 raeburn 16974: }
1.160.6.7 raeburn 16975: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
16976: if (ref($currrules{$balancer}) eq 'HASH') {
16977: if ($rule ne $currrules{$balancer}{$type}) {
16978: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16979: }
16980: } elsif ($rule ne '') {
1.160.6.7 raeburn 16981: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16982: }
16983: }
16984: }
1.160.6.7 raeburn 16985: }
16986: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
16987: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
16988: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
16989: $defaultshash{'loadbalancing'} = {};
16990: }
16991: my $putresult = &Apache::lonnet::put_dom('configuration',
16992: \%defaultshash,$dom);
16993: if ($putresult eq 'ok') {
16994: if (keys(%changes) > 0) {
1.160.6.54 raeburn 16995: my %toupdate;
1.160.6.7 raeburn 16996: if (ref($changes{'delete'}) eq 'ARRAY') {
16997: foreach my $balancer (sort(@{$changes{'delete'}})) {
16998: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 16999: $toupdate{$balancer} = 1;
1.150 raeburn 17000: }
1.160.6.7 raeburn 17001: }
17002: if (ref($changes{'add'}) eq 'ARRAY') {
17003: foreach my $balancer (sort(@{$changes{'add'}})) {
17004: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 17005: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 17006: }
17007: }
17008: if (ref($changes{'curr'}) eq 'HASH') {
17009: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 17010: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 17011: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
17012: if ($changes{'curr'}{$balancer}{'targets'}) {
17013: my %offloadstr;
17014: foreach my $sparetype (@sparestypes) {
17015: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17016: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
17017: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
17018: }
17019: }
1.150 raeburn 17020: }
1.160.6.7 raeburn 17021: if (keys(%offloadstr) == 0) {
17022: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 17023: } else {
1.160.6.7 raeburn 17024: my $showoffload;
17025: foreach my $sparetype (@sparestypes) {
17026: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
17027: if (defined($offloadstr{$sparetype})) {
17028: $showoffload .= $offloadstr{$sparetype};
17029: } else {
17030: $showoffload .= &mt('None');
17031: }
17032: $showoffload .= (' 'x3);
17033: }
17034: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 17035: }
17036: }
17037: }
1.160.6.7 raeburn 17038: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
17039: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
17040: foreach my $type (@{$alltypes}) {
17041: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
17042: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
17043: my $balancetext;
17044: if ($rule eq '') {
17045: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 17046: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 17047: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
17048: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 17049: foreach my $sparetype (@sparestypes) {
17050: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17051: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
17052: }
17053: }
1.160.6.55 raeburn 17054: foreach my $item (@{$alltypes}) {
17055: next if ($item =~ /^_LC_ipchange/);
17056: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
17057: if ($hasrule eq 'homeserver') {
17058: map { $toupdate{$_} = 1; } (keys(%libraryservers));
17059: } else {
17060: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
17061: if ($servers{$hasrule}) {
17062: $toupdate{$hasrule} = 1;
17063: }
17064: }
17065: }
17066: }
17067: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
17068: $balancetext = $ruletitles{$rule};
17069: } else {
17070: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
17071: $balancetext = $ruletitles{'particular'}.' '.$receiver;
17072: if ($receiver) {
17073: $toupdate{$receiver};
17074: }
17075: }
17076: } else {
17077: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 17078: }
1.160.6.7 raeburn 17079: } else {
17080: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
17081: }
1.160.6.26 raeburn 17082: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 17083: }
17084: }
17085: }
17086: }
1.160.6.94 raeburn 17087: if ($changes{'curr'}{$balancer}{'cookie'}) {
17088: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
17089: $balancer).'</li>';
17090: }
1.160.6.106 raeburn 17091: }
17092: }
17093: if (keys(%toupdate)) {
17094: my %thismachine;
17095: my $updatedhere;
17096: my $cachetime = 60*60*24;
17097: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
17098: foreach my $lonhost (keys(%toupdate)) {
17099: if ($thismachine{$lonhost}) {
17100: unless ($updatedhere) {
17101: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
17102: $defaultshash{'loadbalancing'},
17103: $cachetime);
17104: $updatedhere = 1;
1.160.6.54 raeburn 17105: }
1.160.6.106 raeburn 17106: } else {
17107: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
17108: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.160.6.54 raeburn 17109: }
1.150 raeburn 17110: }
1.160.6.7 raeburn 17111: }
17112: if ($resulttext ne '') {
17113: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 17114: } else {
17115: $resulttext = $nochgmsg;
17116: }
17117: } else {
1.160.6.7 raeburn 17118: $resulttext = $nochgmsg;
1.150 raeburn 17119: }
17120: } else {
1.160.6.7 raeburn 17121: $resulttext = '<span class="LC_error">'.
17122: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 17123: }
17124: } else {
1.160.6.7 raeburn 17125: $resulttext = $nochgmsg;
1.150 raeburn 17126: }
17127: return $resulttext;
17128: }
17129:
1.48 raeburn 17130: sub recurse_check {
17131: my ($chkcats,$categories,$depth,$name) = @_;
17132: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
17133: my $chg = 0;
17134: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
17135: my $category = $chkcats->[$depth]{$name}[$j];
17136: my $item;
17137: if ($category eq '') {
17138: $chg ++;
17139: } else {
17140: my $deeper = $depth + 1;
17141: $item = &escape($category).':'.&escape($name).':'.$depth;
17142: if ($chg) {
17143: $categories->{$item} -= $chg;
17144: }
17145: &recurse_check($chkcats,$categories,$deeper,$category);
17146: $deeper --;
17147: }
17148: }
17149: }
17150: return;
17151: }
17152:
17153: sub recurse_cat_deletes {
17154: my ($item,$coursecategories,$deletions) = @_;
17155: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
17156: my $subdepth = $depth + 1;
17157: if (ref($coursecategories) eq 'HASH') {
17158: foreach my $subitem (keys(%{$coursecategories})) {
17159: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
17160: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
17161: delete($coursecategories->{$subitem});
17162: $deletions->{$subitem} = 1;
17163: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 17164: }
1.48 raeburn 17165: }
17166: }
17167: return;
17168: }
17169:
1.125 raeburn 17170: sub active_dc_picker {
1.160.6.16 raeburn 17171: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 17172: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 17173: my @domcoord = keys(%domcoords);
17174: if (keys(%currhash)) {
17175: foreach my $dc (keys(%currhash)) {
17176: unless (exists($domcoords{$dc})) {
17177: push(@domcoord,$dc);
17178: }
17179: }
17180: }
17181: @domcoord = sort(@domcoord);
17182: my $numdcs = scalar(@domcoord);
17183: my $rows = 0;
17184: my $table;
1.125 raeburn 17185: if ($numdcs > 1) {
1.160.6.16 raeburn 17186: $table = '<table>';
17187: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 17188: my $rem = $i%($numinrow);
17189: if ($rem == 0) {
17190: if ($i > 0) {
1.160.6.16 raeburn 17191: $table .= '</tr>';
1.125 raeburn 17192: }
1.160.6.16 raeburn 17193: $table .= '<tr>';
17194: $rows ++;
1.125 raeburn 17195: }
1.160.6.16 raeburn 17196: my $check = '';
17197: if ($inputtype eq 'radio') {
17198: if (keys(%currhash) == 0) {
17199: if (!$i) {
17200: $check = ' checked="checked"';
17201: }
17202: } elsif (exists($currhash{$domcoord[$i]})) {
17203: $check = ' checked="checked"';
17204: }
17205: } else {
17206: if (exists($currhash{$domcoord[$i]})) {
17207: $check = ' checked="checked"';
1.125 raeburn 17208: }
17209: }
1.160.6.16 raeburn 17210: if ($i == @domcoord - 1) {
1.125 raeburn 17211: my $colsleft = $numinrow - $rem;
17212: if ($colsleft > 1) {
1.160.6.16 raeburn 17213: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 17214: } else {
1.160.6.16 raeburn 17215: $table .= '<td class="LC_left_item">';
1.125 raeburn 17216: }
17217: } else {
1.160.6.16 raeburn 17218: $table .= '<td class="LC_left_item">';
17219: }
17220: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
17221: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
17222: $table .= '<span class="LC_nobreak"><label>'.
17223: '<input type="'.$inputtype.'" name="'.$name.'"'.
17224: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
17225: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 17226: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 17227: }
1.160.6.33 raeburn 17228: $table .= '</label></span></td>';
1.125 raeburn 17229: }
1.160.6.16 raeburn 17230: $table .= '</tr></table>';
17231: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 17232: my ($dcname,$dcdom) = split(':',$domcoord[0]);
17233: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 17234: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 17235: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 17236: if ($user ne $dcname.':'.$dcdom) {
17237: $table .= ' ('.$dcname.':'.$dcdom.')';
17238: }
1.160.6.16 raeburn 17239: } else {
17240: my $check;
17241: if (exists($currhash{$domcoord[0]})) {
17242: $check = ' checked="checked"';
17243: }
1.160.6.50 raeburn 17244: $table = '<span class="LC_nobreak"><label>'.
17245: '<input type="checkbox" name="'.$name.'" '.
17246: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 17247: if ($user ne $dcname.':'.$dcdom) {
17248: $table .= ' ('.$dcname.':'.$dcdom.')';
17249: }
17250: $table .= '</label></span>';
1.160.6.16 raeburn 17251: $rows ++;
17252: }
1.125 raeburn 17253: }
1.160.6.16 raeburn 17254: return ($numdcs,$table,$rows);
1.125 raeburn 17255: }
17256:
1.137 raeburn 17257: sub usersession_titles {
17258: return &Apache::lonlocal::texthash(
17259: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
17260: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 17261: spares => 'Servers offloaded to, when busy',
1.137 raeburn 17262: version => 'LON-CAPA version requirement',
1.138 raeburn 17263: excludedomain => 'Allow all, but exclude specific domains',
17264: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 17265: primary => 'Primary (checked first)',
1.154 raeburn 17266: default => 'Default',
1.137 raeburn 17267: );
17268: }
17269:
1.152 raeburn 17270: sub id_for_thisdom {
17271: my (%servers) = @_;
17272: my %altids;
17273: foreach my $server (keys(%servers)) {
17274: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
17275: if ($serverhome ne $server) {
17276: $altids{$serverhome} = $server;
17277: }
17278: }
17279: return %altids;
17280: }
17281:
1.150 raeburn 17282: sub count_servers {
17283: my ($currbalancer,%servers) = @_;
17284: my (@spares,$numspares);
17285: foreach my $lonhost (sort(keys(%servers))) {
17286: next if ($currbalancer eq $lonhost);
17287: push(@spares,$lonhost);
17288: }
17289: if ($currbalancer) {
17290: $numspares = scalar(@spares);
17291: } else {
17292: $numspares = scalar(@spares) - 1;
17293: }
17294: return ($numspares,@spares);
17295: }
17296:
17297: sub lonbalance_targets_js {
1.160.6.7 raeburn 17298: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 17299: my $select = &mt('Select');
17300: my ($alltargets,$allishome,$allinsttypes,@alltypes);
17301: if (ref($servers) eq 'HASH') {
17302: $alltargets = join("','",sort(keys(%{$servers})));
17303: my @homedoms;
17304: foreach my $server (sort(keys(%{$servers}))) {
17305: if (&Apache::lonnet::host_domain($server) eq $dom) {
17306: push(@homedoms,'1');
17307: } else {
17308: push(@homedoms,'0');
17309: }
17310: }
17311: $allishome = join("','",@homedoms);
17312: }
17313: if (ref($types) eq 'ARRAY') {
17314: if (@{$types} > 0) {
17315: @alltypes = @{$types};
17316: }
17317: }
17318: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
17319: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 17320: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 17321: if (ref($settings) eq 'HASH') {
17322: %existing = %{$settings};
17323: }
17324: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 17325: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 17326: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 17327: return <<"END";
17328:
17329: <script type="text/javascript">
17330: // <![CDATA[
17331:
1.160.6.7 raeburn 17332: currBalancers = new Array('$balancers');
17333:
17334: function toggleTargets(balnum) {
17335: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17336: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
17337: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
17338: var prevbalancer = prevhostitem.value;
17339: var baltotal = document.getElementById('loadbalancing_total').value;
17340: prevhostitem.value = balancer;
17341: if (prevbalancer != '') {
17342: var prevIdx = currBalancers.indexOf(prevbalancer);
17343: if (prevIdx != -1) {
17344: currBalancers.splice(prevIdx,1);
17345: }
17346: }
1.150 raeburn 17347: if (balancer == '') {
1.160.6.7 raeburn 17348: hideSpares(balnum);
1.150 raeburn 17349: } else {
1.160.6.7 raeburn 17350: var currIdx = currBalancers.indexOf(balancer);
17351: if (currIdx == -1) {
17352: currBalancers.push(balancer);
17353: }
1.150 raeburn 17354: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 17355: var ishomedom = homedoms[lonhostitem.selectedIndex];
17356: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 17357: }
1.160.6.7 raeburn 17358: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 17359: return;
17360: }
17361:
1.160.6.7 raeburn 17362: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 17363: var alltargets = new Array('$alltargets');
17364: var insttypes = new Array('$allinsttypes');
1.151 raeburn 17365: var offloadtypes = new Array('primary','default');
17366:
1.160.6.7 raeburn 17367: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
17368: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 17369:
1.151 raeburn 17370: for (var i=0; i<offloadtypes.length; i++) {
17371: var count = 0;
17372: for (var j=0; j<alltargets.length; j++) {
17373: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 17374: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
17375: item.value = alltargets[j];
17376: item.style.textAlign='left';
17377: item.style.textFace='normal';
17378: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
17379: if (currBalancers.indexOf(alltargets[j]) == -1) {
17380: item.disabled = '';
17381: } else {
17382: item.disabled = 'disabled';
17383: item.checked = false;
17384: }
1.151 raeburn 17385: count ++;
17386: }
1.150 raeburn 17387: }
17388: }
1.151 raeburn 17389: for (var k=0; k<insttypes.length; k++) {
17390: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 17391: if (ishomedom == 1) {
1.160.6.7 raeburn 17392: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17393: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17394: } else {
1.160.6.7 raeburn 17395: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17396: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 17397: }
17398: } else {
1.160.6.7 raeburn 17399: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17400: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17401: }
1.151 raeburn 17402: if ((insttypes[k] != '_LC_external') &&
17403: ((insttypes[k] != '_LC_internetdom') ||
17404: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 17405: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
17406: item.options.length = 0;
17407: item.options[0] = new Option("","",true,true);
17408: var idx = 0;
1.151 raeburn 17409: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 17410: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
17411: idx ++;
17412: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 17413: }
17414: }
17415: }
17416: }
17417: return;
17418: }
17419:
1.160.6.7 raeburn 17420: function hideSpares(balnum) {
1.150 raeburn 17421: var alltargets = new Array('$alltargets');
17422: var insttypes = new Array('$allinsttypes');
17423: var offloadtypes = new Array('primary','default');
17424:
1.160.6.7 raeburn 17425: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
17426: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 17427:
17428: var total = alltargets.length - 1;
17429: for (var i=0; i<offloadtypes; i++) {
17430: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 17431: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
17432: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
17433: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 17434: }
1.150 raeburn 17435: }
17436: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 17437: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17438: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 17439: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 17440: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
17441: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 17442: }
17443: }
17444: return;
17445: }
17446:
1.160.6.7 raeburn 17447: function checkOffloads(item,balnum,type) {
1.150 raeburn 17448: var alltargets = new Array('$alltargets');
17449: var offloadtypes = new Array('primary','default');
17450: if (item.checked) {
17451: var total = alltargets.length - 1;
17452: var other;
17453: if (type == offloadtypes[0]) {
1.151 raeburn 17454: other = offloadtypes[1];
1.150 raeburn 17455: } else {
1.151 raeburn 17456: other = offloadtypes[0];
1.150 raeburn 17457: }
17458: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 17459: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 17460: if (server == item.value) {
1.160.6.7 raeburn 17461: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
17462: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 17463: }
17464: }
17465: }
17466: }
17467: return;
17468: }
17469:
1.160.6.7 raeburn 17470: function singleServerToggle(balnum,type) {
17471: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 17472: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 17473: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
17474: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17475:
17476: } else {
1.160.6.7 raeburn 17477: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
17478: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 17479: }
17480: return;
17481: }
17482:
1.160.6.7 raeburn 17483: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 17484: if (type == '_LC_external') {
1.160.6.26 raeburn 17485: return;
1.150 raeburn 17486: }
1.160.6.7 raeburn 17487: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 17488: for (var i=0; i<typesRules.length; i++) {
17489: if (formname.elements[typesRules[i]].checked) {
17490: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 17491: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
17492: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17493: } else {
1.160.6.7 raeburn 17494: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
17495: }
17496: }
17497: }
17498: return;
17499: }
17500:
17501: function balancerDeleteChange(balnum) {
17502: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17503: var baltotal = document.getElementById('loadbalancing_total').value;
17504: var addtarget;
17505: var removetarget;
17506: var action = 'delete';
17507: if (document.getElementById('loadbalancing_delete_'+balnum)) {
17508: var lonhost = hostitem.value;
17509: var currIdx = currBalancers.indexOf(lonhost);
17510: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
17511: if (currIdx != -1) {
17512: currBalancers.splice(currIdx,1);
17513: }
17514: addtarget = lonhost;
17515: } else {
17516: if (currIdx == -1) {
17517: currBalancers.push(lonhost);
17518: }
17519: removetarget = lonhost;
17520: action = 'undelete';
17521: }
17522: balancerChange(balnum,baltotal,action,addtarget,removetarget);
17523: }
17524: return;
17525: }
17526:
17527: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
17528: if (baltotal > 1) {
17529: var offloadtypes = new Array('primary','default');
17530: var alltargets = new Array('$alltargets');
17531: var insttypes = new Array('$allinsttypes');
17532: for (var i=0; i<baltotal; i++) {
17533: if (i != balnum) {
17534: for (var j=0; j<offloadtypes.length; j++) {
17535: var total = alltargets.length - 1;
17536: for (var k=0; k<total; k++) {
17537: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
17538: var server = serveritem.value;
17539: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17540: if (server == addtarget) {
17541: serveritem.disabled = '';
17542: }
17543: }
17544: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17545: if (server == removetarget) {
17546: serveritem.disabled = 'disabled';
17547: serveritem.checked = false;
17548: }
17549: }
17550: }
17551: }
17552: for (var j=0; j<insttypes.length; j++) {
17553: if (insttypes[j] != '_LC_external') {
17554: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
17555: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
17556: var currSel = singleserver.selectedIndex;
17557: var currVal = singleserver.options[currSel].value;
17558: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17559: var numoptions = singleserver.options.length;
17560: var needsnew = 1;
17561: for (var k=0; k<numoptions; k++) {
17562: if (singleserver.options[k] == addtarget) {
17563: needsnew = 0;
17564: break;
17565: }
17566: }
17567: if (needsnew == 1) {
17568: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
17569: }
17570: }
17571: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17572: singleserver.options.length = 0;
17573: if ((currVal) && (currVal != removetarget)) {
17574: singleserver.options[0] = new Option("","",false,false);
17575: } else {
17576: singleserver.options[0] = new Option("","",true,true);
17577: }
17578: var idx = 0;
17579: for (var m=0; m<alltargets.length; m++) {
17580: if (currBalancers.indexOf(alltargets[m]) == -1) {
17581: idx ++;
17582: if (currVal == alltargets[m]) {
17583: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
17584: } else {
17585: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
17586: }
17587: }
17588: }
17589: }
17590: }
17591: }
17592: }
1.150 raeburn 17593: }
17594: }
17595: }
17596: return;
17597: }
17598:
1.152 raeburn 17599: // ]]>
17600: </script>
17601:
17602: END
17603: }
17604:
17605: sub new_spares_js {
17606: my @sparestypes = ('primary','default');
17607: my $types = join("','",@sparestypes);
17608: my $select = &mt('Select');
17609: return <<"END";
17610:
17611: <script type="text/javascript">
17612: // <![CDATA[
17613:
17614: function updateNewSpares(formname,lonhost) {
17615: var types = new Array('$types');
17616: var include = new Array();
17617: var exclude = new Array();
17618: for (var i=0; i<types.length; i++) {
17619: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
17620: for (var j=0; j<spareboxes.length; j++) {
17621: if (formname.elements[spareboxes[j]].checked) {
17622: exclude.push(formname.elements[spareboxes[j]].value);
17623: } else {
17624: include.push(formname.elements[spareboxes[j]].value);
17625: }
17626: }
17627: }
17628: for (var i=0; i<types.length; i++) {
17629: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
17630: var selIdx = newSpare.selectedIndex;
17631: var currnew = newSpare.options[selIdx].value;
17632: var okSpares = new Array();
17633: for (var j=0; j<newSpare.options.length; j++) {
17634: var possible = newSpare.options[j].value;
17635: if (possible != '') {
17636: if (exclude.indexOf(possible) == -1) {
17637: okSpares.push(possible);
17638: } else {
17639: if (currnew == possible) {
17640: selIdx = 0;
17641: }
17642: }
17643: }
17644: }
17645: for (var k=0; k<include.length; k++) {
17646: if (okSpares.indexOf(include[k]) == -1) {
17647: okSpares.push(include[k]);
17648: }
17649: }
17650: okSpares.sort();
17651: newSpare.options.length = 0;
17652: if (selIdx == 0) {
17653: newSpare.options[0] = new Option("$select","",true,true);
17654: } else {
17655: newSpare.options[0] = new Option("$select","",false,false);
17656: }
17657: for (var m=0; m<okSpares.length; m++) {
17658: var idx = m+1;
17659: var selThis = 0;
17660: if (selIdx != 0) {
17661: if (okSpares[m] == currnew) {
17662: selThis = 1;
17663: }
17664: }
17665: if (selThis == 1) {
17666: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
17667: } else {
17668: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
17669: }
17670: }
17671: }
17672: return;
17673: }
17674:
17675: function checkNewSpares(lonhost,type) {
17676: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
17677: var chosen = newSpare.options[newSpare.selectedIndex].value;
17678: if (chosen != '') {
17679: var othertype;
17680: var othernewSpare;
17681: if (type == 'primary') {
17682: othernewSpare = document.getElementById('newspare_default_'+lonhost);
17683: }
17684: if (type == 'default') {
17685: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
17686: }
17687: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
17688: othernewSpare.selectedIndex = 0;
17689: }
17690: }
17691: return;
17692: }
17693:
17694: // ]]>
17695: </script>
17696:
17697: END
17698:
17699: }
17700:
17701: sub common_domprefs_js {
17702: return <<"END";
17703:
17704: <script type="text/javascript">
17705: // <![CDATA[
17706:
1.150 raeburn 17707: function getIndicesByName(formname,item) {
1.152 raeburn 17708: var group = new Array();
1.150 raeburn 17709: for (var i=0;i<formname.elements.length;i++) {
17710: if (formname.elements[i].name == item) {
1.152 raeburn 17711: group.push(formname.elements[i].id);
1.150 raeburn 17712: }
17713: }
1.152 raeburn 17714: return group;
1.150 raeburn 17715: }
17716:
17717: // ]]>
17718: </script>
17719:
17720: END
1.152 raeburn 17721:
1.150 raeburn 17722: }
17723:
1.160.6.5 raeburn 17724: sub recaptcha_js {
17725: my %lt = &captcha_phrases();
17726: return <<"END";
17727:
17728: <script type="text/javascript">
17729: // <![CDATA[
17730:
17731: function updateCaptcha(caller,context) {
17732: var privitem;
17733: var pubitem;
17734: var privtext;
17735: var pubtext;
1.160.6.69 raeburn 17736: var versionitem;
17737: var versiontext;
1.160.6.5 raeburn 17738: if (document.getElementById(context+'_recaptchapub')) {
17739: pubitem = document.getElementById(context+'_recaptchapub');
17740: } else {
17741: return;
17742: }
17743: if (document.getElementById(context+'_recaptchapriv')) {
17744: privitem = document.getElementById(context+'_recaptchapriv');
17745: } else {
17746: return;
17747: }
17748: if (document.getElementById(context+'_recaptchapubtxt')) {
17749: pubtext = document.getElementById(context+'_recaptchapubtxt');
17750: } else {
17751: return;
17752: }
17753: if (document.getElementById(context+'_recaptchaprivtxt')) {
17754: privtext = document.getElementById(context+'_recaptchaprivtxt');
17755: } else {
17756: return;
17757: }
1.160.6.69 raeburn 17758: if (document.getElementById(context+'_recaptchaversion')) {
17759: versionitem = document.getElementById(context+'_recaptchaversion');
17760: } else {
17761: return;
17762: }
17763: if (document.getElementById(context+'_recaptchavertxt')) {
17764: versiontext = document.getElementById(context+'_recaptchavertxt');
17765: } else {
17766: return;
17767: }
1.160.6.5 raeburn 17768: if (caller.checked) {
17769: if (caller.value == 'recaptcha') {
17770: pubitem.type = 'text';
17771: privitem.type = 'text';
17772: pubitem.size = '40';
17773: privitem.size = '40';
17774: pubtext.innerHTML = "$lt{'pub'}";
17775: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 17776: versionitem.type = 'text';
17777: versionitem.size = '3';
17778: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 17779: } else {
17780: pubitem.type = 'hidden';
17781: privitem.type = 'hidden';
1.160.6.69 raeburn 17782: versionitem.type = 'hidden';
1.160.6.5 raeburn 17783: pubtext.innerHTML = '';
17784: privtext.innerHTML = '';
1.160.6.69 raeburn 17785: versiontext.innerHTML = '';
1.160.6.5 raeburn 17786: }
17787: }
17788: return;
17789: }
17790:
17791: // ]]>
17792: </script>
17793:
17794: END
17795:
17796: }
17797:
1.160.6.40 raeburn 17798: sub toggle_display_js {
1.160.6.16 raeburn 17799: return <<"END";
17800:
17801: <script type="text/javascript">
17802: // <![CDATA[
17803:
1.160.6.40 raeburn 17804: function toggleDisplay(domForm,caller) {
17805: if (document.getElementById(caller)) {
17806: var divitem = document.getElementById(caller);
17807: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 17808: var checkval = 1;
17809: var dispval = 'block';
1.160.6.93 raeburn 17810: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 17811: if (caller == 'emailoptions') {
17812: optionsElement = domForm.cancreate_email;
17813: }
1.160.6.57 raeburn 17814: if (caller == 'studentsubmission') {
17815: optionsElement = domForm.postsubmit;
17816: }
1.160.6.64 raeburn 17817: if (caller == 'cloneinstcode') {
17818: optionsElement = domForm.canclone;
17819: checkval = 'instcode';
17820: }
1.160.6.93 raeburn 17821: if (selfcreateRegExp.test(caller)) {
17822: optionsElement = domForm.elements[caller];
17823: checkval = 'other';
17824: dispval = 'inline'
17825: }
1.160.6.40 raeburn 17826: if (optionsElement.length) {
1.160.6.16 raeburn 17827: var currval;
1.160.6.40 raeburn 17828: for (var i=0; i<optionsElement.length; i++) {
17829: if (optionsElement[i].checked) {
17830: currval = optionsElement[i].value;
1.160.6.16 raeburn 17831: }
17832: }
1.160.6.64 raeburn 17833: if (currval == checkval) {
17834: divitem.style.display = dispval;
1.160.6.16 raeburn 17835: } else {
1.160.6.40 raeburn 17836: divitem.style.display = 'none';
1.160.6.16 raeburn 17837: }
17838: }
17839: }
17840: return;
17841: }
17842:
17843: // ]]>
17844: </script>
17845:
17846: END
17847:
17848: }
17849:
1.160.6.5 raeburn 17850: sub captcha_phrases {
17851: return &Apache::lonlocal::texthash (
17852: priv => 'Private key',
17853: pub => 'Public key',
17854: original => 'original (CAPTCHA)',
17855: recaptcha => 'successor (ReCAPTCHA)',
17856: notused => 'unused',
1.160.6.69 raeburn 17857: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 17858: );
17859: }
17860:
1.160.6.24 raeburn 17861: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 17862: my ($dom,$cachekeys) = @_;
17863: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 17864: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17865: my %thismachine;
17866: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.98 raeburn 17867: my @posscached = ('domainconfig','domdefaults','usersessions',
1.160.6.113 raeburn 17868: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
17869: 'ipaccess');
17870: my %cache_by_lonhost;
17871: if (exists($cachekeys->{'samllanding'})) {
17872: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
17873: my %landing = %{$cachekeys->{'samllanding'}};
17874: my %domservers = &Apache::lonnet::get_servers($dom);
17875: if (keys(%domservers)) {
17876: foreach my $server (keys(%domservers)) {
17877: my @cached;
17878: next if ($thismachine{$server});
17879: if ($landing{$server}) {
17880: push(@cached,&escape('samllanding').':'.&escape($server));
17881: }
17882: if (@cached) {
17883: $cache_by_lonhost{$server} = \@cached;
17884: }
17885: }
17886: }
17887: }
17888: }
1.160.6.61 raeburn 17889: if (keys(%servers)) {
1.160.6.24 raeburn 17890: foreach my $server (keys(%servers)) {
17891: next if ($thismachine{$server});
1.160.6.27 raeburn 17892: my @cached;
17893: foreach my $name (@posscached) {
17894: if ($cachekeys->{$name}) {
1.160.6.113 raeburn 17895: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
17896: if (ref($cachekeys->{$name}) eq 'HASH') {
17897: foreach my $key (keys(%{$cachekeys->{$name}})) {
17898: push(@cached,&escape($name).':'.&escape($key));
17899: }
17900: }
17901: } else {
17902: push(@cached,&escape($name).':'.&escape($dom));
17903: }
1.160.6.27 raeburn 17904: }
17905: }
1.160.6.113 raeburn 17906: if ((exists($cache_by_lonhost{$server})) &&
17907: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
17908: push(@cached,@{$cache_by_lonhost{$server}});
17909: }
1.160.6.27 raeburn 17910: if (@cached) {
17911: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
17912: }
1.160.6.24 raeburn 17913: }
17914: }
17915: return;
17916: }
17917:
1.3 raeburn 17918: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>