Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.115
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.115! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.114 2021/12/16 19:46:34 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',
1.160.6.115! raeburn 1704: 'search' => 'Course search',
! 1705: 'wishlist' => 'Stored links',
! 1706: 'annotate' => 'Annotations',
1.160.6.113 raeburn 1707: );
1.160.6.115! raeburn 1708: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.160.6.113 raeburn 1709: return ($typeorder,\%types);
1710: }
1711:
1.6 raeburn 1712: sub print_rolecolors {
1.30 raeburn 1713: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1714: my %choices = &color_font_choices();
1715: my @bgs = ('pgbg','tabbg','sidebg');
1716: my @links = ('link','alink','vlink');
1717: my @images = ('img');
1718: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1719: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1720: my %defaultdesign = %Apache::loncommon::defaultdesign;
1721: my (%is_custom,%designs);
1.160.6.22 raeburn 1722: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1723: if (ref($settings) eq 'HASH') {
1724: if (ref($settings->{$role}) eq 'HASH') {
1725: if ($settings->{$role}->{'img'} ne '') {
1726: $designs{'img'} = $settings->{$role}->{'img'};
1727: $is_custom{'img'} = 1;
1728: }
1729: if ($settings->{$role}->{'font'} ne '') {
1730: $designs{'font'} = $settings->{$role}->{'font'};
1731: $is_custom{'font'} = 1;
1732: }
1.97 tempelho 1733: if ($settings->{$role}->{'fontmenu'} ne '') {
1734: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1735: $is_custom{'fontmenu'} = 1;
1736: }
1.6 raeburn 1737: foreach my $item (@bgs) {
1738: if ($settings->{$role}->{$item} ne '') {
1739: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1740: $is_custom{$item} = 1;
1741: }
1742: }
1743: foreach my $item (@links) {
1744: if ($settings->{$role}->{$item} ne '') {
1745: $designs{'links'}{$item} = $settings->{$role}->{$item};
1746: $is_custom{$item} = 1;
1747: }
1748: }
1749: }
1750: } else {
1751: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1752: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1753: $is_custom{'img'} = 1;
1754: }
1.97 tempelho 1755: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1756: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1757: $is_custom{'fontmenu'} = 1;
1758: }
1.6 raeburn 1759: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1760: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1761: $is_custom{'font'} = 1;
1762: }
1763: foreach my $item (@bgs) {
1764: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1765: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1766: $is_custom{$item} = 1;
1767:
1768: }
1769: }
1770: foreach my $item (@links) {
1771: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1772: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1773: $is_custom{$item} = 1;
1774: }
1775: }
1776: }
1777: my $itemcount = 1;
1.30 raeburn 1778: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1779: $datatable .= '</tr></table></td></tr>';
1780: return $datatable;
1781: }
1782:
1.160.6.22 raeburn 1783: sub role_defaults {
1784: my ($role,$bgs,$links,$images,$logintext) = @_;
1785: my %defaults;
1786: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1787: return %defaults;
1788: }
1789: my %defaultdesign = %Apache::loncommon::defaultdesign;
1790: if ($role eq 'login') {
1791: %defaults = (
1792: font => $defaultdesign{$role.'.font'},
1793: );
1794: if (ref($logintext) eq 'ARRAY') {
1795: foreach my $item (@{$logintext}) {
1796: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1797: }
1798: }
1799: foreach my $item (@{$images}) {
1800: $defaults{'showlogo'}{$item} = 1;
1801: }
1802: } else {
1803: %defaults = (
1804: img => $defaultdesign{$role.'.img'},
1805: font => $defaultdesign{$role.'.font'},
1806: fontmenu => $defaultdesign{$role.'.fontmenu'},
1807: );
1808: }
1809: foreach my $item (@{$bgs}) {
1810: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1811: }
1812: foreach my $item (@{$links}) {
1813: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1814: }
1815: foreach my $item (@{$images}) {
1816: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1817: }
1818: return %defaults;
1819: }
1820:
1.6 raeburn 1821: sub display_color_options {
1.9 raeburn 1822: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1823: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1824: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1825: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1826: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1827: '<td>'.$choices->{'font'}.'</td>';
1828: if (!$is_custom->{'font'}) {
1.160.6.87 raeburn 1829: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1830: } else {
1831: $datatable .= '<td> </td>';
1832: }
1.160.6.9 raeburn 1833: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1834:
1.8 raeburn 1835: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1836: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1837: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1838: ' </span></td></tr>';
1.107 raeburn 1839: unless ($role eq 'login') {
1840: $datatable .= '<tr'.$css_class.'>'.
1841: '<td>'.$choices->{'fontmenu'}.'</td>';
1842: if (!$is_custom->{'fontmenu'}) {
1.160.6.87 raeburn 1843: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1844: } else {
1845: $datatable .= '<td> </td>';
1846: }
1.160.6.22 raeburn 1847: $current_color = $designs->{'fontmenu'} ?
1848: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1849: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1850: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1851: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1852: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1853: ' </span></td></tr>';
1.97 tempelho 1854: }
1.9 raeburn 1855: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1856: foreach my $img (@{$images}) {
1.18 albertel 1857: $itemcount ++;
1.6 raeburn 1858: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1859: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1860: '<td>'.$choices->{$img};
1.41 raeburn 1861: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1862: if ($role eq 'login') {
1863: if ($img eq 'login') {
1864: $login_hdr_pick =
1.135 bisitz 1865: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1866: $logincolors =
1867: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1868: $designs,$defaults);
1.70 raeburn 1869: } elsif ($img ne 'domlogo') {
1870: $datatable.= &logo_display_options($img,$defaults,$designs);
1871: }
1872: }
1873: $datatable .= '</td>';
1.6 raeburn 1874: if ($designs->{$img} ne '') {
1875: $imgfile = $designs->{$img};
1.18 albertel 1876: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1877: } else {
1878: $imgfile = $defaults->{$img};
1879: }
1880: if ($imgfile) {
1.9 raeburn 1881: my ($showfile,$fullsize);
1882: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1883: my $urldir = $1;
1884: my $filename = $2;
1885: my @info = &Apache::lonnet::stat_file($designs->{$img});
1886: if (@info) {
1887: my $thumbfile = 'tn-'.$filename;
1888: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1889: if (@thumb) {
1890: $showfile = $urldir.'/'.$thumbfile;
1891: } else {
1892: $showfile = $imgfile;
1893: }
1894: } else {
1895: $showfile = '';
1896: }
1897: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1898: $showfile = $imgfile;
1.6 raeburn 1899: my $imgdir = $1;
1900: my $filename = $2;
1.159 raeburn 1901: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1902: $showfile = "/$imgdir/tn-".$filename;
1903: } else {
1.159 raeburn 1904: my $input = $londocroot.$imgfile;
1905: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1906: if (!-e $output) {
1.9 raeburn 1907: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1908: my ($fullwidth,$fullheight) = &check_dimensions($input);
1909: if ($fullwidth ne '' && $fullheight ne '') {
1910: if ($fullwidth > $width && $fullheight > $height) {
1911: my $size = $width.'x'.$height;
1.160.6.88 raeburn 1912: my @args = ('convert','-sample',$size,$input,$output);
1913: system({$args[0]} @args);
1.159 raeburn 1914: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1915: }
1916: }
1.6 raeburn 1917: }
1918: }
1.16 raeburn 1919: }
1.6 raeburn 1920: if ($showfile) {
1.40 raeburn 1921: if ($showfile =~ m{^/(adm|res)/}) {
1922: if ($showfile =~ m{^/res/}) {
1923: my $local_showfile =
1924: &Apache::lonnet::filelocation('',$showfile);
1925: &Apache::lonnet::repcopy($local_showfile);
1926: }
1927: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1928: }
1929: if ($imgfile) {
1930: if ($imgfile =~ m{^/(adm|res)/}) {
1931: if ($imgfile =~ m{^/res/}) {
1932: my $local_imgfile =
1933: &Apache::lonnet::filelocation('',$imgfile);
1934: &Apache::lonnet::repcopy($local_imgfile);
1935: }
1936: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1937: } else {
1938: $fullsize = $imgfile;
1939: }
1940: }
1.41 raeburn 1941: $datatable .= '<td>';
1942: if ($img eq 'login') {
1.135 bisitz 1943: $datatable .= $login_hdr_pick;
1944: }
1.41 raeburn 1945: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1946: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1947: } else {
1.160.6.22 raeburn 1948: $datatable .= '<td> </td><td class="LC_left_item">'.
1949: &mt('Upload:').'<br />';
1.6 raeburn 1950: }
1951: } else {
1.160.6.22 raeburn 1952: $datatable .= '<td> </td><td class="LC_left_item">'.
1953: &mt('Upload:').'<br />';
1.6 raeburn 1954: }
1.9 raeburn 1955: if ($switchserver) {
1956: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1957: } else {
1.135 bisitz 1958: if ($img ne 'login') { # suppress file selection for Log-in header
1959: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1960: }
1.9 raeburn 1961: }
1962: $datatable .= '</td></tr>';
1.6 raeburn 1963: }
1964: $itemcount ++;
1965: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1966: $datatable .= '<tr'.$css_class.'>'.
1967: '<td>'.$choices->{'bgs'}.'</td>';
1968: my $bgs_def;
1969: foreach my $item (@{$bgs}) {
1970: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1971: $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 1972: }
1973: }
1974: if ($bgs_def) {
1.8 raeburn 1975: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1976: } else {
1977: $datatable .= '<td> </td>';
1978: }
1979: $datatable .= '<td class="LC_right_item">'.
1980: '<table border="0"><tr>';
1.160.6.13 raeburn 1981:
1.6 raeburn 1982: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1983: $datatable .= '<td align="center">'.$choices->{$item};
1984: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1985: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1986: $datatable .= ' ';
1.6 raeburn 1987: }
1.160.6.9 raeburn 1988: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1989: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1990: }
1991: $datatable .= '</tr></table></td></tr>';
1992: $itemcount ++;
1993: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1994: $datatable .= '<tr'.$css_class.'>'.
1995: '<td>'.$choices->{'links'}.'</td>';
1996: my $links_def;
1997: foreach my $item (@{$links}) {
1998: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1999: $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 2000: }
2001: }
2002: if ($links_def) {
1.8 raeburn 2003: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2004: } else {
2005: $datatable .= '<td> </td>';
2006: }
2007: $datatable .= '<td class="LC_right_item">'.
2008: '<table border="0"><tr>';
2009: foreach my $item (@{$links}) {
1.160.6.39 raeburn 2010: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 2011: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 2012: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 2013: $datatable.=' ';
1.6 raeburn 2014: }
1.160.6.9 raeburn 2015: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2016: '" /></td>';
2017: }
1.30 raeburn 2018: $$rowtotal += $itemcount;
1.3 raeburn 2019: return $datatable;
2020: }
2021:
1.70 raeburn 2022: sub logo_display_options {
2023: my ($img,$defaults,$designs) = @_;
2024: my $checkedon;
2025: if (ref($defaults) eq 'HASH') {
2026: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2027: if ($defaults->{'showlogo'}{$img}) {
2028: $checkedon = 'checked="checked" ';
2029: }
2030: }
2031: }
2032: if (ref($designs) eq 'HASH') {
2033: if (ref($designs->{'showlogo'}) eq 'HASH') {
2034: if (defined($designs->{'showlogo'}{$img})) {
2035: if ($designs->{'showlogo'}{$img} == 0) {
2036: $checkedon = '';
2037: } elsif ($designs->{'showlogo'}{$img} == 1) {
2038: $checkedon = 'checked="checked" ';
2039: }
2040: }
2041: }
2042: }
2043: return '<br /><label> <input type="checkbox" name="'.
2044: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2045: &mt('show').'</label>'."\n";
2046: }
2047:
1.41 raeburn 2048: sub login_header_options {
1.135 bisitz 2049: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2050: my $output = '';
1.41 raeburn 2051: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2052: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2053: if (!$is_custom->{'textcol'}) {
2054: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2055: ' ';
2056: }
2057: if (!$is_custom->{'bgcol'}) {
2058: $output .= $choices->{'bgcol'}.': '.
2059: '<span id="css_'.$role.'_font" style="background-color: '.
2060: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2061: }
2062: $output .= '<br />';
2063: }
2064: $output .='<br />';
2065: return $output;
2066: }
2067:
2068: sub login_text_colors {
1.160.6.22 raeburn 2069: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2070: my $color_menu = '<table border="0"><tr>';
2071: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 2072: $color_menu .= '<td align="center">'.$choices->{$item};
2073: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2074: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2075: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2076: }
2077: $color_menu .= '</tr></table><br />';
2078: return $color_menu;
2079: }
2080:
2081: sub image_changes {
2082: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2083: my $output;
1.135 bisitz 2084: if ($img eq 'login') {
1.160.6.87 raeburn 2085: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2086: } elsif (!$is_custom) {
1.70 raeburn 2087: if ($img ne 'domlogo') {
1.160.6.87 raeburn 2088: $output = &mt('Default image:').'<br />';
1.41 raeburn 2089: } else {
1.160.6.87 raeburn 2090: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2091: }
2092: }
1.160.6.87 raeburn 2093: if ($img ne 'login') {
1.135 bisitz 2094: if ($img_import) {
2095: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2096: }
2097: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2098: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2099: if ($is_custom) {
2100: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2101: '<input type="checkbox" name="'.
2102: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2103: '</label> '.&mt('Replace:').'</span><br />';
2104: } else {
1.160.6.22 raeburn 2105: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2106: }
1.41 raeburn 2107: }
2108: return $output;
2109: }
2110:
1.3 raeburn 2111: sub print_quotas {
1.86 raeburn 2112: my ($dom,$settings,$rowtotal,$action) = @_;
2113: my $context;
2114: if ($action eq 'quotas') {
2115: $context = 'tools';
2116: } else {
2117: $context = $action;
2118: }
1.160.6.20 raeburn 2119: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2120: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2121: my $typecount = 0;
1.101 raeburn 2122: my ($css_class,%titles);
1.86 raeburn 2123: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 2124: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 2125: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2126: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2127: %titles = &courserequest_titles();
1.160.6.5 raeburn 2128: } elsif ($context eq 'requestauthor') {
2129: @usertools = ('author');
2130: @options = ('norequest','approval','automatic');
2131: %titles = &authorrequest_titles();
1.86 raeburn 2132: } else {
1.160.6.4 raeburn 2133: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 2134: %titles = &tool_titles();
1.86 raeburn 2135: }
1.26 raeburn 2136: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2137: foreach my $type (@{$types}) {
1.160.6.20 raeburn 2138: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 2139: unless (($context eq 'requestcourses') ||
2140: ($context eq 'requestauthor')) {
1.86 raeburn 2141: if (ref($settings) eq 'HASH') {
2142: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 2143: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2144: } else {
2145: $currdefquota = $settings->{$type};
2146: }
1.160.6.20 raeburn 2147: if (ref($settings->{authorquota}) eq 'HASH') {
2148: $currauthorquota = $settings->{authorquota}->{$type};
2149: }
1.78 raeburn 2150: }
1.72 raeburn 2151: }
1.3 raeburn 2152: if (defined($usertypes->{$type})) {
2153: $typecount ++;
2154: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2155: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2156: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2157: '<td class="LC_left_item">';
1.101 raeburn 2158: if ($context eq 'requestcourses') {
2159: $datatable .= '<table><tr>';
2160: }
2161: my %cell;
1.72 raeburn 2162: foreach my $item (@usertools) {
1.101 raeburn 2163: if ($context eq 'requestcourses') {
2164: my ($curroption,$currlimit);
2165: if (ref($settings) eq 'HASH') {
2166: if (ref($settings->{$item}) eq 'HASH') {
2167: $curroption = $settings->{$item}->{$type};
2168: if ($curroption =~ /^autolimit=(\d*)$/) {
2169: $currlimit = $1;
2170: }
2171: }
2172: }
2173: if (!$curroption) {
2174: $curroption = 'norequest';
2175: }
2176: $datatable .= '<th>'.$titles{$item}.'</th>';
2177: foreach my $option (@options) {
2178: my $val = $option;
2179: if ($option eq 'norequest') {
2180: $val = 0;
2181: }
2182: if ($option eq 'validate') {
2183: my $canvalidate = 0;
2184: if (ref($validations{$item}) eq 'HASH') {
2185: if ($validations{$item}{$type}) {
2186: $canvalidate = 1;
2187: }
2188: }
2189: next if (!$canvalidate);
2190: }
2191: my $checked = '';
2192: if ($option eq $curroption) {
2193: $checked = ' checked="checked"';
2194: } elsif ($option eq 'autolimit') {
2195: if ($curroption =~ /^autolimit/) {
2196: $checked = ' checked="checked"';
2197: }
2198: }
2199: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2200: '<input type="radio" name="crsreq_'.$item.
2201: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2202: $titles{$option}.'</label>';
1.101 raeburn 2203: if ($option eq 'autolimit') {
1.127 raeburn 2204: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2205: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2206: 'value="'.$currlimit.'" />';
1.101 raeburn 2207: }
1.127 raeburn 2208: $cell{$item} .= '</span> ';
1.103 raeburn 2209: if ($option eq 'autolimit') {
1.127 raeburn 2210: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2211: }
1.101 raeburn 2212: }
1.160.6.5 raeburn 2213: } elsif ($context eq 'requestauthor') {
2214: my $curroption;
2215: if (ref($settings) eq 'HASH') {
2216: $curroption = $settings->{$type};
2217: }
2218: if (!$curroption) {
2219: $curroption = 'norequest';
2220: }
2221: foreach my $option (@options) {
2222: my $val = $option;
2223: if ($option eq 'norequest') {
2224: $val = 0;
2225: }
2226: my $checked = '';
2227: if ($option eq $curroption) {
2228: $checked = ' checked="checked"';
2229: }
2230: $datatable .= '<span class="LC_nobreak"><label>'.
2231: '<input type="radio" name="authorreq_'.$type.
2232: '" value="'.$val.'"'.$checked.' />'.
2233: $titles{$option}.'</label></span> ';
2234: }
1.101 raeburn 2235: } else {
2236: my $checked = 'checked="checked" ';
2237: if (ref($settings) eq 'HASH') {
2238: if (ref($settings->{$item}) eq 'HASH') {
2239: if ($settings->{$item}->{$type} == 0) {
2240: $checked = '';
2241: } elsif ($settings->{$item}->{$type} == 1) {
2242: $checked = 'checked="checked" ';
2243: }
1.78 raeburn 2244: }
1.72 raeburn 2245: }
1.101 raeburn 2246: $datatable .= '<span class="LC_nobreak"><label>'.
2247: '<input type="checkbox" name="'.$context.'_'.$item.
2248: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2249: '</label></span> ';
1.72 raeburn 2250: }
1.101 raeburn 2251: }
2252: if ($context eq 'requestcourses') {
2253: $datatable .= '</tr><tr>';
2254: foreach my $item (@usertools) {
1.106 raeburn 2255: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2256: }
2257: $datatable .= '</tr></table>';
1.72 raeburn 2258: }
1.86 raeburn 2259: $datatable .= '</td>';
1.160.6.5 raeburn 2260: unless (($context eq 'requestcourses') ||
2261: ($context eq 'requestauthor')) {
1.86 raeburn 2262: $datatable .=
1.160.6.20 raeburn 2263: '<td class="LC_right_item">'.
2264: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2265: '<input type="text" name="quota_'.$type.
1.72 raeburn 2266: '" value="'.$currdefquota.
1.160.6.20 raeburn 2267: '" size="5" /></span>'.(' ' x 2).
2268: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2269: '<input type="text" name="authorquota_'.$type.
2270: '" value="'.$currauthorquota.
2271: '" size="5" /></span></td>';
1.86 raeburn 2272: }
2273: $datatable .= '</tr>';
1.3 raeburn 2274: }
2275: }
2276: }
1.160.6.5 raeburn 2277: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2278: $defaultquota = '20';
1.160.6.20 raeburn 2279: $authorquota = '500';
1.86 raeburn 2280: if (ref($settings) eq 'HASH') {
2281: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2282: $defaultquota = $settings->{'defaultquota'}->{'default'};
2283: } elsif (defined($settings->{'default'})) {
2284: $defaultquota = $settings->{'default'};
2285: }
1.160.6.20 raeburn 2286: if (ref($settings->{'authorquota'}) eq 'HASH') {
2287: $authorquota = $settings->{'authorquota'}->{'default'};
2288: }
1.3 raeburn 2289: }
2290: }
2291: $typecount ++;
2292: $css_class = $typecount%2?' class="LC_odd_row"':'';
2293: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2294: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2295: '<td class="LC_left_item">';
1.101 raeburn 2296: if ($context eq 'requestcourses') {
2297: $datatable .= '<table><tr>';
2298: }
2299: my %defcell;
1.72 raeburn 2300: foreach my $item (@usertools) {
1.101 raeburn 2301: if ($context eq 'requestcourses') {
2302: my ($curroption,$currlimit);
2303: if (ref($settings) eq 'HASH') {
2304: if (ref($settings->{$item}) eq 'HASH') {
2305: $curroption = $settings->{$item}->{'default'};
2306: if ($curroption =~ /^autolimit=(\d*)$/) {
2307: $currlimit = $1;
2308: }
2309: }
2310: }
2311: if (!$curroption) {
2312: $curroption = 'norequest';
2313: }
2314: $datatable .= '<th>'.$titles{$item}.'</th>';
2315: foreach my $option (@options) {
2316: my $val = $option;
2317: if ($option eq 'norequest') {
2318: $val = 0;
2319: }
2320: if ($option eq 'validate') {
2321: my $canvalidate = 0;
2322: if (ref($validations{$item}) eq 'HASH') {
2323: if ($validations{$item}{'default'}) {
2324: $canvalidate = 1;
2325: }
2326: }
2327: next if (!$canvalidate);
2328: }
2329: my $checked = '';
2330: if ($option eq $curroption) {
2331: $checked = ' checked="checked"';
2332: } elsif ($option eq 'autolimit') {
2333: if ($curroption =~ /^autolimit/) {
2334: $checked = ' checked="checked"';
2335: }
2336: }
2337: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2338: '<input type="radio" name="crsreq_'.$item.
2339: '_default" value="'.$val.'"'.$checked.' />'.
2340: $titles{$option}.'</label>';
2341: if ($option eq 'autolimit') {
1.127 raeburn 2342: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2343: $item.'_limit_default" size="1" '.
2344: 'value="'.$currlimit.'" />';
2345: }
1.127 raeburn 2346: $defcell{$item} .= '</span> ';
1.104 raeburn 2347: if ($option eq 'autolimit') {
1.127 raeburn 2348: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2349: }
1.101 raeburn 2350: }
1.160.6.5 raeburn 2351: } elsif ($context eq 'requestauthor') {
2352: my $curroption;
2353: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 2354: $curroption = $settings->{'default'};
1.160.6.5 raeburn 2355: }
2356: if (!$curroption) {
2357: $curroption = 'norequest';
2358: }
2359: foreach my $option (@options) {
2360: my $val = $option;
2361: if ($option eq 'norequest') {
2362: $val = 0;
2363: }
2364: my $checked = '';
2365: if ($option eq $curroption) {
2366: $checked = ' checked="checked"';
2367: }
2368: $datatable .= '<span class="LC_nobreak"><label>'.
2369: '<input type="radio" name="authorreq_default"'.
2370: ' value="'.$val.'"'.$checked.' />'.
2371: $titles{$option}.'</label></span> ';
2372: }
1.101 raeburn 2373: } else {
2374: my $checked = 'checked="checked" ';
2375: if (ref($settings) eq 'HASH') {
2376: if (ref($settings->{$item}) eq 'HASH') {
2377: if ($settings->{$item}->{'default'} == 0) {
2378: $checked = '';
2379: } elsif ($settings->{$item}->{'default'} == 1) {
2380: $checked = 'checked="checked" ';
2381: }
1.78 raeburn 2382: }
1.72 raeburn 2383: }
1.101 raeburn 2384: $datatable .= '<span class="LC_nobreak"><label>'.
2385: '<input type="checkbox" name="'.$context.'_'.$item.
2386: '" value="default" '.$checked.'/>'.$titles{$item}.
2387: '</label></span> ';
2388: }
2389: }
2390: if ($context eq 'requestcourses') {
2391: $datatable .= '</tr><tr>';
2392: foreach my $item (@usertools) {
1.106 raeburn 2393: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2394: }
1.101 raeburn 2395: $datatable .= '</tr></table>';
1.72 raeburn 2396: }
1.86 raeburn 2397: $datatable .= '</td>';
1.160.6.5 raeburn 2398: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2399: $datatable .= '<td class="LC_right_item">'.
2400: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2401: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2402: $defaultquota.'" size="5" /></span>'.(' ' x2).
2403: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2404: '<input type="text" name="authorquota" value="'.
2405: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2406: }
2407: $datatable .= '</tr>';
1.72 raeburn 2408: $typecount ++;
2409: $css_class = $typecount%2?' class="LC_odd_row"':'';
2410: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2411: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2412: if ($context eq 'requestcourses') {
1.109 raeburn 2413: $datatable .= &mt('(overrides affiliation, if set)').
2414: '</td>'.
2415: '<td class="LC_left_item">'.
2416: '<table><tr>';
1.101 raeburn 2417: } else {
1.109 raeburn 2418: $datatable .= &mt('(overrides affiliation, if checked)').
2419: '</td>'.
2420: '<td class="LC_left_item" colspan="2">'.
2421: '<br />';
1.101 raeburn 2422: }
2423: my %advcell;
1.72 raeburn 2424: foreach my $item (@usertools) {
1.101 raeburn 2425: if ($context eq 'requestcourses') {
2426: my ($curroption,$currlimit);
2427: if (ref($settings) eq 'HASH') {
2428: if (ref($settings->{$item}) eq 'HASH') {
2429: $curroption = $settings->{$item}->{'_LC_adv'};
2430: if ($curroption =~ /^autolimit=(\d*)$/) {
2431: $currlimit = $1;
2432: }
2433: }
2434: }
2435: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2436: my $checked = '';
2437: if ($curroption eq '') {
2438: $checked = ' checked="checked"';
2439: }
2440: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2441: '<input type="radio" name="crsreq_'.$item.
2442: '__LC_adv" value=""'.$checked.' />'.
2443: &mt('No override set').'</label></span> ';
1.101 raeburn 2444: foreach my $option (@options) {
2445: my $val = $option;
2446: if ($option eq 'norequest') {
2447: $val = 0;
2448: }
2449: if ($option eq 'validate') {
2450: my $canvalidate = 0;
2451: if (ref($validations{$item}) eq 'HASH') {
2452: if ($validations{$item}{'_LC_adv'}) {
2453: $canvalidate = 1;
2454: }
2455: }
2456: next if (!$canvalidate);
2457: }
2458: my $checked = '';
1.104 raeburn 2459: if ($val eq $curroption) {
1.101 raeburn 2460: $checked = ' checked="checked"';
2461: } elsif ($option eq 'autolimit') {
2462: if ($curroption =~ /^autolimit/) {
2463: $checked = ' checked="checked"';
2464: }
2465: }
2466: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2467: '<input type="radio" name="crsreq_'.$item.
2468: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2469: $titles{$option}.'</label>';
2470: if ($option eq 'autolimit') {
1.127 raeburn 2471: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2472: $item.'_limit__LC_adv" size="1" '.
2473: 'value="'.$currlimit.'" />';
2474: }
1.127 raeburn 2475: $advcell{$item} .= '</span> ';
1.104 raeburn 2476: if ($option eq 'autolimit') {
1.127 raeburn 2477: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2478: }
1.101 raeburn 2479: }
1.160.6.5 raeburn 2480: } elsif ($context eq 'requestauthor') {
2481: my $curroption;
2482: if (ref($settings) eq 'HASH') {
2483: $curroption = $settings->{'_LC_adv'};
2484: }
2485: my $checked = '';
2486: if ($curroption eq '') {
2487: $checked = ' checked="checked"';
2488: }
2489: $datatable .= '<span class="LC_nobreak"><label>'.
2490: '<input type="radio" name="authorreq__LC_adv"'.
2491: ' value=""'.$checked.' />'.
2492: &mt('No override set').'</label></span> ';
2493: foreach my $option (@options) {
2494: my $val = $option;
2495: if ($option eq 'norequest') {
2496: $val = 0;
2497: }
2498: my $checked = '';
2499: if ($val eq $curroption) {
2500: $checked = ' checked="checked"';
2501: }
2502: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2503: '<input type="radio" name="authorreq__LC_adv"'.
2504: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2505: $titles{$option}.'</label></span> ';
2506: }
1.101 raeburn 2507: } else {
2508: my $checked = 'checked="checked" ';
2509: if (ref($settings) eq 'HASH') {
2510: if (ref($settings->{$item}) eq 'HASH') {
2511: if ($settings->{$item}->{'_LC_adv'} == 0) {
2512: $checked = '';
2513: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2514: $checked = 'checked="checked" ';
2515: }
1.79 raeburn 2516: }
1.72 raeburn 2517: }
1.101 raeburn 2518: $datatable .= '<span class="LC_nobreak"><label>'.
2519: '<input type="checkbox" name="'.$context.'_'.$item.
2520: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2521: '</label></span> ';
2522: }
2523: }
2524: if ($context eq 'requestcourses') {
2525: $datatable .= '</tr><tr>';
2526: foreach my $item (@usertools) {
1.106 raeburn 2527: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2528: }
1.101 raeburn 2529: $datatable .= '</tr></table>';
1.72 raeburn 2530: }
1.98 raeburn 2531: $datatable .= '</td></tr>';
1.30 raeburn 2532: $$rowtotal += $typecount;
1.3 raeburn 2533: return $datatable;
2534: }
2535:
1.160.6.5 raeburn 2536: sub print_requestmail {
1.160.6.93 raeburn 2537: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25 raeburn 2538: my ($now,$datatable,%currapp);
1.102 raeburn 2539: $now = time;
2540: if (ref($settings) eq 'HASH') {
2541: if (ref($settings->{'notify'}) eq 'HASH') {
2542: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2543: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2544: }
2545: }
2546: }
1.160.6.16 raeburn 2547: my $numinrow = 2;
1.160.6.34 raeburn 2548: my $css_class;
1.160.6.93 raeburn 2549: if ($$rowtotal%2) {
2550: $css_class = 'LC_odd_row';
2551: }
2552: if ($customcss) {
2553: $css_class .= " $customcss";
2554: }
2555: $css_class =~ s/^\s+//;
2556: if ($css_class) {
2557: $css_class = ' class="'.$css_class.'"';
2558: }
2559: if ($rowstyle) {
2560: $css_class .= ' style="'.$rowstyle.'"';
2561: }
1.160.6.5 raeburn 2562: my $text;
2563: if ($action eq 'requestcourses') {
2564: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2565: } elsif ($action eq 'requestauthor') {
2566: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2567: } else {
1.160.6.34 raeburn 2568: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2569: }
1.160.6.34 raeburn 2570: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2571: ' <td>'.$text.'</td>'.
1.102 raeburn 2572: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2573: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2574: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2575: if ($numdc > 0) {
2576: $datatable .= $table;
1.102 raeburn 2577: } else {
2578: $datatable .= &mt('There are no active Domain Coordinators');
2579: }
2580: $datatable .='</td></tr>';
2581: return $datatable;
2582: }
2583:
1.160.6.30 raeburn 2584: sub print_studentcode {
2585: my ($settings,$rowtotal) = @_;
2586: my $rownum = 0;
2587: my ($output,%current);
2588: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2589: if (ref($settings) eq 'HASH') {
2590: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2591: foreach my $type (@crstypes) {
2592: $current{$type} = $settings->{'uniquecode'}{$type};
2593: }
1.160.6.30 raeburn 2594: }
2595: }
2596: $output .= '<tr>'.
2597: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2598: '<td class="LC_left_item">';
2599: foreach my $type (@crstypes) {
2600: my $check = ' ';
2601: if ($current{$type}) {
2602: $check = ' checked="checked" ';
2603: }
2604: $output .= '<span class="LC_nobreak"><label>'.
2605: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2606: &mt($type).'</label></span>'.(' 'x2).' ';
2607: }
2608: $output .= '</td></tr>';
2609: $$rowtotal ++;
2610: return $output;
2611: }
2612:
2613: sub print_textbookcourses {
1.160.6.46 raeburn 2614: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2615: my $rownum = 0;
2616: my $css_class;
2617: my $itemcount = 1;
2618: my $maxnum = 0;
2619: my $bookshash;
2620: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2621: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2622: }
2623: my %ordered;
2624: if (ref($bookshash) eq 'HASH') {
2625: foreach my $item (keys(%{$bookshash})) {
2626: if (ref($bookshash->{$item}) eq 'HASH') {
2627: my $num = $bookshash->{$item}{'order'};
2628: $ordered{$num} = $item;
2629: }
2630: }
2631: }
2632: my $confname = $dom.'-domainconfig';
2633: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2634: my $maxnum = scalar(keys(%ordered));
2635: my $datatable;
1.160.6.30 raeburn 2636: if (keys(%ordered)) {
2637: my @items = sort { $a <=> $b } keys(%ordered);
2638: for (my $i=0; $i<@items; $i++) {
2639: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2640: my $key = $ordered{$items[$i]};
2641: my %coursehash=&Apache::lonnet::coursedescription($key);
2642: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2643: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2644: if (ref($bookshash->{$key}) eq 'HASH') {
2645: $subject = $bookshash->{$key}->{'subject'};
2646: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2647: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2648: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2649: $author = $bookshash->{$key}->{'author'};
2650: $image = $bookshash->{$key}->{'image'};
2651: if ($image ne '') {
2652: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2653: my $imagethumb = "$path/tn-".$imagefile;
2654: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2655: }
1.160.6.30 raeburn 2656: }
2657: }
1.160.6.46 raeburn 2658: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2659: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2660: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2661: for (my $k=0; $k<=$maxnum; $k++) {
2662: my $vpos = $k+1;
2663: my $selstr;
2664: if ($k == $i) {
2665: $selstr = ' selected="selected" ';
2666: }
2667: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2668: }
2669: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2670: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2671: &mt('Delete?').'</label></span></td>'.
2672: '<td colspan="2">'.
1.160.6.46 raeburn 2673: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2674: (' 'x2).
1.160.6.46 raeburn 2675: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2676: if ($type eq 'textbooks') {
2677: $datatable .= (' 'x2).
1.160.6.47 raeburn 2678: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2679: (' 'x2).
1.160.6.46 raeburn 2680: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2681: (' 'x2).
2682: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2683: if ($image) {
1.160.6.114 raeburn 2684: $datatable .= $imgsrc.
1.160.6.46 raeburn 2685: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2686: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2687: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2688: }
2689: if ($switchserver) {
2690: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2691: } else {
2692: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2693: }
1.160.6.30 raeburn 2694: }
1.160.6.46 raeburn 2695: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2696: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2697: $coursetitle.'</span></td></tr>'."\n";
2698: $itemcount ++;
2699: }
2700: }
2701: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2702: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2703: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2704: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2705: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2706: for (my $k=0; $k<$maxnum+1; $k++) {
2707: my $vpos = $k+1;
2708: my $selstr;
2709: if ($k == $maxnum) {
2710: $selstr = ' selected="selected" ';
2711: }
2712: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2713: }
2714: $datatable .= '</select> '."\n".
1.160.6.87 raeburn 2715: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2716: '<td colspan="2">'.
1.160.6.46 raeburn 2717: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2718: (' 'x2).
1.160.6.46 raeburn 2719: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2720: (' 'x2);
2721: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2722: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2723: (' 'x2).
2724: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2725: (' 'x2).
2726: '<span class="LC_nobreak">'.&mt('Image:').' ';
2727: if ($switchserver) {
2728: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2729: } else {
2730: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2731: }
1.160.6.87 raeburn 2732: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2733: }
1.160.6.87 raeburn 2734: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2735: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2736: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2737: &Apache::loncommon::selectcourse_link
1.160.6.87 raeburn 2738: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2739: '</span></td>'."\n".
2740: '</tr>'."\n";
2741: $itemcount ++;
2742: return $datatable;
2743: }
2744:
2745: sub textbookcourses_javascript {
1.160.6.46 raeburn 2746: my ($settings) = @_;
2747: return unless(ref($settings) eq 'HASH');
2748: my (%ordered,%total,%jstext);
2749: foreach my $type ('textbooks','templates') {
2750: $total{$type} = 0;
2751: if (ref($settings->{$type}) eq 'HASH') {
2752: foreach my $item (keys(%{$settings->{$type}})) {
2753: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2754: my $num = $settings->{$type}->{$item}{'order'};
2755: $ordered{$type}{$num} = $item;
2756: }
2757: }
2758: $total{$type} = scalar(keys(%{$settings->{$type}}));
2759: }
2760: my @jsarray = ();
2761: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2762: push(@jsarray,$ordered{$type}{$item});
2763: }
2764: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2765: }
2766: return <<"ENDSCRIPT";
2767: <script type="text/javascript">
2768: // <![CDATA[
1.160.6.46 raeburn 2769: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2770: var changedVal;
1.160.6.46 raeburn 2771: $jstext{'textbooks'};
2772: $jstext{'templates'};
2773: var newpos;
2774: var maxh;
2775: if (caller == 'textbooks') {
2776: newpos = 'textbooks_addbook_pos';
2777: maxh = 1 + $total{'textbooks'};
2778: } else {
2779: newpos = 'templates_addbook_pos';
2780: maxh = 1 + $total{'templates'};
2781: }
1.160.6.30 raeburn 2782: var current = new Array;
2783: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2784: if (item == newpos) {
2785: changedVal = newitemVal;
2786: } else {
2787: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2788: current[newitemVal] = newpos;
2789: }
1.160.6.46 raeburn 2790: if (caller == 'textbooks') {
2791: for (var i=0; i<textbooks.length; i++) {
2792: var elementName = 'textbooks_'+textbooks[i];
2793: if (elementName != item) {
2794: if (form.elements[elementName]) {
2795: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2796: current[currVal] = elementName;
2797: }
2798: }
2799: }
2800: }
2801: if (caller == 'templates') {
2802: for (var i=0; i<templates.length; i++) {
2803: var elementName = 'templates_'+templates[i];
2804: if (elementName != item) {
2805: if (form.elements[elementName]) {
2806: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2807: current[currVal] = elementName;
2808: }
1.160.6.30 raeburn 2809: }
2810: }
2811: }
2812: var oldVal;
2813: for (var j=0; j<maxh; j++) {
2814: if (current[j] == undefined) {
2815: oldVal = j;
2816: }
2817: }
2818: if (oldVal < changedVal) {
2819: for (var k=oldVal+1; k<=changedVal ; k++) {
2820: var elementName = current[k];
2821: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2822: }
2823: } else {
2824: for (var k=changedVal; k<oldVal; k++) {
2825: var elementName = current[k];
2826: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2827: }
2828: }
2829: return;
2830: }
2831:
2832: // ]]>
2833: </script>
2834:
2835: ENDSCRIPT
2836: }
2837:
1.160.6.113 raeburn 2838: sub wafproxy_javascript {
2839: my ($dom) = @_;
2840: return <<"ENDSCRIPT";
2841: <script type="text/javascript">
2842: // <![CDATA[
2843: function updateWAF() {
2844: if (document.getElementById('wafproxy_remoteip')) {
2845: var wafremote = 0;
2846: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
2847: wafremote = 1;
2848: }
2849: var fields = new Array('header','trust');
2850: for (var i=0; i<fields.length; i++) {
2851: if (document.getElementById('wafproxy_'+fields[i])) {
2852: if (wafremote == 1) {
2853: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
2854: }
2855: else {
2856: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
2857: }
2858: }
2859: }
2860: if (document.getElementById('wafproxyranges_$dom')) {
2861: if (wafremote == 1) {
2862: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
2863: } else {
2864: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
2865: if (document.display.wafproxy_vpnaccess[i].checked) {
2866: if (document.display.wafproxy_vpnaccess[i].value == 0) {
2867: document.getElementById('wafproxyranges_$dom').style.display = 'none';
2868: }
2869: }
2870: }
2871: }
2872: }
2873: }
2874: return;
2875: }
2876:
2877: function checkWAF() {
2878: if (document.getElementById('wafproxy_remoteip')) {
2879: var wafvpn = 0;
2880: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
2881: if (document.display.wafproxy_vpnaccess[i].checked) {
2882: if (document.display.wafproxy_vpnaccess[i].value == 1) {
2883: wafvpn = 1;
2884: }
2885: break;
2886: }
2887: }
2888: var vpn = new Array('vpnint','vpnext');
2889: for (var i=0; i<vpn.length; i++) {
2890: if (document.getElementById('wafproxy_show_'+vpn[i])) {
2891: if (wafvpn == 1) {
2892: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
2893: }
2894: else {
2895: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
2896: }
2897: }
2898: }
2899: if (document.getElementById('wafproxyranges_$dom')) {
2900: if (wafvpn == 1) {
2901: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
2902: }
2903: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
2904: document.getElementById('wafproxyranges_$dom').style.display = 'none';
2905: }
2906: }
2907: }
2908: return;
2909: }
2910:
2911: function toggleWAF() {
2912: if (document.getElementById('wafproxy_table')) {
2913: var wafproxy = 0;
2914: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
2915: if (document.display.wafproxy_${dom}[i].checked) {
2916: if (document.display.wafproxy_${dom}[i].value == 1) {
2917: wafproxy = 1;
2918: break;
2919: }
2920: }
2921: }
2922: if (wafproxy == 1) {
2923: document.getElementById('wafproxy_table').style.display='inline';
2924: }
2925: else {
2926: document.getElementById('wafproxy_table').style.display='none';
2927: }
2928: if (document.getElementById('wafproxyrow_${dom}')) {
2929: if (wafproxy == 1) {
2930: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
2931: }
2932: else {
2933: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
2934: }
2935: }
2936: if (document.getElementById('nowafproxyrow_$dom')) {
2937: if (wafproxy == 1) {
2938: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
2939: }
2940: else {
2941: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
2942: }
2943: }
2944: }
2945: return;
2946: }
2947: // ]]>
2948: </script>
2949:
2950: ENDSCRIPT
2951: }
2952:
2953: sub autoupdate_javascript {
2954: return <<"ENDSCRIPT";
2955: <script type="text/javascript">
2956: // <![CDATA[
2957: function toggleLastActiveDays(form) {
2958: var radioname = 'lastactive';
2959: var divid = 'lastactive_div';
2960: var num = form.elements[radioname].length;
2961: if (num) {
2962: var setvis = '';
2963: for (var i=0; i<num; i++) {
2964: if (form.elements[radioname][i].checked) {
2965: if (form.elements[radioname][i].value == '1') {
2966: if (document.getElementById(divid)) {
2967: document.getElementById(divid).style.display = 'inline-block';
2968: }
2969: setvis = 1;
2970: }
2971: break;
2972: }
2973: }
2974: if (!setvis) {
2975: if (document.getElementById(divid)) {
2976: document.getElementById(divid).style.display = 'none';
2977: }
2978: }
2979: }
2980: return;
2981: }
2982: // ]]>
2983: </script>
2984:
2985: ENDSCRIPT
2986: }
2987:
2988: sub saml_javascript {
2989: return <<"ENDSCRIPT";
2990: <script type="text/javascript">
2991: // <![CDATA[
2992: function toggleSamlOptions(form,hostid) {
2993: var radioname = 'saml_'+hostid;
2994: var tablecellon = 'samloptionson_'+hostid;
2995: var tablecelloff = 'samloptionsoff_'+hostid;
2996: var num = form.elements[radioname].length;
2997: if (num) {
2998: var setvis = '';
2999: for (var i=0; i<num; i++) {
3000: if (form.elements[radioname][i].checked) {
3001: if (form.elements[radioname][i].value == '1') {
3002: if (document.getElementById(tablecellon)) {
3003: document.getElementById(tablecellon).style.display='';
3004: }
3005: if (document.getElementById(tablecelloff)) {
3006: document.getElementById(tablecelloff).style.display='none';
3007: }
3008: setvis = 1;
3009: }
3010: break;
3011: }
3012: }
3013: if (!setvis) {
3014: if (document.getElementById(tablecellon)) {
3015: document.getElementById(tablecellon).style.display='none';
3016: }
3017: if (document.getElementById(tablecelloff)) {
3018: document.getElementById(tablecelloff).style.display='';
3019: }
3020: }
3021: }
3022: return;
3023: }
3024: // ]]>
3025: </script>
3026:
3027: ENDSCRIPT
3028: }
3029:
3030: sub ipaccess_javascript {
3031: my ($settings) = @_;
3032: my (%ordered,$total,%jstext);
3033: $total = 0;
3034: if (ref($settings) eq 'HASH') {
3035: foreach my $item (keys(%{$settings})) {
3036: if (ref($settings->{$item}) eq 'HASH') {
3037: my $num = $settings->{$item}{'order'};
3038: $ordered{$num} = $item;
3039: }
3040: }
3041: $total = scalar(keys(%{$settings}));
3042: }
3043: my @jsarray = ();
3044: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3045: push(@jsarray,$ordered{$item});
3046: }
3047: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3048: return <<"ENDSCRIPT";
3049: <script type="text/javascript">
3050: // <![CDATA[
3051: function reorderIPaccess(form,item) {
3052: var changedVal;
3053: $jstext
3054: var newpos = 'ipaccess_pos_add';
3055: var maxh = 1 + $total;
3056: var current = new Array;
3057: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3058: if (item == newpos) {
3059: changedVal = newitemVal;
3060: } else {
3061: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3062: current[newitemVal] = newpos;
3063: }
3064: for (var i=0; i<ipaccess.length; i++) {
3065: var elementName = 'ipaccess_pos_'+ipaccess[i];
3066: if (elementName != item) {
3067: if (form.elements[elementName]) {
3068: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3069: current[currVal] = elementName;
3070: }
3071: }
3072: }
3073: var oldVal;
3074: for (var j=0; j<maxh; j++) {
3075: if (current[j] == undefined) {
3076: oldVal = j;
3077: }
3078: }
3079: if (oldVal < changedVal) {
3080: for (var k=oldVal+1; k<=changedVal ; k++) {
3081: var elementName = current[k];
3082: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3083: }
3084: } else {
3085: for (var k=changedVal; k<oldVal; k++) {
3086: var elementName = current[k];
3087: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3088: }
3089: }
3090: return;
3091: }
3092: // ]]>
3093: </script>
3094:
3095: ENDSCRIPT
3096: }
3097:
1.3 raeburn 3098: sub print_autoenroll {
1.30 raeburn 3099: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3100: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68 raeburn 3101: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 3102: if (ref($settings) eq 'HASH') {
3103: if (exists($settings->{'run'})) {
3104: if ($settings->{'run'} eq '0') {
3105: $runoff = ' checked="checked" ';
3106: $runon = ' ';
3107: } else {
3108: $runon = ' checked="checked" ';
3109: $runoff = ' ';
3110: }
3111: } else {
3112: if ($autorun) {
3113: $runon = ' checked="checked" ';
3114: $runoff = ' ';
3115: } else {
3116: $runoff = ' checked="checked" ';
3117: $runon = ' ';
3118: }
3119: }
1.129 raeburn 3120: if (exists($settings->{'co-owners'})) {
3121: if ($settings->{'co-owners'} eq '0') {
3122: $coownersoff = ' checked="checked" ';
3123: $coownerson = ' ';
3124: } else {
3125: $coownerson = ' checked="checked" ';
3126: $coownersoff = ' ';
3127: }
3128: } else {
3129: $coownersoff = ' checked="checked" ';
3130: $coownerson = ' ';
3131: }
1.3 raeburn 3132: if (exists($settings->{'sender_domain'})) {
3133: $defdom = $settings->{'sender_domain'};
3134: }
1.160.6.68 raeburn 3135: if (exists($settings->{'autofailsafe'})) {
3136: $failsafe = $settings->{'autofailsafe'};
3137: }
1.14 raeburn 3138: } else {
3139: if ($autorun) {
3140: $runon = ' checked="checked" ';
3141: $runoff = ' ';
3142: } else {
3143: $runoff = ' checked="checked" ';
3144: $runon = ' ';
3145: }
1.3 raeburn 3146: }
3147: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3148: my $notif_sender;
3149: if (ref($settings) eq 'HASH') {
3150: $notif_sender = $settings->{'sender_uname'};
3151: }
1.3 raeburn 3152: my $datatable='<tr class="LC_odd_row">'.
3153: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3154: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3155: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3156: $runon.' value="1" />'.&mt('Yes').'</label> '.
3157: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3158: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3159: '</tr><tr>'.
3160: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3161: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3162: &mt('username').': '.
3163: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3164: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3165: ': '.$domform.'</span></td></tr>'.
3166: '<tr class="LC_odd_row">'.
3167: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3168: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3169: '<input type="radio" name="autoassign_coowners"'.
3170: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3171: '<label><input type="radio" name="autoassign_coowners"'.
3172: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 3173: '</tr><tr>'.
3174: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3175: '<td class="LC_right_item"><span class="LC_nobreak">'.
3176: '<input type="text" name="autoenroll_failsafe"'.
1.160.6.87 raeburn 3177: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.160.6.68 raeburn 3178: $$rowtotal += 4;
1.3 raeburn 3179: return $datatable;
3180: }
3181:
3182: sub print_autoupdate {
1.30 raeburn 3183: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 3184: my ($enable,$datatable);
1.3 raeburn 3185: if ($position eq 'top') {
1.160.6.113 raeburn 3186: my %choices = &Apache::lonlocal::texthash (
3187: run => 'Auto-update active?',
3188: classlists => 'Update information in classlists?',
3189: unexpired => 'Skip updates for users without active or future roles?',
3190: lastactive => 'Skip updates for inactive users?',
3191: );
3192: my $itemcount = 0;
1.3 raeburn 3193: my $updateon = ' ';
3194: my $updateoff = ' checked="checked" ';
3195: if (ref($settings) eq 'HASH') {
3196: if ($settings->{'run'} eq '1') {
3197: $updateon = $updateoff;
3198: $updateoff = ' ';
3199: }
3200: }
1.160.6.113 raeburn 3201: $enable = '<tr class="LC_odd_row">'.
3202: '<td>'.&mt($choices{'run'}).'</td>'.
3203: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3204: '<input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3205: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 3206: '<label><input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3207: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 3208: '</tr>';
1.160.6.113 raeburn 3209: my @toggles = ('classlists','unexpired');
3210: my %defaultchecked = ('classlists' => 'off',
3211: 'unexpired' => 'off'
3212: );
3213: $$rowtotal ++;
3214: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3215: \%choices,$itemcount,'','','left','no');
3216: $datatable = $enable.$datatable;
3217: $$rowtotal += $itemcount;
3218: my $lastactiveon = ' ';
3219: my $lastactiveoff = ' checked="checked" ';
3220: my $lastactivestyle = 'none';
3221: my $lastactivedays;
3222: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
3223: if (ref($settings) eq 'HASH') {
3224: if ($settings->{'lastactive'} =~ /^\d+$/) {
3225: $lastactiveon = $lastactiveoff;
3226: $lastactiveoff = ' ';
3227: $lastactivestyle = 'inline-block';
3228: $lastactivedays = $settings->{'lastactive'};
3229: }
3230: }
3231: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3232: $datatable .= '<tr'.$css_class.'>'.
3233: '<td>'.$choices{'lastactive'}.'</td>'.
3234: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3235: '<input type="radio" name="lastactive"'.
3236: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
3237: ' <label>'.
3238: '<input type="radio" name="lastactive"'.
3239: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
3240: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
3241: ': '.&mt('inactive = no activity in last [_1] days',
3242: '<input type="text" size="5" name="lastactivedays" value="'.
3243: $lastactivedays.'" />').
3244: '</span></td>'.
3245: '</tr>';
3246: $$rowtotal ++;
1.131 raeburn 3247: } elsif ($position eq 'middle') {
3248: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3249: my $numinrow = 3;
3250: my $locknamesettings;
3251: $datatable .= &insttypes_row($settings,$types,$usertypes,
3252: $dom,$numinrow,$othertitle,
1.160.6.93 raeburn 3253: 'lockablenames',$rowtotal);
1.131 raeburn 3254: $$rowtotal ++;
1.3 raeburn 3255: } else {
1.44 raeburn 3256: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3257: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3258: 'permanentemail','id');
1.33 raeburn 3259: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3260: my $numrows = 0;
1.26 raeburn 3261: if (ref($types) eq 'ARRAY') {
3262: if (@{$types} > 0) {
3263: $datatable =
3264: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3265: \@fields,$types,\$numrows);
1.30 raeburn 3266: $$rowtotal += @{$types};
1.26 raeburn 3267: }
1.3 raeburn 3268: }
3269: $datatable .=
3270: &usertype_update_row($settings,{'default' => $othertitle},
3271: \%fieldtitles,\@fields,['default'],
3272: \$numrows);
1.30 raeburn 3273: $$rowtotal ++;
1.3 raeburn 3274: }
3275: return $datatable;
3276: }
3277:
1.125 raeburn 3278: sub print_autocreate {
3279: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3280: my (%createon,%createoff,%currhash);
1.125 raeburn 3281: my @types = ('xml','req');
3282: if (ref($settings) eq 'HASH') {
3283: foreach my $item (@types) {
3284: $createoff{$item} = ' checked="checked" ';
3285: $createon{$item} = ' ';
3286: if (exists($settings->{$item})) {
3287: if ($settings->{$item}) {
3288: $createon{$item} = ' checked="checked" ';
3289: $createoff{$item} = ' ';
3290: }
3291: }
3292: }
1.160.6.16 raeburn 3293: if ($settings->{'xmldc'} ne '') {
3294: $currhash{$settings->{'xmldc'}} = 1;
3295: }
1.125 raeburn 3296: } else {
3297: foreach my $item (@types) {
3298: $createoff{$item} = ' checked="checked" ';
3299: $createon{$item} = ' ';
3300: }
3301: }
3302: $$rowtotal += 2;
1.160.6.16 raeburn 3303: my $numinrow = 2;
1.125 raeburn 3304: my $datatable='<tr class="LC_odd_row">'.
3305: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3306: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3307: '<input type="radio" name="autocreate_xml"'.
3308: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3309: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3310: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3311: '</td></tr><tr>'.
3312: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3313: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3314: '<input type="radio" name="autocreate_req"'.
3315: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3316: '<label><input type="radio" name="autocreate_req"'.
3317: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 3318: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3319: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 3320: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3321: if ($numdc > 1) {
1.160.6.50 raeburn 3322: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3323: '</td><td class="LC_left_item">';
1.125 raeburn 3324: } else {
1.160.6.50 raeburn 3325: $datatable .= &mt('Course creation processed as:').
3326: '</td><td class="LC_right_item">';
1.125 raeburn 3327: }
1.160.6.50 raeburn 3328: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 3329: $$rowtotal += $rows;
1.125 raeburn 3330: return $datatable;
3331: }
3332:
1.23 raeburn 3333: sub print_directorysrch {
1.160.6.72 raeburn 3334: my ($position,$dom,$settings,$rowtotal) = @_;
3335: my $datatable;
3336: if ($position eq 'top') {
3337: my $instsrchon = ' ';
3338: my $instsrchoff = ' checked="checked" ';
3339: my ($exacton,$containson,$beginson);
3340: my $instlocalon = ' ';
3341: my $instlocaloff = ' checked="checked" ';
3342: if (ref($settings) eq 'HASH') {
3343: if ($settings->{'available'} eq '1') {
3344: $instsrchon = $instsrchoff;
3345: $instsrchoff = ' ';
3346: }
3347: if ($settings->{'localonly'} eq '1') {
3348: $instlocalon = $instlocaloff;
3349: $instlocaloff = ' ';
3350: }
3351: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3352: foreach my $type (@{$settings->{'searchtypes'}}) {
3353: if ($type eq 'exact') {
3354: $exacton = ' checked="checked" ';
3355: } elsif ($type eq 'contains') {
3356: $containson = ' checked="checked" ';
3357: } elsif ($type eq 'begins') {
3358: $beginson = ' checked="checked" ';
3359: }
3360: }
3361: } else {
3362: if ($settings->{'searchtypes'} eq 'exact') {
3363: $exacton = ' checked="checked" ';
3364: } elsif ($settings->{'searchtypes'} eq 'contains') {
3365: $containson = ' checked="checked" ';
3366: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3367: $exacton = ' checked="checked" ';
3368: $containson = ' checked="checked" ';
3369: }
3370: }
1.23 raeburn 3371: }
1.160.6.72 raeburn 3372: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3373: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 3374:
1.160.6.72 raeburn 3375: my $numinrow = 4;
3376: my $cansrchrow = 0;
3377: $datatable='<tr class="LC_odd_row">'.
3378: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3379: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3380: '<input type="radio" name="dirsrch_available"'.
3381: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3382: '<label><input type="radio" name="dirsrch_available"'.
3383: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3384: '</tr><tr>'.
3385: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3386: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3387: '<input type="radio" name="dirsrch_instlocalonly"'.
3388: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3389: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3390: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3391: '</tr>';
3392: $$rowtotal += 2;
3393: if (ref($usertypes) eq 'HASH') {
3394: if (keys(%{$usertypes}) > 0) {
3395: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93 raeburn 3396: $numinrow,$othertitle,'cansearch',
3397: $rowtotal);
1.160.6.72 raeburn 3398: $cansrchrow = 1;
3399: }
1.26 raeburn 3400: }
1.160.6.72 raeburn 3401: if ($cansrchrow) {
3402: $$rowtotal ++;
3403: $datatable .= '<tr>';
3404: } else {
3405: $datatable .= '<tr class="LC_odd_row">';
3406: }
3407: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3408: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3409: foreach my $title (@{$titleorder}) {
3410: if (defined($searchtitles->{$title})) {
3411: my $check = ' ';
3412: if (ref($settings) eq 'HASH') {
3413: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3414: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3415: $check = ' checked="checked" ';
3416: }
1.39 raeburn 3417: }
1.25 raeburn 3418: }
1.160.6.72 raeburn 3419: $datatable .= '<td class="LC_left_item">'.
3420: '<span class="LC_nobreak"><label>'.
3421: '<input type="checkbox" name="searchby" '.
3422: 'value="'.$title.'"'.$check.'/>'.
3423: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3424: }
3425: }
1.160.6.72 raeburn 3426: $datatable .= '</tr></table></td></tr>';
3427: $$rowtotal ++;
3428: if ($cansrchrow) {
3429: $datatable .= '<tr class="LC_odd_row">';
3430: } else {
3431: $datatable .= '<tr>';
3432: }
3433: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3434: '<td class="LC_left_item" colspan="2">'.
3435: '<span class="LC_nobreak"><label>'.
3436: '<input type="checkbox" name="searchtypes" '.
3437: $exacton.' value="exact" />'.&mt('Exact match').
3438: '</label> '.
3439: '<label><input type="checkbox" name="searchtypes" '.
3440: $beginson.' value="begins" />'.&mt('Begins with').
3441: '</label> '.
3442: '<label><input type="checkbox" name="searchtypes" '.
3443: $containson.' value="contains" />'.&mt('Contains').
3444: '</label></span></td></tr>';
3445: $$rowtotal ++;
1.26 raeburn 3446: } else {
1.160.6.72 raeburn 3447: my $domsrchon = ' checked="checked" ';
3448: my $domsrchoff = ' ';
3449: my $domlocalon = ' ';
3450: my $domlocaloff = ' checked="checked" ';
3451: if (ref($settings) eq 'HASH') {
3452: if ($settings->{'lclocalonly'} eq '1') {
3453: $domlocalon = $domlocaloff;
3454: $domlocaloff = ' ';
3455: }
3456: if ($settings->{'lcavailable'} eq '0') {
3457: $domsrchoff = $domsrchon;
3458: $domsrchon = ' ';
3459: }
3460: }
3461: $datatable='<tr class="LC_odd_row">'.
3462: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3463: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3464: '<input type="radio" name="dirsrch_domavailable"'.
3465: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3466: '<label><input type="radio" name="dirsrch_domavailable"'.
3467: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3468: '</tr><tr>'.
3469: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3470: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3471: '<input type="radio" name="dirsrch_domlocalonly"'.
3472: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3473: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3474: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3475: '</tr>';
3476: $$rowtotal += 2;
1.26 raeburn 3477: }
1.25 raeburn 3478: return $datatable;
3479: }
3480:
1.28 raeburn 3481: sub print_contacts {
1.160.6.78 raeburn 3482: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3483: my $datatable;
3484: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 3485: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.160.6.107 raeburn 3486: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.160.6.78 raeburn 3487: if ($position eq 'top') {
3488: if (ref($settings) eq 'HASH') {
3489: foreach my $item (@contacts) {
3490: if (exists($settings->{$item})) {
3491: $to{$item} = $settings->{$item};
3492: }
1.28 raeburn 3493: }
3494: }
1.160.6.78 raeburn 3495: } elsif ($position eq 'middle') {
3496: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91 raeburn 3497: 'updatesmail','idconflictsmail','hostipmail');
1.28 raeburn 3498: foreach my $type (@mailings) {
1.160.6.78 raeburn 3499: $otheremails{$type} = '';
3500: }
1.160.6.107 raeburn 3501: } elsif ($position eq 'lower') {
3502: if (ref($settings) eq 'HASH') {
3503: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3504: %lonstatus = %{$settings->{'lonstatus'}};
3505: }
3506: }
1.160.6.78 raeburn 3507: } else {
3508: @mailings = ('helpdeskmail','otherdomsmail');
3509: foreach my $type (@mailings) {
3510: $otheremails{$type} = '';
3511: }
3512: $bccemails{'helpdeskmail'} = '';
3513: $bccemails{'otherdomsmail'} = '';
3514: $includestr{'helpdeskmail'} = '';
3515: $includestr{'otherdomsmail'} = '';
3516: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3517: }
3518: if (ref($settings) eq 'HASH') {
1.160.6.107 raeburn 3519: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 3520: foreach my $type (@mailings) {
3521: if (exists($settings->{$type})) {
3522: if (ref($settings->{$type}) eq 'HASH') {
3523: foreach my $item (@contacts) {
3524: if ($settings->{$type}{$item}) {
3525: $checked{$type}{$item} = ' checked="checked" ';
3526: }
1.28 raeburn 3527: }
1.160.6.78 raeburn 3528: $otheremails{$type} = $settings->{$type}{'others'};
3529: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3530: $bccemails{$type} = $settings->{$type}{'bcc'};
3531: if ($settings->{$type}{'include'} ne '') {
3532: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3533: $includestr{$type} = &unescape($includestr{$type});
3534: }
3535: }
3536: }
3537: } elsif ($type eq 'lonstatusmail') {
3538: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3539: }
3540: }
3541: }
3542: if ($position eq 'bottom') {
3543: foreach my $type (@mailings) {
3544: $bccemails{$type} = $settings->{$type}{'bcc'};
3545: if ($settings->{$type}{'include'} ne '') {
3546: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3547: $includestr{$type} = &unescape($includestr{$type});
3548: }
3549: }
3550: if (ref($settings->{'helpform'}) eq 'HASH') {
3551: if (ref($fields) eq 'ARRAY') {
3552: foreach my $field (@{$fields}) {
3553: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3554: }
1.160.6.78 raeburn 3555: }
3556: if (exists($settings->{'helpform'}{'maxsize'})) {
3557: $maxsize = $settings->{'helpform'}{'maxsize'};
3558: } else {
3559: $maxsize = '1.0';
3560: }
3561: } else {
3562: if (ref($fields) eq 'ARRAY') {
3563: foreach my $field (@{$fields}) {
3564: $currfield{$field} = 'yes';
1.134 raeburn 3565: }
1.28 raeburn 3566: }
1.160.6.78 raeburn 3567: $maxsize = '1.0';
1.28 raeburn 3568: }
3569: }
3570: } else {
1.160.6.78 raeburn 3571: if ($position eq 'top') {
3572: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3573: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3574: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3575: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
3576: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3577: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3578: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3579: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91 raeburn 3580: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78 raeburn 3581: } elsif ($position eq 'bottom') {
3582: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3583: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3584: if (ref($fields) eq 'ARRAY') {
3585: foreach my $field (@{$fields}) {
3586: $currfield{$field} = 'yes';
3587: }
3588: }
3589: $maxsize = '1.0';
3590: }
1.28 raeburn 3591: }
3592: my ($titles,$short_titles) = &contact_titles();
3593: my $rownum = 0;
3594: my $css_class;
1.160.6.78 raeburn 3595: if ($position eq 'top') {
3596: foreach my $item (@contacts) {
3597: $css_class = $rownum%2?' class="LC_odd_row"':'';
3598: $datatable .= '<tr'.$css_class.'>'.
3599: '<td><span class="LC_nobreak">'.$titles->{$item}.
3600: '</span></td><td class="LC_right_item">'.
3601: '<input type="text" name="'.$item.'" value="'.
3602: $to{$item}.'" /></td></tr>';
3603: $rownum ++;
3604: }
1.160.6.101 raeburn 3605: } elsif ($position eq 'bottom') {
3606: $css_class = $rownum%2?' class="LC_odd_row"':'';
3607: $datatable .= '<tr'.$css_class.'>'.
3608: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3609: &mt('(e-mail, subject, and description always shown)').
3610: '</td><td class="LC_left_item">';
3611: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3612: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3613: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3614: foreach my $field (@{$fields}) {
3615: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3616: if (($field eq 'screenshot') || ($field eq 'cc')) {
3617: $datatable .= ' '.&mt('(logged-in users)');
3618: }
3619: $datatable .='</td><td>';
3620: my $clickaction;
3621: if ($field eq 'screenshot') {
3622: $clickaction = ' onclick="screenshotSize(this);"';
3623: }
3624: if (ref($possoptions->{$field}) eq 'ARRAY') {
3625: foreach my $option (@{$possoptions->{$field}}) {
3626: my $checked;
3627: if ($currfield{$field} eq $option) {
3628: $checked = ' checked="checked"';
3629: }
3630: $datatable .= '<span class="LC_nobreak"><label>'.
3631: '<input type="radio" name="helpform_'.$field.'" '.
3632: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3633: '</label></span>'.(' 'x2);
3634: }
3635: }
3636: if ($field eq 'screenshot') {
3637: my $display;
3638: if ($currfield{$field} eq 'no') {
3639: $display = ' style="display:none"';
3640: }
3641: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
3642: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3643: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3644: }
3645: $datatable .= '</td></tr>';
3646: }
3647: $datatable .= '</table>';
3648: }
3649: $datatable .= '</td></tr>'."\n";
3650: $rownum ++;
3651: }
1.160.6.107 raeburn 3652: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 3653: foreach my $type (@mailings) {
3654: $css_class = $rownum%2?' class="LC_odd_row"':'';
3655: $datatable .= '<tr'.$css_class.'>'.
3656: '<td><span class="LC_nobreak">'.
3657: $titles->{$type}.': </span></td>'.
3658: '<td class="LC_left_item">';
3659: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3660: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3661: }
3662: $datatable .= '<span class="LC_nobreak">';
3663: foreach my $item (@contacts) {
3664: $datatable .= '<label>'.
3665: '<input type="checkbox" name="'.$type.'"'.
3666: $checked{$type}{$item}.
3667: ' value="'.$item.'" />'.$short_titles->{$item}.
3668: '</label> ';
3669: }
3670: $datatable .= '</span><br />'.&mt('Others').': '.
3671: '<input type="text" name="'.$type.'_others" '.
3672: 'value="'.$otheremails{$type}.'" />';
3673: my %locchecked;
3674: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3675: foreach my $loc ('s','b') {
3676: if ($includeloc{$type} eq $loc) {
3677: $locchecked{$loc} = ' checked="checked"';
3678: last;
3679: }
3680: }
3681: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3682: '<input type="text" name="'.$type.'_bcc" '.
3683: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3684: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3685: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 3686: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 3687: '<span class="LC_nobreak">'.&mt('Location:').' '.
3688: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3689: (' 'x2).
3690: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3691: '</span></fieldset>';
3692: }
3693: $datatable .= '</td></tr>'."\n";
3694: $rownum ++;
3695: }
1.28 raeburn 3696: }
1.160.6.78 raeburn 3697: if ($position eq 'middle') {
3698: my %choices;
1.160.6.107 raeburn 3699: my $corelink = &core_link_msu();
3700: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.160.6.78 raeburn 3701: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.160.6.107 raeburn 3702: $corelink);
3703: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
3704: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.160.6.78 raeburn 3705: my %defaultchecked = ('reporterrors' => 'on',
1.160.6.107 raeburn 3706: 'reportupdates' => 'on',
3707: 'reportstatus' => 'on');
1.160.6.78 raeburn 3708: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3709: \%choices,$rownum);
3710: $datatable .= $reports;
1.160.6.107 raeburn 3711: } elsif ($position eq 'lower') {
1.160.6.109 raeburn 3712: my (%current,%excluded,%weights);
1.160.6.107 raeburn 3713: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
3714: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.160.6.109 raeburn 3715: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.160.6.107 raeburn 3716: } else {
1.160.6.109 raeburn 3717: $current{'errorthreshold'} = $defaults->{'threshold'};
1.160.6.107 raeburn 3718: }
3719: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.160.6.109 raeburn 3720: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.160.6.107 raeburn 3721: } else {
1.160.6.109 raeburn 3722: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.160.6.107 raeburn 3723: }
3724: if (ref($lonstatus{'weights'}) eq 'HASH') {
3725: foreach my $type ('E','W','N','U') {
3726: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
3727: $weights{$type} = $lonstatus{'weights'}{$type};
3728: } else {
3729: $weights{$type} = $defaults->{$type};
3730: }
3731: }
3732: } else {
3733: foreach my $type ('E','W','N','U') {
3734: $weights{$type} = $defaults->{$type};
3735: }
3736: }
3737: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
3738: if (@{$lonstatus{'excluded'}} > 0) {
3739: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
3740: }
3741: }
1.160.6.109 raeburn 3742: foreach my $item ('errorthreshold','errorsysmail') {
3743: $css_class = $rownum%2?' class="LC_odd_row"':'';
3744: $datatable .= '<tr'.$css_class.'>'.
3745: '<td class="LC_left_item"><span class="LC_nobreak">'.
3746: $titles->{$item}.
3747: '</span></td><td class="LC_left_item">'.
3748: '<input type="text" name="'.$item.'" value="'.
3749: $current{$item}.'" size="5" /></td></tr>';
3750: $rownum ++;
3751: }
1.160.6.107 raeburn 3752: $css_class = $rownum%2?' class="LC_odd_row"':'';
3753: $datatable .= '<tr'.$css_class.'>'.
3754: '<td class="LC_left_item">'.
3755: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
3756: '</span></td><td class="LC_left_item"><table><tr>';
3757: foreach my $type ('E','W','N','U') {
3758: $datatable .= '<td>'.$names->{$type}.'<br />'.
3759: '<input type="text" name="errorweights_'.$type.'" value="'.
3760: $weights{$type}.'" size="5" /></td>';
3761: }
3762: $datatable .= '</tr></table></tr>';
3763: $rownum ++;
3764: $css_class = $rownum%2?' class="LC_odd_row"':'';
3765: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
3766: $titles->{'errorexcluded'}.'</td>'.
3767: '<td class="LC_left_item"><table>';
3768: my $numinrow = 4;
3769: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
3770: for (my $i=0; $i<@ids; $i++) {
3771: my $rem = $i%($numinrow);
3772: if ($rem == 0) {
3773: if ($i > 0) {
3774: $datatable .= '</tr>';
3775: }
3776: $datatable .= '<tr>';
3777: }
3778: my $check;
3779: if ($excluded{$ids[$i]}) {
3780: $check = ' checked="checked" ';
3781: }
3782: $datatable .= '<td class="LC_left_item">'.
3783: '<span class="LC_nobreak"><label>'.
3784: '<input type="checkbox" name="errorexcluded" '.
3785: 'value="'.$ids[$i].'"'.$check.' />'.
3786: $ids[$i].'</label></span></td>';
3787: }
3788: my $colsleft = $numinrow - @ids%($numinrow);
3789: if ($colsleft > 1 ) {
3790: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3791: ' </td>';
3792: } elsif ($colsleft == 1) {
3793: $datatable .= '<td class="LC_left_item"> </td>';
3794: }
3795: $datatable .= '</tr></table></td></tr>';
3796: $rownum ++;
1.160.6.78 raeburn 3797: } elsif ($position eq 'bottom') {
1.160.6.101 raeburn 3798: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3799: my (@posstypes,%usertypeshash);
3800: if (ref($types) eq 'ARRAY') {
3801: @posstypes = @{$types};
3802: }
3803: if (@posstypes) {
3804: if (ref($usertypes) eq 'HASH') {
3805: %usertypeshash = %{$usertypes};
3806: }
3807: my @overridden;
3808: my $numinrow = 4;
3809: if (ref($settings) eq 'HASH') {
3810: if (ref($settings->{'overrides'}) eq 'HASH') {
3811: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3812: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3813: push(@overridden,$key);
3814: foreach my $item (@contacts) {
3815: if ($settings->{'overrides'}{$key}{$item}) {
3816: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3817: }
3818: }
3819: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3820: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3821: $includeloc{'override_'.$key} = '';
3822: $includestr{'override_'.$key} = '';
3823: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3824: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3825: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3826: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3827: }
1.160.6.78 raeburn 3828: }
3829: }
3830: }
1.160.6.101 raeburn 3831: }
3832: my $customclass = 'LC_helpdesk_override';
3833: my $optionsprefix = 'LC_options_helpdesk_';
3834:
3835: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3836:
3837: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3838: $numinrow,$othertitle,'overrides',
3839: \$rownum,$onclicktypes,$customclass);
3840: $rownum ++;
3841: $usertypeshash{'default'} = $othertitle;
3842: foreach my $status (@posstypes) {
3843: my $css_class;
3844: if ($rownum%2) {
3845: $css_class = 'LC_odd_row ';
3846: }
3847: $css_class .= $customclass;
3848: my $rowid = $optionsprefix.$status;
3849: my $hidden = 1;
3850: my $currstyle = 'display:none';
3851: if (grep(/^\Q$status\E$/,@overridden)) {
3852: $currstyle = 'display:table-row';
3853: $hidden = 0;
3854: }
3855: my $key = 'override_'.$status;
3856: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3857: $includeloc{$key},$includestr{$key},$status,$rowid,
3858: $usertypeshash{$status},$css_class,$currstyle,
3859: \@contacts,$short_titles);
3860: unless ($hidden) {
3861: $rownum ++;
1.160.6.78 raeburn 3862: }
3863: }
1.134 raeburn 3864: }
1.28 raeburn 3865: }
1.30 raeburn 3866: $$rowtotal += $rownum;
1.28 raeburn 3867: return $datatable;
3868: }
3869:
1.160.6.107 raeburn 3870: sub core_link_msu {
3871: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3872: &mt('LON-CAPA core group - MSU'),600,500);
3873: }
3874:
1.160.6.101 raeburn 3875: sub overridden_helpdesk {
3876: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3877: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3878: my $class = 'LC_left_item';
3879: if ($css_class) {
3880: $css_class = ' class="'.$css_class.'"';
3881: }
3882: if ($rowid) {
3883: $rowid = ' id="'.$rowid.'"';
3884: }
3885: if ($rowstyle) {
3886: $rowstyle = ' style="'.$rowstyle.'"';
3887: }
3888: my ($output,$description);
3889: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3890: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3891: "<td>$description</td>\n".
3892: '<td class="'.$class.'" colspan="2">'.
3893: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3894: '<span class="LC_nobreak">';
3895: if (ref($contacts) eq 'ARRAY') {
3896: foreach my $item (@{$contacts}) {
3897: my $check;
3898: if (ref($checked) eq 'HASH') {
3899: $check = $checked->{$item};
3900: }
3901: my $title;
3902: if (ref($short_titles) eq 'HASH') {
3903: $title = $short_titles->{$item};
3904: }
3905: $output .= '<label>'.
3906: '<input type="checkbox" name="override_'.$type.'"'.$check.
3907: ' value="'.$item.'" />'.$title.'</label> ';
3908: }
3909: }
3910: $output .= '</span><br />'.&mt('Others').': '.
3911: '<input type="text" name="override_'.$type.'_others" '.
3912: 'value="'.$otheremails.'" />';
3913: my %locchecked;
3914: foreach my $loc ('s','b') {
3915: if ($includeloc eq $loc) {
3916: $locchecked{$loc} = ' checked="checked"';
3917: last;
3918: }
3919: }
3920: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3921: '<input type="text" name="override_'.$type.'_bcc" '.
3922: 'value="'.$bccemails.'" /></fieldset>'.
3923: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3924: &mt('Text automatically added to e-mail:').' '.
3925: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
3926: '<span class="LC_nobreak">'.&mt('Location:').' '.
3927: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3928: (' 'x2).
3929: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3930: '</span></fieldset>'.
3931: '</td></tr>'."\n";
3932: return $output;
3933: }
3934:
1.160.6.78 raeburn 3935: sub contacts_javascript {
3936: return <<"ENDSCRIPT";
3937:
3938: <script type="text/javascript">
3939: // <![CDATA[
3940:
3941: function screenshotSize(field) {
3942: if (document.getElementById('help_screenshotsize')) {
3943: if (field.value == 'no') {
3944: document.getElementById('help_screenshotsize').style.display="none";
3945: } else {
3946: document.getElementById('help_screenshotsize').style.display="";
3947: }
3948: }
3949: return;
3950: }
3951:
1.160.6.101 raeburn 3952: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3953: if (form.elements[checkbox].length != undefined) {
3954: var count = 0;
3955: if (docount) {
3956: for (var i=0; i<form.elements[checkbox].length; i++) {
3957: if (form.elements[checkbox][i].checked) {
3958: count ++;
3959: }
3960: }
3961: }
3962: for (var i=0; i<form.elements[checkbox].length; i++) {
3963: var type = form.elements[checkbox][i].value;
3964: if (document.getElementById(prefix+type)) {
3965: if (form.elements[checkbox][i].checked) {
3966: document.getElementById(prefix+type).style.display = 'table-row';
3967: if (count % 2 == 1) {
3968: document.getElementById(prefix+type).className = target+' LC_odd_row';
3969: } else {
3970: document.getElementById(prefix+type).className = target;
3971: }
3972: count ++;
3973: } else {
3974: document.getElementById(prefix+type).style.display = 'none';
3975: }
3976: }
3977: }
3978: }
3979: return;
3980: }
3981:
1.160.6.78 raeburn 3982: // ]]>
3983: </script>
3984:
3985: ENDSCRIPT
3986: }
3987:
1.118 jms 3988: sub print_helpsettings {
1.160.6.73 raeburn 3989: my ($position,$dom,$settings,$rowtotal) = @_;
3990: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 3991: my $formname = 'display';
1.160.6.5 raeburn 3992: my ($datatable,$itemcount);
1.160.6.73 raeburn 3993: if ($position eq 'top') {
3994: $itemcount = 1;
3995: my (%choices,%defaultchecked,@toggles);
3996: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3997: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3998: &mt('LON-CAPA bug tracker'),600,500));
3999: %defaultchecked = ('submitbugs' => 'on');
4000: @toggles = ('submitbugs');
4001: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4002: \%choices,$itemcount);
4003: $$rowtotal ++;
4004: } else {
4005: my $css_class;
4006: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 4007: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 4008: if (ref($settings) eq 'HASH') {
4009: if (ref($settings->{'adhoc'}) eq 'HASH') {
4010: %current = %{$settings->{'adhoc'}};
4011: }
1.160.6.77 raeburn 4012: }
4013: my $count = 0;
4014: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 4015: if ($key=~/^rolesdef\_(\w+)$/) {
4016: my $rolename = $1;
1.160.6.77 raeburn 4017: my (%privs,$order);
1.160.6.73 raeburn 4018: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4019: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 4020: if (ref($current{$rolename}) eq 'HASH') {
4021: $order = $current{$rolename}{'order'};
4022: }
4023: if ($order eq '') {
4024: $order = $count;
4025: }
4026: $ordered{$order} = $rolename;
4027: $count++;
1.160.6.73 raeburn 4028: }
4029: }
1.160.6.77 raeburn 4030: my $maxnum = scalar(keys(%ordered));
4031: my @roles_by_num = ();
4032: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4033: push(@roles_by_num,$item);
4034: }
4035: my $context = 'domprefs';
4036: my $crstype = 'Course';
4037: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 4038: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 4039: my ($numstatustypes,@jsarray);
4040: if (ref($types) eq 'ARRAY') {
4041: if (@{$types} > 0) {
4042: $numstatustypes = scalar(@{$types});
4043: push(@accesstypes,'status');
4044: @jsarray = ('bystatus');
4045: }
4046: }
1.160.6.86 raeburn 4047: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 4048: if (keys(%domhelpdesk)) {
4049: push(@accesstypes,('inc','exc'));
4050: push(@jsarray,('notinc','notexc'));
4051: }
4052: my $hiddenstr = join("','",@jsarray);
4053: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 4054: my $context = 'domprefs';
4055: my $crstype = 'Course';
1.160.6.77 raeburn 4056: my $prefix = 'helproles_';
4057: my $add_class = 'LC_hidden';
4058: foreach my $num (@roles_by_num) {
4059: my $role = $ordered{$num};
4060: my ($desc,$access,@statuses);
4061: if (ref($current{$role}) eq 'HASH') {
4062: $desc = $current{$role}{'desc'};
4063: $access = $current{$role}{'access'};
4064: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4065: @statuses = @{$current{$role}{'insttypes'}};
4066: }
4067: }
4068: if ($desc eq '') {
4069: $desc = $role;
4070: }
4071: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 4072: my %full=();
4073: my %levels= (
4074: course => {},
4075: domain => {},
4076: system => {},
4077: );
4078: my %levelscurrent=(
4079: course => {},
4080: domain => {},
4081: system => {},
4082: );
4083: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4084: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4085: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 4086: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
4087: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
4088: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4089: for (my $k=0; $k<=$maxnum; $k++) {
4090: my $vpos = $k+1;
4091: my $selstr;
4092: if ($k == $num) {
4093: $selstr = ' selected="selected" ';
4094: }
4095: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4096: }
4097: $datatable .= '</select>'.(' 'x2).
4098: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4099: '</td>'.
4100: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4101: &mt('Name shown to users:').
4102: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4103: '</fieldset>'.
4104: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4105: $othertitle,$usertypes,$types,\%domhelpdesk).
4106: '<fieldset>'.
4107: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 4108: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 4109: \%levelscurrent,$identifier,
4110: 'LC_hidden',$prefix.$num.'_privs').
4111: '</fieldset></td>';
1.160.6.73 raeburn 4112: $itemcount ++;
4113: }
4114: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4115: my $newcust = 'custhelp'.$count;
4116: my (%privs,%levelscurrent);
4117: my %full=();
4118: my %levels= (
4119: course => {},
4120: domain => {},
4121: system => {},
4122: );
4123: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4124: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 4125: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
4126: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
4127: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4128: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4129: for (my $k=0; $k<$maxnum+1; $k++) {
4130: my $vpos = $k+1;
4131: my $selstr;
4132: if ($k == $maxnum) {
4133: $selstr = ' selected="selected" ';
4134: }
4135: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4136: }
4137: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 4138: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4139: '</label></span></td>'.
1.160.6.77 raeburn 4140: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4141: '<span class="LC_nobreak">'.
4142: &mt('Internal name:').
4143: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4144: '</span>'.(' 'x4).
4145: '<span class="LC_nobreak">'.
4146: &mt('Name shown to users:').
4147: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4148: '</span></fieldset>'.
4149: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4150: $usertypes,$types,\%domhelpdesk).
4151: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 4152: &Apache::lonuserutils::custom_role_header($context,$crstype,
4153: \@templateroles,$newcust).
4154: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4155: \%levelscurrent,$newcust).
1.160.6.87 raeburn 4156: '</fieldset>'.
4157: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4158: '</td></tr>';
1.160.6.73 raeburn 4159: $count ++;
4160: $$rowtotal += $count;
4161: }
1.160.6.5 raeburn 4162: return $datatable;
1.121 raeburn 4163: }
4164:
1.160.6.77 raeburn 4165: sub adhocbutton {
4166: my ($prefix,$num,$field,$visibility) = @_;
4167: my %lt = &Apache::lonlocal::texthash(
4168: show => 'Show details',
4169: hide => 'Hide details',
4170: );
4171: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4172: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4173: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4174: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4175: }
4176:
4177: sub helpsettings_javascript {
4178: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4179: return unless(ref($roles_by_num) eq 'ARRAY');
4180: my %html_js_lt = &Apache::lonlocal::texthash(
4181: show => 'Show details',
4182: hide => 'Hide details',
4183: );
4184: &html_escape(\%html_js_lt);
4185: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4186: return <<"ENDSCRIPT";
4187: <script type="text/javascript">
4188: // <![CDATA[
4189:
4190: function reorderHelpRoles(form,item) {
4191: var changedVal;
4192: $jstext
4193: var newpos = 'helproles_${total}_pos';
4194: var maxh = 1 + $total;
4195: var current = new Array();
4196: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4197: if (item == newpos) {
4198: changedVal = newitemVal;
4199: } else {
4200: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4201: current[newitemVal] = newpos;
4202: }
4203: for (var i=0; i<helproles.length; i++) {
4204: var elementName = 'helproles_'+helproles[i]+'_pos';
4205: if (elementName != item) {
4206: if (form.elements[elementName]) {
4207: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4208: current[currVal] = elementName;
4209: }
4210: }
4211: }
4212: var oldVal;
4213: for (var j=0; j<maxh; j++) {
4214: if (current[j] == undefined) {
4215: oldVal = j;
4216: }
4217: }
4218: if (oldVal < changedVal) {
4219: for (var k=oldVal+1; k<=changedVal ; k++) {
4220: var elementName = current[k];
4221: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4222: }
4223: } else {
4224: for (var k=changedVal; k<oldVal; k++) {
4225: var elementName = current[k];
4226: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4227: }
4228: }
4229: return;
4230: }
4231:
4232: function helpdeskAccess(num) {
4233: var curraccess = null;
4234: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4235: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4236: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4237: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4238: }
4239: }
4240: }
4241: var shown = Array();
4242: var hidden = Array();
4243: if (curraccess == 'none') {
4244: hidden = Array('$hiddenstr');
4245: } else {
4246: if (curraccess == 'status') {
4247: shown = Array('bystatus');
4248: hidden = Array('notinc','notexc');
4249: } else {
4250: if (curraccess == 'exc') {
4251: shown = Array('notexc');
4252: hidden = Array('notinc','bystatus');
4253: }
4254: if (curraccess == 'inc') {
4255: shown = Array('notinc');
4256: hidden = Array('notexc','bystatus');
4257: }
1.160.6.79 raeburn 4258: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 4259: hidden = Array('notinc','notexc','bystatus');
4260: }
4261: }
4262: }
4263: if (hidden.length > 0) {
4264: for (var i=0; i<hidden.length; i++) {
4265: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4266: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4267: }
4268: }
4269: }
4270: if (shown.length > 0) {
4271: for (var i=0; i<shown.length; i++) {
4272: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4273: if (shown[i] == 'privs') {
4274: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4275: } else {
4276: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4277: }
4278: }
4279: }
4280: }
4281: return;
4282: }
4283:
4284: function toggleHelpdeskItem(num,field) {
4285: if (document.getElementById('helproles_'+num+'_'+field)) {
4286: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
4287: document.getElementById('helproles_'+num+'_'+field).className =
4288: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4289: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4290: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4291: }
4292: } else {
4293: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4294: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4295: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4296: }
4297: }
4298: }
4299: return;
4300: }
4301:
4302: // ]]>
4303: </script>
4304:
4305: ENDSCRIPT
4306: }
4307:
4308: sub helpdeskroles_access {
4309: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4310: $usertypes,$types,$domhelpdesk) = @_;
4311: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4312: my %lt = &Apache::lonlocal::texthash(
4313: 'rou' => 'Role usage',
4314: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 4315: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4316: 'dh' => 'All with domain helpdesk role',
4317: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 4318: 'none' => 'None',
4319: 'status' => 'Determined based on institutional status',
4320: 'inc' => 'Include all, but exclude specific personnel',
4321: 'exc' => 'Exclude all, but include specific personnel',
4322: );
4323: my %usecheck = (
4324: all => ' checked="checked"',
4325: );
4326: my %displaydiv = (
4327: status => 'none',
4328: inc => 'none',
4329: exc => 'none',
4330: priv => 'block',
4331: );
4332: my $output;
4333: if (ref($current) eq 'HASH') {
4334: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4335: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4336: $usecheck{$current->{access}} = $usecheck{'all'};
4337: delete($usecheck{'all'});
4338: if ($current->{access} =~ /^(status|inc|exc)$/) {
4339: my $access = $1;
4340: $displaydiv{$access} = 'inline';
4341: } elsif ($current->{access} eq 'none') {
4342: $displaydiv{'priv'} = 'none';
4343: }
4344: }
4345: }
4346: }
4347: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4348: '<p>'.$lt{'whi'}.'</p>';
4349: foreach my $access (@{$accesstypes}) {
4350: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4351: ' onclick="helpdeskAccess('."'$num'".');" />'.
4352: $lt{$access}.'</label>';
4353: if ($access eq 'status') {
4354: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4355: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4356: $othertitle,$usertypes,$types).
4357: '</div>';
4358: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4359: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4360: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4361: '</div>';
4362: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4363: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4364: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4365: '</div>';
4366: }
4367: $output .= '</p>';
4368: }
4369: $output .= '</fieldset>';
4370: return $output;
4371: }
4372:
1.121 raeburn 4373: sub radiobutton_prefs {
1.160.6.16 raeburn 4374: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.113 raeburn 4375: $additional,$align,$firstval) = @_;
1.121 raeburn 4376: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4377: (ref($choices) eq 'HASH'));
4378:
4379: my (%checkedon,%checkedoff,$datatable,$css_class);
4380:
4381: foreach my $item (@{$toggles}) {
4382: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4383: $checkedon{$item} = ' checked="checked" ';
4384: $checkedoff{$item} = ' ';
1.121 raeburn 4385: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4386: $checkedoff{$item} = ' checked="checked" ';
4387: $checkedon{$item} = ' ';
4388: }
4389: }
4390: if (ref($settings) eq 'HASH') {
1.121 raeburn 4391: foreach my $item (@{$toggles}) {
1.118 jms 4392: if ($settings->{$item} eq '1') {
4393: $checkedon{$item} = ' checked="checked" ';
4394: $checkedoff{$item} = ' ';
4395: } elsif ($settings->{$item} eq '0') {
4396: $checkedoff{$item} = ' checked="checked" ';
4397: $checkedon{$item} = ' ';
4398: }
4399: }
1.121 raeburn 4400: }
1.160.6.16 raeburn 4401: if ($onclick) {
4402: $onclick = ' onclick="'.$onclick.'"';
4403: }
1.121 raeburn 4404: foreach my $item (@{$toggles}) {
1.118 jms 4405: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4406: $datatable .=
1.160.6.16 raeburn 4407: '<tr'.$css_class.'><td valign="top">'.
4408: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 4409: '</span></td>';
4410: if ($align eq 'left') {
4411: $datatable .= '<td class="LC_left_item">';
4412: } else {
4413: $datatable .= '<td class="LC_right_item">';
4414: }
1.160.6.113 raeburn 4415: $datatable .= '<span class="LC_nobreak">';
4416: if ($firstval eq 'no') {
4417: $datatable .=
4418: '<label><input type="radio" name="'.
4419: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
4420: '</label> <label><input type="radio" name="'.$item.'" '.
4421: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
4422: } else {
4423: $datatable .=
1.118 jms 4424: '<label><input type="radio" name="'.
1.160.6.16 raeburn 4425: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4426: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.113 raeburn 4427: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
4428: }
4429: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 4430: $itemcount ++;
1.121 raeburn 4431: }
4432: return ($datatable,$itemcount);
4433: }
4434:
4435: sub print_coursedefaults {
1.139 raeburn 4436: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 4437: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4438: my $itemcount = 1;
1.160.6.16 raeburn 4439: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 4440: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 4441: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4442: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 4443: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4444: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.115! raeburn 4445: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.160.6.90 raeburn 4446: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 4447: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 4448: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 4449: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 4450: );
1.160.6.21 raeburn 4451: my %staticdefaults = (
4452: anonsurvey_threshold => 10,
4453: uploadquota => 500,
1.160.6.57 raeburn 4454: postsubmit => 60,
1.160.6.70 raeburn 4455: mysqltables => 172800,
1.160.6.21 raeburn 4456: );
1.139 raeburn 4457: if ($position eq 'top') {
1.160.6.57 raeburn 4458: %defaultchecked = (
4459: 'uselcmath' => 'on',
4460: 'usejsme' => 'on',
1.160.6.115! raeburn 4461: 'inline_chem' => 'on',
1.160.6.64 raeburn 4462: 'canclone' => 'none',
1.160.6.57 raeburn 4463: );
1.160.6.115! raeburn 4464: @toggles = ('uselcmath','usejsme','inline_chem');
1.160.6.90 raeburn 4465: my $deftex = $Apache::lonnet::deftex;
4466: if (ref($settings) eq 'HASH') {
4467: if ($settings->{'texengine'}) {
4468: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
4469: $deftex = $settings->{'texengine'};
4470: }
4471: }
4472: }
4473: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4474: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
4475: '<span class="LC_nobreak">'.$choices{'texengine'}.
4476: '</span></td><td class="LC_right_item">'.
4477: '<select name="texengine">'."\n";
4478: my %texoptions = (
4479: MathJax => 'MathJax',
4480: mimetex => &mt('Convert to Images'),
4481: tth => &mt('TeX to HTML'),
4482: );
4483: foreach my $renderer ('MathJax','mimetex','tth') {
4484: my $selected = '';
4485: if ($renderer eq $deftex) {
4486: $selected = ' selected="selected"';
4487: }
4488: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
4489: }
4490: $mathdisp .= '</select></td></tr>'."\n";
4491: $itemcount ++;
1.139 raeburn 4492: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4493: \%choices,$itemcount);
1.160.6.90 raeburn 4494: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 4495: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4496: $datatable .=
4497: '<tr'.$css_class.'><td valign="top">'.
4498: '<span class="LC_nobreak">'.$choices{'canclone'}.
4499: '</span></td><td class="LC_left_item">';
4500: my $currcanclone = 'none';
4501: my $onclick;
4502: my @cloneoptions = ('none','domain');
1.160.6.111 raeburn 4503: my %clonetitles = &Apache::lonlocal::texthash (
1.160.6.64 raeburn 4504: none => 'No additional course requesters',
4505: domain => "Any course requester in course's domain",
4506: instcode => 'Course requests for official courses ...',
4507: );
4508: my (%codedefaults,@code_order,@posscodes);
4509: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4510: \@code_order) eq 'ok') {
4511: if (@code_order > 0) {
4512: push(@cloneoptions,'instcode');
4513: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4514: }
4515: }
4516: if (ref($settings) eq 'HASH') {
4517: if ($settings->{'canclone'}) {
4518: if (ref($settings->{'canclone'}) eq 'HASH') {
4519: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4520: if (@code_order > 0) {
4521: $currcanclone = 'instcode';
4522: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4523: }
4524: }
4525: } elsif ($settings->{'canclone'} eq 'domain') {
4526: $currcanclone = $settings->{'canclone'};
4527: }
4528: }
4529: }
4530: foreach my $option (@cloneoptions) {
4531: my ($checked,$additional);
4532: if ($currcanclone eq $option) {
4533: $checked = ' checked="checked"';
4534: }
4535: if ($option eq 'instcode') {
4536: if (@code_order) {
4537: my $show = 'none';
4538: if ($checked) {
4539: $show = 'block';
4540: }
4541: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4542: &mt('Institutional codes for new and cloned course have identical:').
4543: '<br />';
4544: foreach my $item (@code_order) {
4545: my $codechk;
4546: if ($checked) {
4547: if (grep(/^\Q$item\E$/,@posscodes)) {
4548: $codechk = ' checked="checked"';
4549: }
4550: }
4551: $additional .= '<label>'.
4552: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4553: $item.'</label>';
4554: }
4555: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4556: }
4557: }
4558: $datatable .=
4559: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4560: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4561: '</label> '.$additional.'</span><br />';
4562: }
4563: $datatable .= '</td>'.
4564: '</tr>';
4565: $itemcount ++;
1.139 raeburn 4566: } else {
4567: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 4568: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 4569: my $currusecredits = 0;
1.160.6.57 raeburn 4570: my $postsubmitclient = 1;
1.160.6.30 raeburn 4571: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 4572: if (ref($settings) eq 'HASH') {
4573: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 4574: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4575: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4576: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4577: }
4578: }
1.160.6.16 raeburn 4579: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 4580: foreach my $type (@types) {
4581: next if ($type eq 'community');
4582: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4583: if ($defcredits{$type} ne '') {
4584: $currusecredits = 1;
4585: }
4586: }
4587: }
4588: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4589: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4590: $postsubmitclient = 0;
4591: foreach my $type (@types) {
4592: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4593: }
4594: } else {
4595: foreach my $type (@types) {
4596: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4597: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
4598: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
4599: } else {
4600: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4601: }
4602: } else {
4603: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4604: }
4605: }
4606: }
4607: } else {
4608: foreach my $type (@types) {
4609: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 4610: }
4611: }
1.160.6.70 raeburn 4612: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4613: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4614: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4615: }
4616: } else {
4617: foreach my $type (@types) {
4618: $currmysql{$type} = $staticdefaults{'mysqltables'};
4619: }
4620: }
1.160.6.58 raeburn 4621: } else {
4622: foreach my $type (@types) {
4623: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4624: }
1.139 raeburn 4625: }
4626: if (!$currdefresponder) {
1.160.6.21 raeburn 4627: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4628: } elsif ($currdefresponder < 1) {
4629: $currdefresponder = 1;
4630: }
1.160.6.21 raeburn 4631: foreach my $type (@types) {
4632: if ($curruploadquota{$type} eq '') {
4633: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4634: }
4635: }
1.139 raeburn 4636: $datatable .=
1.160.6.16 raeburn 4637: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4638: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4639: '</span></td>'.
4640: '<td class="LC_right_item"><span class="LC_nobreak">'.
4641: '<input type="text" name="anonsurvey_threshold"'.
4642: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 4643: '</td></tr>'."\n";
4644: $itemcount ++;
4645: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4646: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4647: $choices{'uploadquota'}.
4648: '</span></td>'.
4649: '<td align="right" class="LC_right_item">'.
4650: '<table><tr>';
1.160.6.21 raeburn 4651: foreach my $type (@types) {
4652: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4653: '<input type="text" name="uploadquota_'.$type.'"'.
4654: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4655: }
4656: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 4657: $itemcount ++;
1.160.6.40 raeburn 4658: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 4659: my $display = 'none';
4660: if ($currusecredits) {
4661: $display = 'block';
4662: }
4663: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 4664: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4665: foreach my $type (@types) {
4666: next if ($type eq 'community');
4667: $additional .= '<td align="center">'.&mt($type).'<br />'.
4668: '<input type="text" name="'.$type.'_credits"'.
4669: ' value="'.$defcredits{$type}.'" size="3" /></td>';
4670: }
4671: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 4672: %defaultchecked = ('coursecredits' => 'off');
4673: @toggles = ('coursecredits');
4674: my $current = {
4675: 'coursecredits' => $currusecredits,
4676: };
4677: (my $table,$itemcount) =
4678: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4679: \%choices,$itemcount,$onclick,$additional,'left');
4680: $datatable .= $table;
4681: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4682: my $display = 'none';
4683: if ($postsubmitclient) {
4684: $display = 'block';
4685: }
4686: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 4687: &mt('Number of seconds submit is disabled').'<br />'.
4688: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4689: '<table><tr>';
1.160.6.57 raeburn 4690: foreach my $type (@types) {
4691: $additional .= '<td align="center">'.&mt($type).'<br />'.
4692: '<input type="text" name="'.$type.'_timeout" value="'.
4693: $deftimeout{$type}.'" size="5" /></td>';
4694: }
4695: $additional .= '</tr></table></div>'."\n";
4696: %defaultchecked = ('postsubmit' => 'on');
4697: @toggles = ('postsubmit');
1.160.6.70 raeburn 4698: $current = {
4699: 'postsubmit' => $postsubmitclient,
4700: };
1.160.6.57 raeburn 4701: ($table,$itemcount) =
4702: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4703: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 4704: $datatable .= $table;
1.160.6.70 raeburn 4705: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4706: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4707: $choices{'mysqltables'}.
4708: '</span></td>'.
4709: '<td align="right" class="LC_right_item">'.
4710: '<table><tr>';
4711: foreach my $type (@types) {
4712: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4713: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 4714: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 4715: }
4716: $datatable .= '</tr></table></td></tr>'."\n";
4717: $itemcount ++;
4718:
1.160.6.37 raeburn 4719: }
4720: $$rowtotal += $itemcount;
4721: return $datatable;
4722: }
4723:
4724: sub print_selfenrollment {
4725: my ($position,$dom,$settings,$rowtotal) = @_;
4726: my ($css_class,$datatable);
4727: my $itemcount = 1;
4728: my @types = ('official','unofficial','community','textbook');
4729: if (($position eq 'top') || ($position eq 'middle')) {
4730: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4731: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
4732: my @rows;
4733: my $key;
4734: if ($position eq 'top') {
4735: $key = 'admin';
4736: if (ref($rowsref) eq 'ARRAY') {
4737: @rows = @{$rowsref};
4738: }
4739: } elsif ($position eq 'middle') {
4740: $key = 'default';
4741: @rows = ('types','registered','approval','limit');
4742: }
4743: foreach my $row (@rows) {
4744: if (defined($titlesref->{$row})) {
4745: $itemcount ++;
4746: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4747: $datatable .= '<tr'.$css_class.'>'.
4748: '<td>'.$titlesref->{$row}.'</td>'.
4749: '<td class="LC_left_item">'.
4750: '<table><tr>';
4751: my (%current,%currentcap);
4752: if (ref($settings) eq 'HASH') {
4753: if (ref($settings->{$key}) eq 'HASH') {
4754: foreach my $type (@types) {
4755: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4756: $current{$type} = $settings->{$key}->{$type}->{$row};
4757: }
4758: if (($row eq 'limit') && ($key eq 'default')) {
4759: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4760: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4761: }
4762: }
4763: }
4764: }
4765: }
4766: my %roles = (
4767: '0' => &Apache::lonnet::plaintext('dc'),
4768: );
4769:
4770: foreach my $type (@types) {
4771: unless (($row eq 'registered') && ($key eq 'default')) {
4772: $datatable .= '<th>'.&mt($type).'</th>';
4773: }
4774: }
4775: unless (($row eq 'registered') && ($key eq 'default')) {
4776: $datatable .= '</tr><tr>';
4777: }
4778: foreach my $type (@types) {
4779: if ($type eq 'community') {
4780: $roles{'1'} = &mt('Community personnel');
4781: } else {
4782: $roles{'1'} = &mt('Course personnel');
4783: }
4784: $datatable .= '<td style="vertical-align: top">';
4785: if ($position eq 'top') {
4786: my %checked;
4787: if ($current{$type} eq '0') {
4788: $checked{'0'} = ' checked="checked"';
4789: } else {
4790: $checked{'1'} = ' checked="checked"';
4791: }
4792: foreach my $role ('1','0') {
4793: $datatable .= '<span class="LC_nobreak"><label>'.
4794: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4795: 'value="'.$role.'"'.$checked{$role}.' />'.
4796: $roles{$role}.'</label></span> ';
4797: }
4798: } else {
4799: if ($row eq 'types') {
4800: my %checked;
4801: if ($current{$type} =~ /^(all|dom)$/) {
4802: $checked{$1} = ' checked="checked"';
4803: } else {
4804: $checked{''} = ' checked="checked"';
4805: }
4806: foreach my $val ('','dom','all') {
4807: $datatable .= '<span class="LC_nobreak"><label>'.
4808: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4809: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4810: }
4811: } elsif ($row eq 'registered') {
4812: my %checked;
4813: if ($current{$type} eq '1') {
4814: $checked{'1'} = ' checked="checked"';
4815: } else {
4816: $checked{'0'} = ' checked="checked"';
4817: }
4818: foreach my $val ('0','1') {
4819: $datatable .= '<span class="LC_nobreak"><label>'.
4820: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4821: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4822: }
4823: } elsif ($row eq 'approval') {
4824: my %checked;
4825: if ($current{$type} =~ /^([12])$/) {
4826: $checked{$1} = ' checked="checked"';
4827: } else {
4828: $checked{'0'} = ' checked="checked"';
4829: }
4830: for my $val (0..2) {
4831: $datatable .= '<span class="LC_nobreak"><label>'.
4832: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4833: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4834: }
4835: } elsif ($row eq 'limit') {
4836: my %checked;
4837: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4838: $checked{$1} = ' checked="checked"';
4839: } else {
4840: $checked{'none'} = ' checked="checked"';
4841: }
4842: my $cap;
4843: if ($currentcap{$type} =~ /^\d+$/) {
4844: $cap = $currentcap{$type};
4845: }
4846: foreach my $val ('none','allstudents','selfenrolled') {
4847: $datatable .= '<span class="LC_nobreak"><label>'.
4848: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4849: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4850: }
4851: $datatable .= '<br />'.
4852: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4853: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4854: '</span>';
4855: }
4856: }
4857: $datatable .= '</td>';
4858: }
4859: $datatable .= '</tr>';
4860: }
4861: $datatable .= '</table></td></tr>';
4862: }
4863: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 4864: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4865: }
4866: $$rowtotal += $itemcount;
4867: return $datatable;
4868: }
4869:
4870: sub print_validation_rows {
4871: my ($caller,$dom,$settings,$rowtotal) = @_;
4872: my ($itemsref,$namesref,$fieldsref);
4873: if ($caller eq 'selfenroll') {
4874: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4875: } elsif ($caller eq 'requestcourses') {
4876: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4877: }
4878: my %currvalidation;
4879: if (ref($settings) eq 'HASH') {
4880: if (ref($settings->{'validation'}) eq 'HASH') {
4881: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 4882: }
1.160.6.39 raeburn 4883: }
4884: my $datatable;
4885: my $itemcount = 0;
4886: foreach my $item (@{$itemsref}) {
4887: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4888: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4889: $namesref->{$item}.
4890: '</span></td>'.
4891: '<td class="LC_left_item">';
4892: if (($item eq 'url') || ($item eq 'button')) {
4893: $datatable .= '<span class="LC_nobreak">'.
4894: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4895: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4896: } elsif ($item eq 'fields') {
4897: my @currfields;
4898: if (ref($currvalidation{$item}) eq 'ARRAY') {
4899: @currfields = @{$currvalidation{$item}};
4900: }
4901: foreach my $field (@{$fieldsref}) {
4902: my $check = '';
4903: if (grep(/^\Q$field\E$/,@currfields)) {
4904: $check = ' checked="checked"';
4905: }
4906: $datatable .= '<span class="LC_nobreak"><label>'.
4907: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4908: ' value="'.$field.'"'.$check.' />'.$field.
4909: '</label></span> ';
4910: }
4911: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 4912: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 4913: $currvalidation{$item}.
1.160.6.37 raeburn 4914: '</textarea>';
1.160.6.39 raeburn 4915: }
4916: $datatable .= '</td></tr>'."\n";
4917: if (ref($rowtotal)) {
1.160.6.37 raeburn 4918: $itemcount ++;
4919: }
1.139 raeburn 4920: }
1.160.6.39 raeburn 4921: if ($caller eq 'requestcourses') {
4922: my %currhash;
1.160.6.51 raeburn 4923: if (ref($settings) eq 'HASH') {
4924: if (ref($settings->{'validation'}) eq 'HASH') {
4925: if ($settings->{'validation'}{'dc'} ne '') {
4926: $currhash{$settings->{'validation'}{'dc'}} = 1;
4927: }
1.160.6.39 raeburn 4928: }
4929: }
4930: my $numinrow = 2;
4931: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4932: 'validationdc',%currhash);
1.160.6.50 raeburn 4933: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 4934: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 4935: if ($numdc > 1) {
1.160.6.50 raeburn 4936: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 4937: } else {
1.160.6.50 raeburn 4938: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 4939: }
1.160.6.50 raeburn 4940: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 4941: $itemcount ++;
4942: }
4943: if (ref($rowtotal)) {
4944: $$rowtotal += $itemcount;
4945: }
1.121 raeburn 4946: return $datatable;
1.118 jms 4947: }
4948:
1.160.6.98 raeburn 4949: sub print_passwords {
4950: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
4951: my ($datatable,$css_class);
4952: my $itemcount = 0;
4953: my %titles = &Apache::lonlocal::texthash (
4954: captcha => '"Forgot Password" CAPTCHA validation',
4955: link => 'Reset link expiration (hours)',
4956: case => 'Case-sensitive usernames/e-mail',
4957: prelink => 'Information required (form 1)',
4958: postlink => 'Information required (form 2)',
4959: emailsrc => 'LON-CAPA e-mail address type(s)',
4960: customtext => 'Domain specific text (HTML)',
4961: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
4962: intauth_check => 'Check bcrypt cost if authenticated',
4963: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
4964: permanent => 'Permanent e-mail address',
4965: critical => 'Critical notification address',
4966: notify => 'Notification address',
4967: min => 'Minimum password length',
4968: max => 'Maximum password length',
4969: chars => 'Required characters',
4970: numsaved => 'Number of previous passwords to save and disallow reuse',
4971: );
4972: if ($position eq 'top') {
4973: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4974: my $shownlinklife = 2;
4975: my $prelink = 'both';
4976: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
4977: if (ref($settings) eq 'HASH') {
4978: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
4979: $shownlinklife = $settings->{resetlink};
4980: }
4981: if (ref($settings->{resetcase}) eq 'ARRAY') {
4982: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
4983: }
4984: if ($settings->{resetprelink} =~ /^(both|either)$/) {
4985: $prelink = $settings->{resetprelink};
4986: }
4987: if (ref($settings->{resetpostlink}) eq 'HASH') {
4988: %postlink = %{$settings->{resetpostlink}};
4989: }
4990: if (ref($settings->{resetemail}) eq 'ARRAY') {
4991: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
4992: }
4993: if ($settings->{resetremove}) {
4994: $nostdtext = 1;
4995: }
4996: if ($settings->{resetcustom}) {
4997: $customurl = $settings->{resetcustom};
4998: }
4999: } else {
5000: if (ref($types) eq 'ARRAY') {
5001: foreach my $item (@{$types}) {
5002: $casesens{$item} = 1;
5003: $postlink{$item} = ['username','email'];
5004: }
5005: }
5006: $casesens{'default'} = 1;
5007: $postlink{'default'} = ['username','email'];
5008: $prelink = 'both';
5009: %emailsrc = (
5010: permanent => 1,
5011: critical => 1,
5012: notify => 1,
5013: );
5014: }
5015: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
5016: $itemcount ++;
5017: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5018: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
5019: '<td class="LC_left_item">'.
5020: '<input type="textbox" value="'.$shownlinklife.'" '.
5021: 'name="passwords_link" size="3" /></td></tr>';
5022: $itemcount ++;
5023: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5024: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
5025: '<td class="LC_left_item">';
5026: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5027: foreach my $item (@{$types}) {
5028: my $checkedcase;
5029: if ($casesens{$item}) {
5030: $checkedcase = ' checked="checked"';
5031: }
5032: $datatable .= '<span class="LC_nobreak"><label>'.
5033: '<input type="checkbox" name="passwords_case_sensitive" value="'.
5034: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.160.6.104 raeburn 5035: '</span> ';
1.160.6.98 raeburn 5036: }
5037: }
5038: my $checkedcase;
5039: if ($casesens{'default'}) {
5040: $checkedcase = ' checked="checked"';
5041: }
5042: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5043: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
5044: $othertitle.'</label></span></td>';
5045: $itemcount ++;
5046: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5047: my %checkedpre = (
5048: both => ' checked="checked"',
5049: either => '',
5050: );
5051: if ($prelink eq 'either') {
5052: $checkedpre{either} = ' checked="checked"';
5053: $checkedpre{both} = '';
5054: }
5055: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
5056: '<td class="LC_left_item"><span class="LC_nobreak">'.
5057: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
5058: &mt('Both username and e-mail address').'</label></span> '.
5059: '<span class="LC_nobreak"><label>'.
5060: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
5061: &mt('Either username or e-mail address').'</label></span></td></tr>';
5062: $itemcount ++;
5063: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5064: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
5065: '<td class="LC_left_item">';
5066: my %postlinked;
5067: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5068: foreach my $item (@{$types}) {
5069: undef(%postlinked);
5070: $datatable .= '<fieldset style="display: inline-block;">'.
5071: '<legend>'.$usertypes->{$item}.'</legend>';
5072: if (ref($postlink{$item}) eq 'ARRAY') {
5073: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
5074: }
5075: foreach my $field ('email','username') {
5076: my $checked;
5077: if ($postlinked{$field}) {
5078: $checked = ' checked="checked"';
5079: }
5080: $datatable .= '<span class="LC_nobreak"><label>'.
5081: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
5082: $field.'"'.$checked.' />'.$field.'</label>'.
5083: '<span> ';
5084: }
5085: $datatable .= '</fieldset>';
5086: }
5087: }
5088: if (ref($postlink{'default'}) eq 'ARRAY') {
5089: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
5090: }
5091: $datatable .= '<fieldset style="display: inline-block;">'.
5092: '<legend>'.$othertitle.'</legend>';
5093: foreach my $field ('email','username') {
5094: my $checked;
5095: if ($postlinked{$field}) {
5096: $checked = ' checked="checked"';
5097: }
5098: $datatable .= '<span class="LC_nobreak"><label>'.
5099: '<input type="checkbox" name="passwords_postlink_default" value="'.
5100: $field.'"'.$checked.' />'.$field.'</label>'.
5101: '<span> ';
5102: }
5103: $datatable .= '</fieldset></td></tr>';
5104: $itemcount ++;
5105: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5106: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
5107: '<td class="LC_left_item">';
5108: foreach my $type ('permanent','critical','notify') {
5109: my $checkedemail;
5110: if ($emailsrc{$type}) {
5111: $checkedemail = ' checked="checked"';
5112: }
5113: $datatable .= '<span class="LC_nobreak"><label>'.
5114: '<input type="checkbox" name="passwords_emailsrc" value="'.
5115: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
5116: '<span> ';
5117: }
5118: $datatable .= '</td></tr>';
5119: $itemcount ++;
5120: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5121: my $switchserver = &check_switchserver($dom,$confname);
5122: my ($showstd,$noshowstd);
5123: if ($nostdtext) {
5124: $noshowstd = ' checked="checked"';
5125: } else {
5126: $showstd = ' checked="checked"';
5127: }
5128: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
5129: '<td class="LC_left_item"><span class="LC_nobreak">'.
5130: &mt('Retain standard text:').
5131: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
5132: &mt('Yes').'</label>'.' '.
5133: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
5134: &mt('No').'</label></span><br />'.
5135: '<span class="LC_fontsize_small">'.
5136: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
5137: &mt('Include custom text:');
5138: if ($customurl) {
1.160.6.104 raeburn 5139: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.160.6.98 raeburn 5140: undef,undef,undef,undef,'background-color:#ffffff');
5141: $datatable .= '<span class="LC_nobreak"> '.$link.
5142: '<label><input type="checkbox" name="passwords_custom_del"'.
5143: ' value="1" />'.&mt('Delete?').'</label></span>'.
5144: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
5145: }
5146: if ($switchserver) {
5147: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
5148: } else {
5149: $datatable .='<span class="LC_nobreak"> '.
5150: '<input type="file" name="passwords_customfile" /></span>';
5151: }
5152: $datatable .= '</td></tr>';
5153: } elsif ($position eq 'middle') {
5154: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
5155: my @items = ('intauth_cost','intauth_check','intauth_switch');
5156: my %defaults;
5157: if (ref($domconf{'defaults'}) eq 'HASH') {
5158: %defaults = %{$domconf{'defaults'}};
5159: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
5160: $defaults{'intauth_cost'} = 10;
5161: }
5162: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
5163: $defaults{'intauth_check'} = 0;
5164: }
5165: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
5166: $defaults{'intauth_switch'} = 0;
5167: }
5168: } else {
5169: %defaults = (
5170: 'intauth_cost' => 10,
5171: 'intauth_check' => 0,
5172: 'intauth_switch' => 0,
5173: );
5174: }
5175: foreach my $item (@items) {
5176: if ($itemcount%2) {
5177: $css_class = '';
5178: } else {
5179: $css_class = ' class="LC_odd_row" ';
5180: }
5181: $datatable .= '<tr'.$css_class.'>'.
5182: '<td><span class="LC_nobreak">'.$titles{$item}.
5183: '</span></td><td class="LC_left_item" colspan="3">';
5184: if ($item eq 'intauth_switch') {
5185: my @options = (0,1,2);
5186: my %optiondesc = &Apache::lonlocal::texthash (
5187: 0 => 'No',
5188: 1 => 'Yes',
5189: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
5190: );
5191: $datatable .= '<table width="100%">';
5192: foreach my $option (@options) {
5193: my $checked = ' ';
5194: if ($defaults{$item} eq $option) {
5195: $checked = ' checked="checked"';
5196: }
5197: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5198: '<label><input type="radio" name="'.$item.
5199: '" value="'.$option.'"'.$checked.' />'.
5200: $optiondesc{$option}.'</label></span></td></tr>';
5201: }
5202: $datatable .= '</table>';
5203: } elsif ($item eq 'intauth_check') {
5204: my @options = (0,1,2);
5205: my %optiondesc = &Apache::lonlocal::texthash (
5206: 0 => 'No',
5207: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
5208: 2 => 'Yes, disallow login if stored cost is less than domain default',
5209: );
5210: $datatable .= '<table width="100%">';
5211: foreach my $option (@options) {
5212: my $checked = ' ';
5213: my $onclick;
5214: if ($defaults{$item} eq $option) {
5215: $checked = ' checked="checked"';
5216: }
5217: if ($option == 2) {
5218: $onclick = ' onclick="javascript:warnIntAuth(this);"';
5219: }
5220: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5221: '<label><input type="radio" name="'.$item.
5222: '" value="'.$option.'"'.$checked.$onclick.' />'.
5223: $optiondesc{$option}.'</label></span></td></tr>';
5224: }
5225: $datatable .= '</table>';
5226: } else {
5227: $datatable .= '<input type="text" name="'.$item.'" value="'.
5228: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
5229: }
5230: $datatable .= '</td></tr>';
5231: $itemcount ++;
5232: }
5233: } elsif ($position eq 'lower') {
5234: my ($min,$max,%chars,$numsaved);
1.160.6.99 raeburn 5235: $min = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 5236: if (ref($settings) eq 'HASH') {
5237: if ($settings->{min}) {
5238: $min = $settings->{min};
5239: }
5240: if ($settings->{max}) {
5241: $max = $settings->{max};
5242: }
5243: if (ref($settings->{chars}) eq 'ARRAY') {
5244: map { $chars{$_} = 1; } (@{$settings->{chars}});
5245: }
5246: if ($settings->{numsaved}) {
5247: $numsaved = $settings->{numsaved};
5248: }
5249: }
5250: my %rulenames = &Apache::lonlocal::texthash(
5251: uc => 'At least one upper case letter',
5252: lc => 'At least one lower case letter',
5253: num => 'At least one number',
5254: spec => 'At least one non-alphanumeric',
5255: );
5256: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5257: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
5258: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 5259: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
5260: 'onblur="javascript:warnIntPass(this);" />'.
5261: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.160.6.98 raeburn 5262: '</span></td></tr>';
5263: $itemcount ++;
5264: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5265: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
5266: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 5267: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
5268: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 5269: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
5270: '</span></td></tr>';
5271: $itemcount ++;
5272: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5273: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
5274: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
5275: '</span></td>';
5276: my $numinrow = 2;
5277: my @possrules = ('uc','lc','num','spec');
5278: $datatable .= '<td class="LC_left_item"><table>';
5279: for (my $i=0; $i<@possrules; $i++) {
5280: my ($rem,$checked);
5281: if ($chars{$possrules[$i]}) {
5282: $checked = ' checked="checked"';
5283: }
5284: $rem = $i%($numinrow);
5285: if ($rem == 0) {
5286: if ($i > 0) {
5287: $datatable .= '</tr>';
5288: }
5289: $datatable .= '<tr>';
5290: }
5291: $datatable .= '<td><span class="LC_nobreak"><label>'.
5292: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
5293: $rulenames{$possrules[$i]}.'</label></span></td>';
5294: }
5295: my $rem = @possrules%($numinrow);
5296: my $colsleft = $numinrow - $rem;
5297: if ($colsleft > 1 ) {
5298: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5299: ' </td>';
5300: } elsif ($colsleft == 1) {
5301: $datatable .= '<td class="LC_left_item"> </td>';
5302: }
5303: $datatable .='</table></td></tr>';
5304: $itemcount ++;
5305: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5306: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
5307: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.100 raeburn 5308: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
1.160.6.99 raeburn 5309: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 5310: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
5311: '</span></td></tr>';
5312: } else {
5313: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5314: my %ownerchg = (
5315: by => {},
5316: for => {},
5317: );
5318: my %ownertitles = &Apache::lonlocal::texthash (
5319: by => 'Course owner status(es) allowed',
5320: for => 'Student status(es) allowed',
5321: );
5322: if (ref($settings) eq 'HASH') {
5323: if (ref($settings->{crsownerchg}) eq 'HASH') {
5324: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
5325: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
5326: }
5327: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
5328: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
5329: }
5330: }
5331: }
5332: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5333: $datatable .= '<tr '.$css_class.'>'.
5334: '<td>'.
5335: &mt('Requirements').'<ul>'.
5336: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
5337: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
5338: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
5339: '<li>'.&mt('User, course, and student share same domain').'</li>'.
5340: '</ul>'.
5341: '</td>'.
5342: '<td class="LC_left_item">';
5343: foreach my $item ('by','for') {
5344: $datatable .= '<fieldset style="display: inline-block;">'.
5345: '<legend>'.$ownertitles{$item}.'</legend>';
5346: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5347: foreach my $type (@{$types}) {
5348: my $checked;
5349: if ($ownerchg{$item}{$type}) {
5350: $checked = ' checked="checked"';
5351: }
5352: $datatable .= '<span class="LC_nobreak"><label>'.
5353: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
5354: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.160.6.104 raeburn 5355: '</span> ';
1.160.6.98 raeburn 5356: }
5357: }
5358: my $checked;
5359: if ($ownerchg{$item}{'default'}) {
5360: $checked = ' checked="checked"';
5361: }
5362: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5363: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
5364: $othertitle.'</label></span></fieldset>';
5365: }
5366: $datatable .= '</td></tr>';
5367: }
5368: return $datatable;
5369: }
5370:
1.160.6.113 raeburn 5371: sub print_wafproxy {
5372: my ($position,$dom,$settings,$rowtotal) = @_;
5373: my $css_class;
5374: my $itemcount = 0;
5375: my $datatable;
5376: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5377: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
5378: my %lt = &wafproxy_titles();
5379: foreach my $server (sort(keys(%servers))) {
5380: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
5381: next if ($serverhome eq '');
5382: my $serverdom;
5383: if ($serverhome ne $server) {
5384: $serverdom = &Apache::lonnet::host_domain($serverhome);
5385: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
5386: $othercontrol{$server} = $serverdom;
5387: }
5388: } else {
5389: $serverdom = &Apache::lonnet::host_domain($server);
5390: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
5391: if ($serverdom ne $dom) {
5392: $othercontrol{$server} = $serverdom;
5393: } else {
5394: $setdom = 1;
5395: if (ref($settings) eq 'HASH') {
5396: if (ref($settings->{'alias'}) eq 'HASH') {
5397: $aliases{$dom} = $settings->{'alias'};
5398: if ($aliases{$dom} ne '') {
5399: $showdom = 1;
5400: }
5401: }
5402: if (ref($settings->{'saml'}) eq 'HASH') {
5403: $saml{$dom} = $settings->{'saml'};
5404: }
5405: }
5406: }
5407: }
5408: }
5409: if ($setdom) {
5410: %{$values{$dom}} = ();
5411: if (ref($settings) eq 'HASH') {
5412: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
5413: $values{$dom}{$item} = $settings->{$item};
5414: }
5415: }
5416: }
5417: if (keys(%othercontrol)) {
5418: %otherdoms = reverse(%othercontrol);
5419: foreach my $domain (keys(%otherdoms)) {
5420: %{$values{$domain}} = ();
5421: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
5422: if (ref($config{'wafproxy'}) eq 'HASH') {
5423: $aliases{$domain} = $config{'wafproxy'}{'alias'};
5424: if (exists($config{'wafproxy'}{'saml'})) {
5425: $saml{$domain} = $config{'wafproxy'}{'saml'};
5426: }
5427: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
5428: $values{$domain}{$item} = $config{'wafproxy'}{$item};
5429: }
5430: }
5431: }
5432: }
5433: if ($position eq 'top') {
5434: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5435: my %aliasinfo;
5436: foreach my $server (sort(keys(%servers))) {
5437: $itemcount ++;
5438: my $dom_in_effect;
5439: my $aliasrows = '<tr>'.
5440: '<td class="LC_left_item" style="vertical-align: baseline;">'.
5441: &mt('Hostname').': '.
5442: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
5443: if ($othercontrol{$server}) {
5444: $dom_in_effect = $othercontrol{$server};
5445: my ($current,$forsaml);
5446: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
5447: $current = $aliases{$dom_in_effect}{$server};
5448: }
5449: if (ref($saml{$dom_in_effect}) eq 'HASH') {
5450: if ($saml{$dom_in_effect}{$server}) {
5451: $forsaml = 1;
5452: }
5453: }
5454: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
5455: &mt('Alias').': ';
5456: if ($current) {
5457: $aliasrows .= $current;
5458: if ($forsaml) {
5459: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
5460: }
5461: } else {
5462: $aliasrows .= &mt('None');
5463: }
5464: $aliasrows .= ' <span class="LC_small">('.
5465: &mt('controlled by domain: [_1]',
5466: '<b>'.$dom_in_effect.'</b>').')</span></td>';
5467: } else {
5468: $dom_in_effect = $dom;
5469: my ($current,$samlon,$samloff);
5470: $samloff = ' checked="checked"';
5471: if (ref($aliases{$dom}) eq 'HASH') {
5472: if ($aliases{$dom}{$server}) {
5473: $current = $aliases{$dom}{$server};
5474: }
5475: }
5476: if (ref($saml{$dom}) eq 'HASH') {
5477: if ($saml{$dom}{$server}) {
5478: $samlon = $samloff;
5479: undef($samloff);
5480: }
5481: }
5482: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
5483: &mt('Alias').': '.
5484: '<input type="text" name="wafproxy_alias_'.$server.'" '.
5485: 'value="'.$current.'" size="30" />'.
5486: (' 'x2).'<span class="LC_nobreak">'.
5487: &mt('Alias used for SSO Auth').': <label>'.
5488: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
5489: &mt('No').'</label> <label>'.
5490: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
5491: &mt('Yes').'</label></span>'.
5492: '</td>';
5493: }
5494: $aliasrows .= '</tr>';
5495: $aliasinfo{$dom_in_effect} .= $aliasrows;
5496: }
5497: if ($aliasinfo{$dom}) {
5498: my ($onclick,$wafon,$wafoff,$showtable);
5499: $onclick = ' onclick="javascript:toggleWAF();"';
5500: $wafoff = ' checked="checked"';
5501: $showtable = ' style="display:none";';
5502: if ($showdom) {
5503: $wafon = $wafoff;
5504: $wafoff = '';
5505: $showtable = ' style="display:inline;"';
5506: }
5507: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5508: $datatable = '<tr'.$css_class.'>'.
5509: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
5510: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
5511: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
5512: &mt('Yes').'</label>'.(' 'x2).'<label>'.
5513: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
5514: &mt('No').'</label></span></td>'.
5515: '<td class="LC_left_item">'.
5516: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
5517: '</table></td></tr>';
5518: $itemcount++;
5519: }
5520: if (keys(%otherdoms)) {
5521: foreach my $key (sort(keys(%otherdoms))) {
5522: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5523: $datatable .= '<tr'.$css_class.'>'.
5524: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
5525: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
5526: '</table></td></tr>';
5527: $itemcount++;
5528: }
5529: }
5530: } else {
5531: my %ip_methods = &remoteip_methods();
5532: if ($setdom) {
5533: $itemcount ++;
5534: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5535: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
5536: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
5537: $wafstyle = ' style="display:none;"';
5538: $nowafstyle = ' style="display:table-row;"';
5539: $currwafdisplay = ' style="display: none"';
5540: $wafrangestyle = ' style="display: none"';
5541: $curr_remotip = 'n';
5542: $ssltossl = ' checked="checked"';
5543: if ($showdom) {
5544: $wafstyle = ' style="display:table-row;"';
5545: $nowafstyle = ' style="display:none;"';
5546: if (keys(%{$values{$dom}})) {
5547: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
5548: $curr_remotip = $values{$dom}{remoteip};
5549: }
5550: if ($curr_remotip eq 'h') {
5551: $currwafdisplay = ' style="display:table-row"';
5552: $wafrangestyle = ' style="display:inline-block;"';
5553: }
5554: if ($values{$dom}{'sslopt'}) {
5555: $alltossl = ' checked="checked"';
5556: $ssltossl = '';
5557: }
5558: }
5559: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
5560: $vpndircheck = ' checked="checked"';
5561: $currwafvpn = ' style="display:table-row;"';
5562: $wafrangestyle = ' style="display:inline-block;"';
5563: } else {
5564: $vpnaliascheck = ' checked="checked"';
5565: $currwafvpn = ' style="display:none;"';
5566: }
5567: }
5568: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
5569: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
5570: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
5571: '</tr>'.
5572: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
5573: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
5574: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
5575: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
5576: &mt('Range(s) stored in CIDR notation').'</div></td>'.
5577: '<td class="LC_left_item"><table>'.
5578: '<tr>'.
5579: '<td valign="top">'.$lt{'remoteip'}.': '.
5580: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
5581: foreach my $option ('m','h','n') {
5582: my $sel;
1.160.6.114 raeburn 5583: if ($option eq $curr_remotip) {
5584: $sel = ' selected="selected"';
5585: }
5586: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
5587: $ip_methods{$option}.'</option>';
5588: }
5589: $datatable .= '</select></td></tr>'."\n".
5590: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
5591: $lt{'ipheader'}.': '.
5592: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
5593: 'name="wafproxy_ipheader" />'.
5594: '</td></tr>'."\n".
5595: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
5596: $lt{'trusted'}.':<br />'.
5597: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
5598: $values{$dom}{'trusted'}.'</textarea>'.
5599: '</td></tr>'."\n".
5600: '<tr><td><hr /></td></tr>'."\n".
5601: '<tr>'.
1.160.6.113 raeburn 5602: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
5603: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
5604: $lt{'vpndirect'}.'</label>'.(' 'x2).
5605: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
5606: $lt{'vpnaliased'}.'</label></span></td></tr>';
5607: foreach my $item ('vpnint','vpnext') {
5608: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
5609: '<td valign="top">'.$lt{$item}.':<br />'.
5610: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
5611: $values{$dom}{$item}.'</textarea>'.
5612: '</td></tr>'."\n";
5613: }
5614: $datatable .= '<tr><td><hr /></td></tr>'."\n".
5615: '<tr>'.
5616: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
5617: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
5618: $lt{'alltossl'}.'</label>'.(' 'x2).
5619: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
5620: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
5621: '</table></td></tr>';
5622: }
5623: if (keys(%otherdoms)) {
5624: foreach my $domain (sort(keys(%otherdoms))) {
5625: $itemcount ++;
5626: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5627: $datatable .= '<tr'.$css_class.'>'.
5628: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
5629: '<td class="LC_left_item"><table>';
5630: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
5631: my $showval = &mt('None');
5632: if ($item eq 'ssl') {
5633: $showval = $lt{'ssltossl'};
5634: }
5635: if ($values{$domain}{$item}) {
5636: $showval = $values{$domain}{$item};
5637: if ($item eq 'ssl') {
5638: $showval = $lt{'alltossl'};
5639: } elsif ($item eq 'remoteip') {
5640: $showval = $ip_methods{$values{$domain}{$item}};
5641: }
5642: }
5643: $datatable .= '<tr>'.
5644: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
5645: }
5646: $datatable .= '</table></td></tr>';
5647: }
5648: }
5649: }
5650: $$rowtotal += $itemcount;
5651: return $datatable;
5652: }
5653:
5654: sub wafproxy_titles {
5655: return &Apache::lonlocal::texthash(
5656: remoteip => "Method for determining user's IP",
5657: ipheader => 'Request header containing remote IP',
5658: trusted => 'Trusted IP range(s)',
5659: vpnaccess => 'Access from institutional VPN',
5660: vpndirect => 'via regular hostname (no WAF)',
5661: vpnaliased => 'via aliased hostname (WAF)',
5662: vpnint => 'Internal IP Range(s) for VPN sessions',
5663: vpnext => 'IP Range(s) for backend WAF connections',
5664: sslopt => 'Forwarding http/https',
5665: alltossl => 'WAF forwards both http and https requests to https',
5666: ssltossl => 'WAF forwards http requests to http and https to https',
5667: );
5668: }
5669:
5670: sub remoteip_methods {
5671: return &Apache::lonlocal::texthash(
5672: m => 'Use Apache mod_remoteip',
5673: h => 'Use headers parsed by LON-CAPA',
5674: n => 'Not in use',
5675: );
5676: }
5677:
1.137 raeburn 5678: sub print_usersessions {
5679: my ($position,$dom,$settings,$rowtotal) = @_;
5680: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 5681: my (%by_ip,%by_location,@intdoms);
5682: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 5683:
5684: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 5685: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 5686: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 5687: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 5688: my $itemcount = 1;
5689: if ($position eq 'top') {
1.152 raeburn 5690: if (keys(%serverhomes) > 1) {
1.145 raeburn 5691: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.105 raeburn 5692: my ($curroffloadnow,$curroffloadoth);
1.160.6.61 raeburn 5693: if (ref($settings) eq 'HASH') {
5694: if (ref($settings->{'offloadnow'}) eq 'HASH') {
5695: $curroffloadnow = $settings->{'offloadnow'};
5696: }
1.160.6.105 raeburn 5697: if (ref($settings->{'offloadoth'}) eq 'HASH') {
5698: $curroffloadoth = $settings->{'offloadoth'};
5699: }
1.160.6.61 raeburn 5700: }
1.160.6.105 raeburn 5701: my $other_insts = scalar(keys(%by_location));
5702: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
5703: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 5704: } else {
1.140 raeburn 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 server.');
1.140 raeburn 5707: }
1.137 raeburn 5708: } else {
1.145 raeburn 5709: if (keys(%by_location) == 0) {
5710: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 5711: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 5712: } else {
5713: my %lt = &usersession_titles();
5714: my $numinrow = 5;
5715: my $prefix;
5716: my @types;
5717: if ($position eq 'bottom') {
5718: $prefix = 'remote';
5719: @types = ('version','excludedomain','includedomain');
5720: } else {
5721: $prefix = 'hosted';
5722: @types = ('excludedomain','includedomain');
5723: }
5724: my (%current,%checkedon,%checkedoff);
5725: my @lcversions = &Apache::lonnet::all_loncaparevs();
5726: my @locations = sort(keys(%by_location));
5727: foreach my $type (@types) {
5728: $checkedon{$type} = '';
5729: $checkedoff{$type} = ' checked="checked"';
5730: }
5731: if (ref($settings) eq 'HASH') {
5732: if (ref($settings->{$prefix}) eq 'HASH') {
5733: foreach my $key (keys(%{$settings->{$prefix}})) {
5734: $current{$key} = $settings->{$prefix}{$key};
5735: if ($key eq 'version') {
5736: if ($current{$key} ne '') {
5737: $checkedon{$key} = ' checked="checked"';
5738: $checkedoff{$key} = '';
5739: }
5740: } elsif (ref($current{$key}) eq 'ARRAY') {
5741: $checkedon{$key} = ' checked="checked"';
5742: $checkedoff{$key} = '';
5743: }
1.137 raeburn 5744: }
5745: }
5746: }
1.145 raeburn 5747: foreach my $type (@types) {
5748: next if ($type ne 'version' && !@locations);
5749: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5750: $datatable .= '<tr'.$css_class.'>
5751: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
5752: <span class="LC_nobreak">
5753: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
5754: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
5755: if ($type eq 'version') {
5756: my $selector = '<select name="'.$prefix.'_version">';
5757: foreach my $version (@lcversions) {
5758: my $selected = '';
5759: if ($current{'version'} eq $version) {
5760: $selected = ' selected="selected"';
5761: }
5762: $selector .= ' <option value="'.$version.'"'.
5763: $selected.'>'.$version.'</option>';
5764: }
5765: $selector .= '</select> ';
5766: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
5767: } else {
5768: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
5769: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
5770: ' />'.(' 'x2).
5771: '<input type="button" value="'.&mt('uncheck all').'" '.
5772: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
5773: "\n".
5774: '</div><div><table>';
5775: my $rem;
5776: for (my $i=0; $i<@locations; $i++) {
5777: my ($showloc,$value,$checkedtype);
5778: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
5779: my $ip = $by_location{$locations[$i]}->[0];
5780: if (ref($by_ip{$ip}) eq 'ARRAY') {
5781: $value = join(':',@{$by_ip{$ip}});
5782: $showloc = join(', ',@{$by_ip{$ip}});
5783: if (ref($current{$type}) eq 'ARRAY') {
5784: foreach my $loc (@{$by_ip{$ip}}) {
5785: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
5786: $checkedtype = ' checked="checked"';
5787: last;
5788: }
5789: }
1.138 raeburn 5790: }
5791: }
5792: }
1.145 raeburn 5793: $rem = $i%($numinrow);
5794: if ($rem == 0) {
5795: if ($i > 0) {
5796: $datatable .= '</tr>';
5797: }
5798: $datatable .= '<tr>';
5799: }
5800: $datatable .= '<td class="LC_left_item">'.
5801: '<span class="LC_nobreak"><label>'.
5802: '<input type="checkbox" name="'.$prefix.'_'.$type.
5803: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
5804: '</label></span></td>';
1.137 raeburn 5805: }
1.145 raeburn 5806: $rem = @locations%($numinrow);
5807: my $colsleft = $numinrow - $rem;
5808: if ($colsleft > 1 ) {
5809: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5810: ' </td>';
5811: } elsif ($colsleft == 1) {
5812: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 5813: }
1.145 raeburn 5814: $datatable .= '</tr></table>';
1.137 raeburn 5815: }
1.145 raeburn 5816: $datatable .= '</td></tr>';
5817: $itemcount ++;
1.137 raeburn 5818: }
5819: }
5820: }
5821: $$rowtotal += $itemcount;
5822: return $datatable;
5823: }
5824:
1.138 raeburn 5825: sub build_location_hashes {
5826: my ($intdoms,$by_ip,$by_location) = @_;
5827: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
5828: (ref($by_location) eq 'HASH'));
5829: my %iphost = &Apache::lonnet::get_iphost();
5830: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
5831: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
5832: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
5833: foreach my $id (@{$iphost{$primary_ip}}) {
5834: my $intdom = &Apache::lonnet::internet_dom($id);
5835: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
5836: push(@{$intdoms},$intdom);
5837: }
5838: }
5839: }
5840: foreach my $ip (keys(%iphost)) {
5841: if (ref($iphost{$ip}) eq 'ARRAY') {
5842: foreach my $id (@{$iphost{$ip}}) {
5843: my $location = &Apache::lonnet::internet_dom($id);
5844: if ($location) {
5845: next if (grep(/^\Q$location\E$/,@{$intdoms}));
5846: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5847: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
5848: push(@{$by_ip->{$ip}},$location);
5849: }
5850: } else {
5851: $by_ip->{$ip} = [$location];
5852: }
5853: }
5854: }
5855: }
5856: }
5857: foreach my $ip (sort(keys(%{$by_ip}))) {
5858: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5859: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
5860: my $first = $by_ip->{$ip}->[0];
5861: if (ref($by_location->{$first}) eq 'ARRAY') {
5862: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
5863: push(@{$by_location->{$first}},$ip);
5864: }
5865: } else {
5866: $by_location->{$first} = [$ip];
5867: }
5868: }
5869: }
5870: return;
5871: }
5872:
1.145 raeburn 5873: sub current_offloads_to {
5874: my ($dom,$settings,$servers) = @_;
5875: my (%spareid,%otherdomconfigs);
1.152 raeburn 5876: if (ref($servers) eq 'HASH') {
1.145 raeburn 5877: foreach my $lonhost (sort(keys(%{$servers}))) {
5878: my $gotspares;
1.152 raeburn 5879: if (ref($settings) eq 'HASH') {
5880: if (ref($settings->{'spares'}) eq 'HASH') {
5881: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
5882: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
5883: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
5884: $gotspares = 1;
5885: }
1.145 raeburn 5886: }
5887: }
5888: unless ($gotspares) {
5889: my $gotspares;
5890: my $serverhomeID =
5891: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
5892: my $serverhomedom =
5893: &Apache::lonnet::host_domain($serverhomeID);
5894: if ($serverhomedom ne $dom) {
5895: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
5896: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5897: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5898: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5899: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5900: $gotspares = 1;
5901: }
5902: }
5903: } else {
5904: $otherdomconfigs{$serverhomedom} =
5905: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
5906: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
5907: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5908: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5909: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
5910: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5911: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5912: $gotspares = 1;
5913: }
5914: }
5915: }
5916: }
5917: }
5918: }
5919: }
5920: unless ($gotspares) {
5921: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
5922: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5923: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5924: } else {
5925: my $server_hostname = &Apache::lonnet::hostname($lonhost);
5926: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
5927: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
5928: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5929: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5930: } else {
1.150 raeburn 5931: my %what = (
5932: spareid => 1,
5933: );
5934: my ($result,$returnhash) =
5935: &Apache::lonnet::get_remote_globals($lonhost,\%what);
5936: if ($result eq 'ok') {
5937: if (ref($returnhash) eq 'HASH') {
5938: if (ref($returnhash->{'spareid'}) eq 'HASH') {
5939: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
5940: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
5941: }
5942: }
1.145 raeburn 5943: }
5944: }
5945: }
5946: }
5947: }
5948: }
5949: return %spareid;
5950: }
5951:
5952: sub spares_row {
1.160.6.105 raeburn 5953: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
5954: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 5955: my $css_class;
5956: my $numinrow = 4;
5957: my $itemcount = 1;
5958: my $datatable;
1.152 raeburn 5959: my %typetitles = &sparestype_titles();
5960: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 5961: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 5962: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
5963: my ($othercontrol,$serverdom);
5964: if ($serverhome ne $server) {
5965: $serverdom = &Apache::lonnet::host_domain($serverhome);
5966: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5967: } else {
5968: $serverdom = &Apache::lonnet::host_domain($server);
5969: if ($serverdom ne $dom) {
5970: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5971: }
5972: }
5973: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.105 raeburn 5974: my ($checkednow,$checkedoth);
1.160.6.61 raeburn 5975: if (ref($curroffloadnow) eq 'HASH') {
5976: if ($curroffloadnow->{$server}) {
5977: $checkednow = ' checked="checked"';
5978: }
5979: }
1.160.6.105 raeburn 5980: if (ref($curroffloadoth) eq 'HASH') {
5981: if ($curroffloadoth->{$server}) {
5982: $checkedoth = ' checked="checked"';
5983: }
5984: }
1.145 raeburn 5985: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5986: $datatable .= '<tr'.$css_class.'>
5987: <td rowspan="2">
1.160.6.13 raeburn 5988: <span class="LC_nobreak">'.
5989: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 5990: ,'<b>'.$server.'</b>').'</span><br />'.
5991: '<span class="LC_nobreak">'."\n".
5992: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.160.6.105 raeburn 5993: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.160.6.13 raeburn 5994: "\n";
1.160.6.105 raeburn 5995: if ($other_insts) {
5996: $datatable .= '<br />'.
5997: '<span class="LC_nobreak">'."\n".
5998: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
5999: ' '.&mt('Switch other institutions on next access').'</label></span>'.
6000: "\n";
6001: }
1.145 raeburn 6002: my (%current,%canselect);
1.152 raeburn 6003: my @choices =
6004: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6005: foreach my $type ('primary','default') {
6006: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 6007: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6008: my @spares = @{$spareid->{$server}{$type}};
6009: if (@spares > 0) {
1.152 raeburn 6010: if ($othercontrol) {
6011: $current{$type} = join(', ',@spares);
6012: } else {
6013: $current{$type} .= '<table>';
6014: my $numspares = scalar(@spares);
6015: for (my $i=0; $i<@spares; $i++) {
6016: my $rem = $i%($numinrow);
6017: if ($rem == 0) {
6018: if ($i > 0) {
6019: $current{$type} .= '</tr>';
6020: }
6021: $current{$type} .= '<tr>';
1.145 raeburn 6022: }
1.152 raeburn 6023: $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'".');" /> '.
6024: $spareid->{$server}{$type}[$i].
6025: '</label></td>'."\n";
6026: }
6027: my $rem = @spares%($numinrow);
6028: my $colsleft = $numinrow - $rem;
6029: if ($colsleft > 1 ) {
6030: $current{$type} .= '<td colspan="'.$colsleft.
6031: '" class="LC_left_item">'.
6032: ' </td>';
6033: } elsif ($colsleft == 1) {
6034: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 6035: }
1.152 raeburn 6036: $current{$type} .= '</tr></table>';
1.150 raeburn 6037: }
1.145 raeburn 6038: }
6039: }
6040: if ($current{$type} eq '') {
6041: $current{$type} = &mt('None specified');
6042: }
1.152 raeburn 6043: if ($othercontrol) {
6044: if ($type eq 'primary') {
6045: $canselect{$type} = $othercontrol;
6046: }
6047: } else {
6048: $canselect{$type} =
6049: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
6050: '<select name="newspare_'.$type.'_'.$server.'" '.
6051: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
6052: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
6053: if (@choices > 0) {
6054: foreach my $lonhost (@choices) {
6055: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
6056: }
6057: }
6058: $canselect{$type} .= '</select>'."\n";
6059: }
6060: } else {
6061: $current{$type} = &mt('Could not be determined');
6062: if ($type eq 'primary') {
6063: $canselect{$type} = $othercontrol;
6064: }
1.145 raeburn 6065: }
1.152 raeburn 6066: if ($type eq 'default') {
6067: $datatable .= '<tr'.$css_class.'>';
6068: }
6069: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
6070: '<td>'.$current{$type}.'</td>'."\n".
6071: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 6072: }
6073: $itemcount ++;
6074: }
6075: }
6076: $$rowtotal += $itemcount;
6077: return $datatable;
6078: }
6079:
1.152 raeburn 6080: sub possible_newspares {
6081: my ($server,$currspares,$serverhomes,$altids) = @_;
6082: my $serverhostname = &Apache::lonnet::hostname($server);
6083: my %excluded;
6084: if ($serverhostname ne '') {
6085: %excluded = (
6086: $serverhostname => 1,
6087: );
6088: }
6089: if (ref($currspares) eq 'HASH') {
6090: foreach my $type (keys(%{$currspares})) {
6091: if (ref($currspares->{$type}) eq 'ARRAY') {
6092: if (@{$currspares->{$type}} > 0) {
6093: foreach my $curr (@{$currspares->{$type}}) {
6094: my $hostname = &Apache::lonnet::hostname($curr);
6095: $excluded{$hostname} = 1;
6096: }
6097: }
6098: }
6099: }
6100: }
6101: my @choices;
6102: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
6103: if (keys(%{$serverhomes}) > 1) {
6104: foreach my $name (sort(keys(%{$serverhomes}))) {
6105: unless ($excluded{$name}) {
6106: if (exists($altids->{$serverhomes->{$name}})) {
6107: push(@choices,$altids->{$serverhomes->{$name}});
6108: } else {
6109: push(@choices,$serverhomes->{$name});
1.145 raeburn 6110: }
6111: }
6112: }
6113: }
6114: }
1.152 raeburn 6115: return sort(@choices);
1.145 raeburn 6116: }
6117:
1.150 raeburn 6118: sub print_loadbalancing {
6119: my ($dom,$settings,$rowtotal) = @_;
6120: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6121: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6122: my $numinrow = 1;
6123: my $datatable;
6124: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 6125: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 6126: if (ref($settings) eq 'HASH') {
6127: %existing = %{$settings};
6128: }
6129: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
6130: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 6131: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 6132: } else {
6133: return;
6134: }
6135: my ($othertitle,$usertypes,$types) =
6136: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 6137: my $rownum = 8;
1.150 raeburn 6138: if (ref($types) eq 'ARRAY') {
6139: $rownum += scalar(@{$types});
6140: }
1.160.6.7 raeburn 6141: my @css_class = ('LC_odd_row','LC_even_row');
6142: my $balnum = 0;
6143: my $islast;
6144: my (@toshow,$disabledtext);
6145: if (keys(%currbalancer) > 0) {
6146: @toshow = sort(keys(%currbalancer));
6147: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
6148: push(@toshow,'');
6149: }
6150: } else {
6151: @toshow = ('');
6152: $disabledtext = &mt('No existing load balancer');
6153: }
6154: foreach my $lonhost (@toshow) {
6155: if ($balnum == scalar(@toshow)-1) {
6156: $islast = 1;
6157: } else {
6158: $islast = 0;
6159: }
6160: my $cssidx = $balnum%2;
6161: my $targets_div_style = 'display: none';
6162: my $disabled_div_style = 'display: block';
6163: my $homedom_div_style = 'display: none';
6164: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
6165: '<td rowspan="'.$rownum.'" valign="top">'.
6166: '<p>';
6167: if ($lonhost eq '') {
6168: $datatable .= '<span class="LC_nobreak">';
6169: if (keys(%currbalancer) > 0) {
6170: $datatable .= &mt('Add balancer:');
6171: } else {
6172: $datatable .= &mt('Enable balancer:');
6173: }
6174: $datatable .= ' '.
6175: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
6176: ' id="loadbalancing_lonhost_'.$balnum.'"'.
6177: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
6178: '<option value="" selected="selected">'.&mt('None').
6179: '</option>'."\n";
6180: foreach my $server (sort(keys(%servers))) {
6181: next if ($currbalancer{$server});
6182: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
6183: }
6184: $datatable .=
6185: '</select>'."\n".
6186: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
6187: } else {
6188: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
6189: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
6190: &mt('Stop balancing').'</label>'.
6191: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
6192: $targets_div_style = 'display: block';
6193: $disabled_div_style = 'display: none';
6194: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
6195: $homedom_div_style = 'display: block';
6196: }
6197: }
6198: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
6199: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
6200: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
6201: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
6202: my ($numspares,@spares) = &count_servers($lonhost,%servers);
6203: my @sparestypes = ('primary','default');
6204: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 6205: my %hostherechecked = (
6206: no => ' checked="checked"',
6207: );
1.160.6.94 raeburn 6208: my %balcookiechecked = (
6209: no => ' checked="checked"',
6210: );
1.160.6.7 raeburn 6211: foreach my $sparetype (@sparestypes) {
6212: my $targettable;
6213: for (my $i=0; $i<$numspares; $i++) {
6214: my $checked;
6215: if (ref($currtargets{$lonhost}) eq 'HASH') {
6216: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6217: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6218: $checked = ' checked="checked"';
6219: }
6220: }
6221: }
6222: my ($chkboxval,$disabled);
6223: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
6224: $chkboxval = $spares[$i];
6225: }
6226: if (exists($currbalancer{$spares[$i]})) {
6227: $disabled = ' disabled="disabled"';
6228: }
6229: $targettable .=
1.160.6.55 raeburn 6230: '<td><span class="LC_nobreak"><label>'.
6231: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 6232: $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 6233: '</span></label></span></td>';
1.160.6.7 raeburn 6234: my $rem = $i%($numinrow);
6235: if ($rem == 0) {
6236: if (($i > 0) && ($i < $numspares-1)) {
6237: $targettable .= '</tr>';
6238: }
6239: if ($i < $numspares-1) {
6240: $targettable .= '<tr>';
1.150 raeburn 6241: }
6242: }
6243: }
1.160.6.7 raeburn 6244: if ($targettable ne '') {
6245: my $rem = $numspares%($numinrow);
6246: my $colsleft = $numinrow - $rem;
6247: if ($colsleft > 1 ) {
6248: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6249: ' </td>';
6250: } elsif ($colsleft == 1) {
6251: $targettable .= '<td class="LC_left_item"> </td>';
6252: }
6253: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
6254: '<table><tr>'.$targettable.'</tr></table><br />';
6255: }
1.160.6.76 raeburn 6256: $hostherechecked{$sparetype} = '';
6257: if (ref($currtargets{$lonhost}) eq 'HASH') {
6258: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6259: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6260: $hostherechecked{$sparetype} = ' checked="checked"';
6261: $hostherechecked{'no'} = '';
6262: }
6263: }
6264: }
6265: }
1.160.6.94 raeburn 6266: if ($currcookies{$lonhost}) {
6267: %balcookiechecked = (
6268: yes => ' checked="checked"',
6269: );
6270: }
1.160.6.76 raeburn 6271: $datatable .= &mt('Hosting on balancer itself').'<br />'.
6272: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
6273: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
6274: foreach my $sparetype (@sparestypes) {
6275: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
6276: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
6277: '</i></label><br />';
1.160.6.7 raeburn 6278: }
1.160.6.94 raeburn 6279: $datatable .= &mt('Use balancer cookie').'<br />'.
6280: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
6281: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
6282: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
6283: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
6284: '</div></td></tr>'.
1.160.6.7 raeburn 6285: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
6286: $othertitle,$usertypes,$types,\%servers,
6287: \%currbalancer,$lonhost,
6288: $targets_div_style,$homedom_div_style,
6289: $css_class[$cssidx],$balnum,$islast);
6290: $$rowtotal += $rownum;
6291: $balnum ++;
6292: }
6293: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
6294: return $datatable;
6295: }
6296:
6297: sub get_loadbalancers_config {
1.160.6.94 raeburn 6298: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 6299: return unless ((ref($servers) eq 'HASH') &&
6300: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 6301: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
6302: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 6303: if (keys(%{$existing}) > 0) {
6304: my $oldlonhost;
6305: foreach my $key (sort(keys(%{$existing}))) {
6306: if ($key eq 'lonhost') {
6307: $oldlonhost = $existing->{'lonhost'};
6308: $currbalancer->{$oldlonhost} = 1;
6309: } elsif ($key eq 'targets') {
6310: if ($oldlonhost) {
6311: $currtargets->{$oldlonhost} = $existing->{'targets'};
6312: }
6313: } elsif ($key eq 'rules') {
6314: if ($oldlonhost) {
6315: $currrules->{$oldlonhost} = $existing->{'rules'};
6316: }
6317: } elsif (ref($existing->{$key}) eq 'HASH') {
6318: $currbalancer->{$key} = 1;
6319: $currtargets->{$key} = $existing->{$key}{'targets'};
6320: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 6321: if ($existing->{$key}{'cookie'}) {
6322: $currcookies->{$key} = 1;
6323: }
1.150 raeburn 6324: }
6325: }
1.160.6.7 raeburn 6326: } else {
6327: my ($balancerref,$targetsref) =
6328: &Apache::lonnet::get_lonbalancer_config($servers);
6329: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
6330: foreach my $server (sort(keys(%{$balancerref}))) {
6331: $currbalancer->{$server} = 1;
6332: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 6333: }
6334: }
6335: }
1.160.6.7 raeburn 6336: return;
1.150 raeburn 6337: }
6338:
6339: sub loadbalancing_rules {
6340: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 6341: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
6342: $css_class,$balnum,$islast) = @_;
1.150 raeburn 6343: my $output;
1.160.6.7 raeburn 6344: my $num = 0;
6345: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 6346: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
6347: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
6348: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 6349: $num ++;
1.150 raeburn 6350: my $current;
6351: if (ref($currrules) eq 'HASH') {
6352: $current = $currrules->{$type};
6353: }
1.160.6.55 raeburn 6354: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 6355: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 6356: $current = '';
6357: }
6358: }
6359: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 6360: $servers,$currbalancer,$lonhost,$dom,
6361: $targets_div_style,$homedom_div_style,
6362: $css_class,$balnum,$num,$islast);
1.150 raeburn 6363: }
6364: }
6365: return $output;
6366: }
6367:
6368: sub loadbalancing_titles {
6369: my ($dom,$intdom,$usertypes,$types) = @_;
6370: my %othertypes = (
6371: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
6372: '_LC_author' => &mt('Users from [_1] with author role',$dom),
6373: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
6374: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 6375: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
6376: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 6377: );
1.160.6.26 raeburn 6378: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 6379: my @available;
1.150 raeburn 6380: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 6381: @available = @{$types};
1.150 raeburn 6382: }
1.160.6.89 raeburn 6383: unless (grep(/^default$/,@available)) {
6384: push(@available,'default');
6385: }
6386: unshift(@alltypes,@available);
1.150 raeburn 6387: my %titles;
6388: foreach my $type (@alltypes) {
6389: if ($type =~ /^_LC_/) {
6390: $titles{$type} = $othertypes{$type};
6391: } elsif ($type eq 'default') {
6392: $titles{$type} = &mt('All users from [_1]',$dom);
6393: if (ref($types) eq 'ARRAY') {
6394: if (@{$types} > 0) {
6395: $titles{$type} = &mt('Other users from [_1]',$dom);
6396: }
6397: }
6398: } elsif (ref($usertypes) eq 'HASH') {
6399: $titles{$type} = $usertypes->{$type};
6400: }
6401: }
6402: return (\@alltypes,\%othertypes,\%titles);
6403: }
6404:
6405: sub loadbalance_rule_row {
1.160.6.7 raeburn 6406: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
6407: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 6408: my @rulenames;
1.150 raeburn 6409: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 6410: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 6411: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 6412: } else {
1.160.6.26 raeburn 6413: @rulenames = ('default','homeserver');
6414: if ($type eq '_LC_external') {
6415: push(@rulenames,'externalbalancer');
6416: } else {
6417: push(@rulenames,'specific');
6418: }
6419: push(@rulenames,'none');
1.150 raeburn 6420: }
6421: my $style = $targets_div_style;
1.160.6.55 raeburn 6422: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 6423: $style = $homedom_div_style;
6424: }
1.160.6.7 raeburn 6425: my $space;
6426: if ($islast && $num == 1) {
6427: $space = '<div display="inline-block"> </div>';
6428: }
6429: my $output =
6430: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
6431: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
6432: '<td valaign="top">'.$space.
6433: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 6434: for (my $i=0; $i<@rulenames; $i++) {
6435: my $rule = $rulenames[$i];
6436: my ($checked,$extra);
6437: if ($rulenames[$i] eq 'default') {
6438: $rule = '';
6439: }
6440: if ($rulenames[$i] eq 'specific') {
6441: if (ref($servers) eq 'HASH') {
6442: my $default;
6443: if (($current ne '') && (exists($servers->{$current}))) {
6444: $checked = ' checked="checked"';
6445: }
6446: unless ($checked) {
6447: $default = ' selected="selected"';
6448: }
1.160.6.7 raeburn 6449: $extra =
6450: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
6451: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
6452: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
6453: '<option value=""'.$default.'></option>'."\n";
6454: foreach my $server (sort(keys(%{$servers}))) {
6455: if (ref($currbalancer) eq 'HASH') {
6456: next if (exists($currbalancer->{$server}));
6457: }
1.150 raeburn 6458: my $selected;
1.160.6.7 raeburn 6459: if ($server eq $current) {
1.150 raeburn 6460: $selected = ' selected="selected"';
6461: }
1.160.6.7 raeburn 6462: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 6463: }
6464: $extra .= '</select>';
6465: }
6466: } elsif ($rule eq $current) {
6467: $checked = ' checked="checked"';
6468: }
6469: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 6470: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
6471: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
6472: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 6473: ')"'.$checked.' /> ';
1.160.6.56 raeburn 6474: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 6475: $output .= $ruletitles{'particular'};
6476: } else {
6477: $output .= $ruletitles{$rulenames[$i]};
6478: }
6479: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 6480: }
6481: $output .= '</div></td></tr>'."\n";
6482: return $output;
6483: }
6484:
6485: sub offloadtype_text {
6486: my %ruletitles = &Apache::lonlocal::texthash (
6487: 'default' => 'Offloads to default destinations',
6488: 'homeserver' => "Offloads to user's home server",
6489: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
6490: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 6491: 'none' => 'No offload',
1.160.6.26 raeburn 6492: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
6493: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 6494: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 6495: );
6496: return %ruletitles;
6497: }
6498:
6499: sub sparestype_titles {
6500: my %typestitles = &Apache::lonlocal::texthash (
6501: 'primary' => 'primary',
6502: 'default' => 'default',
6503: );
6504: return %typestitles;
6505: }
6506:
1.28 raeburn 6507: sub contact_titles {
6508: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 6509: 'supportemail' => 'Support E-mail address',
6510: 'adminemail' => 'Default Server Admin E-mail address',
6511: 'errormail' => 'Error reports to be e-mailed to',
6512: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.101 raeburn 6513: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
6514: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 6515: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
6516: 'requestsmail' => 'E-mail from course requests requiring approval',
6517: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 6518: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 6519: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.160.6.109 raeburn 6520: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
6521: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.160.6.107 raeburn 6522: 'errorweights' => 'Weights used to compute error count',
6523: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 6524: );
6525: my %short_titles = &Apache::lonlocal::texthash (
6526: adminemail => 'Admin E-mail address',
6527: supportemail => 'Support E-mail',
6528: );
6529: return (\%titles,\%short_titles);
6530: }
6531:
1.160.6.78 raeburn 6532: sub helpform_fields {
6533: my %titles = &Apache::lonlocal::texthash (
6534: 'username' => 'Name',
6535: 'user' => 'Username/domain',
6536: 'phone' => 'Phone',
6537: 'cc' => 'Cc e-mail',
6538: 'course' => 'Course Details',
6539: 'section' => 'Sections',
6540: 'screenshot' => 'File upload',
6541: );
6542: my @fields = ('username','phone','user','course','section','cc','screenshot');
6543: my %possoptions = (
6544: username => ['yes','no','req'],
6545: phone => ['yes','no','req'],
6546: user => ['yes','no'],
6547: cc => ['yes','no'],
6548: course => ['yes','no'],
6549: section => ['yes','no'],
6550: screenshot => ['yes','no'],
6551: );
6552: my %fieldoptions = &Apache::lonlocal::texthash (
6553: 'yes' => 'Optional',
6554: 'req' => 'Required',
6555: 'no' => "Not shown",
6556: );
6557: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
6558: }
6559:
1.72 raeburn 6560: sub tool_titles {
6561: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 6562: aboutme => 'Personal web page',
1.86 raeburn 6563: blog => 'Blog',
1.160.6.4 raeburn 6564: webdav => 'WebDAV',
1.86 raeburn 6565: portfolio => 'Portfolio',
1.88 bisitz 6566: official => 'Official courses (with institutional codes)',
6567: unofficial => 'Unofficial courses',
1.98 raeburn 6568: community => 'Communities',
1.160.6.30 raeburn 6569: textbook => 'Textbook courses',
1.86 raeburn 6570: );
1.72 raeburn 6571: return %titles;
6572: }
6573:
1.101 raeburn 6574: sub courserequest_titles {
6575: my %titles = &Apache::lonlocal::texthash (
6576: official => 'Official',
6577: unofficial => 'Unofficial',
6578: community => 'Communities',
1.160.6.30 raeburn 6579: textbook => 'Textbook',
1.101 raeburn 6580: norequest => 'Not allowed',
1.104 raeburn 6581: approval => 'Approval by Dom. Coord.',
1.101 raeburn 6582: validate => 'With validation',
6583: autolimit => 'Numerical limit',
1.103 raeburn 6584: unlimited => '(blank for unlimited)',
1.101 raeburn 6585: );
6586: return %titles;
6587: }
6588:
1.160.6.5 raeburn 6589: sub authorrequest_titles {
6590: my %titles = &Apache::lonlocal::texthash (
6591: norequest => 'Not allowed',
6592: approval => 'Approval by Dom. Coord.',
6593: automatic => 'Automatic approval',
6594: );
6595: return %titles;
6596: }
6597:
1.101 raeburn 6598: sub courserequest_conditions {
6599: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 6600: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 6601: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 6602: );
6603: return %conditions;
6604: }
6605:
6606:
1.27 raeburn 6607: sub print_usercreation {
1.30 raeburn 6608: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 6609: my $numinrow = 4;
1.28 raeburn 6610: my $datatable;
6611: if ($position eq 'top') {
1.30 raeburn 6612: $$rowtotal ++;
1.34 raeburn 6613: my $rowcount = 0;
1.32 raeburn 6614: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 6615: if (ref($rules) eq 'HASH') {
6616: if (keys(%{$rules}) > 0) {
1.32 raeburn 6617: $datatable .= &user_formats_row('username',$settings,$rules,
6618: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 6619: $$rowtotal ++;
1.32 raeburn 6620: $rowcount ++;
6621: }
6622: }
6623: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
6624: if (ref($idrules) eq 'HASH') {
6625: if (keys(%{$idrules}) > 0) {
6626: $datatable .= &user_formats_row('id',$settings,$idrules,
6627: $idruleorder,$numinrow,$rowcount);
6628: $$rowtotal ++;
6629: $rowcount ++;
1.28 raeburn 6630: }
6631: }
1.39 raeburn 6632: if ($rowcount == 0) {
6633: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
6634: $$rowtotal ++;
6635: $rowcount ++;
6636: }
1.34 raeburn 6637: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 6638: my @creators = ('author','course','requestcrs');
1.37 raeburn 6639: my ($rules,$ruleorder) =
6640: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 6641: my %lt = &usercreation_types();
6642: my %checked;
6643: if (ref($settings) eq 'HASH') {
6644: if (ref($settings->{'cancreate'}) eq 'HASH') {
6645: foreach my $item (@creators) {
6646: $checked{$item} = $settings->{'cancreate'}{$item};
6647: }
6648: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
6649: foreach my $item (@creators) {
6650: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
6651: $checked{$item} = 'none';
6652: }
6653: }
6654: }
6655: }
6656: my $rownum = 0;
6657: foreach my $item (@creators) {
6658: $rownum ++;
1.160.6.34 raeburn 6659: if ($checked{$item} eq '') {
6660: $checked{$item} = 'any';
1.34 raeburn 6661: }
6662: my $css_class;
6663: if ($rownum%2) {
6664: $css_class = '';
6665: } else {
6666: $css_class = ' class="LC_odd_row" ';
6667: }
6668: $datatable .= '<tr'.$css_class.'>'.
6669: '<td><span class="LC_nobreak">'.$lt{$item}.
6670: '</span></td><td align="right">';
1.160.6.34 raeburn 6671: my @options = ('any');
6672: if (ref($rules) eq 'HASH') {
6673: if (keys(%{$rules}) > 0) {
6674: push(@options,('official','unofficial'));
1.37 raeburn 6675: }
6676: }
1.160.6.34 raeburn 6677: push(@options,'none');
1.37 raeburn 6678: foreach my $option (@options) {
1.50 raeburn 6679: my $type = 'radio';
1.34 raeburn 6680: my $check = ' ';
1.160.6.34 raeburn 6681: if ($checked{$item} eq $option) {
6682: $check = ' checked="checked" ';
1.34 raeburn 6683: }
6684: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 6685: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 6686: $item.'" value="'.$option.'"'.$check.'/> '.
6687: $lt{$option}.'</label> </span>';
6688: }
6689: $datatable .= '</td></tr>';
6690: }
1.28 raeburn 6691: } else {
6692: my @contexts = ('author','course','domain');
6693: my @authtypes = ('int','krb4','krb5','loc');
6694: my %checked;
6695: if (ref($settings) eq 'HASH') {
6696: if (ref($settings->{'authtypes'}) eq 'HASH') {
6697: foreach my $item (@contexts) {
6698: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
6699: foreach my $auth (@authtypes) {
6700: if ($settings->{'authtypes'}{$item}{$auth}) {
6701: $checked{$item}{$auth} = ' checked="checked" ';
6702: }
6703: }
6704: }
6705: }
1.27 raeburn 6706: }
1.35 raeburn 6707: } else {
6708: foreach my $item (@contexts) {
1.36 raeburn 6709: foreach my $auth (@authtypes) {
1.35 raeburn 6710: $checked{$item}{$auth} = ' checked="checked" ';
6711: }
6712: }
1.27 raeburn 6713: }
1.28 raeburn 6714: my %title = &context_names();
6715: my %authname = &authtype_names();
6716: my $rownum = 0;
6717: my $css_class;
6718: foreach my $item (@contexts) {
6719: if ($rownum%2) {
6720: $css_class = '';
6721: } else {
6722: $css_class = ' class="LC_odd_row" ';
6723: }
1.30 raeburn 6724: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 6725: '<td>'.$title{$item}.
6726: '</td><td class="LC_left_item">'.
6727: '<span class="LC_nobreak">';
6728: foreach my $auth (@authtypes) {
6729: $datatable .= '<label>'.
6730: '<input type="checkbox" name="'.$item.'_auth" '.
6731: $checked{$item}{$auth}.' value="'.$auth.'" />'.
6732: $authname{$auth}.'</label> ';
6733: }
6734: $datatable .= '</span></td></tr>';
6735: $rownum ++;
1.27 raeburn 6736: }
1.30 raeburn 6737: $$rowtotal += $rownum;
1.27 raeburn 6738: }
6739: return $datatable;
6740: }
6741:
1.160.6.34 raeburn 6742: sub print_selfcreation {
6743: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 6744: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
6745: $emaildomain,$datatable);
1.160.6.34 raeburn 6746: if (ref($settings) eq 'HASH') {
6747: if (ref($settings->{'cancreate'}) eq 'HASH') {
6748: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 6749: if (ref($createsettings) eq 'HASH') {
6750: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
6751: @selfcreate = @{$createsettings->{'selfcreate'}};
6752: } elsif ($createsettings->{'selfcreate'} ne '') {
6753: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
6754: @selfcreate = ('email','login','sso');
6755: } elsif ($createsettings->{'selfcreate'} ne 'none') {
6756: @selfcreate = ($createsettings->{'selfcreate'});
6757: }
6758: }
6759: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
6760: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 6761: }
1.160.6.93 raeburn 6762: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
6763: $emailoptions = $createsettings->{'emailoptions'};
6764: }
6765: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
6766: $emailverified = $createsettings->{'emailverified'};
6767: }
6768: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
6769: $emaildomain = $createsettings->{'emaildomain'};
6770: }
1.160.6.34 raeburn 6771: }
6772: }
6773: }
6774: my %radiohash;
6775: my $numinrow = 4;
6776: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 6777: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 6778: if ($position eq 'top') {
6779: my %choices = &Apache::lonlocal::texthash (
6780: cancreate_login => 'Institutional Login',
6781: cancreate_sso => 'Institutional Single Sign On',
6782: );
6783: my @toggles = sort(keys(%choices));
6784: my %defaultchecked = (
6785: 'cancreate_login' => 'off',
6786: 'cancreate_sso' => 'off',
6787: );
1.160.6.35 raeburn 6788: my ($onclick,$itemcount);
1.160.6.34 raeburn 6789: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6790: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 6791: $$rowtotal += $itemcount;
1.160.6.34 raeburn 6792:
6793: if (ref($usertypes) eq 'HASH') {
6794: if (keys(%{$usertypes}) > 0) {
6795: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
6796: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 6797: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 6798: $$rowtotal ++;
6799: }
6800: }
1.160.6.44 raeburn 6801: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
6802: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6803: $fieldtitles{'inststatus'} = &mt('Institutional status');
6804: my $rem;
6805: my $numperrow = 2;
6806: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
6807: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 6808: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 6809: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 6810: '<table>'."\n";
1.160.6.44 raeburn 6811: for (my $i=0; $i<@fields; $i++) {
6812: $rem = $i%($numperrow);
6813: if ($rem == 0) {
6814: if ($i > 0) {
6815: $datatable .= '</tr>';
6816: }
6817: $datatable .= '<tr>';
6818: }
6819: my $currval;
1.160.6.51 raeburn 6820: if (ref($createsettings) eq 'HASH') {
6821: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
6822: $currval = $createsettings->{'shibenv'}{$fields[$i]};
6823: }
1.160.6.44 raeburn 6824: }
6825: $datatable .= '<td class="LC_left_item">'.
6826: '<span class="LC_nobreak">'.
6827: '<input type="text" name="shibenv_'.$fields[$i].'" '.
6828: 'value="'.$currval.'" size="10" /> '.
6829: $fieldtitles{$fields[$i]}.'</span></td>';
6830: }
6831: my $colsleft = $numperrow - $rem;
6832: if ($colsleft > 1 ) {
6833: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6834: ' </td>';
6835: } elsif ($colsleft == 1) {
6836: $datatable .= '<td class="LC_left_item"> </td>';
6837: }
6838: $datatable .= '</tr></table></td></tr>';
6839: $$rowtotal ++;
1.160.6.34 raeburn 6840: } elsif ($position eq 'middle') {
6841: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 6842: my @posstypes;
1.160.6.34 raeburn 6843: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 6844: @posstypes = @{$types};
6845: }
6846: unless (grep(/^default$/,@posstypes)) {
6847: push(@posstypes,'default');
6848: }
6849: my %usertypeshash;
6850: if (ref($usertypes) eq 'HASH') {
6851: %usertypeshash = %{$usertypes};
6852: }
6853: $usertypeshash{'default'} = $othertitle;
6854: foreach my $status (@posstypes) {
6855: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
6856: $numinrow,$$rowtotal,\%usertypeshash);
6857: $$rowtotal ++;
1.160.6.34 raeburn 6858: }
6859: } else {
1.160.6.40 raeburn 6860: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 6861: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 6862: );
6863: my @toggles = sort(keys(%choices));
6864: my %defaultchecked = (
6865: 'cancreate_email' => 'off',
6866: );
1.160.6.93 raeburn 6867: my $customclass = 'LC_selfcreate_email';
6868: my $classprefix = 'LC_canmodify_emailusername_';
6869: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 6870: my $display = 'none';
1.160.6.93 raeburn 6871: my $rowstyle = 'display:none';
1.160.6.40 raeburn 6872: if (grep(/^\Qemail\E$/,@selfcreate)) {
6873: $display = 'block';
1.160.6.93 raeburn 6874: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 6875: }
1.160.6.93 raeburn 6876: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
6877: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6878: \%choices,$$rowtotal,$onclick);
6879: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
6880: $rowstyle);
6881: $$rowtotal ++;
6882: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
6883: $rowstyle);
6884: $$rowtotal ++;
6885: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 6886: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 6887: my ($emailrules,$emailruleorder) =
6888: &Apache::lonnet::inst_userrules($dom,'email');
6889: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6890: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6891: if (ref($types) eq 'ARRAY') {
6892: @posstypes = @{$types};
6893: }
6894: if (@posstypes) {
6895: unless (grep(/^default$/,@posstypes)) {
6896: push(@posstypes,'default');
1.160.6.89 raeburn 6897: }
6898: if (ref($usertypes) eq 'HASH') {
6899: %usertypeshash = %{$usertypes};
6900: }
1.160.6.93 raeburn 6901: my $currassign;
6902: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
6903: $currassign = {
6904: selfassign => $domdefaults{'inststatusguest'},
6905: };
6906: @ordered = @{$domdefaults{'inststatusguest'}};
6907: } else {
6908: $currassign = { selfassign => [] };
6909: }
6910: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
6911: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
6912: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
6913: $numinrow,$othertitle,'selfassign',
6914: $rowtotal,$onclicktypes,$customclass,
6915: $rowstyle);
6916: $$rowtotal ++;
1.160.6.89 raeburn 6917: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 6918: foreach my $status (@posstypes) {
6919: my $css_class;
6920: if ($$rowtotal%2) {
6921: $css_class = 'LC_odd_row ';
6922: }
6923: $css_class .= $customclass;
6924: my $rowid = $optionsprefix.$status;
6925: my $hidden = 1;
6926: my $currstyle = 'display:none';
6927: if (grep(/^\Q$status\E$/,@ordered)) {
6928: $currstyle = $rowstyle;
6929: $hidden = 0;
6930: }
6931: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6932: $emailrules,$emailruleorder,$settings,$status,$rowid,
6933: $usertypeshash{$status},$css_class,$currstyle,$intdom);
6934: unless ($hidden) {
6935: $$rowtotal ++;
6936: }
1.160.6.89 raeburn 6937: }
6938: } else {
1.160.6.93 raeburn 6939: my $css_class;
6940: if ($$rowtotal%2) {
6941: $css_class = 'LC_odd_row ';
6942: }
6943: $css_class .= $customclass;
1.160.6.89 raeburn 6944: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 6945: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6946: $emailrules,$emailruleorder,$settings,'default','',
6947: $othertitle,$css_class,$rowstyle,$intdom);
6948: $$rowtotal ++;
1.160.6.34 raeburn 6949: }
1.160.6.35 raeburn 6950: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
6951: $numinrow = 1;
1.160.6.93 raeburn 6952: if (@posstypes) {
6953: foreach my $status (@posstypes) {
6954: my $rowid = $classprefix.$status;
6955: my $datarowstyle = 'display:none';
6956: if (grep(/^\Q$status\E$/,@ordered)) {
6957: $datarowstyle = $rowstyle;
6958: }
6959: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
6960: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6961: $infotitles,$rowid,$customclass,$datarowstyle);
6962: unless ($datarowstyle eq 'display:none') {
6963: $$rowtotal ++;
6964: }
1.160.6.34 raeburn 6965: }
1.160.6.93 raeburn 6966: } else {
6967: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
6968: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6969: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 6970: }
6971: }
6972: return $datatable;
6973: }
6974:
1.160.6.93 raeburn 6975: sub selfcreate_javascript {
6976: return <<"ENDSCRIPT";
6977:
6978: <script type="text/javascript">
6979: // <![CDATA[
6980:
6981: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
6982: var x = document.getElementsByClassName(target);
6983: var insttypes = 0;
6984: var insttypeRegExp = new RegExp(prefix);
6985: if ((x.length != undefined) && (x.length > 0)) {
6986: if (form.elements[radio].length != undefined) {
6987: for (var i=0; i<form.elements[radio].length; i++) {
6988: if (form.elements[radio][i].checked) {
6989: if (form.elements[radio][i].value == 1) {
6990: for (var j=0; j<x.length; j++) {
6991: if (x[j].id == 'undefined') {
6992: x[j].style.display = 'table-row';
6993: } else if (insttypeRegExp.test(x[j].id)) {
6994: insttypes ++;
6995: } else {
6996: x[j].style.display = 'table-row';
6997: }
6998: }
6999: } else {
7000: for (var j=0; j<x.length; j++) {
7001: x[j].style.display = 'none';
7002: }
1.160.6.40 raeburn 7003: }
1.160.6.93 raeburn 7004: break;
7005: }
7006: }
7007: if (insttypes > 0) {
7008: toggleDataRow(form,checkbox,target,altprefix);
7009: toggleDataRow(form,checkbox,target,prefix,1);
7010: }
7011: }
7012: }
7013: return;
7014: }
7015:
7016: function toggleDataRow(form,checkbox,target,prefix,docount) {
7017: if (form.elements[checkbox].length != undefined) {
7018: var count = 0;
7019: if (docount) {
7020: for (var i=0; i<form.elements[checkbox].length; i++) {
7021: if (form.elements[checkbox][i].checked) {
7022: count ++;
7023: }
7024: }
7025: }
7026: for (var i=0; i<form.elements[checkbox].length; i++) {
7027: var type = form.elements[checkbox][i].value;
7028: if (document.getElementById(prefix+type)) {
7029: if (form.elements[checkbox][i].checked) {
7030: document.getElementById(prefix+type).style.display = 'table-row';
7031: if (count % 2 == 1) {
7032: document.getElementById(prefix+type).className = target+' LC_odd_row';
7033: } else {
7034: document.getElementById(prefix+type).className = target;
7035: }
7036: count ++;
1.160.6.40 raeburn 7037: } else {
1.160.6.93 raeburn 7038: document.getElementById(prefix+type).style.display = 'none';
7039: }
7040: }
7041: }
7042: }
7043: return;
7044: }
7045:
7046: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
7047: var caller = radio+'_'+status;
7048: if (form.elements[caller].length != undefined) {
7049: for (var i=0; i<form.elements[caller].length; i++) {
7050: if (form.elements[caller][i].checked) {
7051: if (document.getElementById(altprefix+'_inst_'+status)) {
7052: var curr = form.elements[caller][i].value;
7053: if (prefix) {
7054: document.getElementById(prefix+'_'+status).style.display = 'none';
7055: }
7056: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
7057: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
7058: if (curr == 'custom') {
7059: if (prefix) {
7060: document.getElementById(prefix+'_'+status).style.display = 'inline';
7061: }
7062: } else if (curr == 'inst') {
7063: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
7064: } else if (curr == 'noninst') {
7065: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 7066: }
1.160.6.93 raeburn 7067: break;
1.160.6.40 raeburn 7068: }
1.160.6.93 raeburn 7069: }
7070: }
7071: }
7072: }
7073:
7074: // ]]>
7075: </script>
7076:
7077: ENDSCRIPT
7078: }
7079:
7080: sub noninst_users {
7081: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
7082: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
7083: my $class = 'LC_left_item';
7084: if ($css_class) {
7085: $css_class = ' class="'.$css_class.'"';
7086: }
7087: if ($rowid) {
7088: $rowid = ' id="'.$rowid.'"';
7089: }
7090: if ($rowstyle) {
7091: $rowstyle = ' style="'.$rowstyle.'"';
7092: }
7093: my ($output,$description);
7094: if ($type eq 'default') {
7095: $description = &mt('Requests for: [_1]',$typetitle);
7096: } else {
7097: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
7098: }
7099: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
7100: "<td>$description</td>\n".
7101: '<td class="'.$class.'" colspan="2">'.
7102: '<table><tr>';
7103: my %headers = &Apache::lonlocal::texthash(
7104: approve => 'Processing',
7105: email => 'E-mail',
7106: username => 'Username',
7107: );
7108: foreach my $item ('approve','email','username') {
7109: $output .= '<th>'.$headers{$item}.'</th>';
7110: }
7111: $output .= '</tr><tr>';
7112: foreach my $item ('approve','email','username') {
7113: $output .= '<td valign="top">';
7114: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
7115: if ($item eq 'approve') {
7116: %choices = &Apache::lonlocal::texthash (
7117: automatic => 'Automatically approved',
7118: approval => 'Queued for approval',
7119: );
7120: @options = ('automatic','approval');
7121: $hashref = $processing;
7122: $defoption = 'automatic';
7123: $name = 'cancreate_emailprocess_'.$type;
7124: } elsif ($item eq 'email') {
7125: %choices = &Apache::lonlocal::texthash (
7126: any => 'Any e-mail',
7127: inst => 'Institutional only',
7128: noninst => 'Non-institutional only',
7129: custom => 'Custom restrictions',
7130: );
7131: @options = ('any','inst','noninst');
7132: my $showcustom;
7133: if (ref($emailrules) eq 'HASH') {
7134: if (keys(%{$emailrules}) > 0) {
7135: push(@options,'custom');
7136: $showcustom = 'cancreate_emailrule';
7137: if (ref($settings) eq 'HASH') {
7138: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
7139: foreach my $rule (@{$settings->{'email_rule'}}) {
7140: if (exists($emailrules->{$rule})) {
7141: $hascustom ++;
7142: }
7143: }
7144: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
7145: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
7146: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
7147: if (exists($emailrules->{$rule})) {
7148: $hascustom ++;
7149: }
7150: }
7151: }
7152: }
7153: }
7154: }
7155: }
7156: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
7157: "'cancreate_emaildomain','$type'".');"';
7158: $hashref = $emailoptions;
7159: $defoption = 'any';
7160: $name = 'cancreate_emailoptions_'.$type;
7161: } elsif ($item eq 'username') {
7162: %choices = &Apache::lonlocal::texthash (
7163: all => 'Same as e-mail',
7164: first => 'Omit @domain',
7165: free => 'Free to choose',
7166: );
7167: @options = ('all','first','free');
7168: $hashref = $emailverified;
7169: $defoption = 'all';
7170: $name = 'cancreate_usernameoptions_'.$type;
7171: }
7172: foreach my $option (@options) {
7173: my $checked;
7174: if (ref($hashref) eq 'HASH') {
7175: if ($type eq '') {
7176: if (!exists($hashref->{'default'})) {
7177: if ($option eq $defoption) {
7178: $checked = ' checked="checked"';
7179: }
7180: } else {
7181: if ($hashref->{'default'} eq $option) {
7182: $checked = ' checked="checked"';
7183: }
1.160.6.40 raeburn 7184: }
7185: } else {
1.160.6.93 raeburn 7186: if (!exists($hashref->{$type})) {
7187: if ($option eq $defoption) {
7188: $checked = ' checked="checked"';
7189: }
7190: } else {
7191: if ($hashref->{$type} eq $option) {
7192: $checked = ' checked="checked"';
7193: }
1.160.6.40 raeburn 7194: }
7195: }
1.160.6.93 raeburn 7196: } elsif (($item eq 'email') && ($hascustom)) {
7197: if ($option eq 'custom') {
7198: $checked = ' checked="checked"';
7199: }
7200: } elsif ($option eq $defoption) {
7201: $checked = ' checked="checked"';
7202: }
7203: $output .= '<span class="LC_nobreak"><label>'.
7204: '<input type="radio" name="'.$name.'"'.
7205: $checked.' value="'.$option.'"'.$onclick.' />'.
7206: $choices{$option}.'</label></span><br />';
7207: if ($item eq 'email') {
7208: if ($option eq 'custom') {
7209: my $id = 'cancreate_emailrule_'.$type;
7210: my $display = 'none';
7211: if ($checked) {
7212: $display = 'inline';
7213: }
7214: my $numinrow = 2;
7215: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
7216: '<legend>'.&mt('Disallow').'</legend><table>'.
7217: &user_formats_row('email',$settings,$emailrules,
7218: $emailruleorder,$numinrow,'',$type);
7219: '</table></fieldset>';
7220: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
7221: my %text = &Apache::lonlocal::texthash (
7222: inst => 'must end:',
7223: noninst => 'cannot end:',
7224: );
7225: my $value;
7226: if (ref($emaildomain) eq 'HASH') {
7227: if (ref($emaildomain->{$type}) eq 'HASH') {
7228: $value = $emaildomain->{$type}->{$option};
7229: }
7230: }
7231: if ($value eq '') {
7232: $value = '@'.$intdom;
7233: }
7234: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
7235: my $display = 'none';
7236: if ($checked) {
7237: $display = 'inline';
7238: }
7239: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
7240: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
7241: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
7242: '</div>';
7243: }
1.160.6.40 raeburn 7244: }
7245: }
1.160.6.93 raeburn 7246: $output .= '</td>'."\n";
1.160.6.40 raeburn 7247: }
1.160.6.93 raeburn 7248: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 7249: return $output;
7250: }
7251:
1.160.6.5 raeburn 7252: sub captcha_choice {
1.160.6.93 raeburn 7253: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 7254: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
7255: $vertext,$currver);
1.160.6.5 raeburn 7256: my %lt = &captcha_phrases();
7257: $keyentry = 'hidden';
1.160.6.98 raeburn 7258: my $colspan=2;
1.160.6.5 raeburn 7259: if ($context eq 'cancreate') {
1.160.6.34 raeburn 7260: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 7261: } elsif ($context eq 'login') {
7262: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98 raeburn 7263: } elsif ($context eq 'passwords') {
7264: $rowname = &mt('"Forgot Password" CAPTCHA validation');
7265: $colspan=1;
1.160.6.5 raeburn 7266: }
7267: if (ref($settings) eq 'HASH') {
7268: if ($settings->{'captcha'}) {
7269: $checked{$settings->{'captcha'}} = ' checked="checked"';
7270: } else {
7271: $checked{'original'} = ' checked="checked"';
7272: }
7273: if ($settings->{'captcha'} eq 'recaptcha') {
7274: $pubtext = $lt{'pub'};
7275: $privtext = $lt{'priv'};
7276: $keyentry = 'text';
1.160.6.69 raeburn 7277: $vertext = $lt{'ver'};
7278: $currver = $settings->{'recaptchaversion'};
7279: if ($currver ne '2') {
7280: $currver = 1;
7281: }
1.160.6.5 raeburn 7282: }
7283: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
7284: $currpub = $settings->{'recaptchakeys'}{'public'};
7285: $currpriv = $settings->{'recaptchakeys'}{'private'};
7286: }
7287: } else {
7288: $checked{'original'} = ' checked="checked"';
7289: }
1.160.6.93 raeburn 7290: my $css_class;
7291: if ($itemcount%2) {
7292: $css_class = 'LC_odd_row';
7293: }
7294: if ($customcss) {
7295: $css_class .= " $customcss";
7296: }
7297: $css_class =~ s/^\s+//;
7298: if ($css_class) {
7299: $css_class = ' class="'.$css_class.'"';
7300: }
7301: if ($rowstyle) {
7302: $css_class .= ' style="'.$rowstyle.'"';
7303: }
1.160.6.5 raeburn 7304: my $output = '<tr'.$css_class.'>'.
1.160.6.98 raeburn 7305: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 7306: '<table><tr><td>'."\n";
7307: foreach my $option ('original','recaptcha','notused') {
7308: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
7309: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
7310: $lt{$option}.'</label></span>';
7311: unless ($option eq 'notused') {
7312: $output .= (' 'x2)."\n";
7313: }
7314: }
7315: #
7316: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
7317: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
7318: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
7319: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
7320: #
7321: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 7322: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 7323: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
7324: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
7325: $currpub.'" size="40" /></span><br />'."\n".
7326: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
7327: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 7328: $currpriv.'" size="40" /></span><br />'.
7329: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
7330: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
7331: $currver.'" size="3" /></span><br />'.
7332: '</td></tr></table>'."\n".
1.160.6.5 raeburn 7333: '</td></tr>';
7334: return $output;
7335: }
7336:
1.32 raeburn 7337: sub user_formats_row {
1.160.6.93 raeburn 7338: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 7339: my $output;
7340: my %text = (
7341: 'username' => 'new usernames',
7342: 'id' => 'IDs',
7343: );
1.160.6.93 raeburn 7344: unless ($type eq 'email') {
7345: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7346: $output = '<tr '.$css_class.'>'.
7347: '<td><span class="LC_nobreak">'.
7348: &mt("Format rules to check for $text{$type}: ").
7349: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 7350: }
1.27 raeburn 7351: my $rem;
7352: if (ref($ruleorder) eq 'ARRAY') {
7353: for (my $i=0; $i<@{$ruleorder}; $i++) {
7354: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
7355: my $rem = $i%($numinrow);
7356: if ($rem == 0) {
7357: if ($i > 0) {
7358: $output .= '</tr>';
7359: }
7360: $output .= '<tr>';
7361: }
7362: my $check = ' ';
1.39 raeburn 7363: if (ref($settings) eq 'HASH') {
7364: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
7365: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
7366: $check = ' checked="checked" ';
7367: }
1.160.6.93 raeburn 7368: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
7369: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
7370: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
7371: $check = ' checked="checked" ';
7372: }
7373: }
1.27 raeburn 7374: }
7375: }
1.160.6.93 raeburn 7376: my $name = $type.'_rule';
7377: if ($type eq 'email') {
7378: $name .= '_'.$status;
7379: }
1.27 raeburn 7380: $output .= '<td class="LC_left_item">'.
7381: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 7382: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 7383: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
7384: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
7385: }
7386: }
7387: $rem = @{$ruleorder}%($numinrow);
7388: }
1.160.6.93 raeburn 7389: my $colsleft;
7390: if ($rem) {
7391: $colsleft = $numinrow - $rem;
7392: }
1.27 raeburn 7393: if ($colsleft > 1 ) {
7394: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7395: ' </td>';
7396: } elsif ($colsleft == 1) {
7397: $output .= '<td class="LC_left_item"> </td>';
7398: }
1.160.6.93 raeburn 7399: $output .= '</tr></table>';
7400: unless ($type eq 'email') {
7401: $output .= '</td></tr>';
7402: }
1.27 raeburn 7403: return $output;
7404: }
7405:
1.34 raeburn 7406: sub usercreation_types {
7407: my %lt = &Apache::lonlocal::texthash (
7408: author => 'When adding a co-author',
7409: course => 'When adding a user to a course',
1.100 raeburn 7410: requestcrs => 'When requesting a course',
1.34 raeburn 7411: any => 'Any',
7412: official => 'Institutional only ',
7413: unofficial => 'Non-institutional only',
7414: none => 'None',
7415: );
7416: return %lt;
1.48 raeburn 7417: }
1.34 raeburn 7418:
1.160.6.34 raeburn 7419: sub selfcreation_types {
7420: my %lt = &Apache::lonlocal::texthash (
7421: selfcreate => 'User creates own account',
7422: any => 'Any',
7423: official => 'Institutional only ',
7424: unofficial => 'Non-institutional only',
7425: email => 'E-mail address',
7426: login => 'Institutional Login',
7427: sso => 'SSO',
7428: );
7429: }
7430:
1.28 raeburn 7431: sub authtype_names {
7432: my %lt = &Apache::lonlocal::texthash(
7433: int => 'Internal',
7434: krb4 => 'Kerberos 4',
7435: krb5 => 'Kerberos 5',
7436: loc => 'Local',
7437: );
7438: return %lt;
7439: }
7440:
7441: sub context_names {
7442: my %context_title = &Apache::lonlocal::texthash(
7443: author => 'Creating users when an Author',
7444: course => 'Creating users when in a course',
7445: domain => 'Creating users when a Domain Coordinator',
7446: );
7447: return %context_title;
7448: }
7449:
1.33 raeburn 7450: sub print_usermodification {
7451: my ($position,$dom,$settings,$rowtotal) = @_;
7452: my $numinrow = 4;
7453: my ($context,$datatable,$rowcount);
7454: if ($position eq 'top') {
7455: $rowcount = 0;
7456: $context = 'author';
7457: foreach my $role ('ca','aa') {
7458: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7459: $numinrow,$rowcount);
7460: $$rowtotal ++;
7461: $rowcount ++;
7462: }
1.160.6.37 raeburn 7463: } elsif ($position eq 'bottom') {
1.33 raeburn 7464: $context = 'course';
7465: $rowcount = 0;
7466: foreach my $role ('st','ep','ta','in','cr') {
7467: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7468: $numinrow,$rowcount);
7469: $$rowtotal ++;
7470: $rowcount ++;
7471: }
7472: }
7473: return $datatable;
7474: }
7475:
1.43 raeburn 7476: sub print_defaults {
1.160.6.40 raeburn 7477: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 7478: my $rownum = 0;
1.160.6.80 raeburn 7479: my ($datatable,$css_class,$titles);
7480: unless ($position eq 'bottom') {
7481: $titles = &defaults_titles($dom);
7482: }
1.160.6.40 raeburn 7483: if ($position eq 'top') {
7484: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
7485: 'datelocale_def','portal_def');
7486: my %defaults;
7487: if (ref($settings) eq 'HASH') {
7488: %defaults = %{$settings};
1.43 raeburn 7489: } else {
1.160.6.40 raeburn 7490: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7491: foreach my $item (@items) {
7492: $defaults{$item} = $domdefaults{$item};
7493: }
1.43 raeburn 7494: }
1.160.6.40 raeburn 7495: foreach my $item (@items) {
7496: if ($rownum%2) {
7497: $css_class = '';
7498: } else {
7499: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 7500: }
1.160.6.40 raeburn 7501: $datatable .= '<tr'.$css_class.'>'.
7502: '<td><span class="LC_nobreak">'.$titles->{$item}.
7503: '</span></td><td class="LC_right_item" colspan="3">';
7504: if ($item eq 'auth_def') {
7505: my @authtypes = ('internal','krb4','krb5','localauth');
7506: my %shortauth = (
7507: internal => 'int',
7508: krb4 => 'krb4',
7509: krb5 => 'krb5',
7510: localauth => 'loc'
7511: );
7512: my %authnames = &authtype_names();
7513: foreach my $auth (@authtypes) {
7514: my $checked = ' ';
7515: if ($defaults{$item} eq $auth) {
7516: $checked = ' checked="checked" ';
7517: }
7518: $datatable .= '<label><input type="radio" name="'.$item.
7519: '" value="'.$auth.'"'.$checked.'/>'.
7520: $authnames{$shortauth{$auth}}.'</label> ';
7521: }
7522: } elsif ($item eq 'timezone_def') {
7523: my $includeempty = 1;
7524: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
7525: } elsif ($item eq 'datelocale_def') {
1.160.6.98 raeburn 7526: my $includeempty = 1;
7527: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
7528: } elsif ($item eq 'lang_def') {
7529: my $includeempty = 1;
7530: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.80 raeburn 7531: } else {
1.160.6.98 raeburn 7532: my $size;
7533: if ($item eq 'portal_def') {
7534: $size = ' size="25"';
7535: }
1.160.6.80 raeburn 7536: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.98 raeburn 7537: $defaults{$item}.'"'.$size.' />';
1.160.6.80 raeburn 7538: }
7539: $datatable .= '</td></tr>';
7540: $rownum ++;
7541: }
1.160.6.40 raeburn 7542: } else {
1.160.6.80 raeburn 7543: my %defaults;
1.160.6.40 raeburn 7544: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 7545: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 7546: my $maxnum = @{$settings->{'inststatusorder'}};
7547: for (my $i=0; $i<$maxnum; $i++) {
7548: $css_class = $rownum%2?' class="LC_odd_row"':'';
7549: my $item = $settings->{'inststatusorder'}->[$i];
7550: my $title = $settings->{'inststatustypes'}->{$item};
7551: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
7552: $datatable .= '<tr'.$css_class.'>'.
7553: '<td><span class="LC_nobreak">'.
7554: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
7555: for (my $k=0; $k<=$maxnum; $k++) {
7556: my $vpos = $k+1;
7557: my $selstr;
7558: if ($k == $i) {
7559: $selstr = ' selected="selected" ';
7560: }
7561: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7562: }
7563: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
7564: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
7565: &mt('delete').'</span></td>'.
1.160.6.112 raeburn 7566: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.160.6.40 raeburn 7567: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 7568: '</span></td></tr>';
1.160.6.40 raeburn 7569: }
7570: $css_class = $rownum%2?' class="LC_odd_row"':'';
7571: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
7572: $datatable .= '<tr '.$css_class.'>'.
7573: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
7574: for (my $k=0; $k<=$maxnum; $k++) {
7575: my $vpos = $k+1;
7576: my $selstr;
7577: if ($k == $maxnum) {
7578: $selstr = ' selected="selected" ';
7579: }
7580: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7581: }
7582: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 7583: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 7584: ' '.&mt('(new)').
7585: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.112 raeburn 7586: &mt('Name displayed').':'.
1.160.6.40 raeburn 7587: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
7588: '</tr>'."\n";
7589: $rownum ++;
1.141 raeburn 7590: }
1.43 raeburn 7591: }
7592: }
7593: $$rowtotal += $rownum;
7594: return $datatable;
7595: }
7596:
1.160.6.5 raeburn 7597: sub get_languages_hash {
7598: my %langchoices;
7599: foreach my $id (&Apache::loncommon::languageids()) {
7600: my $code = &Apache::loncommon::supportedlanguagecode($id);
7601: if ($code ne '') {
7602: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
7603: }
7604: }
7605: return %langchoices;
7606: }
7607:
1.43 raeburn 7608: sub defaults_titles {
1.141 raeburn 7609: my ($dom) = @_;
1.43 raeburn 7610: my %titles = &Apache::lonlocal::texthash (
7611: 'auth_def' => 'Default authentication type',
7612: 'auth_arg_def' => 'Default authentication argument',
7613: 'lang_def' => 'Default language',
1.54 raeburn 7614: 'timezone_def' => 'Default timezone',
1.68 raeburn 7615: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 7616: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 7617: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
7618: 'intauth_check' => 'Check bcrypt cost if authenticated',
7619: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 7620: );
1.141 raeburn 7621: if ($dom) {
7622: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
7623: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
7624: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
7625: $protocol = 'http' if ($protocol ne 'https');
7626: if ($uint_dom) {
7627: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
7628: $uint_dom);
7629: }
7630: }
1.43 raeburn 7631: return (\%titles);
7632: }
7633:
1.160.6.97 raeburn 7634: sub print_scantron {
7635: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
7636: if ($position eq 'top') {
7637: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
7638: } else {
7639: return &print_scantronconfig($dom,$settings,\$rowtotal);
7640: }
7641: }
7642:
7643: sub scantron_javascript {
7644: return <<"ENDSCRIPT";
7645:
7646: <script type="text/javascript">
7647: // <![CDATA[
7648:
7649: function toggleScantron(form) {
7650: var csvfieldset = new Array();
7651: if (document.getElementById('scantroncsv_cols')) {
7652: csvfieldset.push(document.getElementById('scantroncsv_cols'));
7653: }
7654: if (document.getElementById('scantroncsv_options')) {
7655: csvfieldset.push(document.getElementById('scantroncsv_options'));
7656: }
7657: if (csvfieldset.length) {
7658: if (document.getElementById('scantronconfcsv')) {
7659: var scantroncsv = document.getElementById('scantronconfcsv');
7660: if (scantroncsv.checked) {
7661: for (var i=0; i<csvfieldset.length; i++) {
7662: csvfieldset[i].style.display = 'block';
7663: }
7664: } else {
7665: for (var i=0; i<csvfieldset.length; i++) {
7666: csvfieldset[i].style.display = 'none';
7667: }
7668: var csvselects = document.getElementsByClassName('scantronconfig_csv');
7669: if (csvselects.length) {
7670: for (var j=0; j<csvselects.length; j++) {
7671: csvselects[j].selectedIndex = 0;
7672: }
7673: }
7674: }
7675: }
7676: }
7677: return;
7678: }
7679: // ]]>
7680: </script>
7681:
7682: ENDSCRIPT
7683:
7684: }
7685:
1.46 raeburn 7686: sub print_scantronformat {
7687: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
7688: my $itemcount = 1;
1.60 raeburn 7689: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
7690: %confhash);
1.46 raeburn 7691: my $switchserver = &check_switchserver($dom,$confname);
7692: my %lt = &Apache::lonlocal::texthash (
1.95 www 7693: default => 'Default bubblesheet format file error',
7694: custom => 'Custom bubblesheet format file error',
1.46 raeburn 7695: );
7696: my %scantronfiles = (
7697: default => 'default.tab',
7698: custom => 'custom.tab',
7699: );
7700: foreach my $key (keys(%scantronfiles)) {
7701: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
7702: .$scantronfiles{$key};
7703: }
7704: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
7705: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
7706: if (!$switchserver) {
7707: my $servadm = $r->dir_config('lonAdmEMail');
7708: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
7709: if ($configuserok eq 'ok') {
7710: if ($author_ok eq 'ok') {
7711: my %legacyfile = (
1.160.6.97 raeburn 7712: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
7713: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 7714: );
7715: my %md5chk;
7716: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7717: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
7718: chomp($md5chk{$type});
1.46 raeburn 7719: }
7720: if ($md5chk{'default'} ne $md5chk{'custom'}) {
7721: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 7722: ($scantronurls{$type},my $error) =
1.46 raeburn 7723: &legacy_scantronformat($r,$dom,$confname,
7724: $type,$legacyfile{$type},
7725: $scantronurls{$type},
7726: $scantronfiles{$type});
1.60 raeburn 7727: if ($error ne '') {
7728: $error{$type} = $error;
7729: }
7730: }
7731: if (keys(%error) == 0) {
7732: $is_custom = 1;
1.160.6.97 raeburn 7733: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 7734: $scantronurls{'custom'};
1.160.6.97 raeburn 7735: my $putresult =
1.60 raeburn 7736: &Apache::lonnet::put_dom('configuration',
7737: \%confhash,$dom);
7738: if ($putresult ne 'ok') {
1.160.6.97 raeburn 7739: $error{'custom'} =
1.60 raeburn 7740: '<span class="LC_error">'.
7741: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7742: }
1.46 raeburn 7743: }
7744: } else {
1.60 raeburn 7745: ($scantronurls{'default'},my $error) =
1.46 raeburn 7746: &legacy_scantronformat($r,$dom,$confname,
7747: 'default',$legacyfile{'default'},
7748: $scantronurls{'default'},
7749: $scantronfiles{'default'});
1.60 raeburn 7750: if ($error eq '') {
7751: $confhash{'scantron'}{'scantronformat'} = '';
7752: my $putresult =
7753: &Apache::lonnet::put_dom('configuration',
7754: \%confhash,$dom);
7755: if ($putresult ne 'ok') {
7756: $error{'default'} =
7757: '<span class="LC_error">'.
7758: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7759: }
7760: } else {
7761: $error{'default'} = $error;
7762: }
1.46 raeburn 7763: }
7764: }
7765: }
7766: } else {
1.95 www 7767: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 7768: }
7769: }
7770: if (ref($settings) eq 'HASH') {
7771: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
7772: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
7773: if ((!@info) || ($info[0] eq 'no_such_dir')) {
7774: $scantronurl = '';
7775: } else {
7776: $scantronurl = $settings->{'scantronformat'};
7777: }
7778: $is_custom = 1;
7779: } else {
7780: $scantronurl = $scantronurls{'default'};
7781: }
7782: } else {
1.60 raeburn 7783: if ($is_custom) {
7784: $scantronurl = $scantronurls{'custom'};
7785: } else {
7786: $scantronurl = $scantronurls{'default'};
7787: }
1.46 raeburn 7788: }
7789: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7790: $datatable .= '<tr'.$css_class.'>';
7791: if (!$is_custom) {
1.65 raeburn 7792: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
7793: '<span class="LC_nobreak">';
1.46 raeburn 7794: if ($scantronurl) {
1.160.6.21 raeburn 7795: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
7796: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 7797: } else {
7798: $datatable = &mt('File unavailable for display');
7799: }
1.65 raeburn 7800: $datatable .= '</span></td>';
1.60 raeburn 7801: if (keys(%error) == 0) {
7802: $datatable .= '<td valign="bottom">';
7803: if (!$switchserver) {
7804: $datatable .= &mt('Upload:').'<br />';
7805: }
7806: } else {
7807: my $errorstr;
7808: foreach my $key (sort(keys(%error))) {
7809: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7810: }
7811: $datatable .= '<td>'.$errorstr;
7812: }
1.46 raeburn 7813: } else {
7814: if (keys(%error) > 0) {
7815: my $errorstr;
7816: foreach my $key (sort(keys(%error))) {
7817: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7818: }
1.60 raeburn 7819: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 7820: } elsif ($scantronurl) {
1.160.6.26 raeburn 7821: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 7822: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 7823: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 7824: $link.
7825: '<label><input type="checkbox" name="scantronformat_del"'.
7826: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 7827: '<td><span class="LC_nobreak"> '.
7828: &mt('Replace:').'</span><br />';
1.46 raeburn 7829: }
7830: }
7831: if (keys(%error) == 0) {
7832: if ($switchserver) {
7833: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
7834: } else {
1.65 raeburn 7835: $datatable .='<span class="LC_nobreak"> '.
7836: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 7837: }
7838: }
7839: $datatable .= '</td></tr>';
7840: $$rowtotal ++;
7841: return $datatable;
7842: }
7843:
7844: sub legacy_scantronformat {
7845: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
7846: my ($url,$error);
7847: my @statinfo = &Apache::lonnet::stat_file($newurl);
7848: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
7849: (my $result,$url) =
7850: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
7851: '','',$newfile);
7852: if ($result ne 'ok') {
1.130 raeburn 7853: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 7854: }
7855: }
7856: return ($url,$error);
7857: }
1.43 raeburn 7858:
1.160.6.97 raeburn 7859: sub print_scantronconfig {
7860: my ($dom,$settings,$rowtotal) = @_;
7861: my $itemcount = 2;
7862: my $is_checked = ' checked="checked"';
7863: my %optionson = (
7864: hdr => ' checked="checked"',
7865: pad => ' checked="checked"',
7866: rem => ' checked="checked"',
7867: );
7868: my %optionsoff = (
7869: hdr => '',
7870: pad => '',
7871: rem => '',
7872: );
7873: my $currcsvsty = 'none';
7874: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
7875: my @fields = &scantroncsv_fields();
7876: my %titles = &scantronconfig_titles();
7877: if (ref($settings) eq 'HASH') {
7878: if (ref($settings->{config}) eq 'HASH') {
7879: if ($settings->{config}->{dat}) {
7880: $checked{'dat'} = $is_checked;
7881: }
7882: if (ref($settings->{config}->{csv}) eq 'HASH') {
7883: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
7884: %csvfields = %{$settings->{config}->{csv}->{fields}};
7885: if (keys(%csvfields) > 0) {
7886: $checked{'csv'} = $is_checked;
7887: $currcsvsty = 'block';
7888: }
7889: }
7890: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
7891: %csvoptions = %{$settings->{config}->{csv}->{options}};
7892: foreach my $option (keys(%optionson)) {
7893: unless ($csvoptions{$option}) {
7894: $optionsoff{$option} = $optionson{$option};
7895: $optionson{$option} = '';
7896: }
7897: }
7898: }
7899: }
7900: } else {
7901: $checked{'dat'} = $is_checked;
7902: }
7903: } else {
7904: $checked{'dat'} = $is_checked;
7905: }
7906: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
7907: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7908: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
7909: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
7910: foreach my $item ('dat','csv') {
7911: my $id;
7912: if ($item eq 'csv') {
7913: $id = 'id="scantronconfcsv" ';
7914: }
7915: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
7916: $titles{$item}.'</label>'.(' 'x3);
7917: if ($item eq 'csv') {
7918: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
7919: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
7920: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
7921: foreach my $col (@fields) {
7922: my $selnone;
7923: if ($csvfields{$col} eq '') {
7924: $selnone = ' selected="selected"';
7925: }
7926: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
7927: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
7928: '<option value=""'.$selnone.'></option>';
7929: for (my $i=0; $i<20; $i++) {
7930: my $shown = $i+1;
7931: my $sel;
7932: unless ($selnone) {
7933: if (exists($csvfields{$col})) {
7934: if ($csvfields{$col} == $i) {
7935: $sel = ' selected="selected"';
7936: }
7937: }
7938: }
7939: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
7940: }
7941: $datatable .= '</select></td></tr>';
7942: }
7943: $datatable .= '</table></fieldset>'.
7944: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
7945: '<legend>'.&mt('CSV Options').'</legend>';
7946: foreach my $option ('hdr','pad','rem') {
7947: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
7948: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
7949: &mt('Yes').'</label>'.(' 'x2)."\n".
7950: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
7951: }
7952: $datatable .= '</fieldset>';
7953: $itemcount ++;
7954: }
7955: }
7956: $datatable .= '</td></tr>';
7957: $$rowtotal ++;
7958: return $datatable;
7959: }
7960:
7961: sub scantronconfig_titles {
7962: return &Apache::lonlocal::texthash(
7963: dat => 'Standard format (.dat)',
7964: csv => 'Comma separated values (.csv)',
7965: hdr => 'Remove first line in file (contains column titles)',
7966: pad => 'Prepend 0s to PaperID',
7967: rem => 'Remove leading spaces (except Question Response columns)',
7968: CODE => 'CODE',
7969: ID => 'Student ID',
7970: PaperID => 'Paper ID',
7971: FirstName => 'First Name',
7972: LastName => 'Last Name',
7973: FirstQuestion => 'First Question Response',
7974: Section => 'Section',
7975: );
7976: }
7977:
7978: sub scantroncsv_fields {
7979: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
7980: }
7981:
1.49 raeburn 7982: sub print_coursecategories {
1.57 raeburn 7983: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
7984: my $datatable;
7985: if ($position eq 'top') {
1.160.6.42 raeburn 7986: my (%checked);
7987: my @catitems = ('unauth','auth');
7988: my @cattypes = ('std','domonly','codesrch','none');
7989: $checked{'unauth'} = 'std';
7990: $checked{'auth'} = 'std';
7991: if (ref($settings) eq 'HASH') {
7992: foreach my $type (@cattypes) {
7993: if ($type eq $settings->{'unauth'}) {
7994: $checked{'unauth'} = $type;
7995: }
7996: if ($type eq $settings->{'auth'}) {
7997: $checked{'auth'} = $type;
7998: }
7999: }
8000: }
8001: my %lt = &Apache::lonlocal::texthash (
8002: unauth => 'Catalog type for unauthenticated users',
8003: auth => 'Catalog type for authenticated users',
8004: none => 'No catalog',
8005: std => 'Standard catalog',
8006: domonly => 'Domain-only catalog',
8007: codesrch => "Code search form",
8008: );
8009: my $itemcount = 0;
8010: foreach my $item (@catitems) {
8011: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8012: $datatable .= '<tr '.$css_class.'>'.
8013: '<td>'.$lt{$item}.'</td>'.
8014: '<td class="LC_right_item"><span class="LC_nobreak">';
8015: foreach my $type (@cattypes) {
8016: my $ischecked;
8017: if ($checked{$item} eq $type) {
8018: $ischecked=' checked="checked"';
8019: }
8020: $datatable .= '<label>'.
8021: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
8022: ' />'.$lt{$type}.'</label> ';
8023: }
1.160.6.87 raeburn 8024: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 8025: $itemcount ++;
8026: }
8027: $$rowtotal += $itemcount;
8028: } elsif ($position eq 'middle') {
1.57 raeburn 8029: my $toggle_cats_crs = ' ';
8030: my $toggle_cats_dom = ' checked="checked" ';
8031: my $can_cat_crs = ' ';
8032: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 8033: my $toggle_catscomm_comm = ' ';
8034: my $toggle_catscomm_dom = ' checked="checked" ';
8035: my $can_catcomm_comm = ' ';
8036: my $can_catcomm_dom = ' checked="checked" ';
8037:
1.57 raeburn 8038: if (ref($settings) eq 'HASH') {
8039: if ($settings->{'togglecats'} eq 'crs') {
8040: $toggle_cats_crs = $toggle_cats_dom;
8041: $toggle_cats_dom = ' ';
8042: }
8043: if ($settings->{'categorize'} eq 'crs') {
8044: $can_cat_crs = $can_cat_dom;
8045: $can_cat_dom = ' ';
8046: }
1.120 raeburn 8047: if ($settings->{'togglecatscomm'} eq 'comm') {
8048: $toggle_catscomm_comm = $toggle_catscomm_dom;
8049: $toggle_catscomm_dom = ' ';
8050: }
8051: if ($settings->{'categorizecomm'} eq 'comm') {
8052: $can_catcomm_comm = $can_catcomm_dom;
8053: $can_catcomm_dom = ' ';
8054: }
1.57 raeburn 8055: }
8056: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 8057: togglecats => 'Show/Hide a course in catalog',
8058: togglecatscomm => 'Show/Hide a community in catalog',
8059: categorize => 'Assign a category to a course',
8060: categorizecomm => 'Assign a category to a community',
1.57 raeburn 8061: );
8062: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 8063: dom => 'Set in Domain',
8064: crs => 'Set in Course',
8065: comm => 'Set in Community',
1.57 raeburn 8066: );
8067: $datatable = '<tr class="LC_odd_row">'.
8068: '<td>'.$title{'togglecats'}.'</td>'.
8069: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8070: '<input type="radio" name="togglecats"'.
8071: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8072: '<label><input type="radio" name="togglecats"'.
8073: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
8074: '</tr><tr>'.
8075: '<td>'.$title{'categorize'}.'</td>'.
8076: '<td class="LC_right_item"><span class="LC_nobreak">'.
8077: '<label><input type="radio" name="categorize"'.
8078: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8079: '<label><input type="radio" name="categorize"'.
8080: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 8081: '</tr><tr class="LC_odd_row">'.
8082: '<td>'.$title{'togglecatscomm'}.'</td>'.
8083: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8084: '<input type="radio" name="togglecatscomm"'.
8085: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8086: '<label><input type="radio" name="togglecatscomm"'.
8087: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
8088: '</tr><tr>'.
8089: '<td>'.$title{'categorizecomm'}.'</td>'.
8090: '<td class="LC_right_item"><span class="LC_nobreak">'.
8091: '<label><input type="radio" name="categorizecomm"'.
8092: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8093: '<label><input type="radio" name="categorizecomm"'.
8094: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 8095: '</tr>';
1.120 raeburn 8096: $$rowtotal += 4;
1.57 raeburn 8097: } else {
8098: my $css_class;
8099: my $itemcount = 1;
8100: my $cathash;
8101: if (ref($settings) eq 'HASH') {
8102: $cathash = $settings->{'cats'};
8103: }
8104: if (ref($cathash) eq 'HASH') {
8105: my (@cats,@trails,%allitems,%idx,@jsarray);
8106: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
8107: \%allitems,\%idx,\@jsarray);
8108: my $maxdepth = scalar(@cats);
8109: my $colattrib = '';
8110: if ($maxdepth > 2) {
8111: $colattrib = ' colspan="2" ';
8112: }
8113: my @path;
8114: if (@cats > 0) {
8115: if (ref($cats[0]) eq 'ARRAY') {
8116: my $numtop = @{$cats[0]};
8117: my $maxnum = $numtop;
1.120 raeburn 8118: my %default_names = (
8119: instcode => &mt('Official courses'),
8120: communities => &mt('Communities'),
8121: );
8122:
8123: if ((!grep(/^instcode$/,@{$cats[0]})) ||
8124: ($cathash->{'instcode::0'} eq '') ||
8125: (!grep(/^communities$/,@{$cats[0]})) ||
8126: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 8127: $maxnum ++;
8128: }
8129: my $lastidx;
8130: for (my $i=0; $i<$numtop; $i++) {
8131: my $parent = $cats[0][$i];
8132: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8133: my $item = &escape($parent).'::0';
8134: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
8135: $lastidx = $idx{$item};
8136: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8137: .'<select name="'.$item.'"'.$chgstr.'>';
8138: for (my $k=0; $k<=$maxnum; $k++) {
8139: my $vpos = $k+1;
8140: my $selstr;
8141: if ($k == $i) {
8142: $selstr = ' selected="selected" ';
8143: }
8144: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8145: }
1.160.6.29 raeburn 8146: $datatable .= '</select></span></td><td>';
1.120 raeburn 8147: if ($parent eq 'instcode' || $parent eq 'communities') {
8148: $datatable .= '<span class="LC_nobreak">'
8149: .$default_names{$parent}.'</span>';
8150: if ($parent eq 'instcode') {
8151: $datatable .= '<br /><span class="LC_nobreak">('
8152: .&mt('with institutional codes')
8153: .')</span></td><td'.$colattrib.'>';
8154: } else {
8155: $datatable .= '<table><tr><td>';
8156: }
8157: $datatable .= '<span class="LC_nobreak">'
8158: .'<label><input type="radio" name="'
8159: .$parent.'" value="1" checked="checked" />'
8160: .&mt('Display').'</label>';
8161: if ($parent eq 'instcode') {
8162: $datatable .= ' ';
8163: } else {
8164: $datatable .= '</span></td></tr><tr><td>'
8165: .'<span class="LC_nobreak">';
8166: }
8167: $datatable .= '<label><input type="radio" name="'
8168: .$parent.'" value="0" />'
8169: .&mt('Do not display').'</label></span>';
8170: if ($parent eq 'communities') {
8171: $datatable .= '</td></tr></table>';
8172: }
8173: $datatable .= '</td>';
1.57 raeburn 8174: } else {
8175: $datatable .= $parent
1.160.6.29 raeburn 8176: .' <span class="LC_nobreak"><label>'
8177: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 8178: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
8179: }
8180: my $depth = 1;
8181: push(@path,$parent);
8182: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
8183: pop(@path);
8184: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8185: $itemcount ++;
8186: }
1.48 raeburn 8187: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 8188: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
8189: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 8190: for (my $k=0; $k<=$maxnum; $k++) {
8191: my $vpos = $k+1;
8192: my $selstr;
1.57 raeburn 8193: if ($k == $numtop) {
1.48 raeburn 8194: $selstr = ' selected="selected" ';
8195: }
8196: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8197: }
1.59 bisitz 8198: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 8199: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
8200: .'</tr>'."\n";
1.48 raeburn 8201: $itemcount ++;
1.120 raeburn 8202: foreach my $default ('instcode','communities') {
8203: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
8204: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8205: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
8206: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
8207: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
8208: for (my $k=0; $k<=$maxnum; $k++) {
8209: my $vpos = $k+1;
8210: my $selstr;
8211: if ($k == $maxnum) {
8212: $selstr = ' selected="selected" ';
8213: }
8214: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 8215: }
1.120 raeburn 8216: $datatable .= '</select></span></td>'.
8217: '<td><span class="LC_nobreak">'.
8218: $default_names{$default}.'</span>';
8219: if ($default eq 'instcode') {
8220: $datatable .= '<br /><span class="LC_nobreak">('
8221: .&mt('with institutional codes').')</span>';
8222: }
8223: $datatable .= '</td>'
8224: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
8225: .&mt('Display').'</label> '
8226: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
8227: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 8228: }
8229: }
8230: }
1.57 raeburn 8231: } else {
8232: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 8233: }
8234: } else {
1.160.6.87 raeburn 8235: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 8236: .&initialize_categories($itemcount);
1.48 raeburn 8237: }
1.57 raeburn 8238: $$rowtotal += $itemcount;
1.48 raeburn 8239: }
8240: return $datatable;
8241: }
8242:
1.69 raeburn 8243: sub print_serverstatuses {
8244: my ($dom,$settings,$rowtotal) = @_;
8245: my $datatable;
8246: my @pages = &serverstatus_pages();
8247: my (%namedaccess,%machineaccess);
8248: foreach my $type (@pages) {
8249: $namedaccess{$type} = '';
8250: $machineaccess{$type}= '';
8251: }
8252: if (ref($settings) eq 'HASH') {
8253: foreach my $type (@pages) {
8254: if (exists($settings->{$type})) {
8255: if (ref($settings->{$type}) eq 'HASH') {
8256: foreach my $key (keys(%{$settings->{$type}})) {
8257: if ($key eq 'namedusers') {
8258: $namedaccess{$type} = $settings->{$type}->{$key};
8259: } elsif ($key eq 'machines') {
8260: $machineaccess{$type} = $settings->{$type}->{$key};
8261: }
8262: }
8263: }
8264: }
8265: }
8266: }
1.81 raeburn 8267: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8268: my $rownum = 0;
8269: my $css_class;
8270: foreach my $type (@pages) {
8271: $rownum ++;
8272: $css_class = $rownum%2?' class="LC_odd_row"':'';
8273: $datatable .= '<tr'.$css_class.'>'.
8274: '<td><span class="LC_nobreak">'.
8275: $titles->{$type}.'</span></td>'.
8276: '<td class="LC_left_item">'.
8277: '<input type="text" name="'.$type.'_namedusers" '.
8278: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
8279: '<td class="LC_right_item">'.
8280: '<span class="LC_nobreak">'.
8281: '<input type="text" name="'.$type.'_machines" '.
8282: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 8283: '</span></td></tr>'."\n";
1.69 raeburn 8284: }
8285: $$rowtotal += $rownum;
8286: return $datatable;
8287: }
8288:
8289: sub serverstatus_pages {
8290: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 8291: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 8292: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 8293: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 8294: }
8295:
1.160.6.40 raeburn 8296: sub defaults_javascript {
8297: my ($settings) = @_;
1.160.6.98 raeburn 8298: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 8299: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8300: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
8301: if ($maxnum eq '') {
8302: $maxnum = 0;
8303: }
8304: $maxnum ++;
1.160.6.51 raeburn 8305: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 8306: return <<"ENDSCRIPT";
8307: <script type="text/javascript">
8308: // <![CDATA[
8309: function reorderTypes(form,caller) {
8310: var changedVal;
8311: $jstext
8312: var newpos = 'addinststatus_pos';
8313: var current = new Array;
8314: var maxh = $maxnum;
8315: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8316: var oldVal;
8317: if (caller == newpos) {
8318: changedVal = newitemVal;
8319: } else {
8320: var curritem = 'inststatus_pos_'+caller;
8321: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
8322: current[newitemVal] = newpos;
8323: }
8324: for (var i=0; i<inststatuses.length; i++) {
8325: if (inststatuses[i] != caller) {
8326: var elementName = 'inststatus_pos_'+inststatuses[i];
8327: if (form.elements[elementName]) {
8328: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8329: current[currVal] = elementName;
8330: }
8331: }
8332: }
8333: for (var j=0; j<maxh; j++) {
8334: if (current[j] == undefined) {
8335: oldVal = j;
8336: }
8337: }
8338: if (oldVal < changedVal) {
8339: for (var k=oldVal+1; k<=changedVal ; k++) {
8340: var elementName = current[k];
8341: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8342: }
8343: } else {
8344: for (var k=changedVal; k<oldVal; k++) {
8345: var elementName = current[k];
8346: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8347: }
8348: }
8349: return;
8350: }
8351:
8352: // ]]>
8353: </script>
8354:
8355: ENDSCRIPT
8356: }
8357: }
8358:
1.160.6.98 raeburn 8359: sub passwords_javascript {
1.160.6.99 raeburn 8360: my %intalert = &Apache::lonlocal::texthash (
8361: 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.',
8362: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
8363: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
8364: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
8365: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
8366: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
8367: );
8368: &js_escape(\%intalert);
8369: my $defmin = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 8370: my $intauthjs = <<"ENDSCRIPT";
8371:
8372: function warnIntAuth(field) {
8373: if (field.name == 'intauth_check') {
8374: if (field.value == '2') {
1.160.6.99 raeburn 8375: alert('$intalert{authcheck}');
1.160.6.98 raeburn 8376: }
8377: }
8378: if (field.name == 'intauth_cost') {
8379: field.value.replace(/\s/g,'');
8380: if (field.value != '') {
8381: var regexdigit=/^\\d+\$/;
8382: if (!regexdigit.test(field.value)) {
1.160.6.99 raeburn 8383: alert('$intalert{authcost}');
8384: }
8385: }
8386: }
8387: return;
8388: }
8389:
8390: function warnIntPass(field) {
8391: field.value.replace(/^\s+/,'');
8392: field.value.replace(/\s+\$/,'');
8393: var regexdigit=/^\\d+\$/;
8394: if (field.name == 'passwords_min') {
8395: if (field.value == '') {
8396: alert('$intalert{passmin}');
8397: field.value = '$defmin';
8398: } else {
8399: if (!regexdigit.test(field.value)) {
8400: alert('$intalert{passmin}');
8401: field.value = '$defmin';
8402: }
8403: var minval = parseInt(field.value,10);
8404: if (minval < $defmin) {
8405: alert('$intalert{passmin}');
8406: field.value = '$defmin';
8407: }
8408: }
8409: } else {
8410: if (field.value == '0') {
8411: field.value = '';
8412: }
8413: if (field.value != '') {
8414: if (field.name == 'passwords_expire') {
8415: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
8416: if (!regexpposnum.test(field.value)) {
8417: alert('$intalert{passexp}');
8418: field.value = '';
8419: } else {
8420: var expval = parseFloat(field.value);
8421: if (expval == 0) {
8422: alert('$intalert{passexp}');
8423: field.value = '';
8424: }
8425: }
8426: } else {
8427: if (!regexdigit.test(field.value)) {
8428: if (field.name == 'passwords_max') {
8429: alert('$intalert{passmax}');
8430: } else {
8431: if (field.name == 'passwords_numsaved') {
8432: alert('$intalert{passnum}');
8433: }
8434: }
1.160.6.104 raeburn 8435: field.value = '';
1.160.6.99 raeburn 8436: }
1.160.6.98 raeburn 8437: }
8438: }
8439: }
8440: return;
8441: }
8442:
8443: ENDSCRIPT
8444: return &Apache::lonhtmlcommon::scripttag($intauthjs);
8445: }
8446:
1.49 raeburn 8447: sub coursecategories_javascript {
8448: my ($settings) = @_;
1.57 raeburn 8449: my ($output,$jstext,$cathash);
1.49 raeburn 8450: if (ref($settings) eq 'HASH') {
1.57 raeburn 8451: $cathash = $settings->{'cats'};
8452: }
8453: if (ref($cathash) eq 'HASH') {
1.49 raeburn 8454: my (@cats,@jsarray,%idx);
1.57 raeburn 8455: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 8456: if (@jsarray > 0) {
8457: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
8458: for (my $i=0; $i<@jsarray; $i++) {
8459: if (ref($jsarray[$i]) eq 'ARRAY') {
8460: my $catstr = join('","',@{$jsarray[$i]});
8461: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
8462: }
8463: }
8464: }
8465: } else {
8466: $jstext = ' var categories = Array(1);'."\n".
8467: ' categories[0] = Array("instcode_pos");'."\n";
8468: }
1.160.6.42 raeburn 8469: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
8470: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 8471: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
8472: &js_escape(\$instcode_reserved);
8473: &js_escape(\$communities_reserved);
8474: &js_escape(\$choose_again);
1.49 raeburn 8475: $output = <<"ENDSCRIPT";
8476: <script type="text/javascript">
1.109 raeburn 8477: // <![CDATA[
1.49 raeburn 8478: function reorderCats(form,parent,item,idx) {
8479: var changedVal;
8480: $jstext
8481: var newpos = 'addcategory_pos';
8482: if (parent == '') {
8483: var has_instcode = 0;
8484: var maxtop = categories[idx].length;
8485: for (var j=0; j<maxtop; j++) {
8486: if (categories[idx][j] == 'instcode::0') {
8487: has_instcode == 1;
8488: }
8489: }
8490: if (has_instcode == 0) {
8491: categories[idx][maxtop] = 'instcode_pos';
8492: }
8493: } else {
8494: newpos += '_'+parent;
8495: }
8496: var maxh = 1 + categories[idx].length;
8497: var current = new Array;
8498: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8499: if (item == newpos) {
8500: changedVal = newitemVal;
8501: } else {
8502: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
8503: current[newitemVal] = newpos;
8504: }
8505: for (var i=0; i<categories[idx].length; i++) {
8506: var elementName = categories[idx][i];
8507: if (elementName != item) {
8508: if (form.elements[elementName]) {
8509: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8510: current[currVal] = elementName;
8511: }
8512: }
8513: }
8514: var oldVal;
8515: for (var j=0; j<maxh; j++) {
8516: if (current[j] == undefined) {
8517: oldVal = j;
8518: }
8519: }
8520: if (oldVal < changedVal) {
8521: for (var k=oldVal+1; k<=changedVal ; k++) {
8522: var elementName = current[k];
8523: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8524: }
8525: } else {
8526: for (var k=changedVal; k<oldVal; k++) {
8527: var elementName = current[k];
8528: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8529: }
8530: }
8531: return;
8532: }
1.120 raeburn 8533:
8534: function categoryCheck(form) {
8535: if (form.elements['addcategory_name'].value == 'instcode') {
8536: alert('$instcode_reserved\\n$choose_again');
8537: return false;
8538: }
8539: if (form.elements['addcategory_name'].value == 'communities') {
8540: alert('$communities_reserved\\n$choose_again');
8541: return false;
8542: }
8543: return true;
8544: }
8545:
1.109 raeburn 8546: // ]]>
1.49 raeburn 8547: </script>
8548:
8549: ENDSCRIPT
8550: return $output;
8551: }
8552:
1.48 raeburn 8553: sub initialize_categories {
8554: my ($itemcount) = @_;
1.120 raeburn 8555: my ($datatable,$css_class,$chgstr);
1.160.6.111 raeburn 8556: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 8557: instcode => 'Official courses (with institutional codes)',
8558: communities => 'Communities',
8559: );
8560: my $select0 = ' selected="selected"';
8561: my $select1 = '';
8562: foreach my $default ('instcode','communities') {
8563: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 8564: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 8565: if ($default eq 'communities') {
8566: $select1 = $select0;
8567: $select0 = '';
8568: }
8569: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8570: .'<select name="'.$default.'_pos">'
8571: .'<option value="0"'.$select0.'>1</option>'
8572: .'<option value="1"'.$select1.'>2</option>'
8573: .'<option value="2">3</option></select> '
8574: .$default_names{$default}
8575: .'</span></td><td><span class="LC_nobreak">'
8576: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
8577: .&mt('Display').'</label> <label>'
8578: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 8579: .'</label></span></td></tr>';
1.120 raeburn 8580: $itemcount ++;
8581: }
1.48 raeburn 8582: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 8583: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 8584: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 8585: .'<select name="addcategory_pos"'.$chgstr.'>'
8586: .'<option value="0">1</option>'
8587: .'<option value="1">2</option>'
8588: .'<option value="2" selected="selected">3</option></select> '
1.160.6.103 raeburn 8589: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
1.160.6.87 raeburn 8590: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
8591: .'</td></tr>';
1.48 raeburn 8592: return $datatable;
8593: }
8594:
8595: sub build_category_rows {
1.49 raeburn 8596: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
8597: my ($text,$name,$item,$chgstr);
1.48 raeburn 8598: if (ref($cats) eq 'ARRAY') {
8599: my $maxdepth = scalar(@{$cats});
8600: if (ref($cats->[$depth]) eq 'HASH') {
8601: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8602: my $numchildren = @{$cats->[$depth]{$parent}};
8603: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 8604: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 8605: my ($idxnum,$parent_name,$parent_item);
8606: my $higher = $depth - 1;
8607: if ($higher == 0) {
8608: $parent_name = &escape($parent).'::'.$higher;
8609: } else {
8610: if (ref($path) eq 'ARRAY') {
8611: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8612: }
8613: }
8614: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 8615: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 8616: if ($j < $numchildren) {
1.48 raeburn 8617: $name = $cats->[$depth]{$parent}[$j];
8618: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 8619: $idxnum = $idx->{$item};
8620: } else {
8621: $name = $parent_name;
8622: $item = $parent_item;
1.48 raeburn 8623: }
1.49 raeburn 8624: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8625: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 8626: for (my $i=0; $i<=$numchildren; $i++) {
8627: my $vpos = $i+1;
8628: my $selstr;
8629: if ($j == $i) {
8630: $selstr = ' selected="selected" ';
8631: }
8632: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8633: }
8634: $text .= '</select> ';
8635: if ($j < $numchildren) {
8636: my $deeper = $depth+1;
8637: $text .= $name.' '
8638: .'<label><input type="checkbox" name="deletecategory" value="'
8639: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8640: if(ref($path) eq 'ARRAY') {
8641: push(@{$path},$name);
1.49 raeburn 8642: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 8643: pop(@{$path});
8644: }
8645: } else {
1.160.6.87 raeburn 8646: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 8647: if ($j == $numchildren) {
8648: $text .= $name;
8649: } else {
8650: $text .= $item;
8651: }
8652: $text .= '" value="" />';
8653: }
8654: $text .= '</td></tr>';
8655: }
8656: $text .= '</table></td>';
8657: } else {
8658: my $higher = $depth-1;
8659: if ($higher == 0) {
8660: $name = &escape($parent).'::'.$higher;
8661: } else {
8662: if (ref($path) eq 'ARRAY') {
8663: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8664: }
8665: }
8666: my $colspan;
8667: if ($parent ne 'instcode') {
8668: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 8669: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 8670: }
8671: }
8672: }
8673: }
8674: return $text;
8675: }
8676:
1.33 raeburn 8677: sub modifiable_userdata_row {
1.160.6.93 raeburn 8678: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
8679: $rowid,$customcss,$rowstyle) = @_;
1.160.6.35 raeburn 8680: my ($role,$rolename,$statustype);
8681: $role = $item;
1.160.6.34 raeburn 8682: if ($context eq 'cancreate') {
1.160.6.93 raeburn 8683: if ($item =~ /^(emailusername)_(.+)$/) {
8684: $role = $1;
8685: $statustype = $2;
1.160.6.35 raeburn 8686: if (ref($usertypes) eq 'HASH') {
8687: if ($usertypes->{$statustype}) {
8688: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
8689: } else {
8690: $rolename = &mt('Data provided by user');
8691: }
8692: }
1.160.6.34 raeburn 8693: }
8694: } elsif ($context eq 'selfcreate') {
1.63 raeburn 8695: if (ref($usertypes) eq 'HASH') {
8696: $rolename = $usertypes->{$role};
8697: } else {
8698: $rolename = $role;
8699: }
1.33 raeburn 8700: } else {
1.63 raeburn 8701: if ($role eq 'cr') {
8702: $rolename = &mt('Custom role');
8703: } else {
8704: $rolename = &Apache::lonnet::plaintext($role);
8705: }
1.33 raeburn 8706: }
1.160.6.34 raeburn 8707: my (@fields,%fieldtitles);
8708: if (ref($fieldsref) eq 'ARRAY') {
8709: @fields = @{$fieldsref};
8710: } else {
8711: @fields = ('lastname','firstname','middlename','generation',
8712: 'permanentemail','id');
8713: }
8714: if ((ref($titlesref) eq 'HASH')) {
8715: %fieldtitles = %{$titlesref};
8716: } else {
8717: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8718: }
1.33 raeburn 8719: my $output;
1.160.6.93 raeburn 8720: my $css_class;
8721: if ($rowcount%2) {
8722: $css_class = 'LC_odd_row';
8723: }
8724: if ($customcss) {
8725: $css_class .= " $customcss";
8726: }
8727: $css_class =~ s/^\s+//;
8728: if ($css_class) {
8729: $css_class = ' class="'.$css_class.'"';
8730: }
8731: if ($rowstyle) {
8732: $css_class .= ' style="'.$rowstyle.'"';
8733: }
8734: if ($rowid) {
8735: $rowid = ' id="'.$rowid.'"';
8736: }
8737:
8738: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 8739: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
8740: '<td class="LC_left_item" colspan="2"><table>';
8741: my $rem;
8742: my %checks;
8743: if (ref($settings) eq 'HASH') {
8744: if (ref($settings->{$context}) eq 'HASH') {
8745: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 8746: my $hashref = $settings->{$context}->{$role};
8747: if ($role eq 'emailusername') {
8748: if ($statustype) {
8749: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
8750: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 8751: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 8752: foreach my $field (@fields) {
8753: if ($hashref->{$field}) {
8754: $checks{$field} = $hashref->{$field};
8755: }
8756: }
8757: }
8758: }
8759: }
8760: } else {
8761: if (ref($hashref) eq 'HASH') {
8762: foreach my $field (@fields) {
8763: if ($hashref->{$field}) {
8764: $checks{$field} = ' checked="checked" ';
8765: }
8766: }
1.33 raeburn 8767: }
8768: }
8769: }
8770: }
8771: }
1.160.6.93 raeburn 8772:
8773: my $total = scalar(@fields);
8774: for (my $i=0; $i<$total; $i++) {
8775: $rem = $i%($numinrow);
1.33 raeburn 8776: if ($rem == 0) {
8777: if ($i > 0) {
8778: $output .= '</tr>';
8779: }
8780: $output .= '<tr>';
8781: }
8782: my $check = ' ';
1.160.6.35 raeburn 8783: unless ($role eq 'emailusername') {
8784: if (exists($checks{$fields[$i]})) {
1.160.6.98 raeburn 8785: $check = $checks{$fields[$i]};
1.160.6.35 raeburn 8786: } else {
8787: if ($role eq 'st') {
8788: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 8789: $check = ' checked="checked" ';
1.160.6.35 raeburn 8790: }
1.33 raeburn 8791: }
8792: }
8793: }
8794: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 8795: '<span class="LC_nobreak">';
8796: if ($role eq 'emailusername') {
8797: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
8798: $checks{$fields[$i]} = 'omit';
8799: }
8800: foreach my $option ('required','optional','omit') {
8801: my $checked='';
8802: if ($checks{$fields[$i]} eq $option) {
8803: $checked='checked="checked" ';
8804: }
8805: $output .= '<label>'.
8806: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
8807: &mt($option).'</label>'.(' ' x2);
8808: }
8809: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
8810: } else {
8811: $output .= '<label>'.
8812: '<input type="checkbox" name="canmodify_'.$role.'" '.
8813: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
8814: '</label>';
8815: }
8816: $output .= '</span></td>';
1.33 raeburn 8817: }
1.160.6.93 raeburn 8818: $rem = $total%$numinrow;
8819: my $colsleft;
8820: if ($rem) {
8821: $colsleft = $numinrow - $rem;
8822: }
8823: if ($colsleft > 1) {
1.33 raeburn 8824: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8825: ' </td>';
8826: } elsif ($colsleft == 1) {
8827: $output .= '<td class="LC_left_item"> </td>';
8828: }
8829: $output .= '</tr></table></td></tr>';
8830: return $output;
8831: }
1.28 raeburn 8832:
1.93 raeburn 8833: sub insttypes_row {
1.160.6.93 raeburn 8834: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
8835: $customcss,$rowstyle) = @_;
1.93 raeburn 8836: my %lt = &Apache::lonlocal::texthash (
8837: cansearch => 'Users allowed to search',
8838: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 8839: lockablenames => 'User preference to lock name',
1.160.6.93 raeburn 8840: selfassign => 'Self-reportable affiliations',
1.160.6.101 raeburn 8841: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 8842: );
8843: my $showdom;
8844: if ($context eq 'cansearch') {
8845: $showdom = ' ('.$dom.')';
8846: }
1.160.6.5 raeburn 8847: my $class = 'LC_left_item';
8848: if ($context eq 'statustocreate') {
8849: $class = 'LC_right_item';
8850: }
1.160.6.93 raeburn 8851: my $css_class;
8852: if ($$rowtotal%2) {
8853: $css_class = 'LC_odd_row';
8854: }
8855: if ($customcss) {
8856: $css_class .= ' '.$customcss;
8857: }
8858: $css_class =~ s/^\s+//;
8859: if ($css_class) {
8860: $css_class = ' class="'.$css_class.'"';
8861: }
8862: if ($rowstyle) {
8863: $css_class .= ' style="'.$rowstyle.'"';
8864: }
8865: if ($onclick) {
8866: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 8867: }
8868: my $output = '<tr'.$css_class.'>'.
8869: '<td>'.$lt{$context}.$showdom.
8870: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 8871: my $rem;
8872: if (ref($types) eq 'ARRAY') {
8873: for (my $i=0; $i<@{$types}; $i++) {
8874: if (defined($usertypes->{$types->[$i]})) {
8875: my $rem = $i%($numinrow);
8876: if ($rem == 0) {
8877: if ($i > 0) {
8878: $output .= '</tr>';
8879: }
8880: $output .= '<tr>';
1.23 raeburn 8881: }
1.26 raeburn 8882: my $check = ' ';
1.99 raeburn 8883: if (ref($settings) eq 'HASH') {
8884: if (ref($settings->{$context}) eq 'ARRAY') {
8885: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
8886: $check = ' checked="checked" ';
8887: }
1.160.6.101 raeburn 8888: } elsif (ref($settings->{$context}) eq 'HASH') {
8889: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
8890: $check = ' checked="checked" ';
8891: }
1.99 raeburn 8892: } elsif ($context eq 'statustocreate') {
1.26 raeburn 8893: $check = ' checked="checked" ';
8894: }
1.23 raeburn 8895: }
1.26 raeburn 8896: $output .= '<td class="LC_left_item">'.
8897: '<span class="LC_nobreak"><label>'.
1.93 raeburn 8898: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 8899: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
1.26 raeburn 8900: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 8901: }
8902: }
1.26 raeburn 8903: $rem = @{$types}%($numinrow);
1.23 raeburn 8904: }
8905: my $colsleft = $numinrow - $rem;
1.160.6.101 raeburn 8906: if ($context eq 'overrides') {
8907: if ($colsleft > 1) {
8908: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8909: } else {
8910: $output .= '<td class="LC_left_item">';
8911: }
8912: $output .= ' ';
1.23 raeburn 8913: } else {
1.160.6.101 raeburn 8914: if ($rem == 0) {
8915: $output .= '<tr>';
8916: }
8917: if ($colsleft > 1) {
8918: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8919: } else {
8920: $output .= '<td class="LC_left_item">';
8921: }
8922: my $defcheck = ' ';
8923: if (ref($settings) eq 'HASH') {
8924: if (ref($settings->{$context}) eq 'ARRAY') {
8925: if (grep(/^default$/,@{$settings->{$context}})) {
8926: $defcheck = ' checked="checked" ';
8927: }
8928: } elsif ($context eq 'statustocreate') {
1.99 raeburn 8929: $defcheck = ' checked="checked" ';
8930: }
1.26 raeburn 8931: }
1.160.6.101 raeburn 8932: $output .= '<span class="LC_nobreak"><label>'.
8933: '<input type="checkbox" name="'.$context.'" '.
8934: 'value="default"'.$defcheck.$onclick.' />'.
8935: $othertitle.'</label></span>';
1.23 raeburn 8936: }
1.160.6.101 raeburn 8937: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 8938: return $output;
1.23 raeburn 8939: }
8940:
8941: sub sorted_searchtitles {
8942: my %searchtitles = &Apache::lonlocal::texthash(
8943: 'uname' => 'username',
8944: 'lastname' => 'last name',
8945: 'lastfirst' => 'last name, first name',
8946: );
8947: my @titleorder = ('uname','lastname','lastfirst');
8948: return (\%searchtitles,\@titleorder);
8949: }
8950:
1.25 raeburn 8951: sub sorted_searchtypes {
8952: my %srchtypes_desc = (
8953: exact => 'is exact match',
8954: contains => 'contains ..',
8955: begins => 'begins with ..',
8956: );
8957: my @srchtypeorder = ('exact','begins','contains');
8958: return (\%srchtypes_desc,\@srchtypeorder);
8959: }
8960:
1.3 raeburn 8961: sub usertype_update_row {
8962: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
8963: my $datatable;
8964: my $numinrow = 4;
8965: foreach my $type (@{$types}) {
8966: if (defined($usertypes->{$type})) {
8967: $$rownums ++;
8968: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
8969: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
8970: '</td><td class="LC_left_item"><table>';
8971: for (my $i=0; $i<@{$fields}; $i++) {
8972: my $rem = $i%($numinrow);
8973: if ($rem == 0) {
8974: if ($i > 0) {
8975: $datatable .= '</tr>';
8976: }
8977: $datatable .= '<tr>';
8978: }
8979: my $check = ' ';
1.39 raeburn 8980: if (ref($settings) eq 'HASH') {
8981: if (ref($settings->{'fields'}) eq 'HASH') {
8982: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
8983: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
8984: $check = ' checked="checked" ';
8985: }
1.3 raeburn 8986: }
8987: }
8988: }
8989:
8990: if ($i == @{$fields}-1) {
8991: my $colsleft = $numinrow - $rem;
8992: if ($colsleft > 1) {
8993: $datatable .= '<td colspan="'.$colsleft.'">';
8994: } else {
8995: $datatable .= '<td>';
8996: }
8997: } else {
8998: $datatable .= '<td>';
8999: }
1.8 raeburn 9000: $datatable .= '<span class="LC_nobreak"><label>'.
9001: '<input type="checkbox" name="updateable_'.$type.
9002: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
9003: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 9004: }
9005: $datatable .= '</tr></table></td></tr>';
9006: }
9007: }
9008: return $datatable;
1.1 raeburn 9009: }
9010:
9011: sub modify_login {
1.160.6.24 raeburn 9012: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 9013: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.160.6.113 raeburn 9014: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
9015: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso);
1.160.6.5 raeburn 9016: %title = ( coursecatalog => 'Display course catalog',
9017: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 9018: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 9019: newuser => 'Link for visitors to create a user account',
1.160.6.113 raeburn 9020: loginheader => 'Log-in box header',
9021: saml => 'Dual SSO and non-SSO login');
1.160.6.5 raeburn 9022: @offon = ('off','on');
1.112 raeburn 9023: if (ref($domconfig{login}) eq 'HASH') {
9024: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
9025: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
9026: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
9027: }
9028: }
1.160.6.113 raeburn 9029: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
9030: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
9031: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
9032: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
9033: $saml{$lonhost} = 1;
9034: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
9035: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
9036: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
9037: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
9038: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
9039: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
9040: }
9041: }
9042: }
1.112 raeburn 9043: }
1.9 raeburn 9044: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
9045: \%domconfig,\%loginhash);
1.160.6.14 raeburn 9046: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9047: foreach my $item (@toggles) {
9048: $loginhash{login}{$item} = $env{'form.'.$item};
9049: }
1.41 raeburn 9050: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 9051: if (ref($colchanges{'login'}) eq 'HASH') {
9052: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
9053: \%loginhash);
9054: }
1.110 raeburn 9055:
1.149 raeburn 9056: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 9057: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 9058: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 9059: if (keys(%servers) > 1) {
9060: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 9061: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
9062: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
9063: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
9064: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
9065: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
9066: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9067: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9068: $changes{'loginvia'}{$lonhost} = 1;
9069: } else {
9070: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
9071: $changes{'loginvia'}{$lonhost} = 1;
9072: }
9073: } else {
9074: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9075: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9076: $changes{'loginvia'}{$lonhost} = 1;
9077: }
9078: }
9079: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
9080: foreach my $item (@loginvia_attribs) {
9081: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
9082: }
9083: } else {
9084: foreach my $item (@loginvia_attribs) {
9085: my $new = $env{'form.'.$lonhost.'_'.$item};
9086: if (($item eq 'serverpath') && ($new eq 'custom')) {
9087: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
9088: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9089: $new = '/';
9090: }
9091: }
9092: if (($item eq 'custompath') &&
9093: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9094: $new = '';
9095: }
9096: if ($new ne $curr_loginvia{$lonhost}{$item}) {
9097: $changes{'loginvia'}{$lonhost} = 1;
9098: }
9099: if ($item eq 'exempt') {
1.160.6.56 raeburn 9100: $new = &check_exempt_addresses($new);
1.128 raeburn 9101: }
9102: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9103: }
9104: }
1.112 raeburn 9105: } else {
1.128 raeburn 9106: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9107: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 9108: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 9109: foreach my $item (@loginvia_attribs) {
9110: my $new = $env{'form.'.$lonhost.'_'.$item};
9111: if (($item eq 'serverpath') && ($new eq 'custom')) {
9112: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9113: $new = '/';
9114: }
9115: }
9116: if (($item eq 'custompath') &&
9117: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9118: $new = '';
9119: }
9120: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9121: }
1.110 raeburn 9122: }
9123: }
9124: }
9125: }
1.119 raeburn 9126:
1.160.6.5 raeburn 9127: my $servadm = $r->dir_config('lonAdmEMail');
9128: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
9129: if (ref($domconfig{'login'}) eq 'HASH') {
9130: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
9131: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
9132: if ($lang eq 'nolang') {
9133: push(@currlangs,$lang);
9134: } elsif (defined($langchoices{$lang})) {
9135: push(@currlangs,$lang);
9136: } else {
9137: next;
9138: }
9139: }
9140: }
9141: }
9142: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
9143: if (@currlangs > 0) {
9144: foreach my $lang (@currlangs) {
9145: if (grep(/^\Q$lang\E$/,@delurls)) {
9146: $changes{'helpurl'}{$lang} = 1;
9147: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
9148: $changes{'helpurl'}{$lang} = 1;
9149: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
9150: push(@newlangs,$lang);
9151: } else {
9152: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9153: }
9154: }
9155: }
9156: unless (grep(/^nolang$/,@currlangs)) {
9157: if ($env{'form.loginhelpurl_nolang.filename'}) {
9158: $changes{'helpurl'}{'nolang'} = 1;
9159: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
9160: push(@newlangs,'nolang');
9161: }
9162: }
9163: if ($env{'form.loginhelpurl_add_lang'}) {
9164: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
9165: ($env{'form.loginhelpurl_add_file.filename'})) {
9166: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
9167: $addedfile = $env{'form.loginhelpurl_add_lang'};
9168: }
9169: }
9170: if ((@newlangs > 0) || ($addedfile)) {
9171: my $error;
9172: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9173: if ($configuserok eq 'ok') {
9174: if ($switchserver) {
9175: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
9176: } elsif ($author_ok eq 'ok') {
9177: my @allnew = @newlangs;
9178: if ($addedfile ne '') {
9179: push(@allnew,$addedfile);
9180: }
9181: foreach my $lang (@allnew) {
9182: my $formelem = 'loginhelpurl_'.$lang;
9183: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
9184: $formelem = 'loginhelpurl_add_file';
9185: }
9186: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9187: "help/$lang",'','',$newfile{$lang});
9188: if ($result eq 'ok') {
9189: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
9190: $changes{'helpurl'}{$lang} = 1;
9191: } else {
9192: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
9193: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9194: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
9195: (!grep(/^\Q$lang\E$/,@delurls))) {
9196: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9197: }
9198: }
9199: }
9200: } else {
9201: $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);
9202: }
9203: } else {
9204: $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);
9205: }
9206: if ($error) {
9207: &Apache::lonnet::logthis($error);
9208: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9209: }
9210: }
1.160.6.56 raeburn 9211:
9212: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
9213: if (ref($domconfig{'login'}) eq 'HASH') {
9214: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
9215: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
9216: if ($domservers{$lonhost}) {
9217: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9218: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 9219: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 9220: }
9221: }
9222: }
9223: }
9224: }
9225: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
9226: foreach my $lonhost (sort(keys(%domservers))) {
9227: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9228: $changes{'headtag'}{$lonhost} = 1;
9229: } else {
9230: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
9231: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
9232: }
9233: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
9234: push(@newhosts,$lonhost);
9235: } elsif ($currheadtagurls{$lonhost}) {
9236: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
9237: if ($currexempt{$lonhost}) {
9238: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
9239: $changes{'headtag'}{$lonhost} = 1;
9240: }
9241: } elsif ($possexempt{$lonhost}) {
9242: $changes{'headtag'}{$lonhost} = 1;
9243: }
9244: if ($possexempt{$lonhost}) {
9245: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9246: }
9247: }
9248: }
9249: }
9250: if (@newhosts) {
9251: my $error;
9252: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9253: if ($configuserok eq 'ok') {
9254: if ($switchserver) {
9255: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
9256: } elsif ($author_ok eq 'ok') {
9257: foreach my $lonhost (@newhosts) {
9258: my $formelem = 'loginheadtag_'.$lonhost;
9259: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9260: "login/headtag/$lonhost",'','',
9261: $env{'form.loginheadtag_'.$lonhost.'.filename'});
9262: if ($result eq 'ok') {
1.160.6.113 raeburn 9263: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
9264: $changes{'headtag'}{$lonhost} = 1;
9265: if ($possexempt{$lonhost}) {
9266: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9267: }
9268: } else {
9269: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
9270: $newheadtagurls{$lonhost},$result);
9271: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9272: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
9273: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
9274: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
9275: }
9276: }
9277: }
9278: } else {
9279: $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);
9280: }
9281: } else {
9282: $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);
9283: }
9284: if ($error) {
9285: &Apache::lonnet::logthis($error);
9286: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9287: }
9288: }
9289: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
9290: my @newsamlimgs;
9291: foreach my $lonhost (keys(%domservers)) {
9292: if ($env{'form.saml_'.$lonhost}) {
9293: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
9294: push(@newsamlimgs,$lonhost);
9295: }
9296: foreach my $item ('text','alt','url','title','notsso') {
9297: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
9298: }
9299: if ($saml{$lonhost}) {
9300: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
9301: #FIXME Need to obsolete published image
9302: delete($currsaml{$lonhost}{'img'});
9303: $changes{'saml'}{$lonhost} = 1;
9304: }
9305: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
9306: $changes{'saml'}{$lonhost} = 1;
9307: }
9308: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
9309: $changes{'saml'}{$lonhost} = 1;
9310: }
9311: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
9312: $changes{'saml'}{$lonhost} = 1;
9313: }
9314: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
9315: $changes{'saml'}{$lonhost} = 1;
9316: }
9317: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
9318: $changes{'saml'}{$lonhost} = 1;
9319: }
9320: } else {
9321: $changes{'saml'}{$lonhost} = 1;
9322: }
9323: foreach my $item ('text','alt','url','title','notsso') {
9324: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
9325: }
9326: } else {
9327: if ($saml{$lonhost}) {
9328: $changes{'saml'}{$lonhost} = 1;
9329: delete($currsaml{$lonhost});
9330: }
9331: }
9332: }
9333: foreach my $posshost (keys(%currsaml)) {
9334: unless (exists($domservers{$posshost})) {
9335: delete($currsaml{$posshost});
9336: }
9337: }
9338: %{$loginhash{'login'}{'saml'}} = %currsaml;
9339: if (@newsamlimgs) {
9340: my $error;
9341: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9342: if ($configuserok eq 'ok') {
9343: if ($switchserver) {
9344: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
9345: } elsif ($author_ok eq 'ok') {
9346: foreach my $lonhost (@newsamlimgs) {
9347: my $formelem = 'saml_img_'.$lonhost;
9348: my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9349: "login/saml/$lonhost",'','',
9350: $env{'form.saml_img_'.$lonhost.'.filename'});
9351: if ($result eq 'ok') {
9352: $currsaml{$lonhost}{'img'} = $imgurl;
9353: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
9354: $changes{'saml'}{$lonhost} = 1;
1.160.6.56 raeburn 9355: } else {
1.160.6.113 raeburn 9356: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
9357: $lonhost,$result);
1.160.6.56 raeburn 9358: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9359: }
9360: }
9361: } else {
1.160.6.113 raeburn 9362: $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 9363: }
9364: } else {
1.160.6.113 raeburn 9365: $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 9366: }
9367: if ($error) {
9368: &Apache::lonnet::logthis($error);
9369: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9370: }
9371: }
1.160.6.5 raeburn 9372: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
9373:
9374: my $defaulthelpfile = '/adm/loginproblems.html';
9375: my $defaulttext = &mt('Default in use');
9376:
1.1 raeburn 9377: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
9378: $dom);
9379: if ($putresult eq 'ok') {
1.160.6.14 raeburn 9380: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9381: my %defaultchecked = (
9382: 'coursecatalog' => 'on',
1.160.6.14 raeburn 9383: 'helpdesk' => 'on',
1.42 raeburn 9384: 'adminmail' => 'off',
1.43 raeburn 9385: 'newuser' => 'off',
1.42 raeburn 9386: );
1.55 raeburn 9387: if (ref($domconfig{'login'}) eq 'HASH') {
9388: foreach my $item (@toggles) {
9389: if ($defaultchecked{$item} eq 'on') {
9390: if (($domconfig{'login'}{$item} eq '0') &&
9391: ($env{'form.'.$item} eq '1')) {
9392: $changes{$item} = 1;
9393: } elsif (($domconfig{'login'}{$item} eq '' ||
9394: $domconfig{'login'}{$item} eq '1') &&
9395: ($env{'form.'.$item} eq '0')) {
9396: $changes{$item} = 1;
9397: }
9398: } elsif ($defaultchecked{$item} eq 'off') {
9399: if (($domconfig{'login'}{$item} eq '1') &&
9400: ($env{'form.'.$item} eq '0')) {
9401: $changes{$item} = 1;
9402: } elsif (($domconfig{'login'}{$item} eq '' ||
9403: $domconfig{'login'}{$item} eq '0') &&
9404: ($env{'form.'.$item} eq '1')) {
9405: $changes{$item} = 1;
9406: }
1.42 raeburn 9407: }
9408: }
1.41 raeburn 9409: }
1.6 raeburn 9410: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 9411: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.113 raeburn 9412: if (exists($changes{'saml'})) {
9413: my $hostid_in_use;
9414: my @hosts = &Apache::lonnet::current_machine_ids();
9415: if (@hosts > 1) {
9416: foreach my $hostid (@hosts) {
9417: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
9418: $hostid_in_use = $hostid;
9419: last;
9420: }
9421: }
9422: } else {
9423: $hostid_in_use = $r->dir_config('lonHostID');
9424: }
9425: if (($hostid_in_use) &&
9426: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
9427: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
9428: }
9429: if (ref($lastactref) eq 'HASH') {
9430: if (ref($changes{'saml'}) eq 'HASH') {
9431: my %updates;
9432: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
9433: $lastactref->{'samllanding'} = \%updates;
9434: }
9435: }
9436: }
1.160.6.27 raeburn 9437: if (ref($lastactref) eq 'HASH') {
9438: $lastactref->{'domainconfig'} = 1;
9439: }
1.1 raeburn 9440: $resulttext = &mt('Changes made:').'<ul>';
9441: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 9442: if ($item eq 'loginvia') {
1.112 raeburn 9443: if (ref($changes{$item}) eq 'HASH') {
9444: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
9445: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 9446: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
9447: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
9448: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
9449: $protocol = 'http' if ($protocol ne 'https');
9450: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
9451:
9452: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
9453: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
9454: } else {
9455: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
9456: }
9457: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
9458: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
9459: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
9460: }
9461: $resulttext .= '</li>';
9462: } else {
9463: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
9464: }
1.112 raeburn 9465: } else {
1.128 raeburn 9466: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 9467: }
9468: }
1.128 raeburn 9469: $resulttext .= '</ul></li>';
1.112 raeburn 9470: }
1.160.6.5 raeburn 9471: } elsif ($item eq 'helpurl') {
9472: if (ref($changes{$item}) eq 'HASH') {
9473: foreach my $lang (sort(keys(%{$changes{$item}}))) {
9474: if (grep(/^\Q$lang\E$/,@delurls)) {
9475: my ($chg,$link);
9476: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
9477: if ($lang eq 'nolang') {
9478: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
9479: } else {
9480: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
9481: }
9482: $resulttext .= '<li>'.$chg.'</li>';
9483: } else {
9484: my $chg;
9485: if ($lang eq 'nolang') {
9486: $chg = &mt('custom log-in help file for no preferred language');
9487: } else {
9488: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
9489: }
9490: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
9491: $loginhash{'login'}{'helpurl'}{$lang}.
9492: '?inhibitmenu=yes',$chg,600,500).
9493: '</li>';
9494: }
9495: }
9496: }
1.160.6.56 raeburn 9497: } elsif ($item eq 'headtag') {
9498: if (ref($changes{$item}) eq 'HASH') {
9499: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9500: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9501: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
9502: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9503: $resulttext .= '<li><a href="'.
9504: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
9505: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
9506: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
9507: if ($possexempt{$lonhost}) {
9508: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
9509: } else {
9510: $resulttext .= &mt('included for any client IP');
9511: }
9512: $resulttext .= '</li>';
9513: }
9514: }
9515: }
1.160.6.113 raeburn 9516: } elsif ($item eq 'saml') {
9517: if (ref($changes{$item}) eq 'HASH') {
9518: my %notlt = (
9519: text => 'Text for log-in by SSO',
9520: img => 'SSO button image',
9521: alt => 'Alt text for button image',
9522: url => 'SSO URL',
9523: title => 'Tooltip for SSO link',
9524: notsso => 'Text for non-SSO log-in',
9525: );
9526: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9527: if (ref($currsaml{$lonhost}) eq 'HASH') {
9528: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
9529: '<ul>';
9530: foreach my $key ('text','img','alt','url','title','notsso') {
9531: if ($currsaml{$lonhost}{$key} eq '') {
9532: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
9533: } else {
9534: my $value = "'$currsaml{$lonhost}{$key}'";
9535: if ($key eq 'img') {
9536: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
9537: }
9538: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
9539: $value).'</li>';
9540: }
9541: }
9542: $resulttext .= '</ul></li>';
9543: } else {
9544: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
9545: }
9546: }
9547: }
1.160.6.5 raeburn 9548: } elsif ($item eq 'captcha') {
9549: if (ref($loginhash{'login'}) eq 'HASH') {
9550: my $chgtxt;
9551: if ($loginhash{'login'}{$item} eq 'notused') {
9552: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
9553: } else {
9554: my %captchas = &captcha_phrases();
9555: if ($captchas{$loginhash{'login'}{$item}}) {
9556: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
9557: } else {
9558: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
9559: }
9560: }
9561: $resulttext .= '<li>'.$chgtxt.'</li>';
9562: }
9563: } elsif ($item eq 'recaptchakeys') {
9564: if (ref($loginhash{'login'}) eq 'HASH') {
9565: my ($privkey,$pubkey);
9566: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
9567: $pubkey = $loginhash{'login'}{$item}{'public'};
9568: $privkey = $loginhash{'login'}{$item}{'private'};
9569: }
9570: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
9571: if (!$pubkey) {
9572: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
9573: } else {
9574: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9575: }
9576: if (!$privkey) {
9577: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
9578: } else {
1.160.6.53 raeburn 9579: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 9580: }
9581: $chgtxt .= '</ul>';
9582: $resulttext .= '<li>'.$chgtxt.'</li>';
9583: }
1.160.6.69 raeburn 9584: } elsif ($item eq 'recaptchaversion') {
9585: if (ref($loginhash{'login'}) eq 'HASH') {
9586: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
9587: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
9588: '</li>';
9589: }
9590: }
1.41 raeburn 9591: } else {
9592: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
9593: }
1.1 raeburn 9594: }
1.6 raeburn 9595: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 9596: } else {
9597: $resulttext = &mt('No changes made to log-in page settings');
9598: }
9599: } else {
1.11 albertel 9600: $resulttext = '<span class="LC_error">'.
9601: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9602: }
1.6 raeburn 9603: if ($errors) {
1.9 raeburn 9604: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 9605: $errors.'</ul>';
9606: }
9607: return $resulttext;
9608: }
9609:
1.160.6.56 raeburn 9610: sub check_exempt_addresses {
9611: my ($iplist) = @_;
9612: $iplist =~ s/^\s+//;
9613: $iplist =~ s/\s+$//;
9614: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
9615: my (@okips,$new);
9616: foreach my $ip (@poss_ips) {
9617: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
9618: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
9619: push(@okips,$ip);
9620: }
9621: }
9622: }
9623: if (@okips > 0) {
9624: $new = join(',',@okips);
9625: } else {
9626: $new = '';
9627: }
9628: return $new;
9629: }
9630:
1.6 raeburn 9631: sub color_font_choices {
9632: my %choices =
9633: &Apache::lonlocal::texthash (
9634: img => "Header",
9635: bgs => "Background colors",
9636: links => "Link colors",
1.55 raeburn 9637: images => "Images",
1.6 raeburn 9638: font => "Font color",
1.160.6.22 raeburn 9639: fontmenu => "Font menu",
1.76 raeburn 9640: pgbg => "Page",
1.6 raeburn 9641: tabbg => "Header",
9642: sidebg => "Border",
9643: link => "Link",
9644: alink => "Active link",
9645: vlink => "Visited link",
9646: );
9647: return %choices;
9648: }
9649:
1.160.6.113 raeburn 9650: sub modify_ipaccess {
9651: my ($dom,$lastactref,%domconfig) = @_;
9652: my (@allpos,%changes,%confhash,$errors,$resulttext);
9653: my (@items,%deletions,%itemids,@warnings);
9654: my ($typeorder,$types) = &commblocktype_text();
9655: if ($env{'form.ipaccess_add'}) {
9656: my $name = $env{'form.ipaccess_name_add'};
9657: my ($newid,$error) = &get_ipaccess_id($dom,$name);
9658: if ($newid) {
9659: $itemids{'add'} = $newid;
9660: push(@items,'add');
9661: $changes{$newid} = 1;
9662: } else {
9663: $error = &mt('Failed to acquire unique ID for new IP access control item');
9664: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9665: }
9666: }
9667: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
9668: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
9669: if (@todelete) {
9670: map { $deletions{$_} = 1; } @todelete;
9671: }
9672: my $maxnum = $env{'form.ipaccess_maxnum'};
9673: for (my $i=0; $i<$maxnum; $i++) {
9674: my $itemid = $env{'form.ipaccess_id_'.$i};
9675: $itemid =~ s/\D+//g;
9676: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
9677: if ($deletions{$itemid}) {
9678: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
9679: } else {
9680: push(@items,$i);
9681: $itemids{$i} = $itemid;
9682: }
9683: }
9684: }
9685: }
9686: foreach my $idx (@items) {
9687: my $itemid = $itemids{$idx};
9688: next unless ($itemid);
9689: my %current;
9690: unless ($idx eq 'add') {
9691: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
9692: %current = %{$domconfig{'ipaccess'}{$itemid}};
9693: }
9694: }
9695: my $position = $env{'form.ipaccess_pos_'.$itemid};
9696: $position =~ s/\D+//g;
9697: if ($position ne '') {
9698: $allpos[$position] = $itemid;
9699: }
9700: my $name = $env{'form.ipaccess_name_'.$idx};
9701: $name =~ s/^\s+|\s+$//g;
9702: $confhash{$itemid}{'name'} = $name;
9703: my $possrange = $env{'form.ipaccess_range_'.$idx};
9704: $possrange =~ s/^\s+|\s+$//g;
9705: unless ($possrange eq '') {
9706: $possrange =~ s/[\r\n]+/\s/g;
9707: $possrange =~ s/\s*-\s*/-/g;
9708: $possrange =~ s/\s+/,/g;
9709: $possrange =~ s/,+/,/g;
9710: if ($possrange ne '') {
9711: my (@ok,$count);
9712: $count = 0;
9713: foreach my $poss (split(/\,/,$possrange)) {
9714: $count ++;
9715: $poss = &validate_ip_pattern($poss);
9716: if ($poss ne '') {
9717: push(@ok,$poss);
9718: }
9719: }
9720: my $diff = $count - scalar(@ok);
9721: if ($diff) {
9722: $errors .= '<li><span class="LC_error">'.
9723: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
9724: $diff,$name).
9725: '</span></li>';
9726: }
9727: if (@ok) {
9728: my @cidr_list;
9729: foreach my $item (@ok) {
9730: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
9731: }
9732: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
9733: }
9734: }
9735: }
9736: foreach my $field ('name','ip') {
9737: unless (($idx eq 'add') || ($changes{$itemid})) {
9738: if ($current{$field} ne $confhash{$itemid}{$field}) {
9739: $changes{$itemid} = 1;
9740: last;
9741: }
9742: }
9743: }
9744: $confhash{$itemid}{'commblocks'} = {};
9745:
9746: my %commblocks;
9747: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
9748: foreach my $type (@{$typeorder}) {
9749: if ($commblocks{$type}) {
9750: $confhash{$itemid}{'commblocks'}{$type} = 'on';
9751: }
9752: unless (($idx eq 'add') || ($changes{$itemid})) {
9753: if (ref($current{'commblocks'}) eq 'HASH') {
9754: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
9755: $changes{$itemid} = 1;
9756: }
9757: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
9758: $changes{$itemid} = 1;
9759: }
9760: }
9761: }
9762: $confhash{$itemid}{'courses'} = {};
9763: my %crsdeletions;
9764: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
9765: if (@delcrs) {
9766: map { $crsdeletions{$_} = 1; } @delcrs;
9767: }
9768: if (ref($current{'courses'}) eq 'HASH') {
9769: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
9770: if ($crsdeletions{$cid}) {
9771: $changes{$itemid} = 1;
9772: } else {
9773: $confhash{$itemid}{'courses'}{$cid} = 1;
9774: }
9775: }
9776: }
9777: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
9778: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
9779: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
9780: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
9781: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
9782: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
9783: $errors .= '<li><span class="LC_error">'.
9784: &mt('Invalid courseID [_1] omitted from list of allowed courses',
9785: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
9786: '</span></li>';
9787: } else {
9788: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
9789: $changes{$itemid} = 1;
9790: }
9791: }
9792: }
9793: if (@allpos > 0) {
9794: my $idx = 0;
9795: foreach my $itemid (@allpos) {
9796: if ($itemid ne '') {
9797: $confhash{$itemid}{'order'} = $idx;
9798: unless ($changes{$itemid}) {
9799: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
9800: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
9801: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
9802: $changes{$itemid} = 1;
9803: }
9804: }
9805: }
9806: }
9807: $idx ++;
9808: }
9809: }
9810: }
9811: if (keys(%changes)) {
9812: my %defaultshash = (
9813: ipaccess => \%confhash,
9814: );
9815: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
9816: $dom);
9817: if ($putresult eq 'ok') {
9818: my $cachetime = 1800;
9819: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
9820: if (ref($lastactref) eq 'HASH') {
9821: $lastactref->{'ipaccess'} = 1;
9822: }
9823: $resulttext = &mt('Changes made:').'<ul>';
9824: my %bynum;
9825: foreach my $itemid (sort(keys(%changes))) {
9826: if (ref($confhash{$itemid}) eq 'HASH') {
9827: my $position = $confhash{$itemid}{'order'};
9828: if ($position =~ /^\d+$/) {
9829: $bynum{$position} = $itemid;
9830: }
9831: }
9832: }
9833: if (keys(%deletions)) {
9834: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
9835: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
9836: }
9837: }
9838: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
9839: my $itemid = $bynum{$pos};
9840: if (ref($confhash{$itemid}) eq 'HASH') {
9841: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
9842: my $position = $pos + 1;
9843: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
9844: if ($confhash{$itemid}{'ip'} eq '') {
9845: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
9846: } else {
9847: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
9848: }
9849: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
9850: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
9851: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
9852: '</li>';
9853: } else {
9854: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
9855: }
9856: if (keys(%{$confhash{$itemid}{'courses'}})) {
9857: my @courses;
9858: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
9859: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
9860: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
9861: }
9862: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
9863: join('</li><li>',@courses).'</li></ul>';
9864: } else {
9865: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
9866: }
9867: $resulttext .= '</ul></li>';
9868: }
9869: }
9870: $resulttext .= '</ul>';
9871: } else {
9872: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9873: }
9874: } else {
9875: $resulttext = &mt('No changes made');
9876: }
9877: if ($errors) {
9878: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
9879: $errors.'</ul></p>';
9880: }
9881: return $resulttext;
9882: }
9883:
9884: sub get_ipaccess_id {
9885: my ($domain,$location) = @_;
9886: # get lock on ipaccess db
9887: my $lockhash = {
9888: lock => $env{'user.name'}.
9889: ':'.$env{'user.domain'},
9890: };
9891: my $tries = 0;
9892: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
9893: my ($id,$error);
9894:
9895: while (($gotlock ne 'ok') && ($tries<10)) {
9896: $tries ++;
9897: sleep (0.1);
9898: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
9899: }
9900: if ($gotlock eq 'ok') {
9901: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
9902: if ($currids{'lock'}) {
9903: delete($currids{'lock'});
9904: if (keys(%currids)) {
9905: my @curr = sort { $a <=> $b } keys(%currids);
9906: if ($curr[-1] =~ /^\d+$/) {
9907: $id = 1 + $curr[-1];
9908: }
9909: } else {
9910: $id = 1;
9911: }
9912: if ($id) {
9913: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
9914: $error = 'nostore';
9915: }
9916: } else {
9917: $error = 'nonumber';
9918: }
9919: }
9920: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
9921: } else {
9922: $error = 'nolock';
9923: }
9924: return ($id,$error);
9925: }
9926:
1.6 raeburn 9927: sub modify_rolecolors {
1.160.6.24 raeburn 9928: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 9929: my ($resulttext,%rolehash);
9930: $rolehash{'rolecolors'} = {};
1.55 raeburn 9931: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
9932: if ($domconfig{'rolecolors'} eq '') {
9933: $domconfig{'rolecolors'} = {};
9934: }
9935: }
1.9 raeburn 9936: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 9937: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
9938: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
9939: $dom);
9940: if ($putresult eq 'ok') {
9941: if (keys(%changes) > 0) {
1.41 raeburn 9942: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9943: if (ref($lastactref) eq 'HASH') {
9944: $lastactref->{'domainconfig'} = 1;
9945: }
1.6 raeburn 9946: $resulttext = &display_colorchgs($dom,\%changes,$roles,
9947: $rolehash{'rolecolors'});
9948: } else {
9949: $resulttext = &mt('No changes made to default color schemes');
9950: }
9951: } else {
1.11 albertel 9952: $resulttext = '<span class="LC_error">'.
9953: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 9954: }
9955: if ($errors) {
9956: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9957: $errors.'</ul>';
9958: }
9959: return $resulttext;
9960: }
9961:
9962: sub modify_colors {
1.9 raeburn 9963: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 9964: my (%changes,%choices);
1.51 raeburn 9965: my @bgs;
1.6 raeburn 9966: my @links = ('link','alink','vlink');
1.41 raeburn 9967: my @logintext;
1.6 raeburn 9968: my @images;
9969: my $servadm = $r->dir_config('lonAdmEMail');
9970: my $errors;
1.160.6.22 raeburn 9971: my %defaults;
1.6 raeburn 9972: foreach my $role (@{$roles}) {
9973: if ($role eq 'login') {
1.12 raeburn 9974: %choices = &login_choices();
1.41 raeburn 9975: @logintext = ('textcol','bgcol');
1.12 raeburn 9976: } else {
9977: %choices = &color_font_choices();
9978: }
9979: if ($role eq 'login') {
1.41 raeburn 9980: @images = ('img','logo','domlogo','login');
1.51 raeburn 9981: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 9982: } else {
9983: @images = ('img');
1.160.6.22 raeburn 9984: @bgs = ('pgbg','tabbg','sidebg');
9985: }
9986: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
9987: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
9988: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
9989: }
9990: if ($role eq 'login') {
9991: foreach my $item (@logintext) {
1.160.6.39 raeburn 9992: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9993: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9994: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9995: }
9996: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 9997: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9998: }
9999: }
10000: } else {
1.160.6.39 raeburn 10001: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
10002: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
10003: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
10004: }
10005: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 10006: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
10007: }
1.6 raeburn 10008: }
1.160.6.22 raeburn 10009: foreach my $item (@bgs) {
1.160.6.39 raeburn 10010: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10011: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10012: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10013: }
10014: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 10015: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10016: }
10017: }
10018: foreach my $item (@links) {
1.160.6.39 raeburn 10019: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10020: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10021: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10022: }
10023: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 10024: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10025: }
1.6 raeburn 10026: }
1.46 raeburn 10027: my ($configuserok,$author_ok,$switchserver) =
10028: &config_check($dom,$confname,$servadm);
1.9 raeburn 10029: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 10030: if (ref($domconfig->{$role}) ne 'HASH') {
10031: $domconfig->{$role} = {};
10032: }
1.8 raeburn 10033: foreach my $img (@images) {
1.70 raeburn 10034: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
10035: if (defined($env{'form.login_showlogo_'.$img})) {
10036: $confhash->{$role}{'showlogo'}{$img} = 1;
10037: } else {
10038: $confhash->{$role}{'showlogo'}{$img} = 0;
10039: }
10040: }
1.18 albertel 10041: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
10042: && !defined($domconfig->{$role}{$img})
10043: && !$env{'form.'.$role.'_del_'.$img}
10044: && $env{'form.'.$role.'_import_'.$img}) {
10045: # import the old configured image from the .tab setting
10046: # if they haven't provided a new one
10047: $domconfig->{$role}{$img} =
10048: $env{'form.'.$role.'_import_'.$img};
10049: }
1.6 raeburn 10050: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 10051: my $error;
1.6 raeburn 10052: if ($configuserok eq 'ok') {
1.9 raeburn 10053: if ($switchserver) {
1.12 raeburn 10054: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 10055: } else {
10056: if ($author_ok eq 'ok') {
10057: my ($result,$logourl) =
10058: &publishlogo($r,'upload',$role.'_'.$img,
10059: $dom,$confname,$img,$width,$height);
10060: if ($result eq 'ok') {
10061: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 10062: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10063: } else {
1.12 raeburn 10064: $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 10065: }
10066: } else {
1.46 raeburn 10067: $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 10068: }
10069: }
10070: } else {
1.46 raeburn 10071: $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 10072: }
10073: if ($error) {
1.8 raeburn 10074: &Apache::lonnet::logthis($error);
1.11 albertel 10075: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 10076: }
10077: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 10078: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
10079: my $error;
10080: if ($configuserok eq 'ok') {
10081: # is confname an author?
10082: if ($switchserver eq '') {
10083: if ($author_ok eq 'ok') {
10084: my ($result,$logourl) =
10085: &publishlogo($r,'copy',$domconfig->{$role}{$img},
10086: $dom,$confname,$img,$width,$height);
10087: if ($result eq 'ok') {
10088: $confhash->{$role}{$img} = $logourl;
1.18 albertel 10089: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10090: }
10091: }
10092: }
10093: }
1.6 raeburn 10094: }
10095: }
10096: }
10097: if (ref($domconfig) eq 'HASH') {
10098: if (ref($domconfig->{$role}) eq 'HASH') {
10099: foreach my $img (@images) {
10100: if ($domconfig->{$role}{$img} ne '') {
10101: if ($env{'form.'.$role.'_del_'.$img}) {
10102: $confhash->{$role}{$img} = '';
1.12 raeburn 10103: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10104: } else {
1.9 raeburn 10105: if ($confhash->{$role}{$img} eq '') {
10106: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
10107: }
1.6 raeburn 10108: }
10109: } else {
10110: if ($env{'form.'.$role.'_del_'.$img}) {
10111: $confhash->{$role}{$img} = '';
1.12 raeburn 10112: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10113: }
10114: }
1.70 raeburn 10115: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
10116: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
10117: if ($confhash->{$role}{'showlogo'}{$img} ne
10118: $domconfig->{$role}{'showlogo'}{$img}) {
10119: $changes{$role}{'showlogo'}{$img} = 1;
10120: }
10121: } else {
10122: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10123: $changes{$role}{'showlogo'}{$img} = 1;
10124: }
10125: }
10126: }
10127: }
1.6 raeburn 10128: if ($domconfig->{$role}{'font'} ne '') {
10129: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
10130: $changes{$role}{'font'} = 1;
10131: }
10132: } else {
10133: if ($confhash->{$role}{'font'}) {
10134: $changes{$role}{'font'} = 1;
10135: }
10136: }
1.107 raeburn 10137: if ($role ne 'login') {
10138: if ($domconfig->{$role}{'fontmenu'} ne '') {
10139: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
10140: $changes{$role}{'fontmenu'} = 1;
10141: }
10142: } else {
10143: if ($confhash->{$role}{'fontmenu'}) {
10144: $changes{$role}{'fontmenu'} = 1;
10145: }
1.97 tempelho 10146: }
10147: }
1.6 raeburn 10148: foreach my $item (@bgs) {
10149: if ($domconfig->{$role}{$item} ne '') {
10150: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10151: $changes{$role}{'bgs'}{$item} = 1;
10152: }
10153: } else {
10154: if ($confhash->{$role}{$item}) {
10155: $changes{$role}{'bgs'}{$item} = 1;
10156: }
10157: }
10158: }
10159: foreach my $item (@links) {
10160: if ($domconfig->{$role}{$item} ne '') {
10161: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10162: $changes{$role}{'links'}{$item} = 1;
10163: }
10164: } else {
10165: if ($confhash->{$role}{$item}) {
10166: $changes{$role}{'links'}{$item} = 1;
10167: }
10168: }
10169: }
1.41 raeburn 10170: foreach my $item (@logintext) {
10171: if ($domconfig->{$role}{$item} ne '') {
10172: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10173: $changes{$role}{'logintext'}{$item} = 1;
10174: }
10175: } else {
10176: if ($confhash->{$role}{$item}) {
10177: $changes{$role}{'logintext'}{$item} = 1;
10178: }
10179: }
10180: }
1.6 raeburn 10181: } else {
10182: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10183: \@logintext,$confhash,\%changes);
1.6 raeburn 10184: }
10185: } else {
10186: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10187: \@logintext,$confhash,\%changes);
1.6 raeburn 10188: }
10189: }
10190: return ($errors,%changes);
10191: }
10192:
1.46 raeburn 10193: sub config_check {
10194: my ($dom,$confname,$servadm) = @_;
10195: my ($configuserok,$author_ok,$switchserver,%currroles);
10196: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
10197: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
10198: $confname,$servadm);
10199: if ($configuserok eq 'ok') {
10200: $switchserver = &check_switchserver($dom,$confname);
10201: if ($switchserver eq '') {
10202: $author_ok = &check_authorstatus($dom,$confname,%currroles);
10203: }
10204: }
10205: return ($configuserok,$author_ok,$switchserver);
10206: }
10207:
1.6 raeburn 10208: sub default_change_checker {
1.41 raeburn 10209: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 10210: foreach my $item (@{$links}) {
10211: if ($confhash->{$role}{$item}) {
10212: $changes->{$role}{'links'}{$item} = 1;
10213: }
10214: }
10215: foreach my $item (@{$bgs}) {
10216: if ($confhash->{$role}{$item}) {
10217: $changes->{$role}{'bgs'}{$item} = 1;
10218: }
10219: }
1.41 raeburn 10220: foreach my $item (@{$logintext}) {
10221: if ($confhash->{$role}{$item}) {
10222: $changes->{$role}{'logintext'}{$item} = 1;
10223: }
10224: }
1.6 raeburn 10225: foreach my $img (@{$images}) {
10226: if ($env{'form.'.$role.'_del_'.$img}) {
10227: $confhash->{$role}{$img} = '';
1.12 raeburn 10228: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 10229: }
1.70 raeburn 10230: if ($role eq 'login') {
10231: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10232: $changes->{$role}{'showlogo'}{$img} = 1;
10233: }
10234: }
1.6 raeburn 10235: }
10236: if ($confhash->{$role}{'font'}) {
10237: $changes->{$role}{'font'} = 1;
10238: }
1.48 raeburn 10239: }
1.6 raeburn 10240:
10241: sub display_colorchgs {
10242: my ($dom,$changes,$roles,$confhash) = @_;
10243: my (%choices,$resulttext);
10244: if (!grep(/^login$/,@{$roles})) {
10245: $resulttext = &mt('Changes made:').'<br />';
10246: }
10247: foreach my $role (@{$roles}) {
10248: if ($role eq 'login') {
10249: %choices = &login_choices();
10250: } else {
10251: %choices = &color_font_choices();
10252: }
10253: if (ref($changes->{$role}) eq 'HASH') {
10254: if ($role ne 'login') {
10255: $resulttext .= '<h4>'.&mt($role).'</h4>';
10256: }
10257: foreach my $key (sort(keys(%{$changes->{$role}}))) {
10258: if ($role ne 'login') {
10259: $resulttext .= '<ul>';
10260: }
10261: if (ref($changes->{$role}{$key}) eq 'HASH') {
10262: if ($role ne 'login') {
10263: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
10264: }
10265: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 10266: if (($role eq 'login') && ($key eq 'showlogo')) {
10267: if ($confhash->{$role}{$key}{$item}) {
10268: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
10269: } else {
10270: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
10271: }
10272: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 10273: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
10274: } else {
1.12 raeburn 10275: my $newitem = $confhash->{$role}{$item};
10276: if ($key eq 'images') {
10277: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
10278: }
10279: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 10280: }
10281: }
10282: if ($role ne 'login') {
10283: $resulttext .= '</ul></li>';
10284: }
10285: } else {
10286: if ($confhash->{$role}{$key} eq '') {
10287: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
10288: } else {
10289: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
10290: }
10291: }
10292: if ($role ne 'login') {
10293: $resulttext .= '</ul>';
10294: }
10295: }
10296: }
10297: }
1.3 raeburn 10298: return $resulttext;
1.1 raeburn 10299: }
10300:
1.9 raeburn 10301: sub thumb_dimensions {
10302: return ('200','50');
10303: }
10304:
1.16 raeburn 10305: sub check_dimensions {
10306: my ($inputfile) = @_;
10307: my ($fullwidth,$fullheight);
10308: if ($inputfile =~ m|^[/\w.\-]+$|) {
10309: if (open(PIPE,"identify $inputfile 2>&1 |")) {
10310: my $imageinfo = <PIPE>;
10311: if (!close(PIPE)) {
10312: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
10313: }
10314: chomp($imageinfo);
10315: my ($fullsize) =
1.21 raeburn 10316: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 10317: if ($fullsize) {
10318: ($fullwidth,$fullheight) = split(/x/,$fullsize);
10319: }
10320: }
10321: }
10322: return ($fullwidth,$fullheight);
10323: }
10324:
1.9 raeburn 10325: sub check_configuser {
10326: my ($uhome,$dom,$confname,$servadm) = @_;
10327: my ($configuserok,%currroles);
10328: if ($uhome eq 'no_host') {
10329: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98 raeburn 10330: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 10331: $configuserok =
10332: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
10333: $configpass,'','','','','',undef,$servadm);
10334: } else {
10335: $configuserok = 'ok';
10336: %currroles =
10337: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
10338: }
10339: return ($configuserok,%currroles);
10340: }
10341:
10342: sub check_authorstatus {
10343: my ($dom,$confname,%currroles) = @_;
10344: my $author_ok;
1.40 raeburn 10345: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 10346: my $start = time;
10347: my $end = 0;
10348: $author_ok =
10349: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 10350: 'au',$end,$start,'','','domconfig');
1.9 raeburn 10351: } else {
10352: $author_ok = 'ok';
10353: }
10354: return $author_ok;
10355: }
10356:
10357: sub publishlogo {
1.46 raeburn 10358: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 10359: my ($output,$fname,$logourl);
10360: if ($action eq 'upload') {
10361: $fname=$env{'form.'.$formname.'.filename'};
10362: chop($env{'form.'.$formname});
10363: } else {
10364: ($fname) = ($formname =~ /([^\/]+)$/);
10365: }
1.46 raeburn 10366: if ($savefileas ne '') {
10367: $fname = $savefileas;
10368: }
1.9 raeburn 10369: $fname=&Apache::lonnet::clean_filename($fname);
10370: # See if there is anything left
10371: unless ($fname) { return ('error: no uploaded file'); }
10372: $fname="$subdir/$fname";
1.160.6.5 raeburn 10373: my $docroot=$r->dir_config('lonDocRoot');
10374: my $filepath="$docroot/priv";
10375: my $relpath = "$dom/$confname";
1.9 raeburn 10376: my ($fnamepath,$file,$fetchthumb);
10377: $file=$fname;
10378: if ($fname=~m|/|) {
10379: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
10380: }
1.160.6.26 raeburn 10381: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 10382: my $count;
1.160.6.5 raeburn 10383: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 10384: $filepath.="/$parts[$count]";
10385: if ((-e $filepath)!=1) {
10386: mkdir($filepath,02770);
10387: }
10388: }
10389: # Check for bad extension and disallow upload
10390: if ($file=~/\.(\w+)$/ &&
10391: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
10392: $output =
1.160.6.25 raeburn 10393: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 10394: } elsif ($file=~/\.(\w+)$/ &&
10395: !defined(&Apache::loncommon::fileembstyle($1))) {
10396: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
10397: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 10398: $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 10399: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 10400: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 10401: } else {
10402: my $source = $filepath.'/'.$file;
10403: my $logfile;
1.160.6.88 raeburn 10404: if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 10405: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 10406: }
10407: print $logfile
10408: "\n================= Publish ".localtime()." ================\n".
10409: $env{'user.name'}.':'.$env{'user.domain'}."\n";
10410: # Save the file
1.160.6.88 raeburn 10411: if (!open(FH,">",$source)) {
1.9 raeburn 10412: &Apache::lonnet::logthis('Failed to create '.$source);
10413: return (&mt('Failed to create file'));
10414: }
10415: if ($action eq 'upload') {
10416: if (!print FH ($env{'form.'.$formname})) {
10417: &Apache::lonnet::logthis('Failed to write to '.$source);
10418: return (&mt('Failed to write file'));
10419: }
10420: } else {
10421: my $original = &Apache::lonnet::filelocation('',$formname);
10422: if(!copy($original,$source)) {
10423: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
10424: return (&mt('Failed to write file'));
10425: }
10426: }
10427: close(FH);
10428: chmod(0660, $source); # Permissions to rw-rw---.
10429:
10430: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
10431: my $copyfile=$targetdir.'/'.$file;
10432:
10433: my @parts=split(/\//,$targetdir);
10434: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
10435: for (my $count=5;$count<=$#parts;$count++) {
10436: $path.="/$parts[$count]";
10437: if (!-e $path) {
10438: print $logfile "\nCreating directory ".$path;
10439: mkdir($path,02770);
10440: }
10441: }
10442: my $versionresult;
10443: if (-e $copyfile) {
10444: $versionresult = &logo_versioning($targetdir,$file,$logfile);
10445: } else {
10446: $versionresult = 'ok';
10447: }
10448: if ($versionresult eq 'ok') {
10449: if (copy($source,$copyfile)) {
10450: print $logfile "\nCopied original source to ".$copyfile."\n";
10451: $output = 'ok';
10452: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 10453: push(@{$modified_urls},[$copyfile,$source]);
10454: my $metaoutput =
10455: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
10456: unless ($registered_cleanup) {
10457: my $handlers = $r->get_handlers('PerlCleanupHandler');
10458: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10459: $registered_cleanup=1;
10460: }
1.9 raeburn 10461: } else {
10462: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
10463: $output = &mt('Failed to copy file to RES space').", $!";
10464: }
10465: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
10466: my $inputfile = $filepath.'/'.$file;
10467: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 10468: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
10469: if ($fullwidth ne '' && $fullheight ne '') {
10470: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
10471: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88 raeburn 10472: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
10473: system({$args[0]} @args);
1.16 raeburn 10474: chmod(0660, $filepath.'/tn-'.$file);
10475: if (-e $outfile) {
10476: my $copyfile=$targetdir.'/tn-'.$file;
10477: if (copy($outfile,$copyfile)) {
10478: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 10479: my $thumb_metaoutput =
10480: &write_metadata($dom,$confname,$formname,
10481: $targetdir,'tn-'.$file,$logfile);
10482: push(@{$modified_urls},[$copyfile,$outfile]);
10483: unless ($registered_cleanup) {
10484: my $handlers = $r->get_handlers('PerlCleanupHandler');
10485: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10486: $registered_cleanup=1;
10487: }
1.16 raeburn 10488: } else {
10489: print $logfile "\nUnable to write ".$copyfile.
10490: ':'.$!."\n";
10491: }
10492: }
1.9 raeburn 10493: }
10494: }
10495: }
10496: } else {
10497: $output = $versionresult;
10498: }
10499: }
10500: return ($output,$logourl);
10501: }
10502:
10503: sub logo_versioning {
10504: my ($targetdir,$file,$logfile) = @_;
10505: my $target = $targetdir.'/'.$file;
10506: my ($maxversion,$fn,$extn,$output);
10507: $maxversion = 0;
10508: if ($file =~ /^(.+)\.(\w+)$/) {
10509: $fn=$1;
10510: $extn=$2;
10511: }
10512: opendir(DIR,$targetdir);
10513: while (my $filename=readdir(DIR)) {
10514: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
10515: $maxversion=($1>$maxversion)?$1:$maxversion;
10516: }
10517: }
10518: $maxversion++;
10519: print $logfile "\nCreating old version ".$maxversion."\n";
10520: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
10521: if (copy($target,$copyfile)) {
10522: print $logfile "Copied old target to ".$copyfile."\n";
10523: $copyfile=$copyfile.'.meta';
10524: if (copy($target.'.meta',$copyfile)) {
10525: print $logfile "Copied old target metadata to ".$copyfile."\n";
10526: $output = 'ok';
10527: } else {
10528: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
10529: $output = &mt('Failed to copy old meta').", $!, ";
10530: }
10531: } else {
10532: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
10533: $output = &mt('Failed to copy old target').", $!, ";
10534: }
10535: return $output;
10536: }
10537:
10538: sub write_metadata {
10539: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
10540: my (%metadatafields,%metadatakeys,$output);
10541: $metadatafields{'title'}=$formname;
10542: $metadatafields{'creationdate'}=time;
10543: $metadatafields{'lastrevisiondate'}=time;
10544: $metadatafields{'copyright'}='public';
10545: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
10546: $env{'user.domain'};
10547: $metadatafields{'authorspace'}=$confname.':'.$dom;
10548: $metadatafields{'domain'}=$dom;
10549: {
10550: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
10551: my $mfh;
1.160.6.88 raeburn 10552: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 10553: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 10554: unless ($_=~/\./) {
10555: my $unikey=$_;
10556: $unikey=~/^([A-Za-z]+)/;
10557: my $tag=$1;
10558: $tag=~tr/A-Z/a-z/;
10559: print $mfh "\n\<$tag";
10560: foreach (split(/\,/,$metadatakeys{$unikey})) {
10561: my $value=$metadatafields{$unikey.'.'.$_};
10562: $value=~s/\"/\'\'/g;
10563: print $mfh ' '.$_.'="'.$value.'"';
10564: }
10565: print $mfh '>'.
10566: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
10567: .'</'.$tag.'>';
10568: }
10569: }
10570: $output = 'ok';
10571: print $logfile "\nWrote metadata";
10572: close($mfh);
10573: } else {
10574: print $logfile "\nFailed to open metadata file";
1.9 raeburn 10575: $output = &mt('Could not write metadata');
10576: }
10577: }
1.155 raeburn 10578: return $output;
10579: }
10580:
10581: sub notifysubscribed {
10582: foreach my $targetsource (@{$modified_urls}){
10583: next unless (ref($targetsource) eq 'ARRAY');
10584: my ($target,$source)=@{$targetsource};
10585: if ($source ne '') {
1.160.6.88 raeburn 10586: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 10587: print $logfh "\nCleanup phase: Notifications\n";
10588: my @subscribed=&subscribed_hosts($target);
10589: foreach my $subhost (@subscribed) {
10590: print $logfh "\nNotifying host ".$subhost.':';
10591: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
10592: print $logfh $reply;
10593: }
10594: my @subscribedmeta=&subscribed_hosts("$target.meta");
10595: foreach my $subhost (@subscribedmeta) {
10596: print $logfh "\nNotifying host for metadata only ".$subhost.':';
10597: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
10598: $subhost);
10599: print $logfh $reply;
10600: }
10601: print $logfh "\n============ Done ============\n";
1.160 raeburn 10602: close($logfh);
1.155 raeburn 10603: }
10604: }
10605: }
10606: return OK;
10607: }
10608:
10609: sub subscribed_hosts {
10610: my ($target) = @_;
10611: my @subscribed;
1.160.6.88 raeburn 10612: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 10613: while (my $subline=<$fh>) {
10614: if ($subline =~ /^($match_lonid):/) {
10615: my $host = $1;
10616: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
10617: unless (grep(/^\Q$host\E$/,@subscribed)) {
10618: push(@subscribed,$host);
10619: }
10620: }
10621: }
10622: }
10623: }
10624: return @subscribed;
1.9 raeburn 10625: }
10626:
10627: sub check_switchserver {
10628: my ($dom,$confname) = @_;
10629: my ($allowed,$switchserver);
10630: my $home = &Apache::lonnet::homeserver($confname,$dom);
10631: if ($home eq 'no_host') {
10632: $home = &Apache::lonnet::domain($dom,'primary');
10633: }
10634: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 10635: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
10636: if (!$allowed) {
1.160.6.11 raeburn 10637: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 10638: }
10639: return $switchserver;
10640: }
10641:
1.1 raeburn 10642: sub modify_quotas {
1.160.6.30 raeburn 10643: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 10644: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 10645: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 10646: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
10647: $validationfieldsref);
1.86 raeburn 10648: if ($action eq 'quotas') {
10649: $context = 'tools';
1.160.6.26 raeburn 10650: } else {
1.86 raeburn 10651: $context = $action;
10652: }
10653: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 10654: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 10655: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 10656: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
10657: %titles = &courserequest_titles();
10658: $toolregexp = join('|',@usertools);
10659: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 10660: $confname = $dom.'-domainconfig';
10661: my $servadm = $r->dir_config('lonAdmEMail');
10662: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 10663: ($validationitemsref,$validationnamesref,$validationfieldsref) =
10664: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 10665: } elsif ($context eq 'requestauthor') {
10666: @usertools = ('author');
10667: %titles = &authorrequest_titles();
1.86 raeburn 10668: } else {
1.160.6.4 raeburn 10669: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 10670: %titles = &tool_titles();
1.86 raeburn 10671: }
1.160.6.27 raeburn 10672: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 10673: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10674: foreach my $key (keys(%env)) {
1.101 raeburn 10675: if ($context eq 'requestcourses') {
10676: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
10677: my $item = $1;
10678: my $type = $2;
10679: if ($type =~ /^limit_(.+)/) {
10680: $limithash{$item}{$1} = $env{$key};
10681: } else {
10682: $confhash{$item}{$type} = $env{$key};
10683: }
10684: }
1.160.6.5 raeburn 10685: } elsif ($context eq 'requestauthor') {
10686: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
10687: $confhash{$1} = $env{$key};
10688: }
1.101 raeburn 10689: } else {
1.86 raeburn 10690: if ($key =~ /^form\.quota_(.+)$/) {
10691: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 10692: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
10693: $confhash{'authorquota'}{$1} = $env{$key};
10694: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 10695: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
10696: }
1.72 raeburn 10697: }
10698: }
1.160.6.5 raeburn 10699: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 10700: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 10701: @approvalnotify = sort(@approvalnotify);
10702: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 10703: my @crstypes = ('official','unofficial','community','textbook');
10704: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
10705: foreach my $type (@hasuniquecode) {
10706: if (grep(/^\Q$type\E$/,@crstypes)) {
10707: $confhash{'uniquecode'}{$type} = 1;
10708: }
10709: }
1.160.6.46 raeburn 10710: my (%newbook,%allpos);
1.160.6.30 raeburn 10711: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 10712: foreach my $type ('textbooks','templates') {
10713: @{$allpos{$type}} = ();
10714: my $invalid;
10715: if ($type eq 'textbooks') {
10716: $invalid = &mt('Invalid LON-CAPA course for textbook');
10717: } else {
10718: $invalid = &mt('Invalid LON-CAPA course for template');
10719: }
10720: if ($env{'form.'.$type.'_addbook'}) {
10721: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
10722: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
10723: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
10724: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
10725: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
10726: } else {
10727: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
10728: my $position = $env{'form.'.$type.'_addbook_pos'};
10729: $position =~ s/\D+//g;
10730: if ($position ne '') {
10731: $allpos{$type}[$position] = $newbook{$type};
10732: }
1.160.6.30 raeburn 10733: }
1.160.6.46 raeburn 10734: } else {
10735: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 10736: }
10737: }
1.160.6.46 raeburn 10738: }
1.160.6.30 raeburn 10739: }
1.102 raeburn 10740: if (ref($domconfig{$action}) eq 'HASH') {
10741: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
10742: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
10743: $changes{'notify'}{'approval'} = 1;
10744: }
10745: } else {
1.144 raeburn 10746: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10747: $changes{'notify'}{'approval'} = 1;
10748: }
10749: }
1.160.6.30 raeburn 10750: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
10751: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10752: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
10753: unless ($confhash{'uniquecode'}{$crstype}) {
10754: $changes{'uniquecode'} = 1;
10755: }
10756: }
10757: unless ($changes{'uniquecode'}) {
10758: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
10759: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
10760: $changes{'uniquecode'} = 1;
10761: }
10762: }
10763: }
10764: } else {
10765: $changes{'uniquecode'} = 1;
10766: }
10767: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
10768: $changes{'uniquecode'} = 1;
10769: }
10770: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 10771: foreach my $type ('textbooks','templates') {
10772: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10773: my %deletions;
10774: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
10775: if (@todelete) {
10776: map { $deletions{$_} = 1; } @todelete;
10777: }
10778: my %imgdeletions;
10779: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
10780: if (@todeleteimages) {
10781: map { $imgdeletions{$_} = 1; } @todeleteimages;
10782: }
10783: my $maxnum = $env{'form.'.$type.'_maxnum'};
10784: for (my $i=0; $i<=$maxnum; $i++) {
10785: my $itemid = $env{'form.'.$type.'_id_'.$i};
10786: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
10787: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
10788: if ($deletions{$key}) {
10789: if ($domconfig{$action}{$type}{$key}{'image'}) {
10790: #FIXME need to obsolete item in RES space
10791: }
10792: next;
10793: } else {
10794: my $newpos = $env{'form.'.$itemid};
10795: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 10796: foreach my $item ('subject','title','publisher','author') {
10797: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10798: ($type eq 'templates'));
1.160.6.46 raeburn 10799: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
10800: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
10801: $changes{$type}{$key} = 1;
10802: }
10803: }
10804: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 10805: }
1.160.6.46 raeburn 10806: if ($imgdeletions{$key}) {
10807: $changes{$type}{$key} = 1;
10808: #FIXME need to obsolete item in RES space
10809: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
10810: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 10811: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10812: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10813: } else {
10814: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
10815: $cdom,$cnum,$type,$configuserok,
10816: $switchserver,$author_ok);
10817: if ($imgurl) {
10818: $confhash{$type}{$key}{'image'} = $imgurl;
10819: $changes{$type}{$key} = 1;
10820: }
10821: if ($error) {
10822: &Apache::lonnet::logthis($error);
10823: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10824: }
1.160.6.46 raeburn 10825: }
10826: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
10827: $confhash{$type}{$key}{'image'} =
10828: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 10829: }
10830: }
10831: }
10832: }
10833: }
10834: }
1.102 raeburn 10835: } else {
1.144 raeburn 10836: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10837: $changes{'notify'}{'approval'} = 1;
10838: }
1.160.6.30 raeburn 10839: if (ref($confhash{'uniquecode'} eq 'HASH')) {
10840: $changes{'uniquecode'} = 1;
10841: }
10842: }
10843: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 10844: foreach my $type ('textbooks','templates') {
10845: if ($newbook{$type}) {
10846: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 10847: foreach my $item ('subject','title','publisher','author') {
10848: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10849: ($type eq 'template'));
1.160.6.46 raeburn 10850: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
10851: if ($env{'form.'.$type.'_addbook_'.$item}) {
10852: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
10853: }
10854: }
10855: if ($type eq 'textbooks') {
10856: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
10857: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 10858: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10859: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10860: } else {
10861: my ($imageurl,$error) =
10862: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
10863: $configuserok,$switchserver,$author_ok);
10864: if ($imageurl) {
10865: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
10866: }
10867: if ($error) {
10868: &Apache::lonnet::logthis($error);
10869: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10870: }
1.160.6.46 raeburn 10871: }
10872: }
1.160.6.30 raeburn 10873: }
10874: }
1.160.6.46 raeburn 10875: if (@{$allpos{$type}} > 0) {
10876: my $idx = 0;
10877: foreach my $item (@{$allpos{$type}}) {
10878: if ($item ne '') {
10879: $confhash{$type}{$item}{'order'} = $idx;
10880: if (ref($domconfig{$action}) eq 'HASH') {
10881: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10882: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
10883: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
10884: $changes{$type}{$item} = 1;
10885: }
1.160.6.30 raeburn 10886: }
10887: }
10888: }
1.160.6.46 raeburn 10889: $idx ++;
1.160.6.30 raeburn 10890: }
10891: }
10892: }
10893: }
1.160.6.39 raeburn 10894: if (ref($validationitemsref) eq 'ARRAY') {
10895: foreach my $item (@{$validationitemsref}) {
10896: if ($item eq 'fields') {
10897: my @changed;
10898: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
10899: if (@{$confhash{'validation'}{$item}} > 0) {
10900: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
10901: }
1.160.6.65 raeburn 10902: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10903: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10904: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
10905: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
10906: $domconfig{'requestcourses'}{'validation'}{$item});
10907: } else {
10908: @changed = @{$confhash{'validation'}{$item}};
10909: }
1.160.6.39 raeburn 10910: } else {
10911: @changed = @{$confhash{'validation'}{$item}};
10912: }
10913: } else {
10914: @changed = @{$confhash{'validation'}{$item}};
10915: }
10916: if (@changed) {
10917: if ($confhash{'validation'}{$item}) {
10918: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
10919: } else {
10920: $changes{'validation'}{$item} = &mt('None');
10921: }
10922: }
10923: } else {
10924: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
10925: if ($item eq 'markup') {
10926: if ($env{'form.requestcourses_validation_'.$item}) {
10927: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10928: }
10929: }
1.160.6.65 raeburn 10930: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10931: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10932: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
10933: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10934: }
10935: } else {
10936: if ($confhash{'validation'}{$item} ne '') {
10937: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10938: }
1.160.6.39 raeburn 10939: }
10940: } else {
10941: if ($confhash{'validation'}{$item} ne '') {
10942: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10943: }
10944: }
10945: }
10946: }
10947: }
10948: if ($env{'form.validationdc'}) {
10949: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 10950: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 10951: if (exists($domcoords{$newval})) {
10952: $confhash{'validation'}{'dc'} = $newval;
10953: }
10954: }
10955: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 10956: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10957: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10958: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10959: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
10960: if ($confhash{'validation'}{'dc'} eq '') {
10961: $changes{'validation'}{'dc'} = &mt('None');
10962: } else {
10963: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10964: }
1.160.6.39 raeburn 10965: }
1.160.6.65 raeburn 10966: } elsif ($confhash{'validation'}{'dc'} ne '') {
10967: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 10968: }
10969: } elsif ($confhash{'validation'}{'dc'} ne '') {
10970: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10971: }
10972: } elsif ($confhash{'validation'}{'dc'} ne '') {
10973: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10974: }
1.160.6.65 raeburn 10975: } else {
10976: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10977: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10978: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10979: $changes{'validation'}{'dc'} = &mt('None');
10980: }
10981: }
1.160.6.39 raeburn 10982: }
10983: }
1.102 raeburn 10984: }
10985: } else {
1.86 raeburn 10986: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 10987: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 10988: }
1.72 raeburn 10989: foreach my $item (@usertools) {
10990: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 10991: my $unset;
1.101 raeburn 10992: if ($context eq 'requestcourses') {
1.104 raeburn 10993: $unset = '0';
10994: if ($type eq '_LC_adv') {
10995: $unset = '';
10996: }
1.101 raeburn 10997: if ($confhash{$item}{$type} eq 'autolimit') {
10998: $confhash{$item}{$type} .= '=';
10999: unless ($limithash{$item}{$type} =~ /\D/) {
11000: $confhash{$item}{$type} .= $limithash{$item}{$type};
11001: }
11002: }
1.160.6.5 raeburn 11003: } elsif ($context eq 'requestauthor') {
11004: $unset = '0';
11005: if ($type eq '_LC_adv') {
11006: $unset = '';
11007: }
1.72 raeburn 11008: } else {
1.101 raeburn 11009: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
11010: $confhash{$item}{$type} = 1;
11011: } else {
11012: $confhash{$item}{$type} = 0;
11013: }
1.72 raeburn 11014: }
1.86 raeburn 11015: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 11016: if ($action eq 'requestauthor') {
11017: if ($domconfig{$action}{$type} ne $confhash{$type}) {
11018: $changes{$type} = 1;
11019: }
11020: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 11021: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
11022: $changes{$item}{$type} = 1;
11023: }
11024: } else {
11025: if ($context eq 'requestcourses') {
1.104 raeburn 11026: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 11027: $changes{$item}{$type} = 1;
11028: }
11029: } else {
11030: if (!$confhash{$item}{$type}) {
11031: $changes{$item}{$type} = 1;
11032: }
11033: }
11034: }
11035: } else {
11036: if ($context eq 'requestcourses') {
1.104 raeburn 11037: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 11038: $changes{$item}{$type} = 1;
11039: }
1.160.6.5 raeburn 11040: } elsif ($context eq 'requestauthor') {
11041: if ($confhash{$type} ne $unset) {
11042: $changes{$type} = 1;
11043: }
1.72 raeburn 11044: } else {
11045: if (!$confhash{$item}{$type}) {
11046: $changes{$item}{$type} = 1;
11047: }
11048: }
11049: }
1.1 raeburn 11050: }
11051: }
1.160.6.5 raeburn 11052: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 11053: if (ref($domconfig{'quotas'}) eq 'HASH') {
11054: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11055: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
11056: if (exists($confhash{'defaultquota'}{$key})) {
11057: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
11058: $changes{'defaultquota'}{$key} = 1;
11059: }
11060: } else {
11061: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 11062: }
11063: }
1.86 raeburn 11064: } else {
11065: foreach my $key (keys(%{$domconfig{'quotas'}})) {
11066: if (exists($confhash{'defaultquota'}{$key})) {
11067: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
11068: $changes{'defaultquota'}{$key} = 1;
11069: }
11070: } else {
11071: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 11072: }
1.1 raeburn 11073: }
11074: }
1.160.6.20 raeburn 11075: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11076: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
11077: if (exists($confhash{'authorquota'}{$key})) {
11078: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
11079: $changes{'authorquota'}{$key} = 1;
11080: }
11081: } else {
11082: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
11083: }
11084: }
11085: }
1.1 raeburn 11086: }
1.86 raeburn 11087: if (ref($confhash{'defaultquota'}) eq 'HASH') {
11088: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
11089: if (ref($domconfig{'quotas'}) eq 'HASH') {
11090: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11091: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
11092: $changes{'defaultquota'}{$key} = 1;
11093: }
11094: } else {
11095: if (!exists($domconfig{'quotas'}{$key})) {
11096: $changes{'defaultquota'}{$key} = 1;
11097: }
1.72 raeburn 11098: }
11099: } else {
1.86 raeburn 11100: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 11101: }
1.1 raeburn 11102: }
11103: }
1.160.6.20 raeburn 11104: if (ref($confhash{'authorquota'}) eq 'HASH') {
11105: foreach my $key (keys(%{$confhash{'authorquota'}})) {
11106: if (ref($domconfig{'quotas'}) eq 'HASH') {
11107: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11108: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
11109: $changes{'authorquota'}{$key} = 1;
11110: }
11111: } else {
11112: $changes{'authorquota'}{$key} = 1;
11113: }
11114: } else {
11115: $changes{'authorquota'}{$key} = 1;
11116: }
11117: }
11118: }
1.1 raeburn 11119: }
1.72 raeburn 11120:
1.160.6.5 raeburn 11121: if ($context eq 'requestauthor') {
11122: $domdefaults{'requestauthor'} = \%confhash;
11123: } else {
11124: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 11125: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 11126: $domdefaults{$key} = $confhash{$key};
11127: }
1.160.6.5 raeburn 11128: }
1.72 raeburn 11129: }
1.160.6.5 raeburn 11130:
1.1 raeburn 11131: my %quotahash = (
1.86 raeburn 11132: $action => { %confhash }
1.1 raeburn 11133: );
11134: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
11135: $dom);
11136: if ($putresult eq 'ok') {
11137: if (keys(%changes) > 0) {
1.72 raeburn 11138: my $cachetime = 24*60*60;
11139: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11140: if (ref($lastactref) eq 'HASH') {
11141: $lastactref->{'domdefaults'} = 1;
11142: }
1.1 raeburn 11143: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 11144: unless (($context eq 'requestcourses') ||
11145: ($context eq 'requestauthor')) {
1.86 raeburn 11146: if (ref($changes{'defaultquota'}) eq 'HASH') {
11147: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
11148: foreach my $type (@{$types},'default') {
11149: if (defined($changes{'defaultquota'}{$type})) {
11150: my $typetitle = $usertypes->{$type};
11151: if ($type eq 'default') {
11152: $typetitle = $othertitle;
11153: }
1.160.6.28 raeburn 11154: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 11155: }
11156: }
1.86 raeburn 11157: $resulttext .= '</ul></li>';
1.72 raeburn 11158: }
1.160.6.20 raeburn 11159: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 11160: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 11161: foreach my $type (@{$types},'default') {
11162: if (defined($changes{'authorquota'}{$type})) {
11163: my $typetitle = $usertypes->{$type};
11164: if ($type eq 'default') {
11165: $typetitle = $othertitle;
11166: }
1.160.6.28 raeburn 11167: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 11168: }
11169: }
11170: $resulttext .= '</ul></li>';
11171: }
1.72 raeburn 11172: }
1.80 raeburn 11173: my %newenv;
1.72 raeburn 11174: foreach my $item (@usertools) {
1.160.6.5 raeburn 11175: my (%haschgs,%inconf);
11176: if ($context eq 'requestauthor') {
11177: %haschgs = %changes;
11178: %inconf = %confhash;
11179: } else {
11180: if (ref($changes{$item}) eq 'HASH') {
11181: %haschgs = %{$changes{$item}};
11182: }
11183: if (ref($confhash{$item}) eq 'HASH') {
11184: %inconf = %{$confhash{$item}};
11185: }
11186: }
11187: if (keys(%haschgs) > 0) {
1.80 raeburn 11188: my $newacc =
11189: &Apache::lonnet::usertools_access($env{'user.name'},
11190: $env{'user.domain'},
1.86 raeburn 11191: $item,'reload',$context);
1.160.6.5 raeburn 11192: if (($context eq 'requestcourses') ||
11193: ($context eq 'requestauthor')) {
1.108 raeburn 11194: if ($env{'environment.canrequest.'.$item} ne $newacc) {
11195: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 11196: }
11197: } else {
11198: if ($env{'environment.availabletools.'.$item} ne $newacc) {
11199: $newenv{'environment.availabletools.'.$item} = $newacc;
11200: }
1.80 raeburn 11201: }
1.160.6.5 raeburn 11202: unless ($context eq 'requestauthor') {
11203: $resulttext .= '<li>'.$titles{$item}.'<ul>';
11204: }
1.72 raeburn 11205: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 11206: if ($haschgs{$type}) {
1.72 raeburn 11207: my $typetitle = $usertypes->{$type};
11208: if ($type eq 'default') {
11209: $typetitle = $othertitle;
11210: } elsif ($type eq '_LC_adv') {
11211: $typetitle = 'LON-CAPA Advanced Users';
11212: }
1.160.6.5 raeburn 11213: if ($inconf{$type}) {
1.101 raeburn 11214: if ($context eq 'requestcourses') {
11215: my $cond;
1.160.6.5 raeburn 11216: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 11217: if ($1 eq '') {
11218: $cond = &mt('(Automatic processing of any request).');
11219: } else {
11220: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
11221: }
11222: } else {
1.160.6.5 raeburn 11223: $cond = $conditions{$inconf{$type}};
1.101 raeburn 11224: }
11225: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 11226: } elsif ($context eq 'requestauthor') {
11227: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
11228: $titles{$inconf{$type}},$typetitle);
11229:
1.101 raeburn 11230: } else {
11231: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
11232: }
1.72 raeburn 11233: } else {
1.104 raeburn 11234: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 11235: if ($inconf{$type} eq '0') {
1.104 raeburn 11236: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11237: } else {
11238: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
11239: }
11240: } else {
11241: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11242: }
1.72 raeburn 11243: }
11244: }
1.26 raeburn 11245: }
1.160.6.5 raeburn 11246: unless ($context eq 'requestauthor') {
11247: $resulttext .= '</ul></li>';
11248: }
1.26 raeburn 11249: }
1.1 raeburn 11250: }
1.160.6.5 raeburn 11251: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 11252: if (ref($changes{'notify'}) eq 'HASH') {
11253: if ($changes{'notify'}{'approval'}) {
11254: if (ref($confhash{'notify'}) eq 'HASH') {
11255: if ($confhash{'notify'}{'approval'}) {
11256: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
11257: } else {
1.160.6.5 raeburn 11258: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 11259: }
11260: }
11261: }
11262: }
11263: }
1.160.6.30 raeburn 11264: if ($action eq 'requestcourses') {
11265: my @offon = ('off','on');
11266: if ($changes{'uniquecode'}) {
11267: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11268: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
11269: $resulttext .= '<li>'.
11270: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
11271: '</li>';
11272: } else {
11273: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
11274: '</li>';
11275: }
11276: }
1.160.6.46 raeburn 11277: foreach my $type ('textbooks','templates') {
11278: if (ref($changes{$type}) eq 'HASH') {
11279: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
11280: foreach my $key (sort(keys(%{$changes{$type}}))) {
11281: my %coursehash = &Apache::lonnet::coursedescription($key);
11282: my $coursetitle = $coursehash{'description'};
11283: my $position = $confhash{$type}{$key}{'order'} + 1;
11284: $resulttext .= '<li>';
1.160.6.47 raeburn 11285: foreach my $item ('subject','title','publisher','author') {
11286: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11287: ($type eq 'templates'));
1.160.6.46 raeburn 11288: my $name = $item.':';
11289: $name =~ s/^(\w)/\U$1/;
11290: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
11291: }
11292: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
11293: if ($type eq 'textbooks') {
11294: if ($confhash{$type}{$key}{'image'}) {
11295: $resulttext .= ' '.&mt('Image: [_1]',
11296: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
11297: ' alt="Textbook cover" />').'<br />';
11298: }
11299: }
11300: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 11301: }
1.160.6.46 raeburn 11302: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 11303: }
11304: }
1.160.6.39 raeburn 11305: if (ref($changes{'validation'}) eq 'HASH') {
11306: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
11307: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
11308: foreach my $item (@{$validationitemsref}) {
11309: if (exists($changes{'validation'}{$item})) {
11310: if ($item eq 'markup') {
11311: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11312: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
11313: } else {
11314: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11315: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
11316: }
11317: }
11318: }
11319: if (exists($changes{'validation'}{'dc'})) {
11320: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
11321: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
11322: }
11323: }
11324: }
1.160.6.30 raeburn 11325: }
1.1 raeburn 11326: $resulttext .= '</ul>';
1.80 raeburn 11327: if (keys(%newenv)) {
11328: &Apache::lonnet::appenv(\%newenv);
11329: }
1.1 raeburn 11330: } else {
1.86 raeburn 11331: if ($context eq 'requestcourses') {
11332: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 11333: } elsif ($context eq 'requestauthor') {
11334: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 11335: } else {
1.90 weissno 11336: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 11337: }
1.1 raeburn 11338: }
11339: } else {
1.11 albertel 11340: $resulttext = '<span class="LC_error">'.
11341: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11342: }
1.160.6.30 raeburn 11343: if ($errors) {
11344: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
11345: '<ul>'.$errors.'</ul></p>';
11346: }
1.3 raeburn 11347: return $resulttext;
1.1 raeburn 11348: }
11349:
1.160.6.30 raeburn 11350: sub process_textbook_image {
1.160.6.46 raeburn 11351: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 11352: my $filename = $env{'form.'.$caller.'.filename'};
11353: my ($error,$url);
11354: my ($width,$height) = (50,50);
11355: if ($configuserok eq 'ok') {
11356: if ($switchserver) {
11357: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
11358: $switchserver);
11359: } elsif ($author_ok eq 'ok') {
11360: my ($result,$imageurl) =
11361: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88 raeburn 11362: "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 11363: if ($result eq 'ok') {
11364: $url = $imageurl;
11365: } else {
11366: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11367: }
11368: } else {
11369: $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);
11370: }
11371: } else {
11372: $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);
11373: }
11374: return ($url,$error);
11375: }
11376:
1.3 raeburn 11377: sub modify_autoenroll {
1.160.6.24 raeburn 11378: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 11379: my ($resulttext,%changes);
11380: my %currautoenroll;
11381: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
11382: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
11383: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
11384: }
11385: }
11386: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
11387: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 11388: sender => 'Sender for notification messages',
1.160.6.68 raeburn 11389: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
11390: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 11391: my @offon = ('off','on');
1.17 raeburn 11392: my $sender_uname = $env{'form.sender_uname'};
11393: my $sender_domain = $env{'form.sender_domain'};
11394: if ($sender_domain eq '') {
11395: $sender_uname = '';
11396: } elsif ($sender_uname eq '') {
11397: $sender_domain = '';
11398: }
1.129 raeburn 11399: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 11400: my $failsafe = $env{'form.autoenroll_failsafe'};
11401: $failsafe =~ s{^\s+|\s+$}{}g;
11402: if ($failsafe =~ /\D/) {
11403: undef($failsafe);
11404: }
1.1 raeburn 11405: my %autoenrollhash = (
1.129 raeburn 11406: autoenroll => { 'run' => $env{'form.autoenroll_run'},
11407: 'sender_uname' => $sender_uname,
11408: 'sender_domain' => $sender_domain,
11409: 'co-owners' => $coowners,
1.160.6.68 raeburn 11410: 'autofailsafe' => $failsafe,
1.1 raeburn 11411: }
11412: );
1.4 raeburn 11413: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
11414: $dom);
1.1 raeburn 11415: if ($putresult eq 'ok') {
11416: if (exists($currautoenroll{'run'})) {
11417: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
11418: $changes{'run'} = 1;
11419: }
11420: } elsif ($autorun) {
11421: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 11422: $changes{'run'} = 1;
1.1 raeburn 11423: }
11424: }
1.17 raeburn 11425: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 11426: $changes{'sender'} = 1;
11427: }
1.17 raeburn 11428: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 11429: $changes{'sender'} = 1;
11430: }
1.129 raeburn 11431: if ($currautoenroll{'co-owners'} ne '') {
11432: if ($currautoenroll{'co-owners'} ne $coowners) {
11433: $changes{'coowners'} = 1;
11434: }
11435: } elsif ($coowners) {
11436: $changes{'coowners'} = 1;
1.160.6.68 raeburn 11437: }
11438: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
11439: $changes{'autofailsafe'} = 1;
11440: }
1.1 raeburn 11441: if (keys(%changes) > 0) {
11442: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 11443: if ($changes{'run'}) {
1.1 raeburn 11444: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
11445: }
11446: if ($changes{'sender'}) {
1.17 raeburn 11447: if ($sender_uname eq '' || $sender_domain eq '') {
11448: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
11449: } else {
11450: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
11451: }
1.1 raeburn 11452: }
1.129 raeburn 11453: if ($changes{'coowners'}) {
11454: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
11455: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 11456: if (ref($lastactref) eq 'HASH') {
11457: $lastactref->{'domainconfig'} = 1;
11458: }
1.129 raeburn 11459: }
1.160.6.68 raeburn 11460: if ($changes{'autofailsafe'}) {
11461: if ($failsafe ne '') {
1.160.6.82 raeburn 11462: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68 raeburn 11463: } else {
1.160.6.82 raeburn 11464: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68 raeburn 11465: }
11466: &Apache::lonnet::get_domain_defaults($dom,1);
11467: if (ref($lastactref) eq 'HASH') {
11468: $lastactref->{'domdefaults'} = 1;
11469: }
11470: }
1.1 raeburn 11471: $resulttext .= '</ul>';
11472: } else {
11473: $resulttext = &mt('No changes made to auto-enrollment settings');
11474: }
11475: } else {
1.11 albertel 11476: $resulttext = '<span class="LC_error">'.
11477: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11478: }
1.3 raeburn 11479: return $resulttext;
1.1 raeburn 11480: }
11481:
11482: sub modify_autoupdate {
1.3 raeburn 11483: my ($dom,%domconfig) = @_;
1.1 raeburn 11484: my ($resulttext,%currautoupdate,%fields,%changes);
11485: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
11486: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
11487: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
11488: }
11489: }
11490: my @offon = ('off','on');
11491: my %title = &Apache::lonlocal::texthash (
1.160.6.113 raeburn 11492: run => 'Auto-update:',
11493: classlists => 'Updates to user information in classlists?',
11494: unexpired => 'Skip updates for users without active or future roles?',
11495: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 11496: );
1.44 raeburn 11497: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 11498: my %fieldtitles = &Apache::lonlocal::texthash (
11499: id => 'Student/Employee ID',
1.20 raeburn 11500: permanentemail => 'E-mail address',
1.1 raeburn 11501: lastname => 'Last Name',
11502: firstname => 'First Name',
11503: middlename => 'Middle Name',
1.132 raeburn 11504: generation => 'Generation',
1.1 raeburn 11505: );
1.142 raeburn 11506: $othertitle = &mt('All users');
1.1 raeburn 11507: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 11508: $othertitle = &mt('Other users');
1.1 raeburn 11509: }
11510: foreach my $key (keys(%env)) {
11511: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 11512: my ($usertype,$item) = ($1,$2);
11513: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
11514: if ($usertype eq 'default') {
11515: push(@{$fields{$1}},$2);
11516: } elsif (ref($types) eq 'ARRAY') {
11517: if (grep(/^\Q$usertype\E$/,@{$types})) {
11518: push(@{$fields{$1}},$2);
11519: }
11520: }
11521: }
1.1 raeburn 11522: }
11523: }
1.131 raeburn 11524: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
11525: @lockablenames = sort(@lockablenames);
11526: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
11527: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11528: if (@changed) {
11529: $changes{'lockablenames'} = 1;
11530: }
11531: } else {
11532: if (@lockablenames) {
11533: $changes{'lockablenames'} = 1;
11534: }
11535: }
1.1 raeburn 11536: my %updatehash = (
11537: autoupdate => { run => $env{'form.autoupdate_run'},
11538: classlists => $env{'form.classlists'},
1.160.6.113 raeburn 11539: unexpired => $env{'form.unexpired'},
1.1 raeburn 11540: fields => {%fields},
1.131 raeburn 11541: lockablenames => \@lockablenames,
1.1 raeburn 11542: }
11543: );
1.160.6.113 raeburn 11544: my $lastactivedays;
11545: if ($env{'form.lastactive'}) {
11546: $lastactivedays = $env{'form.lastactivedays'};
11547: $lastactivedays =~ s/^\s+|\s+$//g;
11548: unless ($lastactivedays =~ /^\d+$/) {
11549: undef($lastactivedays);
11550: $env{'form.lastactive'} = 0;
11551: }
11552: }
11553: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 11554: foreach my $key (keys(%currautoupdate)) {
1.160.6.113 raeburn 11555: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 11556: if (exists($updatehash{autoupdate}{$key})) {
11557: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
11558: $changes{$key} = 1;
11559: }
11560: }
11561: } elsif ($key eq 'fields') {
11562: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 11563: foreach my $item (@{$types},'default') {
1.1 raeburn 11564: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
11565: my $change = 0;
11566: foreach my $type (@{$currautoupdate{$key}{$item}}) {
11567: if (!exists($fields{$item})) {
11568: $change = 1;
1.132 raeburn 11569: last;
1.1 raeburn 11570: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 11571: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 11572: $change = 1;
1.132 raeburn 11573: last;
1.1 raeburn 11574: }
11575: }
11576: }
11577: if ($change) {
11578: push(@{$changes{$key}},$item);
11579: }
1.26 raeburn 11580: }
1.1 raeburn 11581: }
11582: }
1.131 raeburn 11583: } elsif ($key eq 'lockablenames') {
11584: if (ref($currautoupdate{$key}) eq 'ARRAY') {
11585: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11586: if (@changed) {
11587: $changes{'lockablenames'} = 1;
11588: }
11589: } else {
11590: if (@lockablenames) {
11591: $changes{'lockablenames'} = 1;
11592: }
11593: }
11594: }
11595: }
11596: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
11597: if (@lockablenames) {
11598: $changes{'lockablenames'} = 1;
1.1 raeburn 11599: }
11600: }
1.160.6.113 raeburn 11601: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
11602: if ($updatehash{'autoupdate'}{'unexpired'}) {
11603: $changes{'unexpired'} = 1;
11604: }
11605: }
11606: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
11607: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
11608: $changes{'lastactive'} = 1;
11609: }
11610: }
1.26 raeburn 11611: foreach my $item (@{$types},'default') {
11612: if (defined($fields{$item})) {
11613: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 11614: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
11615: my $change = 0;
11616: if (ref($fields{$item}) eq 'ARRAY') {
11617: foreach my $type (@{$fields{$item}}) {
11618: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
11619: $change = 1;
11620: last;
11621: }
11622: }
11623: }
11624: if ($change) {
11625: push(@{$changes{'fields'}},$item);
11626: }
11627: } else {
1.26 raeburn 11628: push(@{$changes{'fields'}},$item);
11629: }
11630: } else {
11631: push(@{$changes{'fields'}},$item);
1.1 raeburn 11632: }
11633: }
11634: }
11635: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
11636: $dom);
11637: if ($putresult eq 'ok') {
11638: if (keys(%changes) > 0) {
11639: $resulttext = &mt('Changes made:').'<ul>';
11640: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 11641: if ($key eq 'lockablenames') {
11642: $resulttext .= '<li>';
11643: if (@lockablenames) {
11644: $usertypes->{'default'} = $othertitle;
11645: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
11646: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
11647: } else {
11648: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
11649: }
11650: $resulttext .= '</li>';
11651: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 11652: foreach my $item (@{$changes{$key}}) {
11653: my @newvalues;
11654: foreach my $type (@{$fields{$item}}) {
11655: push(@newvalues,$fieldtitles{$type});
11656: }
1.3 raeburn 11657: my $newvaluestr;
11658: if (@newvalues > 0) {
11659: $newvaluestr = join(', ',@newvalues);
11660: } else {
11661: $newvaluestr = &mt('none');
1.6 raeburn 11662: }
1.1 raeburn 11663: if ($item eq 'default') {
1.26 raeburn 11664: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 11665: } else {
1.26 raeburn 11666: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 11667: }
11668: }
11669: } else {
11670: my $newvalue;
11671: if ($key eq 'run') {
11672: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.160.6.113 raeburn 11673: } elsif ($key eq 'lastactive') {
11674: $newvalue = $offon[$env{'form.lastactive'}];
11675: unless ($lastactivedays eq '') {
11676: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
11677: }
1.1 raeburn 11678: } else {
11679: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 11680: }
1.1 raeburn 11681: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
11682: }
11683: }
11684: $resulttext .= '</ul>';
11685: } else {
1.3 raeburn 11686: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 11687: }
11688: } else {
1.11 albertel 11689: $resulttext = '<span class="LC_error">'.
11690: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11691: }
1.3 raeburn 11692: return $resulttext;
1.1 raeburn 11693: }
11694:
1.125 raeburn 11695: sub modify_autocreate {
11696: my ($dom,%domconfig) = @_;
11697: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
11698: if (ref($domconfig{'autocreate'}) eq 'HASH') {
11699: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
11700: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
11701: }
11702: }
11703: my %title= ( xml => 'Auto-creation of courses in XML course description files',
11704: req => 'Auto-creation of validated requests for official courses',
11705: xmldc => 'Identity of course creator of courses from XML files',
11706: );
11707: my @types = ('xml','req');
11708: foreach my $item (@types) {
11709: $newvals{$item} = $env{'form.autocreate_'.$item};
11710: $newvals{$item} =~ s/\D//g;
11711: $newvals{$item} = 0 if ($newvals{$item} eq '');
11712: }
11713: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 11714: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 11715: unless (exists($domcoords{$newvals{'xmldc'}})) {
11716: $newvals{'xmldc'} = '';
11717: }
11718: %autocreatehash = (
11719: autocreate => { xml => $newvals{'xml'},
11720: req => $newvals{'req'},
11721: }
11722: );
11723: if ($newvals{'xmldc'} ne '') {
11724: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
11725: }
11726: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
11727: $dom);
11728: if ($putresult eq 'ok') {
11729: my @items = @types;
11730: if ($newvals{'xml'}) {
11731: push(@items,'xmldc');
11732: }
11733: foreach my $item (@items) {
11734: if (exists($currautocreate{$item})) {
11735: if ($currautocreate{$item} ne $newvals{$item}) {
11736: $changes{$item} = 1;
11737: }
11738: } elsif ($newvals{$item}) {
11739: $changes{$item} = 1;
11740: }
11741: }
11742: if (keys(%changes) > 0) {
11743: my @offon = ('off','on');
11744: $resulttext = &mt('Changes made:').'<ul>';
11745: foreach my $item (@types) {
11746: if ($changes{$item}) {
11747: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 11748: $resulttext .= '<li>'.
11749: &mt("$title{$item} set to [_1]$newtxt [_2]",
11750: '<b>','</b>').
11751: '</li>';
1.125 raeburn 11752: }
11753: }
11754: if ($changes{'xmldc'}) {
11755: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
11756: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 11757: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 11758: }
11759: $resulttext .= '</ul>';
11760: } else {
11761: $resulttext = &mt('No changes made to auto-creation settings');
11762: }
11763: } else {
11764: $resulttext = '<span class="LC_error">'.
11765: &mt('An error occurred: [_1]',$putresult).'</span>';
11766: }
11767: return $resulttext;
11768: }
11769:
1.23 raeburn 11770: sub modify_directorysrch {
1.160.6.81 raeburn 11771: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 11772: my ($resulttext,%changes);
11773: my %currdirsrch;
11774: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
11775: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
11776: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
11777: }
11778: }
1.160.6.72 raeburn 11779: my %title = ( available => 'Institutional directory search available',
11780: localonly => 'Other domains can search institution',
11781: lcavailable => 'LON-CAPA directory search available',
11782: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 11783: searchby => 'Search types',
11784: searchtypes => 'Search latitude');
11785: my @offon = ('off','on');
1.24 raeburn 11786: my @otherdoms = ('Yes','No');
1.23 raeburn 11787:
1.25 raeburn 11788: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 11789: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
11790: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
11791:
1.44 raeburn 11792: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 11793: if (keys(%{$usertypes}) == 0) {
11794: @cansearch = ('default');
11795: } else {
11796: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
11797: foreach my $type (@{$currdirsrch{'cansearch'}}) {
11798: if (!grep(/^\Q$type\E$/,@cansearch)) {
11799: push(@{$changes{'cansearch'}},$type);
11800: }
1.23 raeburn 11801: }
1.26 raeburn 11802: foreach my $type (@cansearch) {
11803: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
11804: push(@{$changes{'cansearch'}},$type);
11805: }
1.23 raeburn 11806: }
1.26 raeburn 11807: } else {
11808: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 11809: }
11810: }
11811:
11812: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
11813: foreach my $by (@{$currdirsrch{'searchby'}}) {
11814: if (!grep(/^\Q$by\E$/,@searchby)) {
11815: push(@{$changes{'searchby'}},$by);
11816: }
11817: }
11818: foreach my $by (@searchby) {
11819: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
11820: push(@{$changes{'searchby'}},$by);
11821: }
11822: }
11823: } else {
11824: push(@{$changes{'searchby'}},@searchby);
11825: }
1.25 raeburn 11826:
11827: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
11828: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
11829: if (!grep(/^\Q$type\E$/,@searchtypes)) {
11830: push(@{$changes{'searchtypes'}},$type);
11831: }
11832: }
11833: foreach my $type (@searchtypes) {
11834: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
11835: push(@{$changes{'searchtypes'}},$type);
11836: }
11837: }
11838: } else {
11839: if (exists($currdirsrch{'searchtypes'})) {
11840: foreach my $type (@searchtypes) {
11841: if ($type ne $currdirsrch{'searchtypes'}) {
11842: push(@{$changes{'searchtypes'}},$type);
11843: }
11844: }
11845: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
11846: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
11847: }
11848: } else {
11849: push(@{$changes{'searchtypes'}},@searchtypes);
11850: }
11851: }
11852:
1.23 raeburn 11853: my %dirsrch_hash = (
11854: directorysrch => { available => $env{'form.dirsrch_available'},
11855: cansearch => \@cansearch,
1.160.6.72 raeburn 11856: localonly => $env{'form.dirsrch_instlocalonly'},
11857: lclocalonly => $env{'form.dirsrch_domlocalonly'},
11858: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 11859: searchby => \@searchby,
1.25 raeburn 11860: searchtypes => \@searchtypes,
1.23 raeburn 11861: }
11862: );
11863: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
11864: $dom);
11865: if ($putresult eq 'ok') {
11866: if (exists($currdirsrch{'available'})) {
11867: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
11868: $changes{'available'} = 1;
11869: }
11870: } else {
11871: if ($env{'form.dirsrch_available'} eq '1') {
11872: $changes{'available'} = 1;
11873: }
11874: }
1.160.6.72 raeburn 11875: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 11876: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
11877: $changes{'lcavailable'} = 1;
11878: }
1.24 raeburn 11879: } else {
1.160.6.72 raeburn 11880: if ($env{'form.dirsrch_lcavailable'} eq '1') {
11881: $changes{'lcavailable'} = 1;
11882: }
11883: }
11884: if (exists($currdirsrch{'localonly'})) {
11885: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 11886: $changes{'localonly'} = 1;
11887: }
1.160.6.72 raeburn 11888: } else {
11889: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
11890: $changes{'localonly'} = 1;
11891: }
11892: }
11893: if (exists($currdirsrch{'lclocalonly'})) {
11894: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
11895: $changes{'lclocalonly'} = 1;
11896: }
11897: } else {
11898: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
11899: $changes{'lclocalonly'} = 1;
11900: }
1.24 raeburn 11901: }
1.23 raeburn 11902: if (keys(%changes) > 0) {
11903: $resulttext = &mt('Changes made:').'<ul>';
11904: if ($changes{'available'}) {
11905: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
11906: }
1.160.6.72 raeburn 11907: if ($changes{'lcavailable'}) {
11908: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
11909: }
1.24 raeburn 11910: if ($changes{'localonly'}) {
1.160.6.72 raeburn 11911: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
11912: }
11913: if ($changes{'lclocalonly'}) {
11914: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 11915: }
1.23 raeburn 11916: if (ref($changes{'cansearch'}) eq 'ARRAY') {
11917: my $chgtext;
1.26 raeburn 11918: if (ref($usertypes) eq 'HASH') {
11919: if (keys(%{$usertypes}) > 0) {
11920: foreach my $type (@{$types}) {
11921: if (grep(/^\Q$type\E$/,@cansearch)) {
11922: $chgtext .= $usertypes->{$type}.'; ';
11923: }
11924: }
11925: if (grep(/^default$/,@cansearch)) {
11926: $chgtext .= $othertitle;
11927: } else {
11928: $chgtext =~ s/\; $//;
11929: }
1.160.6.13 raeburn 11930: $resulttext .=
11931: '<li>'.
11932: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
11933: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
11934: '</li>';
1.23 raeburn 11935: }
11936: }
11937: }
11938: if (ref($changes{'searchby'}) eq 'ARRAY') {
11939: my ($searchtitles,$titleorder) = &sorted_searchtitles();
11940: my $chgtext;
11941: foreach my $type (@{$titleorder}) {
11942: if (grep(/^\Q$type\E$/,@searchby)) {
11943: if (defined($searchtitles->{$type})) {
11944: $chgtext .= $searchtitles->{$type}.'; ';
11945: }
11946: }
11947: }
11948: $chgtext =~ s/\; $//;
11949: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
11950: }
1.25 raeburn 11951: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
11952: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
11953: my $chgtext;
11954: foreach my $type (@{$srchtypeorder}) {
11955: if (grep(/^\Q$type\E$/,@searchtypes)) {
11956: if (defined($srchtypes_desc->{$type})) {
11957: $chgtext .= $srchtypes_desc->{$type}.'; ';
11958: }
11959: }
11960: }
11961: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 11962: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 11963: }
11964: $resulttext .= '</ul>';
1.160.6.81 raeburn 11965: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
11966: if (ref($lastactref) eq 'HASH') {
11967: $lastactref->{'directorysrch'} = 1;
11968: }
1.23 raeburn 11969: } else {
1.160.6.72 raeburn 11970: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 11971: }
11972: } else {
11973: $resulttext = '<span class="LC_error">'.
1.27 raeburn 11974: &mt('An error occurred: [_1]',$putresult).'</span>';
11975: }
11976: return $resulttext;
11977: }
11978:
1.28 raeburn 11979: sub modify_contacts {
1.160.6.24 raeburn 11980: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 11981: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
11982: if (ref($domconfig{'contacts'}) eq 'HASH') {
11983: foreach my $key (keys(%{$domconfig{'contacts'}})) {
11984: $currsetting{$key} = $domconfig{'contacts'}{$key};
11985: }
11986: }
1.160.6.78 raeburn 11987: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 11988: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 11989: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 11990: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.107 raeburn 11991: my @toggles = ('reporterrors','reportupdates','reportstatus');
11992: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.160.6.78 raeburn 11993: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 11994: foreach my $type (@mailings) {
11995: @{$newsetting{$type}} =
11996: &Apache::loncommon::get_env_multiple('form.'.$type);
11997: foreach my $item (@contacts) {
11998: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
11999: $contacts_hash{contacts}{$type}{$item} = 1;
12000: } else {
12001: $contacts_hash{contacts}{$type}{$item} = 0;
12002: }
1.160.6.78 raeburn 12003: }
1.28 raeburn 12004: $others{$type} = $env{'form.'.$type.'_others'};
12005: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 12006: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12007: $bcc{$type} = $env{'form.'.$type.'_bcc'};
12008: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 12009: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
12010: $includestr{$type} = $env{'form.'.$type.'_includestr'};
12011: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
12012: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12013: }
1.134 raeburn 12014: }
1.28 raeburn 12015: }
12016: foreach my $item (@contacts) {
12017: $to{$item} = $env{'form.'.$item};
12018: $contacts_hash{'contacts'}{$item} = $to{$item};
12019: }
1.160.6.23 raeburn 12020: foreach my $item (@toggles) {
12021: if ($env{'form.'.$item} =~ /^(0|1)$/) {
12022: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
12023: }
12024: }
1.160.6.107 raeburn 12025: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
12026: foreach my $item (@lonstatus) {
12027: if ($item eq 'excluded') {
12028: my (%serverhomes,@excluded);
12029: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
12030: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
12031: if (@possexcluded) {
12032: foreach my $id (sort(@possexcluded)) {
12033: if ($serverhomes{$id}) {
12034: push(@excluded,$id);
12035: }
12036: }
12037: }
12038: if (@excluded) {
12039: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
12040: }
12041: } elsif ($item eq 'weights') {
12042: foreach my $type ('E','W','N','U') {
12043: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
12044: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
12045: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
12046: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
12047: $env{'form.error'.$item.'_'.$type};
12048: }
12049: }
12050: }
12051: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
12052: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
12053: if ($env{'form.error'.$item} =~ /^\d+$/) {
12054: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
12055: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
12056: }
12057: }
12058: }
12059: }
1.160.6.78 raeburn 12060: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
12061: foreach my $field (@{$fields}) {
12062: if (ref($possoptions->{$field}) eq 'ARRAY') {
12063: my $value = $env{'form.helpform_'.$field};
12064: $value =~ s/^\s+|\s+$//g;
12065: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101 raeburn 12066: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 12067: if ($field eq 'screenshot') {
12068: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
12069: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101 raeburn 12070: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 12071: }
12072: }
12073: }
12074: }
12075: }
12076: }
1.160.6.101 raeburn 12077: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12078: my (@statuses,%usertypeshash,@overrides);
12079: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
12080: @statuses = @{$types};
12081: if (ref($usertypes) eq 'HASH') {
12082: %usertypeshash = %{$usertypes};
12083: }
12084: }
12085: if (@statuses) {
12086: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
12087: foreach my $type (@possoverrides) {
12088: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
12089: push(@overrides,$type);
12090: }
12091: }
12092: if (@overrides) {
12093: foreach my $type (@overrides) {
12094: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
12095: foreach my $item (@contacts) {
12096: if (grep(/^\Q$item\E$/,@standard)) {
12097: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
12098: $newsetting{'override_'.$type}{$item} = 1;
12099: } else {
12100: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
12101: $newsetting{'override_'.$type}{$item} = 0;
12102: }
12103: }
12104: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
12105: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12106: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
12107: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12108: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
12109: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
12110: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
12111: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12112: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
12113: }
12114: }
12115: }
12116: }
1.28 raeburn 12117: if (keys(%currsetting) > 0) {
12118: foreach my $item (@contacts) {
12119: if ($to{$item} ne $currsetting{$item}) {
12120: $changes{$item} = 1;
12121: }
12122: }
12123: foreach my $type (@mailings) {
12124: foreach my $item (@contacts) {
12125: if (ref($currsetting{$type}) eq 'HASH') {
12126: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
12127: push(@{$changes{$type}},$item);
12128: }
12129: } else {
12130: push(@{$changes{$type}},@{$newsetting{$type}});
12131: }
12132: }
12133: if ($others{$type} ne $currsetting{$type}{'others'}) {
12134: push(@{$changes{$type}},'others');
12135: }
1.160.6.78 raeburn 12136: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12137: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
12138: push(@{$changes{$type}},'bcc');
12139: }
1.160.6.78 raeburn 12140: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
12141: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
12142: push(@{$changes{$type}},'include');
12143: }
12144: }
12145: }
12146: if (ref($fields) eq 'ARRAY') {
12147: if (ref($currsetting{'helpform'}) eq 'HASH') {
12148: foreach my $field (@{$fields}) {
12149: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
12150: push(@{$changes{'helpform'}},$field);
12151: }
12152: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12153: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
12154: push(@{$changes{'helpform'}},'maxsize');
12155: }
12156: }
12157: }
12158: } else {
12159: foreach my $field (@{$fields}) {
12160: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12161: push(@{$changes{'helpform'}},$field);
12162: }
12163: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12164: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12165: push(@{$changes{'helpform'}},'maxsize');
12166: }
12167: }
12168: }
1.134 raeburn 12169: }
1.28 raeburn 12170: }
1.160.6.101 raeburn 12171: if (@statuses) {
12172: if (ref($currsetting{'overrides'}) eq 'HASH') {
12173: foreach my $key (keys(%{$currsetting{'overrides'}})) {
12174: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
12175: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
12176: foreach my $item (@contacts,'bcc','others','include') {
12177: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
12178: push(@{$changes{'overrides'}},$key);
12179: last;
12180: }
12181: }
12182: } else {
12183: push(@{$changes{'overrides'}},$key);
12184: }
12185: }
12186: }
12187: foreach my $key (@overrides) {
12188: unless (exists($currsetting{'overrides'}{$key})) {
12189: push(@{$changes{'overrides'}},$key);
12190: }
12191: }
12192: } else {
12193: foreach my $key (@overrides) {
12194: push(@{$changes{'overrides'}},$key);
12195: }
12196: }
12197: }
1.160.6.107 raeburn 12198: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
12199: foreach my $key ('excluded','weights','threshold','sysmail') {
12200: if ($key eq 'excluded') {
12201: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
12202: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
12203: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
12204: (@{$currsetting{'lonstatus'}{$key}})) {
12205: my @diffs =
12206: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
12207: $currsetting{'lonstatus'}{$key});
12208: if (@diffs) {
12209: push(@{$changes{'lonstatus'}},$key);
12210: }
12211: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
12212: push(@{$changes{'lonstatus'}},$key);
12213: }
12214: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
12215: (@{$currsetting{'lonstatus'}{$key}})) {
12216: push(@{$changes{'lonstatus'}},$key);
12217: }
12218: } elsif ($key eq 'weights') {
12219: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
12220: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
12221: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
12222: foreach my $type ('E','W','N','U') {
12223: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
12224: $currsetting{'lonstatus'}{$key}{$type}) {
12225: push(@{$changes{'lonstatus'}},$key);
12226: last;
12227: }
12228: }
12229: } else {
12230: foreach my $type ('E','W','N','U') {
12231: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
12232: push(@{$changes{'lonstatus'}},$key);
12233: last;
12234: }
12235: }
12236: }
12237: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
12238: foreach my $type ('E','W','N','U') {
12239: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
12240: push(@{$changes{'lonstatus'}},$key);
12241: last;
12242: }
12243: }
12244: }
12245: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
12246: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12247: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
12248: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
12249: push(@{$changes{'lonstatus'}},$key);
12250: }
12251: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
12252: push(@{$changes{'lonstatus'}},$key);
12253: }
12254: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
12255: push(@{$changes{'lonstatus'}},$key);
12256: }
12257: }
12258: }
12259: } else {
12260: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12261: foreach my $key ('excluded','weights','threshold','sysmail') {
12262: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
12263: push(@{$changes{'lonstatus'}},$key);
12264: }
12265: }
12266: }
12267: }
1.28 raeburn 12268: } else {
12269: my %default;
12270: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
12271: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
12272: $default{'errormail'} = 'adminemail';
12273: $default{'packagesmail'} = 'adminemail';
12274: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 12275: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 12276: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 12277: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 12278: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 12279: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 12280: foreach my $item (@contacts) {
12281: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 12282: $changes{$item} = 1;
1.160.6.23 raeburn 12283: }
1.28 raeburn 12284: }
12285: foreach my $type (@mailings) {
12286: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
12287: push(@{$changes{$type}},@{$newsetting{$type}});
12288: }
12289: if ($others{$type} ne '') {
12290: push(@{$changes{$type}},'others');
1.134 raeburn 12291: }
1.160.6.78 raeburn 12292: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12293: if ($bcc{$type} ne '') {
12294: push(@{$changes{$type}},'bcc');
12295: }
1.160.6.78 raeburn 12296: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
12297: push(@{$changes{$type}},'include');
12298: }
12299: }
12300: }
12301: if (ref($fields) eq 'ARRAY') {
12302: foreach my $field (@{$fields}) {
12303: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12304: push(@{$changes{'helpform'}},$field);
12305: }
12306: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12307: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12308: push(@{$changes{'helpform'}},'maxsize');
12309: }
12310: }
1.134 raeburn 12311: }
1.28 raeburn 12312: }
1.160.6.107 raeburn 12313: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12314: foreach my $key ('excluded','weights','threshold','sysmail') {
12315: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
12316: push(@{$changes{'lonstatus'}},$key);
12317: }
12318: }
12319: }
1.28 raeburn 12320: }
1.160.6.23 raeburn 12321: foreach my $item (@toggles) {
12322: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
12323: $changes{$item} = 1;
12324: } elsif ((!$env{'form.'.$item}) &&
12325: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
12326: $changes{$item} = 1;
12327: }
12328: }
1.28 raeburn 12329: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
12330: $dom);
12331: if ($putresult eq 'ok') {
12332: if (keys(%changes) > 0) {
1.160.6.24 raeburn 12333: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 12334: if (ref($lastactref) eq 'HASH') {
12335: $lastactref->{'domainconfig'} = 1;
12336: }
1.28 raeburn 12337: my ($titles,$short_titles) = &contact_titles();
12338: $resulttext = &mt('Changes made:').'<ul>';
12339: foreach my $item (@contacts) {
12340: if ($changes{$item}) {
12341: $resulttext .= '<li>'.$titles->{$item}.
12342: &mt(' set to: ').
12343: '<span class="LC_cusr_emph">'.
12344: $to{$item}.'</span></li>';
12345: }
12346: }
12347: foreach my $type (@mailings) {
12348: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 12349: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
12350: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
12351: } else {
12352: $resulttext .= '<li>'.$titles->{$type}.': ';
12353: }
1.28 raeburn 12354: my @text;
12355: foreach my $item (@{$newsetting{$type}}) {
12356: push(@text,$short_titles->{$item});
12357: }
12358: if ($others{$type} ne '') {
12359: push(@text,$others{$type});
12360: }
1.160.6.78 raeburn 12361: if (@text) {
12362: $resulttext .= '<span class="LC_cusr_emph">'.
12363: join(', ',@text).'</span>';
12364: }
12365: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12366: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 12367: my $bcctext;
12368: if (@text) {
12369: $bcctext = ' '.&mt('with Bcc to');
12370: } else {
12371: $bcctext = '(Bcc)';
12372: }
12373: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
12374: } elsif (!@text) {
12375: $resulttext .= &mt('No one');
1.134 raeburn 12376: }
1.160.6.78 raeburn 12377: if ($includestr{$type} ne '') {
12378: if ($includeloc{$type} eq 'b') {
12379: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
12380: } elsif ($includeloc{$type} eq 's') {
12381: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
12382: }
12383: }
12384: } elsif (!@text) {
12385: $resulttext .= &mt('No recipients');
1.134 raeburn 12386: }
12387: $resulttext .= '</li>';
1.28 raeburn 12388: }
12389: }
1.160.6.101 raeburn 12390: if (ref($changes{'overrides'}) eq 'ARRAY') {
12391: my @deletions;
12392: foreach my $type (@{$changes{'overrides'}}) {
12393: if ($usertypeshash{$type}) {
12394: if (grep(/^\Q$type\E/,@overrides)) {
12395: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
12396: $usertypeshash{$type}).'<ul><li>';
12397: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
12398: my @text;
12399: foreach my $item (@contacts) {
12400: if ($newsetting{'override_'.$type}{$item}) {
12401: push(@text,$short_titles->{$item});
12402: }
12403: }
12404: if ($newsetting{'override_'.$type}{'others'} ne '') {
12405: push(@text,$newsetting{'override_'.$type}{'others'});
12406: }
12407:
12408: if (@text) {
12409: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
12410: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
12411: }
12412: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
12413: my $bcctext;
12414: if (@text) {
12415: $bcctext = ' '.&mt('with Bcc to');
12416: } else {
12417: $bcctext = '(Bcc)';
12418: }
12419: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
12420: } elsif (!@text) {
12421: $resulttext .= &mt('Helpdesk e-mail sent to no one');
12422: }
12423: $resulttext .= '</li>';
12424: if ($newsetting{'override_'.$type}{'include'} ne '') {
12425: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
12426: if ($loc eq 'b') {
12427: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
12428: } elsif ($loc eq 's') {
12429: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
12430: }
12431: }
12432: }
12433: $resulttext .= '</li></ul></li>';
12434: } else {
12435: push(@deletions,$usertypeshash{$type});
12436: }
12437: }
12438: }
12439: if (@deletions) {
12440: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
12441: join(', ',@deletions)).'</li>';
12442: }
12443: }
1.160.6.23 raeburn 12444: my @offon = ('off','on');
1.160.6.107 raeburn 12445: my $corelink = &core_link_msu();
1.160.6.23 raeburn 12446: if ($changes{'reporterrors'}) {
12447: $resulttext .= '<li>'.
12448: &mt('E-mail error reports to [_1] set to "'.
12449: $offon[$env{'form.reporterrors'}].'".',
1.160.6.107 raeburn 12450: $corelink).
1.160.6.23 raeburn 12451: '</li>';
12452: }
12453: if ($changes{'reportupdates'}) {
12454: $resulttext .= '<li>'.
12455: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
12456: $offon[$env{'form.reportupdates'}].'".',
1.160.6.107 raeburn 12457: $corelink).
1.160.6.23 raeburn 12458: '</li>';
12459: }
1.160.6.107 raeburn 12460: if ($changes{'reportstatus'}) {
12461: $resulttext .= '<li>'.
12462: &mt('E-mail status if errors above threshold to [_1] set to "'.
12463: $offon[$env{'form.reportstatus'}].'".',
12464: $corelink).
12465: '</li>';
12466: }
12467: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
12468: $resulttext .= '<li>'.
12469: &mt('Nightly status check e-mail settings').':<ul>';
12470: my (%defval,%use_def,%shown);
12471: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
12472: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
12473: $defval{'weights'} =
12474: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
12475: $defval{'excluded'} = &mt('None');
12476: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
12477: foreach my $item ('threshold','sysmail','weights','excluded') {
12478: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
12479: if (($item eq 'threshold') || ($item eq 'sysmail')) {
12480: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
12481: } elsif ($item eq 'weights') {
12482: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
12483: foreach my $type ('E','W','N','U') {
12484: $shown{$item} .= $lonstatus_names->{$type}.'=';
12485: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
12486: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
12487: } else {
12488: $shown{$item} .= $lonstatus_defs->{$type};
12489: }
12490: $shown{$item} .= ', ';
12491: }
12492: $shown{$item} =~ s/, $//;
12493: } else {
12494: $shown{$item} = $defval{$item};
12495: }
12496: } elsif ($item eq 'excluded') {
12497: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
12498: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
12499: } else {
12500: $shown{$item} = $defval{$item};
12501: }
12502: }
12503: } else {
12504: $shown{$item} = $defval{$item};
12505: }
12506: }
12507: } else {
12508: foreach my $item ('threshold','weights','excluded','sysmail') {
12509: $shown{$item} = $defval{$item};
12510: }
12511: }
12512: foreach my $item ('threshold','weights','excluded','sysmail') {
12513: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
12514: $shown{$item}).'</li>';
12515: }
12516: $resulttext .= '</ul></li>';
12517: }
1.160.6.78 raeburn 12518: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
12519: my (@optional,@required,@unused,$maxsizechg);
12520: foreach my $field (@{$changes{'helpform'}}) {
12521: if ($field eq 'maxsize') {
12522: $maxsizechg = 1;
12523: next;
12524: }
12525: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
12526: push(@optional,$field);
12527: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
12528: push(@unused,$field);
12529: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
12530: push(@required,$field);
12531: }
12532: }
12533: if (@optional) {
12534: $resulttext .= '<li>'.
12535: &mt('Help form fields changed to "Optional": [_1].',
12536: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
12537: '</li>';
12538: }
12539: if (@required) {
12540: $resulttext .= '<li>'.
12541: &mt('Help form fields changed to "Required": [_1].',
12542: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
12543: '</li>';
12544: }
12545: if (@unused) {
12546: $resulttext .= '<li>'.
12547: &mt('Help form fields changed to "Not shown": [_1].',
12548: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
12549: '</li>';
12550: }
12551: if ($maxsizechg) {
12552: $resulttext .= '<li>'.
12553: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
12554: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
12555: '</li>';
12556: }
12557: }
1.28 raeburn 12558: $resulttext .= '</ul>';
12559: } else {
1.160.6.78 raeburn 12560: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 12561: }
12562: } else {
12563: $resulttext = '<span class="LC_error">'.
12564: &mt('An error occurred: [_1].',$putresult).'</span>';
12565: }
12566: return $resulttext;
12567: }
12568:
1.160.6.98 raeburn 12569: sub modify_passwords {
12570: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
12571: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
12572: $updatedefaults,$updateconf);
12573: my $customfn = 'resetpw.html';
12574: if (ref($domconfig{'passwords'}) eq 'HASH') {
12575: %current = %{$domconfig{'passwords'}};
12576: }
12577: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12578: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12579: if (ref($types) eq 'ARRAY') {
12580: @oktypes = @{$types};
12581: }
12582: push(@oktypes,'default');
12583:
12584: my %titles = &Apache::lonlocal::texthash (
12585: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
12586: intauth_check => 'Check bcrypt cost if authenticated',
12587: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
12588: permanent => 'Permanent e-mail address',
12589: critical => 'Critical notification address',
12590: notify => 'Notification address',
12591: min => 'Minimum password length',
12592: max => 'Maximum password length',
12593: chars => 'Required characters',
12594: numsaved => 'Number of previous passwords to save',
12595: reset => 'Resetting Forgotten Password',
12596: intauth => 'Encryption of Stored Passwords (Internal Auth)',
12597: rules => 'Rules for LON-CAPA Passwords',
12598: crsownerchg => 'Course Owner Changing Student Passwords',
12599: username => 'Username',
12600: email => 'E-mail address',
12601: );
12602:
12603: #
12604: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
12605: #
12606: my (%curr_defaults,%save_defaults);
12607: if (ref($domconfig{'defaults'}) eq 'HASH') {
12608: foreach my $key (keys(%{$domconfig{'defaults'}})) {
12609: if ($key =~ /^intauth_(cost|check|switch)$/) {
12610: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
12611: } else {
12612: $save_defaults{$key} = $domconfig{'defaults'}{$key};
12613: }
12614: }
12615: }
12616: my %staticdefaults = (
12617: 'resetlink' => 2,
12618: 'resetcase' => \@oktypes,
12619: 'resetprelink' => 'both',
12620: 'resetemail' => ['critical','notify','permanent'],
12621: 'intauth_cost' => 10,
12622: 'intauth_check' => 0,
12623: 'intauth_switch' => 0,
12624: );
1.160.6.99 raeburn 12625: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 12626: foreach my $type (@oktypes) {
12627: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
12628: }
12629: my $linklife = $env{'form.passwords_link'};
12630: $linklife =~ s/^\s+|\s+$//g;
12631: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
12632: $newvalues{'resetlink'} = $linklife;
12633: if ($current{'resetlink'}) {
12634: if ($current{'resetlink'} ne $linklife) {
12635: $changes{'reset'} = 1;
12636: }
1.160.6.102 raeburn 12637: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12638: if ($staticdefaults{'resetlink'} ne $linklife) {
12639: $changes{'reset'} = 1;
12640: }
12641: }
12642: } elsif ($current{'resetlink'}) {
12643: $changes{'reset'} = 1;
12644: }
12645: my @casesens;
12646: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
12647: foreach my $case (sort(@posscase)) {
12648: if (grep(/^\Q$case\E$/,@oktypes)) {
12649: push(@casesens,$case);
12650: }
12651: }
12652: $newvalues{'resetcase'} = \@casesens;
12653: if (ref($current{'resetcase'}) eq 'ARRAY') {
12654: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
12655: if (@diffs > 0) {
12656: $changes{'reset'} = 1;
12657: }
1.160.6.102 raeburn 12658: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12659: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
12660: if (@diffs > 0) {
12661: $changes{'reset'} = 1;
12662: }
12663: }
12664: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
12665: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
12666: if (exists($current{'resetprelink'})) {
12667: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
12668: $changes{'reset'} = 1;
12669: }
1.160.6.102 raeburn 12670: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12671: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
12672: $changes{'reset'} = 1;
12673: }
12674: }
12675: } elsif ($current{'resetprelink'}) {
12676: $changes{'reset'} = 1;
12677: }
12678: foreach my $type (@oktypes) {
12679: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
12680: my @postlink;
12681: foreach my $item (sort(@possplink)) {
12682: if ($item =~ /^(email|username)$/) {
12683: push(@postlink,$item);
12684: }
12685: }
12686: $newvalues{'resetpostlink'}{$type} = \@postlink;
12687: unless ($changes{'reset'}) {
12688: if (ref($current{'resetpostlink'}) eq 'HASH') {
12689: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
12690: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
12691: if (@diffs > 0) {
12692: $changes{'reset'} = 1;
12693: }
12694: } else {
12695: $changes{'reset'} = 1;
12696: }
1.160.6.102 raeburn 12697: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12698: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
12699: if (@diffs > 0) {
12700: $changes{'reset'} = 1;
12701: }
12702: }
12703: }
12704: }
12705: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
12706: my @resetemail;
12707: foreach my $item (sort(@possemailsrc)) {
12708: if ($item =~ /^(permanent|critical|notify)$/) {
12709: push(@resetemail,$item);
12710: }
12711: }
12712: $newvalues{'resetemail'} = \@resetemail;
12713: unless ($changes{'reset'}) {
12714: if (ref($current{'resetemail'}) eq 'ARRAY') {
12715: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
12716: if (@diffs > 0) {
12717: $changes{'reset'} = 1;
12718: }
1.160.6.102 raeburn 12719: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12720: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
12721: if (@diffs > 0) {
12722: $changes{'reset'} = 1;
12723: }
12724: }
12725: }
12726: if ($env{'form.passwords_stdtext'} == 0) {
12727: $newvalues{'resetremove'} = 1;
12728: unless ($current{'resetremove'}) {
12729: $changes{'reset'} = 1;
12730: }
12731: } elsif ($current{'resetremove'}) {
12732: $changes{'reset'} = 1;
12733: }
12734: if ($env{'form.passwords_customfile.filename'} ne '') {
12735: my $servadm = $r->dir_config('lonAdmEMail');
12736: my $servadm = $r->dir_config('lonAdmEMail');
12737: my ($configuserok,$author_ok,$switchserver) =
12738: &config_check($dom,$confname,$servadm);
12739: my $error;
12740: if ($configuserok eq 'ok') {
12741: if ($switchserver) {
12742: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
12743: } else {
12744: if ($author_ok eq 'ok') {
12745: my ($result,$customurl) =
12746: &publishlogo($r,'upload','passwords_customfile',$dom,
12747: $confname,'customtext/resetpw','','',$customfn);
12748: if ($result eq 'ok') {
12749: $newvalues{'resetcustom'} = $customurl;
12750: $changes{'reset'} = 1;
12751: } else {
12752: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
12753: }
12754: } else {
12755: $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);
12756: }
12757: }
12758: } else {
12759: $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);
12760: }
12761: if ($error) {
12762: &Apache::lonnet::logthis($error);
12763: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12764: }
12765: } elsif ($current{'resetcustom'}) {
12766: if ($env{'form.passwords_custom_del'}) {
12767: $changes{'reset'} = 1;
12768: } else {
12769: $newvalues{'resetcustom'} = $current{'resetcustom'};
12770: }
12771: }
12772: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
12773: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
12774: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
12775: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
12776: $changes{'intauth'} = 1;
12777: }
12778: } else {
12779: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
12780: }
12781: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
12782: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
12783: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
12784: $changes{'intauth'} = 1;
12785: }
12786: } else {
12787: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
12788: }
12789: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
12790: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
12791: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
12792: $changes{'intauth'} = 1;
12793: }
12794: } else {
12795: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
12796: }
12797: foreach my $item ('cost','check','switch') {
12798: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
12799: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
12800: $updatedefaults = 1;
12801: }
12802: }
12803: foreach my $rule ('min','max','numsaved') {
12804: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.160.6.99 raeburn 12805: my $ruleok;
12806: if ($rule eq 'min') {
12807: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
12808: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
12809: $ruleok = 1;
12810: }
12811: }
12812: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
12813: ($env{'form.passwords_'.$rule} ne '0')) {
12814: $ruleok = 1;
12815: }
12816: if ($ruleok) {
1.160.6.98 raeburn 12817: $newvalues{$rule} = $env{'form.passwords_'.$rule};
12818: if (exists($current{$rule})) {
12819: if ($newvalues{$rule} ne $current{$rule}) {
12820: $changes{'rules'} = 1;
12821: }
12822: } elsif ($rule eq 'min') {
12823: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
12824: $changes{'rules'} = 1;
12825: }
1.160.6.104 raeburn 12826: } else {
12827: $changes{'rules'} = 1;
1.160.6.98 raeburn 12828: }
12829: } elsif (exists($current{$rule})) {
12830: $changes{'rules'} = 1;
12831: }
12832: }
12833: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
12834: my @chars;
12835: foreach my $item (sort(@posschars)) {
12836: if ($item =~ /^(uc|lc|num|spec)$/) {
12837: push(@chars,$item);
12838: }
12839: }
12840: $newvalues{'chars'} = \@chars;
12841: unless ($changes{'rules'}) {
12842: if (ref($current{'chars'}) eq 'ARRAY') {
12843: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
12844: if (@diffs > 0) {
12845: $changes{'rules'} = 1;
12846: }
12847: } else {
12848: if (@chars > 0) {
12849: $changes{'rules'} = 1;
12850: }
12851: }
12852: }
12853: my %crsownerchg = (
12854: by => [],
12855: for => [],
12856: );
12857: foreach my $item ('by','for') {
12858: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
12859: foreach my $type (sort(@posstypes)) {
12860: if (grep(/^\Q$type\E$/,@oktypes)) {
12861: push(@{$crsownerchg{$item}},$type);
12862: }
12863: }
12864: }
12865: $newvalues{'crsownerchg'} = \%crsownerchg;
12866: if (ref($current{'crsownerchg'}) eq 'HASH') {
12867: foreach my $item ('by','for') {
12868: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
12869: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
12870: if (@diffs > 0) {
12871: $changes{'crsownerchg'} = 1;
12872: last;
12873: }
12874: }
12875: }
1.160.6.102 raeburn 12876: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98 raeburn 12877: foreach my $item ('by','for') {
12878: if (@{$crsownerchg{$item}} > 0) {
12879: $changes{'crsownerchg'} = 1;
12880: last;
12881: }
12882: }
12883: }
12884:
12885: my %confighash = (
12886: defaults => \%save_defaults,
12887: passwords => \%newvalues,
12888: );
12889: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
12890:
12891: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
12892: if ($putresult eq 'ok') {
12893: if (keys(%changes) > 0) {
12894: $resulttext = &mt('Changes made: ').'<ul>';
12895: foreach my $key ('reset','intauth','rules','crsownerchg') {
12896: if ($changes{$key}) {
12897: unless ($key eq 'intauth') {
12898: $updateconf = 1;
12899: }
12900: $resulttext .= '<li>'.$titles{$key}.':<ul>';
12901: if ($key eq 'reset') {
12902: if ($confighash{'passwords'}{'captcha'} eq 'original') {
12903: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
12904: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
12905: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.160.6.104 raeburn 12906: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
12907: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
12908: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
12909: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
12910: }
1.160.6.98 raeburn 12911: } else {
12912: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
12913: }
12914: if ($confighash{'passwords'}{'resetlink'}) {
12915: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
12916: } else {
12917: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
12918: &mt('Will default to 2 hours').'</li>';
12919: }
12920: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
12921: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
12922: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
12923: } else {
12924: my $casesens;
12925: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
12926: if ($type eq 'default') {
12927: $casesens .= $othertitle.', ';
12928: } elsif ($usertypes->{$type} ne '') {
12929: $casesens .= $usertypes->{$type}.', ';
12930: }
12931: }
12932: $casesens =~ s/\Q, \E$//;
12933: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
12934: }
12935: } else {
12936: $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>';
12937: }
12938: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
12939: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
12940: } else {
12941: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
12942: }
12943: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
12944: my $output;
12945: if (ref($types) eq 'ARRAY') {
12946: foreach my $type (@{$types}) {
12947: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
12948: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
12949: $output .= $usertypes->{$type}.' -- '.&mt('none');
12950: } else {
12951: $output .= $usertypes->{$type}.' -- '.
12952: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
12953: }
12954: }
12955: }
12956: }
12957: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
12958: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
12959: $output .= $othertitle.' -- '.&mt('none');
12960: } else {
12961: $output .= $othertitle.' -- '.
12962: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
12963: }
12964: }
12965: if ($output) {
12966: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
12967: } else {
12968: $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>';
12969: }
12970: } else {
12971: $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>';
12972: }
12973: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
12974: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
12975: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
12976: } else {
12977: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
12978: }
12979: } else {
1.160.6.110 raeburn 12980: $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 12981: }
12982: if ($confighash{'passwords'}{'resetremove'}) {
12983: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
12984: } else {
12985: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
12986: }
12987: if ($confighash{'passwords'}{'resetcustom'}) {
12988: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.160.6.104 raeburn 12989: &mt('custom text'),600,500,undef,undef,
12990: undef,undef,'background-color:#ffffff');
12991: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.160.6.98 raeburn 12992: } else {
12993: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
12994: }
12995: } elsif ($key eq 'intauth') {
12996: foreach my $item ('cost','switch','check') {
12997: my $value = $save_defaults{$key.'_'.$item};
12998: if ($item eq 'switch') {
12999: my %optiondesc = &Apache::lonlocal::texthash (
13000: 0 => 'No',
13001: 1 => 'Yes',
13002: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
13003: );
13004: if ($value =~ /^(0|1|2)$/) {
13005: $value = $optiondesc{$value};
13006: } else {
13007: $value = &mt('none -- defaults to No');
13008: }
13009: } elsif ($item eq 'check') {
13010: my %optiondesc = &Apache::lonlocal::texthash (
13011: 0 => 'No',
13012: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
13013: 2 => 'Yes, disallow login if stored cost is less than domain default',
13014: );
13015: if ($value =~ /^(0|1|2)$/) {
13016: $value = $optiondesc{$value};
13017: } else {
13018: $value = &mt('none -- defaults to No');
13019: }
13020: }
13021: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
13022: }
13023: } elsif ($key eq 'rules') {
13024: foreach my $rule ('min','max','numsaved') {
13025: if ($confighash{'passwords'}{$rule} eq '') {
13026: if ($rule eq 'min') {
13027: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99 raeburn 13028: ' '.&mt('Default of [_1] will be used',
13029: $Apache::lonnet::passwdmin).'</li>';
1.160.6.98 raeburn 13030: } else {
13031: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
13032: }
13033: } else {
13034: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
13035: }
13036: }
1.160.6.104 raeburn 13037: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
13038: if (@{$confighash{'passwords'}{'chars'}} > 0) {
13039: my %rulenames = &Apache::lonlocal::texthash(
13040: uc => 'At least one upper case letter',
13041: lc => 'At least one lower case letter',
13042: num => 'At least one number',
13043: spec => 'At least one non-alphanumeric',
13044: );
13045: my $needed = '<ul><li>'.
13046: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
13047: '</li></ul>';
13048: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
13049: } else {
13050: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13051: }
13052: } else {
13053: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13054: }
1.160.6.98 raeburn 13055: } elsif ($key eq 'crsownerchg') {
13056: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
13057: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
13058: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
13059: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
13060: } else {
13061: my %crsownerstr;
13062: foreach my $item ('by','for') {
13063: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
13064: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
13065: if ($type eq 'default') {
13066: $crsownerstr{$item} .= $othertitle.', ';
13067: } elsif ($usertypes->{$type} ne '') {
13068: $crsownerstr{$item} .= $usertypes->{$type}.', ';
13069: }
13070: }
13071: $crsownerstr{$item} =~ s/\Q, \E$//;
13072: }
13073: }
13074: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
13075: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
13076: }
13077: } else {
13078: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
13079: }
13080: }
13081: $resulttext .= '</ul></li>';
13082: }
13083: }
13084: $resulttext .= '</ul>';
13085: } else {
13086: $resulttext = &mt('No changes made to password settings');
13087: }
13088: my $cachetime = 24*60*60;
13089: if ($updatedefaults) {
13090: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13091: if (ref($lastactref) eq 'HASH') {
13092: $lastactref->{'domdefaults'} = 1;
13093: }
13094: }
13095: if ($updateconf) {
13096: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
13097: if (ref($lastactref) eq 'HASH') {
13098: $lastactref->{'passwdconf'} = 1;
13099: }
13100: }
13101: } else {
13102: $resulttext = '<span class="LC_error">'.
13103: &mt('An error occurred: [_1]',$putresult).'</span>';
13104: }
13105: if ($errors) {
13106: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13107: $errors.'</ul></p>';
13108: }
13109: return $resulttext;
13110: }
13111:
1.28 raeburn 13112: sub modify_usercreation {
1.27 raeburn 13113: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 13114: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 13115: my $warningmsg;
1.27 raeburn 13116: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13117: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 13118: if ($key eq 'cancreate') {
13119: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13120: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 13121: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 13122: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 13123: } else {
13124: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 13125: }
1.50 raeburn 13126: }
1.43 raeburn 13127: }
1.160.6.34 raeburn 13128: } elsif ($key eq 'email_rule') {
13129: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13130: } else {
13131: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 13132: }
13133: }
1.34 raeburn 13134: }
1.160.6.34 raeburn 13135: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
13136: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
13137: my @contexts = ('author','course','requestcrs');
13138: foreach my $item(@contexts) {
13139: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 13140: }
1.34 raeburn 13141: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13142: foreach my $item (@contexts) {
1.160.6.34 raeburn 13143: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
13144: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 13145: }
1.27 raeburn 13146: }
1.34 raeburn 13147: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
13148: foreach my $item (@contexts) {
1.43 raeburn 13149: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 13150: if ($cancreate{$item} ne 'any') {
13151: push(@{$changes{'cancreate'}},$item);
13152: }
13153: } else {
13154: if ($cancreate{$item} ne 'none') {
13155: push(@{$changes{'cancreate'}},$item);
13156: }
1.27 raeburn 13157: }
13158: }
13159: } else {
1.43 raeburn 13160: foreach my $item (@contexts) {
1.34 raeburn 13161: push(@{$changes{'cancreate'}},$item);
13162: }
1.27 raeburn 13163: }
1.34 raeburn 13164:
1.27 raeburn 13165: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
13166: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
13167: if (!grep(/^\Q$type\E$/,@username_rule)) {
13168: push(@{$changes{'username_rule'}},$type);
13169: }
13170: }
13171: foreach my $type (@username_rule) {
13172: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
13173: push(@{$changes{'username_rule'}},$type);
13174: }
13175: }
13176: } else {
13177: push(@{$changes{'username_rule'}},@username_rule);
13178: }
13179:
1.32 raeburn 13180: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
13181: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
13182: if (!grep(/^\Q$type\E$/,@id_rule)) {
13183: push(@{$changes{'id_rule'}},$type);
13184: }
13185: }
13186: foreach my $type (@id_rule) {
13187: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
13188: push(@{$changes{'id_rule'}},$type);
13189: }
13190: }
13191: } else {
13192: push(@{$changes{'id_rule'}},@id_rule);
13193: }
13194:
1.43 raeburn 13195: my @authen_contexts = ('author','course','domain');
1.28 raeburn 13196: my @authtypes = ('int','krb4','krb5','loc');
13197: my %authhash;
1.43 raeburn 13198: foreach my $item (@authen_contexts) {
1.28 raeburn 13199: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
13200: foreach my $auth (@authtypes) {
13201: if (grep(/^\Q$auth\E$/,@authallowed)) {
13202: $authhash{$item}{$auth} = 1;
13203: } else {
13204: $authhash{$item}{$auth} = 0;
13205: }
13206: }
13207: }
13208: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 13209: foreach my $item (@authen_contexts) {
1.28 raeburn 13210: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
13211: foreach my $auth (@authtypes) {
13212: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
13213: push(@{$changes{'authtypes'}},$item);
13214: last;
13215: }
13216: }
13217: }
13218: }
13219: } else {
1.43 raeburn 13220: foreach my $item (@authen_contexts) {
1.28 raeburn 13221: push(@{$changes{'authtypes'}},$item);
13222: }
13223: }
13224:
1.160.6.34 raeburn 13225: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
13226: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
13227: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
13228: $save_usercreate{'id_rule'} = \@id_rule;
13229: $save_usercreate{'username_rule'} = \@username_rule,
13230: $save_usercreate{'authtypes'} = \%authhash;
13231:
1.27 raeburn 13232: my %usercreation_hash = (
1.160.6.34 raeburn 13233: usercreation => \%save_usercreate,
13234: );
1.27 raeburn 13235:
13236: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
13237: $dom);
1.50 raeburn 13238:
1.160.6.34 raeburn 13239: if ($putresult eq 'ok') {
13240: if (keys(%changes) > 0) {
13241: $resulttext = &mt('Changes made:').'<ul>';
13242: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13243: my %lt = &usercreation_types();
13244: foreach my $type (@{$changes{'cancreate'}}) {
13245: my $chgtext = $lt{$type}.', ';
13246: if ($cancreate{$type} eq 'none') {
13247: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
13248: } elsif ($cancreate{$type} eq 'any') {
13249: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
13250: } elsif ($cancreate{$type} eq 'official') {
13251: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
13252: } elsif ($cancreate{$type} eq 'unofficial') {
13253: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
13254: }
13255: $resulttext .= '<li>'.$chgtext.'</li>';
13256: }
13257: }
13258: if (ref($changes{'username_rule'}) eq 'ARRAY') {
13259: my ($rules,$ruleorder) =
13260: &Apache::lonnet::inst_userrules($dom,'username');
13261: my $chgtext = '<ul>';
13262: foreach my $type (@username_rule) {
13263: if (ref($rules->{$type}) eq 'HASH') {
13264: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
13265: }
13266: }
13267: $chgtext .= '</ul>';
13268: if (@username_rule > 0) {
13269: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13270: } else {
13271: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
13272: }
13273: }
13274: if (ref($changes{'id_rule'}) eq 'ARRAY') {
13275: my ($idrules,$idruleorder) =
13276: &Apache::lonnet::inst_userrules($dom,'id');
13277: my $chgtext = '<ul>';
13278: foreach my $type (@id_rule) {
13279: if (ref($idrules->{$type}) eq 'HASH') {
13280: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
13281: }
13282: }
13283: $chgtext .= '</ul>';
13284: if (@id_rule > 0) {
13285: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13286: } else {
13287: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
13288: }
13289: }
13290: my %authname = &authtype_names();
13291: my %context_title = &context_names();
13292: if (ref($changes{'authtypes'}) eq 'ARRAY') {
13293: my $chgtext = '<ul>';
13294: foreach my $type (@{$changes{'authtypes'}}) {
13295: my @allowed;
13296: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
13297: foreach my $auth (@authtypes) {
13298: if ($authhash{$type}{$auth}) {
13299: push(@allowed,$authname{$auth});
13300: }
13301: }
13302: if (@allowed > 0) {
13303: $chgtext .= join(', ',@allowed).'</li>';
13304: } else {
13305: $chgtext .= &mt('none').'</li>';
13306: }
13307: }
13308: $chgtext .= '</ul>';
13309: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
13310: $resulttext .= '</li>';
13311: }
13312: $resulttext .= '</ul>';
13313: } else {
13314: $resulttext = &mt('No changes made to user creation settings');
13315: }
13316: } else {
13317: $resulttext = '<span class="LC_error">'.
13318: &mt('An error occurred: [_1]',$putresult).'</span>';
13319: }
13320: if ($warningmsg ne '') {
13321: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13322: }
13323: return $resulttext;
13324: }
13325:
13326: sub modify_selfcreation {
1.160.6.93 raeburn 13327: my ($dom,$lastactref,%domconfig) = @_;
13328: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
13329: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
13330: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13331: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
13332: if (ref($typesref) eq 'ARRAY') {
13333: @types = @{$typesref};
13334: }
13335: if (ref($usertypesref) eq 'HASH') {
13336: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 13337: }
1.160.6.93 raeburn 13338: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 13339: #
13340: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
13341: #
13342: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13343: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
13344: if ($key eq 'cancreate') {
13345: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13346: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
13347: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 13348: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
13349: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
13350: ($item eq 'emailusername') || ($item eq 'shibenv') ||
13351: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
13352: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 13353: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13354: } else {
13355: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13356: }
13357: }
13358: }
13359: } elsif ($key eq 'email_rule') {
13360: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13361: } else {
13362: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13363: }
13364: }
13365: }
13366: #
13367: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
13368: #
13369: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13370: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
13371: if ($key eq 'selfcreate') {
13372: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
13373: } else {
13374: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
13375: }
13376: }
13377: }
1.160.6.93 raeburn 13378: #
13379: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
13380: #
13381: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13382: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
13383: if ($key eq 'inststatusguest') {
13384: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
13385: } else {
13386: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
13387: }
13388: }
13389: }
1.160.6.34 raeburn 13390:
13391: my @contexts = ('selfcreate');
13392: @{$cancreate{'selfcreate'}} = ();
13393: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 13394: if (@types) {
13395: @{$cancreate{'statustocreate'}} = ();
13396: }
1.160.6.40 raeburn 13397: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 13398: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 13399: %{$cancreate{'emailverified'}} = ();
13400: %{$cancreate{'emailoptions'}} = ();
13401: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 13402: my %selfcreatetypes = (
13403: sso => 'users authenticated by institutional single sign on',
13404: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 13405: email => 'users verified by e-mail',
1.50 raeburn 13406: );
1.160.6.34 raeburn 13407: #
13408: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
13409: # is permitted.
13410: #
1.160.6.40 raeburn 13411:
1.160.6.93 raeburn 13412: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 13413:
1.160.6.93 raeburn 13414: my (@statuses,%email_rule);
1.160.6.35 raeburn 13415: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 13416: if ($item eq 'email') {
1.160.6.40 raeburn 13417: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 13418: if (@types) {
13419: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
13420: foreach my $status (@poss_statuses) {
13421: if (grep(/^\Q$status\E$/,(@types,'default'))) {
13422: push(@statuses,$status);
13423: }
13424: }
13425: $save_inststatus{'inststatusguest'} = \@statuses;
13426: } else {
13427: push(@statuses,'default');
13428: }
13429: if (@statuses) {
13430: my %curr_rule;
13431: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
13432: foreach my $type (@statuses) {
13433: $curr_rule{$type} = $curr_usercreation{'email_rule'};
13434: }
13435: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
13436: foreach my $type (@statuses) {
13437: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
13438: }
13439: }
13440: push(@{$cancreate{'selfcreate'}},'email');
13441: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
13442: my %curremaildom;
13443: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
13444: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
13445: }
13446: foreach my $type (@statuses) {
13447: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
13448: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
13449: }
13450: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
13451: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
13452: }
13453: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
13454: #
13455: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
13456: #
13457: my $chosen = $1;
13458: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
13459: my $emaildom;
13460: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
13461: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
13462: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
13463: if (ref($curremaildom{$type}) eq 'HASH') {
13464: if (exists($curremaildom{$type}{$chosen})) {
13465: if ($curremaildom{$type}{$chosen} ne $emaildom) {
13466: push(@{$changes{'cancreate'}},'emaildomain');
13467: }
13468: } elsif ($emaildom ne '') {
13469: push(@{$changes{'cancreate'}},'emaildomain');
13470: }
13471: } elsif ($emaildom ne '') {
13472: push(@{$changes{'cancreate'}},'emaildomain');
13473: }
13474: }
13475: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13476: } elsif ($chosen eq 'custom') {
13477: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
13478: $email_rule{$type} = [];
13479: if (ref($emailrules) eq 'HASH') {
13480: foreach my $rule (@possemail_rules) {
13481: if (exists($emailrules->{$rule})) {
13482: push(@{$email_rule{$type}},$rule);
13483: }
13484: }
13485: }
13486: if (@{$email_rule{$type}}) {
13487: $cancreate{'emailoptions'}{$type} = 'custom';
13488: if (ref($curr_rule{$type}) eq 'ARRAY') {
13489: if (@{$curr_rule{$type}} > 0) {
13490: foreach my $rule (@{$curr_rule{$type}}) {
13491: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
13492: push(@{$changes{'email_rule'}},$type);
13493: }
13494: }
13495: }
13496: foreach my $type (@{$email_rule{$type}}) {
13497: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
13498: push(@{$changes{'email_rule'}},$type);
13499: }
13500: }
13501: } else {
13502: push(@{$changes{'email_rule'}},$type);
13503: }
13504: }
13505: } else {
13506: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13507: }
13508: }
13509: }
13510: if (@types) {
13511: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13512: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
13513: if (@changed) {
13514: push(@{$changes{'inststatus'}},'inststatusguest');
13515: }
13516: } else {
13517: push(@{$changes{'inststatus'}},'inststatusguest');
13518: }
13519: }
13520: } else {
13521: delete($env{'form.cancreate_email'});
13522: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13523: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13524: push(@{$changes{'inststatus'}},'inststatusguest');
13525: }
13526: }
13527: }
13528: } else {
13529: $save_inststatus{'inststatusguest'} = [];
13530: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13531: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13532: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 13533: }
13534: }
1.160.6.34 raeburn 13535: }
13536: } else {
13537: if ($env{'form.cancreate_'.$item}) {
13538: push(@{$cancreate{'selfcreate'}},$item);
13539: }
13540: }
13541: }
1.160.6.93 raeburn 13542: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 13543: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
13544: #
1.160.6.35 raeburn 13545: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
13546: # 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 13547: #
1.160.6.40 raeburn 13548:
1.160.6.48 raeburn 13549: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 13550: push(@contexts,'emailusername');
1.160.6.93 raeburn 13551: if (@statuses) {
13552: foreach my $type (@statuses) {
1.160.6.35 raeburn 13553: if (ref($infofields) eq 'ARRAY') {
13554: foreach my $field (@{$infofields}) {
13555: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
13556: $cancreate{'emailusername'}{$type}{$field} = $1;
13557: }
13558: }
1.160.6.34 raeburn 13559: }
13560: }
13561: }
13562: #
13563: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 13564: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 13565: #
13566:
13567: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
13568: @approvalnotify = sort(@approvalnotify);
13569: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
13570: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13571: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
13572: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
13573: push(@{$changes{'cancreate'}},'notify');
13574: }
13575: } else {
13576: if ($cancreate{'notify'}{'approval'}) {
13577: push(@{$changes{'cancreate'}},'notify');
13578: }
13579: }
13580: } elsif ($cancreate{'notify'}{'approval'}) {
13581: push(@{$changes{'cancreate'}},'notify');
13582: }
13583:
13584: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
13585: }
13586: #
1.160.6.40 raeburn 13587: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 13588: # institutional log-in.
13589: #
13590: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
13591: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
13592: ($domdefaults{'auth_def'} eq 'localauth'))) {
13593: $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.').' '.
13594: &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.');
13595: }
13596: }
13597: my @fields = ('lastname','firstname','middlename','generation',
13598: 'permanentemail','id');
1.160.6.44 raeburn 13599: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 13600: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13601: #
13602: # Where usernames may created for institutional log-in and/or institutional single sign on:
13603: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
13604: # may self-create accounts
13605: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
13606: # which the user may supply, if institutional data is unavailable.
13607: #
13608: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 13609: if (@types) {
13610: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
13611: push(@contexts,'statustocreate');
13612: foreach my $type (@types) {
1.160.6.34 raeburn 13613: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
13614: foreach my $field (@fields) {
13615: if (grep(/^\Q$field\E$/,@modifiable)) {
13616: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
13617: } else {
13618: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
13619: }
13620: }
13621: }
13622: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 13623: foreach my $type (@types) {
1.160.6.34 raeburn 13624: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
13625: foreach my $field (@fields) {
13626: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
13627: $curr_usermodify{'selfcreate'}{$type}{$field}) {
13628: push(@{$changes{'selfcreate'}},$type);
13629: last;
13630: }
13631: }
13632: }
13633: }
13634: } else {
1.160.6.93 raeburn 13635: foreach my $type (@types) {
1.160.6.34 raeburn 13636: push(@{$changes{'selfcreate'}},$type);
13637: }
13638: }
13639: }
1.160.6.44 raeburn 13640: foreach my $field (@shibfields) {
13641: if ($env{'form.shibenv_'.$field} ne '') {
13642: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
13643: }
13644: }
13645: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13646: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
13647: foreach my $field (@shibfields) {
13648: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
13649: push(@{$changes{'cancreate'}},'shibenv');
13650: }
13651: }
13652: } else {
13653: foreach my $field (@shibfields) {
13654: if ($env{'form.shibenv_'.$field}) {
13655: push(@{$changes{'cancreate'}},'shibenv');
13656: last;
13657: }
13658: }
13659: }
13660: }
1.160.6.34 raeburn 13661: }
13662: foreach my $item (@contexts) {
13663: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
13664: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
13665: if (ref($cancreate{$item}) eq 'ARRAY') {
13666: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
13667: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13668: push(@{$changes{'cancreate'}},$item);
13669: }
13670: }
13671: }
13672: }
13673: if (ref($cancreate{$item}) eq 'ARRAY') {
13674: foreach my $type (@{$cancreate{$item}}) {
13675: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
13676: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13677: push(@{$changes{'cancreate'}},$item);
13678: }
13679: }
13680: }
13681: }
13682: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
13683: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 13684: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
13685: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13686: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
13687: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 13688: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13689: push(@{$changes{'cancreate'}},$item);
13690: }
13691: }
13692: }
1.160.6.93 raeburn 13693: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13694: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 13695: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13696: push(@{$changes{'cancreate'}},$item);
13697: }
1.160.6.34 raeburn 13698: }
13699: }
13700: }
1.160.6.93 raeburn 13701: foreach my $type (keys(%{$cancreate{$item}})) {
13702: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13703: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13704: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13705: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 13706: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13707: push(@{$changes{'cancreate'}},$item);
13708: }
13709: }
13710: } else {
13711: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13712: push(@{$changes{'cancreate'}},$item);
13713: }
13714: }
13715: }
1.160.6.93 raeburn 13716: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13717: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 13718: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13719: push(@{$changes{'cancreate'}},$item);
13720: }
1.160.6.34 raeburn 13721: }
13722: }
13723: }
13724: }
13725: } elsif ($curr_usercreation{'cancreate'}{$item}) {
13726: if (ref($cancreate{$item}) eq 'ARRAY') {
13727: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
13728: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13729: push(@{$changes{'cancreate'}},$item);
13730: }
13731: }
1.160.6.93 raeburn 13732: }
13733: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13734: if (ref($cancreate{$item}) eq 'HASH') {
13735: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13736: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 13737: }
13738: }
13739: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 13740: if (ref($cancreate{$item}) eq 'HASH') {
13741: foreach my $type (keys(%{$cancreate{$item}})) {
13742: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13743: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13744: if ($cancreate{$item}{$type}{$field}) {
13745: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13746: push(@{$changes{'cancreate'}},$item);
13747: }
13748: last;
13749: }
13750: }
13751: }
13752: }
1.160.6.34 raeburn 13753: }
13754: }
13755: }
13756: #
13757: # Populate %save_usercreate hash with updates to self-creation configuration.
13758: #
13759: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
13760: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 13761: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 13762: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
13763: if (ref($cancreate{'notify'}) eq 'HASH') {
13764: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
13765: }
1.160.6.40 raeburn 13766: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
13767: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
13768: }
1.160.6.93 raeburn 13769: if (ref($cancreate{'emailverified'}) eq 'HASH') {
13770: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
13771: }
13772: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
13773: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
13774: }
13775: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
13776: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
13777: }
1.160.6.34 raeburn 13778: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13779: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
13780: }
1.160.6.44 raeburn 13781: if (ref($cancreate{'shibenv'}) eq 'HASH') {
13782: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
13783: }
1.160.6.34 raeburn 13784: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 13785: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 13786:
13787: my %userconfig_hash = (
13788: usercreation => \%save_usercreate,
13789: usermodification => \%save_usermodify,
1.160.6.93 raeburn 13790: inststatus => \%save_inststatus,
1.160.6.34 raeburn 13791: );
1.160.6.93 raeburn 13792:
1.160.6.34 raeburn 13793: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
13794: $dom);
13795: #
1.160.6.93 raeburn 13796: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 13797: #
1.27 raeburn 13798: if ($putresult eq 'ok') {
13799: if (keys(%changes) > 0) {
13800: $resulttext = &mt('Changes made:').'<ul>';
13801: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 13802: my %lt = &selfcreation_types();
1.34 raeburn 13803: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 13804: my $chgtext = '';
1.45 raeburn 13805: if ($type eq 'selfcreate') {
1.50 raeburn 13806: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 13807: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 13808: } else {
1.160.6.34 raeburn 13809: $chgtext .= &mt('Self-creation of a new account is permitted for:').
13810: '<ul>';
1.50 raeburn 13811: foreach my $case (@{$cancreate{$type}}) {
13812: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
13813: }
13814: $chgtext .= '</ul>';
1.100 raeburn 13815: if (ref($cancreate{$type}) eq 'ARRAY') {
13816: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
13817: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13818: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 13819: $chgtext .= '<span class="LC_warning">'.
13820: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
13821: '</span><br />';
1.100 raeburn 13822: }
13823: }
13824: }
1.160.6.93 raeburn 13825: if (grep(/^email$/,@{$cancreate{$type}})) {
13826: if (!@statuses) {
13827: $chgtext .= '<span class="LC_warning">'.
13828: &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.").
13829: '</span><br />';
13830:
13831: }
13832: }
1.100 raeburn 13833: }
1.43 raeburn 13834: }
1.160.6.44 raeburn 13835: } elsif ($type eq 'shibenv') {
13836: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 13837: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 13838: } else {
13839: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
13840: '<ul>';
13841: foreach my $field (@shibfields) {
13842: next if ($cancreate{$type}{$field} eq '');
13843: if ($field eq 'inststatus') {
13844: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
13845: } else {
13846: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
13847: }
13848: }
13849: $chgtext .= '</ul>';
1.160.6.93 raeburn 13850: }
1.93 raeburn 13851: } elsif ($type eq 'statustocreate') {
1.96 raeburn 13852: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
13853: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
13854: if (@{$cancreate{'selfcreate'}} > 0) {
13855: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 13856: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 13857: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 13858: $chgtext .= '<br />'.
13859: '<span class="LC_warning">'.
13860: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
13861: '</span>';
13862: }
1.160.6.93 raeburn 13863: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 13864: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 13865: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
13866: } else {
13867: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
13868: }
13869: $chgtext .= '<ul>';
13870: foreach my $case (@{$cancreate{$type}}) {
13871: if ($case eq 'default') {
13872: $chgtext .= '<li>'.$othertitle.'</li>';
13873: } else {
1.160.6.93 raeburn 13874: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 13875: }
13876: }
1.100 raeburn 13877: $chgtext .= '</ul>';
13878: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 13879: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 13880: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
13881: '</span>';
1.100 raeburn 13882: }
13883: }
13884: } else {
13885: if (@{$cancreate{$type}} == 0) {
13886: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
13887: } else {
13888: $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 13889: }
13890: }
1.160.6.93 raeburn 13891: $chgtext .= '<br />';
1.93 raeburn 13892: }
1.160.6.40 raeburn 13893: } elsif ($type eq 'selfcreateprocessing') {
13894: my %choices = &Apache::lonlocal::texthash (
13895: automatic => 'Automatic approval',
13896: approval => 'Queued for approval',
13897: );
1.160.6.93 raeburn 13898: if (@types) {
13899: if (@statuses) {
13900: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
13901: '<ul>';
13902: foreach my $status (@statuses) {
13903: if ($status eq 'default') {
13904: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
13905: } else {
13906: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
13907: }
13908: }
13909: $chgtext .= '</ul>';
13910: }
13911: } else {
13912: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
13913: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
13914: }
13915: } elsif ($type eq 'emailverified') {
13916: my %options = &Apache::lonlocal::texthash (
13917: all => 'Same as e-mail',
13918: first => 'Omit @domain',
13919: free => 'Free to choose',
13920: );
13921: if (@types) {
13922: if (@statuses) {
13923: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
13924: '<ul>';
13925: foreach my $status (@statuses) {
13926: if ($status eq 'default') {
13927: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
13928: } else {
13929: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
13930: }
13931: }
13932: $chgtext .= '</ul>';
13933: }
1.160.6.40 raeburn 13934: } else {
1.160.6.93 raeburn 13935: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
13936: $options{$cancreate{'emailverified'}{'default'}});
13937: }
13938: } elsif ($type eq 'emailoptions') {
13939: my %options = &Apache::lonlocal::texthash (
13940: any => 'Any e-mail',
13941: inst => 'Institutional only',
13942: noninst => 'Non-institutional only',
13943: custom => 'Custom restrictions',
13944: );
13945: if (@types) {
13946: if (@statuses) {
13947: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
13948: '<ul>';
13949: foreach my $status (@statuses) {
13950: if ($type eq 'default') {
13951: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13952: } else {
13953: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13954: }
13955: }
13956: $chgtext .= '</ul>';
13957: }
13958: } else {
13959: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
13960: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
13961: } else {
13962: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
13963: $options{$cancreate{'emailoptions'}{'default'}});
13964: }
13965: }
13966: } elsif ($type eq 'emaildomain') {
13967: my $output;
13968: if (@statuses) {
13969: foreach my $type (@statuses) {
13970: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
13971: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
13972: if ($type eq 'default') {
13973: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13974: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13975: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13976: } else {
13977: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
13978: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13979: }
13980: } else {
13981: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13982: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13983: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13984: } else {
13985: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
13986: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13987: }
13988: }
13989: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
13990: if ($type eq 'default') {
13991: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13992: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13993: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13994: } else {
13995: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
13996: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13997: }
13998: } else {
13999: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14000: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
14001: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
14002: } else {
14003: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
14004: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
14005: }
14006: }
14007: }
14008: }
14009: }
14010: }
14011: if ($output ne '') {
14012: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
14013: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 14014: }
1.160.6.5 raeburn 14015: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 14016: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 14017: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
14018: } else {
14019: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 14020: if ($captchas{$savecaptcha{$type}}) {
14021: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 14022: } else {
14023: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
14024: }
14025: }
14026: } elsif ($type eq 'recaptchakeys') {
14027: my ($privkey,$pubkey);
1.160.6.34 raeburn 14028: if (ref($savecaptcha{$type}) eq 'HASH') {
14029: $pubkey = $savecaptcha{$type}{'public'};
14030: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 14031: }
14032: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
14033: if (!$pubkey) {
14034: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
14035: } else {
14036: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
14037: }
14038: if (!$privkey) {
14039: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
14040: } else {
14041: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
14042: }
14043: $chgtext .= '</ul>';
1.160.6.69 raeburn 14044: } elsif ($type eq 'recaptchaversion') {
14045: if ($savecaptcha{'captcha'} eq 'recaptcha') {
14046: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
14047: }
1.160.6.34 raeburn 14048: } elsif ($type eq 'emailusername') {
14049: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 14050: if (@statuses) {
14051: foreach my $type (@statuses) {
1.160.6.35 raeburn 14052: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
14053: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 14054: $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 14055: '<ul>';
14056: foreach my $field (@{$infofields}) {
14057: if ($cancreate{'emailusername'}{$type}{$field}) {
14058: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
14059: }
14060: }
1.160.6.50 raeburn 14061: $chgtext .= '</ul>';
14062: } else {
1.160.6.93 raeburn 14063: $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 14064: }
14065: } else {
1.160.6.93 raeburn 14066: $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 14067: }
14068: }
14069: }
14070: }
14071: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 14072: my $numapprove = 0;
1.160.6.34 raeburn 14073: if (ref($changes{'cancreate'}) eq 'ARRAY') {
14074: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
14075: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 14076: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
14077: $numapprove ++;
1.160.6.34 raeburn 14078: }
14079: }
1.43 raeburn 14080: }
1.160.6.93 raeburn 14081: unless ($numapprove) {
14082: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
14083: }
1.34 raeburn 14084: }
1.160.6.34 raeburn 14085: if ($chgtext) {
14086: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 14087: }
14088: }
14089: }
1.160.6.93 raeburn 14090: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 14091: my ($emailrules,$emailruleorder) =
14092: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 14093: foreach my $type (@{$changes{'email_rule'}}) {
14094: if (ref($email_rule{$type}) eq 'ARRAY') {
14095: my $chgtext = '<ul>';
14096: foreach my $rule (@{$email_rule{$type}}) {
14097: if (ref($emailrules->{$rule}) eq 'HASH') {
14098: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
14099: }
14100: }
14101: $chgtext .= '</ul>';
14102: my $typename;
14103: if (@types) {
14104: if ($type eq 'default') {
14105: $typename = $othertitle;
14106: } else {
14107: $typename = $usertypes{$type};
14108: }
14109: $chgtext .= &mt('(Affiliation: [_1])',$typename);
14110: }
14111: if (@{$email_rule{$type}} > 0) {
14112: $resulttext .= '<li>'.
14113: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
14114: $usertypes{$type}).
14115: $chgtext.
14116: '</li>';
14117: } else {
14118: $resulttext .= '<li>'.
14119: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
14120: '</li>'.
14121: &mt('(Affiliation: [_1])',$typename);
14122: }
1.43 raeburn 14123: }
14124: }
1.160.6.93 raeburn 14125: }
14126: if (ref($changes{'inststatus'}) eq 'ARRAY') {
14127: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
14128: if (@{$save_inststatus{'inststatusguest'}} > 0) {
14129: my $chgtext = '<ul>';
14130: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
14131: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
14132: }
14133: $chgtext .= '</ul>';
14134: $resulttext .= '<li>'.
14135: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
14136: $chgtext.
14137: '</li>';
14138: } else {
14139: $resulttext .= '<li>'.
14140: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
14141: '</li>';
14142: }
1.43 raeburn 14143: }
14144: }
1.160.6.34 raeburn 14145: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
14146: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
14147: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14148: foreach my $type (@{$changes{'selfcreate'}}) {
14149: my $typename = $type;
1.160.6.93 raeburn 14150: if (keys(%usertypes) > 0) {
14151: if ($usertypes{$type} ne '') {
14152: $typename = $usertypes{$type};
1.28 raeburn 14153: }
14154: }
1.160.6.34 raeburn 14155: my @modifiable;
14156: $resulttext .= '<li>'.
14157: &mt('Self-creation of account by users with status: [_1]',
14158: '<span class="LC_cusr_emph">'.$typename.'</span>').
14159: ' - '.&mt('modifiable fields (if institutional data blank): ');
14160: foreach my $field (@fields) {
14161: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
14162: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
14163: }
14164: }
14165: if (@modifiable > 0) {
14166: $resulttext .= join(', ',@modifiable);
1.43 raeburn 14167: } else {
1.160.6.34 raeburn 14168: $resulttext .= &mt('none');
1.43 raeburn 14169: }
1.160.6.34 raeburn 14170: $resulttext .= '</li>';
1.28 raeburn 14171: }
1.160.6.34 raeburn 14172: $resulttext .= '</ul></li>';
1.28 raeburn 14173: }
1.27 raeburn 14174: $resulttext .= '</ul>';
1.160.6.93 raeburn 14175: my $cachetime = 24*60*60;
14176: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
14177: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14178: if (ref($lastactref) eq 'HASH') {
14179: $lastactref->{'domdefaults'} = 1;
14180: }
1.27 raeburn 14181: } else {
1.160.6.34 raeburn 14182: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 14183: }
14184: } else {
14185: $resulttext = '<span class="LC_error">'.
1.23 raeburn 14186: &mt('An error occurred: [_1]',$putresult).'</span>';
14187: }
1.43 raeburn 14188: if ($warningmsg ne '') {
14189: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
14190: }
1.23 raeburn 14191: return $resulttext;
14192: }
14193:
1.160.6.5 raeburn 14194: sub process_captcha {
1.160.6.104 raeburn 14195: my ($container,$changes,$newsettings,$currsettings) = @_;
14196: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.160.6.5 raeburn 14197: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
14198: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
14199: $newsettings->{'captcha'} = 'original';
14200: }
1.160.6.104 raeburn 14201: my %current;
14202: if (ref($currsettings) eq 'HASH') {
14203: %current = %{$currsettings};
14204: }
14205: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.160.6.5 raeburn 14206: if ($container eq 'cancreate') {
14207: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14208: push(@{$changes->{'cancreate'}},'captcha');
14209: } elsif (!defined($changes->{'cancreate'})) {
14210: $changes->{'cancreate'} = ['captcha'];
14211: }
1.160.6.102 raeburn 14212: } elsif ($container eq 'passwords') {
14213: $changes->{'reset'} = 1;
1.160.6.5 raeburn 14214: } else {
14215: $changes->{'captcha'} = 1;
14216: }
14217: }
1.160.6.69 raeburn 14218: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 14219: if ($newsettings->{'captcha'} eq 'recaptcha') {
14220: $newpub = $env{'form.'.$container.'_recaptchapub'};
14221: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 14222: $newpub =~ s/[^\w\-]//g;
14223: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 14224: $newsettings->{'recaptchakeys'} = {
14225: public => $newpub,
14226: private => $newpriv,
14227: };
1.160.6.69 raeburn 14228: $newversion = $env{'form.'.$container.'_recaptchaversion'};
14229: $newversion =~ s/\D//g;
14230: if ($newversion ne '2') {
14231: $newversion = 1;
14232: }
14233: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 14234: }
1.160.6.104 raeburn 14235: if (ref($current{'recaptchakeys'}) eq 'HASH') {
14236: $currpub = $current{'recaptchakeys'}{'public'};
14237: $currpriv = $current{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 14238: unless ($newsettings->{'captcha'} eq 'recaptcha') {
14239: $newsettings->{'recaptchakeys'} = {
14240: public => '',
14241: private => '',
14242: }
14243: }
1.160.6.5 raeburn 14244: }
1.160.6.104 raeburn 14245: if ($current{'captcha'} eq 'recaptcha') {
14246: $currversion = $current{'recaptchaversion'};
1.160.6.69 raeburn 14247: if ($currversion ne '2') {
14248: $currversion = 1;
14249: }
14250: }
14251: if ($currversion ne $newversion) {
14252: if ($container eq 'cancreate') {
14253: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14254: push(@{$changes->{'cancreate'}},'recaptchaversion');
14255: } elsif (!defined($changes->{'cancreate'})) {
14256: $changes->{'cancreate'} = ['recaptchaversion'];
14257: }
1.160.6.102 raeburn 14258: } elsif ($container eq 'passwords') {
14259: $changes->{'reset'} = 1;
1.160.6.69 raeburn 14260: } else {
14261: $changes->{'recaptchaversion'} = 1;
14262: }
14263: }
1.160.6.5 raeburn 14264: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
14265: if ($container eq 'cancreate') {
14266: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14267: push(@{$changes->{'cancreate'}},'recaptchakeys');
14268: } elsif (!defined($changes->{'cancreate'})) {
14269: $changes->{'cancreate'} = ['recaptchakeys'];
14270: }
1.160.6.102 raeburn 14271: } elsif ($container eq 'passwords') {
14272: $changes->{'reset'} = 1;
1.160.6.5 raeburn 14273: } else {
14274: $changes->{'recaptchakeys'} = 1;
14275: }
14276: }
14277: return;
14278: }
14279:
1.33 raeburn 14280: sub modify_usermodification {
14281: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 14282: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 14283: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14284: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 14285: if ($key eq 'selfcreate') {
14286: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
14287: } else {
14288: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
14289: }
1.33 raeburn 14290: }
14291: }
1.160.6.34 raeburn 14292: my @contexts = ('author','course');
1.33 raeburn 14293: my %context_title = (
14294: author => 'In author context',
14295: course => 'In course context',
14296: );
14297: my @fields = ('lastname','firstname','middlename','generation',
14298: 'permanentemail','id');
14299: my %roles = (
14300: author => ['ca','aa'],
14301: course => ['st','ep','ta','in','cr'],
14302: );
14303: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14304: foreach my $context (@contexts) {
14305: foreach my $role (@{$roles{$context}}) {
14306: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
14307: foreach my $item (@fields) {
14308: if (grep(/^\Q$item\E$/,@modifiable)) {
14309: $modifyhash{$context}{$role}{$item} = 1;
14310: } else {
14311: $modifyhash{$context}{$role}{$item} = 0;
14312: }
14313: }
14314: }
14315: if (ref($curr_usermodification{$context}) eq 'HASH') {
14316: foreach my $role (@{$roles{$context}}) {
14317: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
14318: foreach my $field (@fields) {
14319: if ($modifyhash{$context}{$role}{$field} ne
14320: $curr_usermodification{$context}{$role}{$field}) {
14321: push(@{$changes{$context}},$role);
14322: last;
14323: }
14324: }
14325: }
14326: }
14327: } else {
14328: foreach my $context (@contexts) {
14329: foreach my $role (@{$roles{$context}}) {
14330: push(@{$changes{$context}},$role);
14331: }
14332: }
14333: }
14334: }
14335: my %usermodification_hash = (
14336: usermodification => \%modifyhash,
14337: );
14338: my $putresult = &Apache::lonnet::put_dom('configuration',
14339: \%usermodification_hash,$dom);
14340: if ($putresult eq 'ok') {
14341: if (keys(%changes) > 0) {
14342: $resulttext = &mt('Changes made: ').'<ul>';
14343: foreach my $context (@contexts) {
14344: if (ref($changes{$context}) eq 'ARRAY') {
14345: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
14346: if (ref($changes{$context}) eq 'ARRAY') {
14347: foreach my $role (@{$changes{$context}}) {
14348: my $rolename;
1.160.6.34 raeburn 14349: if ($role eq 'cr') {
14350: $rolename = &mt('Custom');
1.33 raeburn 14351: } else {
1.160.6.34 raeburn 14352: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 14353: }
14354: my @modifiable;
1.160.6.34 raeburn 14355: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 14356: foreach my $field (@fields) {
14357: if ($modifyhash{$context}{$role}{$field}) {
14358: push(@modifiable,$fieldtitles{$field});
14359: }
14360: }
14361: if (@modifiable > 0) {
14362: $resulttext .= join(', ',@modifiable);
14363: } else {
14364: $resulttext .= &mt('none');
14365: }
14366: $resulttext .= '</li>';
14367: }
14368: $resulttext .= '</ul></li>';
14369: }
14370: }
14371: }
14372: $resulttext .= '</ul>';
14373: } else {
14374: $resulttext = &mt('No changes made to user modification settings');
14375: }
14376: } else {
14377: $resulttext = '<span class="LC_error">'.
14378: &mt('An error occurred: [_1]',$putresult).'</span>';
14379: }
14380: return $resulttext;
14381: }
14382:
1.43 raeburn 14383: sub modify_defaults {
1.160.6.27 raeburn 14384: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 14385: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 14386: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 14387: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98 raeburn 14388: 'portal_def');
1.43 raeburn 14389: my @authtypes = ('internal','krb4','krb5','localauth');
14390: foreach my $item (@items) {
14391: $newvalues{$item} = $env{'form.'.$item};
14392: if ($item eq 'auth_def') {
14393: if ($newvalues{$item} ne '') {
14394: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
14395: push(@errors,$item);
14396: }
14397: }
14398: } elsif ($item eq 'lang_def') {
14399: if ($newvalues{$item} ne '') {
14400: if ($newvalues{$item} =~ /^(\w+)/) {
14401: my $langcode = $1;
1.103 raeburn 14402: if ($langcode ne 'x_chef') {
14403: if (code2language($langcode) eq '') {
14404: push(@errors,$item);
14405: }
1.43 raeburn 14406: }
14407: } else {
14408: push(@errors,$item);
14409: }
14410: }
1.54 raeburn 14411: } elsif ($item eq 'timezone_def') {
14412: if ($newvalues{$item} ne '') {
1.62 raeburn 14413: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 14414: push(@errors,$item);
14415: }
14416: }
1.68 raeburn 14417: } elsif ($item eq 'datelocale_def') {
14418: if ($newvalues{$item} ne '') {
14419: my @datelocale_ids = DateTime::Locale->ids();
14420: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
14421: push(@errors,$item);
14422: }
14423: }
1.141 raeburn 14424: } elsif ($item eq 'portal_def') {
14425: if ($newvalues{$item} ne '') {
14426: 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])\/?$/) {
14427: push(@errors,$item);
14428: }
14429: }
1.43 raeburn 14430: }
14431: if (grep(/^\Q$item\E$/,@errors)) {
14432: $newvalues{$item} = $domdefaults{$item};
14433: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
14434: $changes{$item} = 1;
14435: }
1.72 raeburn 14436: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 14437: }
1.160.6.98 raeburn 14438: my %staticdefaults = (
14439: 'intauth_cost' => 10,
14440: 'intauth_check' => 0,
14441: 'intauth_switch' => 0,
14442: );
14443: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
14444: if (exists($domdefaults{$item})) {
14445: $newvalues{$item} = $domdefaults{$item};
14446: } else {
14447: $newvalues{$item} = $staticdefaults{$item};
14448: }
14449: }
1.43 raeburn 14450: my %defaults_hash = (
1.72 raeburn 14451: defaults => \%newvalues,
14452: );
1.43 raeburn 14453: my $title = &defaults_titles();
1.160.6.40 raeburn 14454:
14455: my $currinststatus;
14456: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14457: $currinststatus = $domconfig{'inststatus'};
14458: } else {
14459: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14460: $currinststatus = {
14461: inststatustypes => $usertypes,
14462: inststatusorder => $types,
14463: inststatusguest => [],
14464: };
14465: }
14466: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
14467: my @allpos;
14468: my %alltypes;
1.160.6.93 raeburn 14469: my @inststatusguest;
14470: if (ref($currinststatus) eq 'HASH') {
14471: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
14472: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
14473: unless (grep(/^\Q$type\E$/,@todelete)) {
14474: push(@inststatusguest,$type);
14475: }
14476: }
14477: }
14478: }
14479: my ($currtitles,$currorder);
1.160.6.40 raeburn 14480: if (ref($currinststatus) eq 'HASH') {
14481: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
14482: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
14483: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
14484: if ($currinststatus->{inststatustypes}->{$type} ne '') {
14485: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
14486: }
14487: }
14488: unless (grep(/^\Q$type\E$/,@todelete)) {
14489: my $position = $env{'form.inststatus_pos_'.$type};
14490: $position =~ s/\D+//g;
14491: $allpos[$position] = $type;
14492: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
14493: $alltypes{$type} =~ s/`//g;
14494: }
14495: }
14496: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
14497: $currtitles =~ s/,$//;
14498: }
14499: }
14500: if ($env{'form.addinststatus'}) {
14501: my $newtype = $env{'form.addinststatus'};
14502: $newtype =~ s/\W//g;
14503: unless (exists($alltypes{$newtype})) {
14504: $alltypes{$newtype} = $env{'form.addinststatus_title'};
14505: $alltypes{$newtype} =~ s/`//g;
14506: my $position = $env{'form.addinststatus_pos'};
14507: $position =~ s/\D+//g;
14508: if ($position ne '') {
14509: $allpos[$position] = $newtype;
14510: }
14511: }
14512: }
1.160.6.93 raeburn 14513: my @orderedstatus;
1.160.6.40 raeburn 14514: foreach my $type (@allpos) {
14515: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
14516: push(@orderedstatus,$type);
14517: }
14518: }
14519: foreach my $type (keys(%alltypes)) {
14520: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
14521: delete($alltypes{$type});
14522: }
14523: }
14524: $defaults_hash{'inststatus'} = {
14525: inststatustypes => \%alltypes,
14526: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 14527: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 14528: };
14529: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
14530: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
14531: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
14532: }
14533: }
14534: if ($currorder ne join(',',@orderedstatus)) {
14535: $changes{'inststatus'}{'inststatusorder'} = 1;
14536: }
14537: my $newtitles;
14538: foreach my $item (@orderedstatus) {
14539: $newtitles .= $alltypes{$item}.',';
14540: }
14541: $newtitles =~ s/,$//;
14542: if ($currtitles ne $newtitles) {
14543: $changes{'inststatus'}{'inststatustypes'} = 1;
14544: }
1.43 raeburn 14545: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
14546: $dom);
14547: if ($putresult eq 'ok') {
14548: if (keys(%changes) > 0) {
14549: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 14550: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 14551: 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";
14552: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 14553: if ($item eq 'inststatus') {
14554: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 14555: if (@orderedstatus) {
1.160.6.40 raeburn 14556: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
14557: foreach my $type (@orderedstatus) {
14558: $resulttext .= $alltypes{$type}.', ';
14559: }
14560: $resulttext =~ s/, $//;
14561: $resulttext .= '</li>';
1.160.6.93 raeburn 14562: } else {
14563: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 14564: }
14565: }
14566: } else {
14567: my $value = $env{'form.'.$item};
14568: if ($value eq '') {
14569: $value = &mt('none');
14570: } elsif ($item eq 'auth_def') {
14571: my %authnames = &authtype_names();
14572: my %shortauth = (
14573: internal => 'int',
14574: krb4 => 'krb4',
14575: krb5 => 'krb5',
14576: localauth => 'loc',
14577: );
14578: $value = $authnames{$shortauth{$value}};
14579: }
14580: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
14581: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 14582: }
14583: }
14584: $resulttext .= '</ul>';
14585: $mailmsgtext .= "\n";
14586: my $cachetime = 24*60*60;
1.72 raeburn 14587: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 14588: if (ref($lastactref) eq 'HASH') {
14589: $lastactref->{'domdefaults'} = 1;
14590: }
1.68 raeburn 14591: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 14592: my $notify = 1;
14593: if (ref($domconfig{'contacts'}) eq 'HASH') {
14594: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
14595: $notify = 0;
14596: }
14597: }
14598: if ($notify) {
14599: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
14600: "LON-CAPA Domain Settings Change - $dom",
14601: $mailmsgtext);
14602: }
1.54 raeburn 14603: }
1.43 raeburn 14604: } else {
1.54 raeburn 14605: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 14606: }
14607: } else {
14608: $resulttext = '<span class="LC_error">'.
14609: &mt('An error occurred: [_1]',$putresult).'</span>';
14610: }
14611: if (@errors > 0) {
14612: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
14613: foreach my $item (@errors) {
14614: $resulttext .= ' "'.$title->{$item}.'",';
14615: }
14616: $resulttext =~ s/,$//;
14617: }
14618: return $resulttext;
14619: }
14620:
1.46 raeburn 14621: sub modify_scantron {
1.160.6.24 raeburn 14622: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 14623: my ($resulttext,%confhash,%changes,$errors);
14624: my $custom = 'custom.tab';
14625: my $default = 'default.tab';
14626: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 14627: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 14628: &config_check($dom,$confname,$servadm);
14629: if ($env{'form.scantronformat.filename'} ne '') {
14630: my $error;
14631: if ($configuserok eq 'ok') {
14632: if ($switchserver) {
1.130 raeburn 14633: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 14634: } else {
14635: if ($author_ok eq 'ok') {
14636: my ($result,$scantronurl) =
14637: &publishlogo($r,'upload','scantronformat',$dom,
14638: $confname,'scantron','','',$custom);
14639: if ($result eq 'ok') {
14640: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 14641: $changes{'scantronformat'} = 1;
1.46 raeburn 14642: } else {
14643: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
14644: }
14645: } else {
14646: $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);
14647: }
14648: }
14649: } else {
14650: $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);
14651: }
14652: if ($error) {
14653: &Apache::lonnet::logthis($error);
14654: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14655: }
14656: }
1.48 raeburn 14657: if (ref($domconfig{'scantron'}) eq 'HASH') {
14658: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
14659: if ($env{'form.scantronformat_del'}) {
14660: $confhash{'scantron'}{'scantronformat'} = '';
14661: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 14662: } else {
14663: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
14664: }
14665: }
14666: }
14667: my @options = ('hdr','pad','rem');
14668: my @fields = &scantroncsv_fields();
14669: my %titles = &scantronconfig_titles();
14670: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
14671: my ($newdat,$currdat,%newcol,%currcol);
14672: if (grep(/^dat$/,@formats)) {
14673: $confhash{'scantron'}{config}{dat} = 1;
14674: $newdat = 1;
14675: } else {
14676: $newdat = 0;
14677: }
14678: if (grep(/^csv$/,@formats)) {
14679: my %bynum;
14680: foreach my $field (@fields) {
14681: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
14682: my $posscol = $1;
14683: if (($posscol < 20) && (!$bynum{$posscol})) {
14684: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
14685: $bynum{$posscol} = $field;
14686: $newcol{$field} = $posscol;
14687: }
14688: }
14689: }
14690: if (keys(%newcol)) {
14691: foreach my $option (@options) {
14692: if ($env{'form.scantroncsv_'.$option}) {
14693: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
14694: }
14695: }
14696: }
14697: }
14698: $currdat = 1;
14699: if (ref($domconfig{'scantron'}) eq 'HASH') {
14700: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
14701: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
14702: $currdat = 0;
14703: }
14704: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
14705: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
14706: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
14707: }
14708: }
14709: }
14710: }
14711: if ($currdat != $newdat) {
14712: $changes{'config'} = 1;
14713: } else {
14714: foreach my $field (@fields) {
14715: if ($currcol{$field} ne '') {
14716: if ($currcol{$field} ne $newcol{$field}) {
14717: $changes{'config'} = 1;
14718: last;
14719: }
14720: } elsif ($newcol{$field} ne '') {
14721: $changes{'config'} = 1;
14722: last;
1.46 raeburn 14723: }
14724: }
14725: }
14726: if (keys(%confhash) > 0) {
14727: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
14728: $dom);
14729: if ($putresult eq 'ok') {
14730: if (keys(%changes) > 0) {
1.48 raeburn 14731: if (ref($confhash{'scantron'}) eq 'HASH') {
14732: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 14733: if ($changes{'scantronformat'}) {
14734: if ($confhash{'scantron'}{'scantronformat'} eq '') {
14735: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
14736: } else {
14737: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
14738: }
14739: }
14740: if ($changes{'config'}) {
14741: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
14742: if ($confhash{'scantron'}{'config'}{'dat'}) {
14743: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
14744: }
14745: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
14746: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
14747: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
14748: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
14749: foreach my $field (@fields) {
14750: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
14751: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
14752: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
14753: }
14754: }
14755: $resulttext .= '</ul></li>';
14756: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
14757: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
14758: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
14759: foreach my $option (@options) {
14760: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
14761: $resulttext .= '<li>'.$titles{$option}.'</li>';
14762: }
14763: }
14764: $resulttext .= '</ul></li>';
14765: }
14766: }
14767: }
14768: }
14769: }
14770: } else {
14771: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
14772: }
1.46 raeburn 14773: }
1.48 raeburn 14774: $resulttext .= '</ul>';
14775: } else {
1.130 raeburn 14776: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 14777: }
14778: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 14779: if (ref($lastactref) eq 'HASH') {
14780: $lastactref->{'domainconfig'} = 1;
14781: }
1.46 raeburn 14782: } else {
1.160.6.97 raeburn 14783: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 14784: }
14785: } else {
14786: $resulttext = '<span class="LC_error">'.
14787: &mt('An error occurred: [_1]',$putresult).'</span>';
14788: }
14789: } else {
1.160.6.97 raeburn 14790: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 14791: }
14792: if ($errors) {
14793: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14794: $errors.'</ul>';
14795: }
14796: return $resulttext;
14797: }
14798:
1.48 raeburn 14799: sub modify_coursecategories {
1.160.6.43 raeburn 14800: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 14801: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
14802: $cathash);
1.48 raeburn 14803: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 14804: my @catitems = ('unauth','auth');
14805: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 14806: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 14807: $cathash = $domconfig{'coursecategories'}{'cats'};
14808: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
14809: $changes{'togglecats'} = 1;
14810: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
14811: }
14812: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
14813: $changes{'categorize'} = 1;
14814: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
14815: }
1.120 raeburn 14816: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
14817: $changes{'togglecatscomm'} = 1;
14818: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
14819: }
14820: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
14821: $changes{'categorizecomm'} = 1;
14822: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
14823: }
1.160.6.42 raeburn 14824: foreach my $item (@catitems) {
14825: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14826: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
14827: $changes{$item} = 1;
14828: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14829: }
14830: }
14831: }
1.57 raeburn 14832: } else {
14833: $changes{'togglecats'} = 1;
14834: $changes{'categorize'} = 1;
1.124 raeburn 14835: $changes{'togglecatscomm'} = 1;
14836: $changes{'categorizecomm'} = 1;
1.87 raeburn 14837: $domconfig{'coursecategories'} = {
14838: togglecats => $env{'form.togglecats'},
14839: categorize => $env{'form.categorize'},
1.124 raeburn 14840: togglecatscomm => $env{'form.togglecatscomm'},
14841: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 14842: };
1.160.6.42 raeburn 14843: foreach my $item (@catitems) {
14844: if ($env{'form.coursecat_'.$item} ne 'std') {
14845: $changes{$item} = 1;
14846: }
14847: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14848: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14849: }
14850: }
1.57 raeburn 14851: }
14852: if (ref($cathash) eq 'HASH') {
14853: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 14854: push (@deletecategory,'instcode::0');
14855: }
1.120 raeburn 14856: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
14857: push(@deletecategory,'communities::0');
14858: }
1.48 raeburn 14859: }
1.57 raeburn 14860: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
14861: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14862: if (@deletecategory > 0) {
14863: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 14864: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 14865: foreach my $item (@deletecategory) {
1.57 raeburn 14866: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
14867: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 14868: $deletions{$item} = 1;
1.57 raeburn 14869: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 14870: }
14871: }
14872: }
1.57 raeburn 14873: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 14874: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 14875: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 14876: $reorderings{$item} = 1;
1.57 raeburn 14877: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 14878: }
14879: if ($env{'form.addcategory_name_'.$item} ne '') {
14880: my $newcat = $env{'form.addcategory_name_'.$item};
14881: my $newdepth = $depth+1;
14882: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14883: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 14884: $adds{$newitem} = 1;
14885: }
14886: if ($env{'form.subcat_'.$item} ne '') {
14887: my $newcat = $env{'form.subcat_'.$item};
14888: my $newdepth = $depth+1;
14889: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14890: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 14891: $adds{$newitem} = 1;
14892: }
14893: }
14894: }
14895: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 14896: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14897: my $newitem = 'instcode::0';
1.57 raeburn 14898: if ($cathash->{$newitem} eq '') {
14899: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14900: $adds{$newitem} = 1;
14901: }
14902: } else {
14903: my $newitem = 'instcode::0';
1.57 raeburn 14904: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14905: $adds{$newitem} = 1;
14906: }
14907: }
1.120 raeburn 14908: if ($env{'form.communities'} eq '1') {
14909: if (ref($cathash) eq 'HASH') {
14910: my $newitem = 'communities::0';
14911: if ($cathash->{$newitem} eq '') {
14912: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14913: $adds{$newitem} = 1;
14914: }
14915: } else {
14916: my $newitem = 'communities::0';
14917: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14918: $adds{$newitem} = 1;
14919: }
14920: }
1.48 raeburn 14921: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 14922: if (($env{'form.addcategory_name'} ne 'instcode') &&
14923: ($env{'form.addcategory_name'} ne 'communities')) {
14924: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
14925: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
14926: $adds{$newitem} = 1;
14927: }
1.48 raeburn 14928: }
1.57 raeburn 14929: my $putresult;
1.48 raeburn 14930: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14931: if (keys(%deletions) > 0) {
14932: foreach my $key (keys(%deletions)) {
14933: if ($predelallitems{$key} ne '') {
14934: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
14935: }
14936: }
14937: }
14938: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 14939: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 14940: if (ref($chkcats[0]) eq 'ARRAY') {
14941: my $depth = 0;
14942: my $chg = 0;
14943: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
14944: my $name = $chkcats[0][$i];
14945: my $item;
14946: if ($name eq '') {
14947: $chg ++;
14948: } else {
14949: $item = &escape($name).'::0';
14950: if ($chg) {
1.57 raeburn 14951: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 14952: }
14953: $depth ++;
1.57 raeburn 14954: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 14955: $depth --;
14956: }
14957: }
14958: }
1.57 raeburn 14959: }
14960: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14961: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 14962: if ($putresult eq 'ok') {
1.57 raeburn 14963: my %title = (
1.120 raeburn 14964: togglecats => 'Show/Hide a course in catalog',
14965: categorize => 'Assign a category to a course',
14966: togglecatscomm => 'Show/Hide a community in catalog',
14967: categorizecomm => 'Assign a category to a community',
1.57 raeburn 14968: );
14969: my %level = (
1.120 raeburn 14970: dom => 'set in Domain ("Modify Course/Community")',
14971: crs => 'set in Course ("Course Configuration")',
14972: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 14973: none => 'No catalog',
14974: std => 'Standard catalog',
14975: domonly => 'Domain-only catalog',
14976: codesrch => 'Code search form',
1.57 raeburn 14977: );
1.48 raeburn 14978: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 14979: if ($changes{'togglecats'}) {
14980: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
14981: }
14982: if ($changes{'categorize'}) {
14983: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 14984: }
1.120 raeburn 14985: if ($changes{'togglecatscomm'}) {
14986: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
14987: }
14988: if ($changes{'categorizecomm'}) {
14989: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
14990: }
1.160.6.42 raeburn 14991: if ($changes{'unauth'}) {
14992: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
14993: }
14994: if ($changes{'auth'}) {
14995: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
14996: }
1.57 raeburn 14997: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14998: my $cathash;
14999: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
15000: $cathash = $domconfig{'coursecategories'}{'cats'};
15001: } else {
15002: $cathash = {};
15003: }
15004: my (@cats,@trails,%allitems);
15005: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
15006: if (keys(%deletions) > 0) {
15007: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
15008: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
15009: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
15010: }
15011: $resulttext .= '</ul></li>';
15012: }
15013: if (keys(%reorderings) > 0) {
15014: my %sort_by_trail;
15015: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
15016: foreach my $key (keys(%reorderings)) {
15017: if ($allitems{$key} ne '') {
15018: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
15019: }
1.48 raeburn 15020: }
1.57 raeburn 15021: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
15022: $resulttext .= '<li>'.$trails[$trail].'</li>';
15023: }
15024: $resulttext .= '</ul></li>';
1.48 raeburn 15025: }
1.57 raeburn 15026: if (keys(%adds) > 0) {
15027: my %sort_by_trail;
15028: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
15029: foreach my $key (keys(%adds)) {
15030: if ($allitems{$key} ne '') {
15031: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
15032: }
15033: }
15034: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
15035: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 15036: }
1.57 raeburn 15037: $resulttext .= '</ul></li>';
1.48 raeburn 15038: }
1.160.6.92 raeburn 15039: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
15040: if (ref($lastactref) eq 'HASH') {
15041: $lastactref->{'cats'} = 1;
15042: }
1.48 raeburn 15043: }
15044: $resulttext .= '</ul>';
1.160.6.43 raeburn 15045: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 15046: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15047: if ($changes{'auth'}) {
15048: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
15049: }
15050: if ($changes{'unauth'}) {
15051: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
15052: }
15053: my $cachetime = 24*60*60;
15054: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 15055: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 15056: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 15057: }
15058: }
1.48 raeburn 15059: } else {
15060: $resulttext = '<span class="LC_error">'.
1.57 raeburn 15061: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 15062: }
15063: } else {
1.120 raeburn 15064: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 15065: }
15066: return $resulttext;
15067: }
15068:
1.69 raeburn 15069: sub modify_serverstatuses {
15070: my ($dom,%domconfig) = @_;
15071: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
15072: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
15073: %currserverstatus = %{$domconfig{'serverstatuses'}};
15074: }
15075: my @pages = &serverstatus_pages();
15076: foreach my $type (@pages) {
15077: $newserverstatus{$type}{'namedusers'} = '';
15078: $newserverstatus{$type}{'machines'} = '';
15079: if (defined($env{'form.'.$type.'_namedusers'})) {
15080: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
15081: my @okusers;
15082: foreach my $user (@users) {
15083: my ($uname,$udom) = split(/:/,$user);
15084: if (($udom =~ /^$match_domain$/) &&
15085: (&Apache::lonnet::domain($udom)) &&
15086: ($uname =~ /^$match_username$/)) {
15087: if (!grep(/^\Q$user\E/,@okusers)) {
15088: push(@okusers,$user);
15089: }
15090: }
15091: }
15092: if (@okusers > 0) {
15093: @okusers = sort(@okusers);
15094: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
15095: }
15096: }
15097: if (defined($env{'form.'.$type.'_machines'})) {
15098: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
15099: my @okmachines;
15100: foreach my $ip (@machines) {
15101: my @parts = split(/\./,$ip);
15102: next if (@parts < 4);
15103: my $badip = 0;
15104: for (my $i=0; $i<4; $i++) {
15105: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
15106: $badip = 1;
15107: last;
15108: }
15109: }
15110: if (!$badip) {
15111: push(@okmachines,$ip);
15112: }
15113: }
15114: @okmachines = sort(@okmachines);
15115: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
15116: }
15117: }
15118: my %serverstatushash = (
15119: serverstatuses => \%newserverstatus,
15120: );
15121: foreach my $type (@pages) {
1.83 raeburn 15122: foreach my $setting ('namedusers','machines') {
1.84 raeburn 15123: my (@current,@new);
1.83 raeburn 15124: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 15125: if ($currserverstatus{$type}{$setting} ne '') {
15126: @current = split(/,/,$currserverstatus{$type}{$setting});
15127: }
15128: }
15129: if ($newserverstatus{$type}{$setting} ne '') {
15130: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 15131: }
15132: if (@current > 0) {
15133: if (@new > 0) {
15134: foreach my $item (@current) {
15135: if (!grep(/^\Q$item\E$/,@new)) {
15136: $changes{$type}{$setting} = 1;
1.82 raeburn 15137: last;
15138: }
15139: }
1.84 raeburn 15140: foreach my $item (@new) {
15141: if (!grep(/^\Q$item\E$/,@current)) {
15142: $changes{$type}{$setting} = 1;
15143: last;
1.82 raeburn 15144: }
15145: }
15146: } else {
1.83 raeburn 15147: $changes{$type}{$setting} = 1;
1.69 raeburn 15148: }
1.83 raeburn 15149: } elsif (@new > 0) {
15150: $changes{$type}{$setting} = 1;
1.69 raeburn 15151: }
15152: }
15153: }
15154: if (keys(%changes) > 0) {
1.81 raeburn 15155: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 15156: my $putresult = &Apache::lonnet::put_dom('configuration',
15157: \%serverstatushash,$dom);
15158: if ($putresult eq 'ok') {
15159: $resulttext .= &mt('Changes made:').'<ul>';
15160: foreach my $type (@pages) {
1.84 raeburn 15161: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 15162: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 15163: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 15164: if ($newserverstatus{$type}{'namedusers'} eq '') {
15165: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
15166: } else {
15167: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
15168: }
1.84 raeburn 15169: }
15170: if ($changes{$type}{'machines'}) {
1.69 raeburn 15171: if ($newserverstatus{$type}{'machines'} eq '') {
15172: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
15173: } else {
15174: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
15175: }
15176:
15177: }
15178: $resulttext .= '</ul></li>';
15179: }
15180: }
15181: $resulttext .= '</ul>';
15182: } else {
15183: $resulttext = '<span class="LC_error">'.
15184: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
15185:
15186: }
15187: } else {
15188: $resulttext = &mt('No changes made to access to server status pages');
15189: }
15190: return $resulttext;
15191: }
15192:
1.118 jms 15193: sub modify_helpsettings {
1.160.6.77 raeburn 15194: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 15195: my ($resulttext,$errors,%changes,%helphash);
15196: my %defaultchecked = ('submitbugs' => 'on');
15197: my @offon = ('off','on');
1.118 jms 15198: my @toggles = ('submitbugs');
1.160.6.77 raeburn 15199: my %current = ('submitbugs' => '',
15200: 'adhoc' => {},
15201: );
1.118 jms 15202: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 15203: %current = %{$domconfig{'helpsettings'}};
15204: }
1.160.6.77 raeburn 15205: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 15206: foreach my $item (@toggles) {
15207: if ($defaultchecked{$item} eq 'on') {
15208: if ($current{$item} eq '') {
15209: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 15210: $changes{$item} = 1;
15211: }
1.160.6.73 raeburn 15212: } elsif ($current{$item} ne $env{'form.'.$item}) {
15213: $changes{$item} = 1;
15214: }
15215: } elsif ($defaultchecked{$item} eq 'off') {
15216: if ($current{$item} eq '') {
15217: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 15218: $changes{$item} = 1;
15219: }
1.160.6.73 raeburn 15220: } elsif ($current{$item} ne $env{'form.'.$item}) {
15221: $changes{$item} = 1;
15222: }
15223: }
15224: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
15225: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
15226: }
15227: }
1.160.6.77 raeburn 15228: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 15229: my $confname = $dom.'-domainconfig';
15230: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 15231: my (@allpos,%newsettings,%changedprivs,$newrole);
15232: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 15233: my @accesstypes = ('all','dh','da','none','status','inc','exc');
15234: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 15235: my %lt = &Apache::lonlocal::texthash(
15236: s => 'system',
15237: d => 'domain',
15238: order => 'Display order',
15239: access => 'Role usage',
1.160.6.79 raeburn 15240: all => 'All with domain helpdesk or helpdesk assistant role',
15241: dh => 'All with domain helpdesk role',
15242: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 15243: none => 'None',
15244: status => 'Determined based on institutional status',
15245: inc => 'Include all, but exclude specific personnel',
15246: exc => 'Exclude all, but include specific personnel',
15247: );
15248: for (my $num=0; $num<=$maxnum; $num++) {
15249: my ($prefix,$identifier,$rolename,%curr);
15250: if ($num == $maxnum) {
15251: next unless ($env{'form.newcusthelp'} == $maxnum);
15252: $identifier = 'custhelp'.$num;
15253: $prefix = 'helproles_'.$num;
15254: $rolename = $env{'form.custhelpname'.$num};
15255: $rolename=~s/[^A-Za-z0-9]//gs;
15256: next if ($rolename eq '');
15257: next if (exists($existing{'rolesdef_'.$rolename}));
15258: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15259: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15260: $newprivs{'c'},$confname,$dom);
15261: if ($result ne 'ok') {
15262: $errors .= '<li><span class="LC_error">'.
15263: &mt('An error occurred storing the new custom role: [_1]',
15264: $result).'</span></li>';
15265: next;
15266: } else {
15267: $changedprivs{$rolename} = \%newprivs;
15268: $newrole = $rolename;
15269: }
15270: } else {
15271: $prefix = 'helproles_'.$num;
15272: $rolename = $env{'form.'.$prefix};
15273: next if ($rolename eq '');
15274: next unless (exists($existing{'rolesdef_'.$rolename}));
15275: $identifier = 'custhelp'.$num;
15276: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15277: my %currprivs;
15278: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
15279: split(/\_/,$existing{'rolesdef_'.$rolename});
15280: foreach my $level ('c','d','s') {
15281: if ($newprivs{$level} ne $currprivs{$level}) {
15282: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15283: $newprivs{'c'},$confname,$dom);
15284: if ($result ne 'ok') {
15285: $errors .= '<li><span class="LC_error">'.
15286: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
15287: $rolename,$result).'</span></li>';
15288: } else {
15289: $changedprivs{$rolename} = \%newprivs;
15290: }
15291: last;
15292: }
15293: }
15294: if (ref($current{'adhoc'}) eq 'HASH') {
15295: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15296: %curr = %{$current{'adhoc'}{$rolename}};
15297: }
15298: }
15299: }
15300: my $newpos = $env{'form.'.$prefix.'_pos'};
15301: $newpos =~ s/\D+//g;
15302: $allpos[$newpos] = $rolename;
15303: my $newdesc = $env{'form.'.$prefix.'_desc'};
15304: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
15305: if ($curr{'desc'}) {
15306: if ($curr{'desc'} ne $newdesc) {
15307: $changes{'customrole'}{$rolename}{'desc'} = 1;
15308: $newsettings{$rolename}{'desc'} = $newdesc;
15309: }
15310: } elsif ($newdesc ne '') {
15311: $changes{'customrole'}{$rolename}{'desc'} = 1;
15312: $newsettings{$rolename}{'desc'} = $newdesc;
15313: }
15314: my $access = $env{'form.'.$prefix.'_access'};
15315: if (grep(/^\Q$access\E$/,@accesstypes)) {
15316: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
15317: if ($access eq 'status') {
15318: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
15319: if (scalar(@statuses) == 0) {
15320: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
15321: } else {
15322: my (@shownstatus,$numtypes);
15323: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15324: if (ref($types) eq 'ARRAY') {
15325: $numtypes = scalar(@{$types});
15326: foreach my $type (sort(@statuses)) {
15327: if ($type eq 'default') {
15328: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15329: } elsif (grep(/^\Q$type\E$/,@{$types})) {
15330: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15331: push(@shownstatus,$usertypes->{$type});
15332: }
1.160.6.73 raeburn 15333: }
15334: }
1.160.6.77 raeburn 15335: if (grep(/^default$/,@statuses)) {
15336: push(@shownstatus,$othertitle);
15337: }
15338: if (scalar(@shownstatus) == 1+$numtypes) {
15339: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
15340: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
15341: } else {
15342: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
15343: if (ref($curr{'status'}) eq 'ARRAY') {
15344: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15345: if (@diffs) {
15346: $changes{'customrole'}{$rolename}{$access} = 1;
15347: }
15348: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15349: $changes{'customrole'}{$rolename}{$access} = 1;
15350: }
15351: }
15352: }
15353: } elsif (($access eq 'inc') || ($access eq 'exc')) {
15354: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
15355: my @newspecstaff;
15356: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15357: foreach my $person (sort(@personnel)) {
15358: if ($domhelpdesk{$person}) {
15359: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
15360: }
15361: }
15362: if (ref($curr{$access}) eq 'ARRAY') {
15363: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15364: if (@diffs) {
15365: $changes{'customrole'}{$rolename}{$access} = 1;
15366: }
15367: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15368: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 15369: }
1.160.6.77 raeburn 15370: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15371: my ($uname,$udom) = split(/:/,$person);
15372: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
15373: }
15374: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 15375: }
1.160.6.77 raeburn 15376: } else {
15377: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
15378: }
15379: unless ($curr{'access'} eq $access) {
15380: $changes{'customrole'}{$rolename}{'access'} = 1;
15381: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 15382: }
15383: }
1.160.6.77 raeburn 15384: if (@allpos > 0) {
15385: my $idx = 0;
15386: foreach my $rolename (@allpos) {
15387: if ($rolename ne '') {
15388: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
15389: if (ref($current{'adhoc'}) eq 'HASH') {
15390: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15391: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
15392: $changes{'customrole'}{$rolename}{'order'} = 1;
15393: $newsettings{$rolename}{'order'} = $idx+1;
15394: }
15395: }
1.160.6.73 raeburn 15396: }
1.160.6.77 raeburn 15397: $idx ++;
1.122 jms 15398: }
15399: }
1.118 jms 15400: }
1.123 jms 15401: my $putresult;
15402: if (keys(%changes) > 0) {
1.160.6.5 raeburn 15403: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
15404: if ($putresult eq 'ok') {
1.160.6.77 raeburn 15405: if (ref($helphash{'helpsettings'}) eq 'HASH') {
15406: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
15407: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
15408: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
15409: }
15410: }
15411: my $cachetime = 24*60*60;
15412: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15413: if (ref($lastactref) eq 'HASH') {
15414: $lastactref->{'domdefaults'} = 1;
15415: }
15416: } else {
15417: $errors .= '<li><span class="LC_error">'.
15418: &mt('An error occurred storing the settings: [_1]',
15419: $putresult).'</span></li>';
15420: }
15421: }
15422: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
15423: $resulttext = &mt('Changes made:').'<ul>';
15424: my (%shownprivs,@levelorder);
15425: @levelorder = ('c','d','s');
15426: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 15427: foreach my $item (sort(keys(%changes))) {
15428: if ($item eq 'submitbugs') {
15429: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
15430: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
15431: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 15432: } elsif ($item eq 'customrole') {
15433: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 15434: my @keyorder = ('order','desc','access','status','exc','inc');
15435: my %keytext = &Apache::lonlocal::texthash(
15436: order => 'Order',
15437: desc => 'Role description',
15438: access => 'Role usage',
1.160.6.83 raeburn 15439: status => 'Allowed institutional types',
1.160.6.77 raeburn 15440: exc => 'Allowed personnel',
15441: inc => 'Disallowed personnel',
15442: );
1.160.6.73 raeburn 15443: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 15444: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
15445: if ($role eq $newrole) {
15446: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
15447: $role).'<ul>';
15448: } else {
15449: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15450: $role).'<ul>';
15451: }
15452: foreach my $key (@keyorder) {
15453: if ($changes{'customrole'}{$role}{$key}) {
15454: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
15455: $keytext{$key},$newsettings{$role}{$key}).
15456: '</li>';
15457: }
15458: }
15459: if (ref($changedprivs{$role}) eq 'HASH') {
15460: $shownprivs{$role} = 1;
15461: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
15462: foreach my $level (@levelorder) {
15463: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15464: next if ($item eq '');
15465: my ($priv) = split(/\&/,$item,2);
15466: if (&Apache::lonnet::plaintext($priv)) {
15467: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15468: unless ($level eq 'c') {
15469: $resulttext .= ' ('.$lt{$level}.')';
15470: }
15471: $resulttext .= '</li>';
15472: }
15473: }
15474: }
15475: $resulttext .= '</ul>';
15476: }
15477: $resulttext .= '</ul></li>';
15478: }
1.160.6.73 raeburn 15479: }
15480: }
1.160.6.5 raeburn 15481: }
15482: }
15483: }
1.160.6.77 raeburn 15484: if (keys(%changedprivs)) {
15485: foreach my $role (sort(keys(%changedprivs))) {
15486: unless ($shownprivs{$role}) {
15487: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15488: $role).'<ul>'.
15489: '<li>'.&mt('Privileges set to :').'<ul>';
15490: foreach my $level (@levelorder) {
15491: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15492: next if ($item eq '');
15493: my ($priv) = split(/\&/,$item,2);
15494: if (&Apache::lonnet::plaintext($priv)) {
15495: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15496: unless ($level eq 'c') {
15497: $resulttext .= ' ('.$lt{$level}.')';
15498: }
15499: $resulttext .= '</li>';
15500: }
15501: }
15502: }
15503: $resulttext .= '</ul></li></ul></li>';
15504: }
15505: }
15506: }
15507: $resulttext .= '</ul>';
15508: } else {
15509: $resulttext = &mt('No changes made to help settings');
1.118 jms 15510: }
15511: if ($errors) {
1.160.6.5 raeburn 15512: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 15513: $errors.'</ul>';
1.118 jms 15514: }
15515: return $resulttext;
15516: }
15517:
1.121 raeburn 15518: sub modify_coursedefaults {
1.160.6.27 raeburn 15519: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 15520: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 15521: my %defaultchecked = (
15522: 'uselcmath' => 'on',
1.160.6.115! raeburn 15523: 'usejsme' => 'on',
! 15524: 'inline_chem' => 'on',
1.160.6.57 raeburn 15525: );
1.160.6.115! raeburn 15526: my @toggles = ('uselcmath','usejsme','inline_chem');
1.160.6.21 raeburn 15527: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 15528: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
15529: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 15530: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 15531: my %staticdefaults = (
15532: anonsurvey_threshold => 10,
15533: uploadquota => 500,
1.160.6.57 raeburn 15534: postsubmit => 60,
1.160.6.70 raeburn 15535: mysqltables => 172800,
1.160.6.21 raeburn 15536: );
1.160.6.90 raeburn 15537: my %texoptions = (
15538: MathJax => 'MathJax',
15539: mimetex => &mt('Convert to Images'),
15540: tth => &mt('TeX to HTML'),
15541: );
1.121 raeburn 15542: $defaultshash{'coursedefaults'} = {};
15543:
15544: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
15545: if ($domconfig{'coursedefaults'} eq '') {
15546: $domconfig{'coursedefaults'} = {};
15547: }
15548: }
15549:
15550: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
15551: foreach my $item (@toggles) {
15552: if ($defaultchecked{$item} eq 'on') {
15553: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15554: ($env{'form.'.$item} eq '0')) {
15555: $changes{$item} = 1;
1.160.6.16 raeburn 15556: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 15557: $changes{$item} = 1;
15558: }
15559: } elsif ($defaultchecked{$item} eq 'off') {
15560: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15561: ($env{'form.'.$item} eq '1')) {
15562: $changes{$item} = 1;
15563: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
15564: $changes{$item} = 1;
15565: }
15566: }
15567: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
15568: }
1.160.6.21 raeburn 15569: foreach my $item (@numbers) {
15570: my ($currdef,$newdef);
1.160.6.26 raeburn 15571: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 15572: if ($item eq 'anonsurvey_threshold') {
15573: $currdef = $domconfig{'coursedefaults'}{$item};
15574: $newdef =~ s/\D//g;
15575: if ($newdef eq '' || $newdef < 1) {
15576: $newdef = 1;
15577: }
15578: $defaultshash{'coursedefaults'}{$item} = $newdef;
15579: } else {
1.160.6.70 raeburn 15580: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
15581: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
15582: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 15583: }
15584: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 15585: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 15586: }
15587: if ($currdef ne $newdef) {
15588: if ($item eq 'anonsurvey_threshold') {
15589: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
15590: $changes{$item} = 1;
15591: }
1.160.6.70 raeburn 15592: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
15593: my $setting = $1;
15594: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
15595: $changes{$setting} = 1;
1.160.6.21 raeburn 15596: }
15597: }
1.139 raeburn 15598: }
15599: }
1.160.6.90 raeburn 15600: my $texengine;
15601: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
15602: $texengine = $env{'form.texengine'};
15603: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
15604: if ($currdef eq '') {
15605: unless ($texengine eq $Apache::lonnet::deftex) {
15606: $changes{'texengine'} = 1;
15607: }
15608: } elsif ($currdef ne $texengine) {
15609: $changes{'texengine'} = 1;
15610: }
15611: }
15612: if ($texengine ne '') {
15613: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
15614: }
1.160.6.64 raeburn 15615: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
15616: my @currclonecode;
15617: if (ref($currclone) eq 'HASH') {
15618: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
15619: @currclonecode = @{$currclone->{'instcode'}};
15620: }
15621: }
15622: my $newclone;
15623: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
15624: $newclone = $env{'form.canclone'};
15625: }
15626: if ($newclone eq 'instcode') {
15627: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
15628: my (%codedefaults,@code_order,@clonecode);
15629: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
15630: \@code_order);
15631: foreach my $item (@code_order) {
15632: if (grep(/^\Q$item\E$/,@newcodes)) {
15633: push(@clonecode,$item);
15634: }
15635: }
15636: if (@clonecode) {
15637: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
15638: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
15639: if (@diffs) {
15640: $changes{'canclone'} = 1;
15641: }
15642: } else {
15643: $newclone eq '';
15644: }
15645: } elsif ($newclone ne '') {
15646: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
15647: }
15648: if ($newclone ne $currclone) {
15649: $changes{'canclone'} = 1;
15650: }
1.160.6.57 raeburn 15651: my %credits;
15652: foreach my $type (@types) {
15653: unless ($type eq 'community') {
15654: $credits{$type} = $env{'form.'.$type.'_credits'};
15655: $credits{$type} =~ s/[^\d.]+//g;
15656: }
15657: }
15658: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
15659: ($env{'form.coursecredits'} eq '1')) {
15660: $changes{'coursecredits'} = 1;
15661: foreach my $type (keys(%credits)) {
15662: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15663: }
15664: } else {
15665: if ($env{'form.coursecredits'} eq '1') {
15666: foreach my $type (@types) {
15667: unless ($type eq 'community') {
15668: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
15669: $changes{'coursecredits'} = 1;
15670: }
15671: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15672: }
15673: }
15674: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15675: foreach my $type (@types) {
15676: unless ($type eq 'community') {
15677: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
15678: $changes{'coursecredits'} = 1;
15679: last;
15680: }
15681: }
15682: }
15683: }
15684: }
15685: if ($env{'form.postsubmit'} eq '1') {
15686: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
15687: my %currtimeout;
15688: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15689: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
15690: $changes{'postsubmit'} = 1;
15691: }
15692: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15693: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
15694: }
15695: } else {
15696: $changes{'postsubmit'} = 1;
15697: }
15698: foreach my $type (@types) {
15699: my $timeout = $env{'form.'.$type.'_timeout'};
15700: $timeout =~ s/\D//g;
15701: if ($timeout == $staticdefaults{'postsubmit'}) {
15702: $timeout = '';
15703: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
15704: $timeout = '0';
15705: }
15706: unless ($timeout eq '') {
15707: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
15708: }
15709: if (exists($currtimeout{$type})) {
15710: if ($timeout ne $currtimeout{$type}) {
15711: $changes{'postsubmit'} = 1;
15712: }
15713: } elsif ($timeout ne '') {
15714: $changes{'postsubmit'} = 1;
15715: }
15716: }
15717: } else {
15718: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
15719: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15720: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
15721: $changes{'postsubmit'} = 1;
15722: }
15723: } else {
15724: $changes{'postsubmit'} = 1;
15725: }
1.160.6.16 raeburn 15726: }
1.121 raeburn 15727: }
15728: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15729: $dom);
15730: if ($putresult eq 'ok') {
15731: if (keys(%changes) > 0) {
1.160.6.27 raeburn 15732: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 15733: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 15734: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.115! raeburn 15735: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
! 15736: ($changes{'inline_chem'})) {
! 15737: foreach my $item ('uselcmath','usejsme','inline_chem','texengine') {
1.160.6.57 raeburn 15738: if ($changes{$item}) {
15739: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
15740: }
1.160.6.16 raeburn 15741: }
15742: if ($changes{'coursecredits'}) {
15743: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 15744: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
15745: $domdefaults{$type.'credits'} =
15746: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
15747: }
15748: }
15749: }
15750: if ($changes{'postsubmit'}) {
15751: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15752: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
15753: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15754: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
15755: $domdefaults{$type.'postsubtimeout'} =
15756: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15757: }
15758: }
1.160.6.16 raeburn 15759: }
15760: }
1.160.6.21 raeburn 15761: if ($changes{'uploadquota'}) {
15762: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15763: foreach my $type (@types) {
15764: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
15765: }
15766: }
15767: }
1.160.6.64 raeburn 15768: if ($changes{'canclone'}) {
15769: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15770: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15771: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
15772: if (@clonecodes) {
15773: $domdefaults{'canclone'} = join('+',@clonecodes);
15774: }
15775: }
15776: } else {
15777: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
15778: }
15779: }
1.121 raeburn 15780: my $cachetime = 24*60*60;
15781: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 15782: if (ref($lastactref) eq 'HASH') {
15783: $lastactref->{'domdefaults'} = 1;
15784: }
1.121 raeburn 15785: }
15786: $resulttext = &mt('Changes made:').'<ul>';
15787: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 15788: if ($item eq 'uselcmath') {
1.121 raeburn 15789: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 15790: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 15791: } else {
1.160.6.57 raeburn 15792: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
15793: }
15794: } elsif ($item eq 'usejsme') {
15795: if ($env{'form.'.$item} eq '1') {
15796: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
15797: } else {
15798: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 15799: }
1.160.6.115! raeburn 15800: } elsif ($item eq 'inline_chem') {
! 15801: if ($env{'form.'.$item} eq '1') {
! 15802: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
! 15803: } else {
! 15804: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
! 15805: }
1.160.6.90 raeburn 15806: } elsif ($item eq 'texengine') {
15807: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
15808: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
15809: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
15810: }
1.139 raeburn 15811: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 15812: $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 15813: } elsif ($item eq 'uploadquota') {
15814: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15815: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
15816: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
15817: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 15818: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
15819:
1.160.6.21 raeburn 15820: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
15821: '</ul>'.
15822: '</li>';
15823: } else {
15824: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
15825: }
1.160.6.70 raeburn 15826: } elsif ($item eq 'mysqltables') {
15827: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
15828: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
15829: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
15830: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
15831: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
15832: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
15833: '</ul>'.
15834: '</li>';
15835: } else {
15836: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
15837: }
1.160.6.57 raeburn 15838: } elsif ($item eq 'postsubmit') {
15839: if ($domdefaults{'postsubmit'} eq 'off') {
15840: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
15841: } else {
15842: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
15843: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15844: $resulttext .= &mt('durations:').'<ul>';
15845: foreach my $type (@types) {
15846: $resulttext .= '<li>';
15847: my $timeout;
15848: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15849: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15850: }
15851: my $display;
15852: if ($timeout eq '0') {
15853: $display = &mt('unlimited');
15854: } elsif ($timeout eq '') {
15855: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
15856: } else {
15857: $display = &mt('[quant,_1,second]',$timeout);
15858: }
15859: if ($type eq 'community') {
15860: $resulttext .= &mt('Communities');
15861: } elsif ($type eq 'official') {
15862: $resulttext .= &mt('Official courses');
15863: } elsif ($type eq 'unofficial') {
15864: $resulttext .= &mt('Unofficial courses');
15865: } elsif ($type eq 'textbook') {
15866: $resulttext .= &mt('Textbook courses');
15867: }
15868: $resulttext .= ' -- '.$display.'</li>';
15869: }
15870: $resulttext .= '</ul>';
15871: }
15872: $resulttext .= '</li>';
15873: }
1.160.6.16 raeburn 15874: } elsif ($item eq 'coursecredits') {
15875: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15876: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 15877: ($domdefaults{'unofficialcredits'} eq '') &&
15878: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 15879: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15880: } else {
15881: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
15882: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
15883: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 15884: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 15885: '</ul>'.
15886: '</li>';
15887: }
15888: } else {
15889: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15890: }
1.160.6.64 raeburn 15891: } elsif ($item eq 'canclone') {
15892: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15893: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15894: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
15895: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
15896: }
15897: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
15898: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
15899: } else {
15900: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
15901: }
1.140 raeburn 15902: }
1.121 raeburn 15903: }
15904: $resulttext .= '</ul>';
15905: } else {
15906: $resulttext = &mt('No changes made to course defaults');
15907: }
15908: } else {
15909: $resulttext = '<span class="LC_error">'.
15910: &mt('An error occurred: [_1]',$putresult).'</span>';
15911: }
15912: return $resulttext;
15913: }
15914:
1.160.6.37 raeburn 15915: sub modify_selfenrollment {
15916: my ($dom,$lastactref,%domconfig) = @_;
15917: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
15918: my @types = ('official','unofficial','community','textbook');
15919: my %titles = &tool_titles();
15920: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
15921: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
15922: $ordered{'default'} = ['types','registered','approval','limit'];
15923:
15924: my (%roles,%shown,%toplevel);
15925: $roles{'0'} = &Apache::lonnet::plaintext('dc');
15926:
15927: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
15928: if ($domconfig{'selfenrollment'} eq '') {
15929: $domconfig{'selfenrollment'} = {};
15930: }
15931: }
15932: %toplevel = (
15933: admin => 'Configuration Rights',
15934: default => 'Default settings',
15935: validation => 'Validation of self-enrollment requests',
15936: );
15937: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
15938:
15939: if (ref($ordered{'admin'}) eq 'ARRAY') {
15940: foreach my $item (@{$ordered{'admin'}}) {
15941: foreach my $type (@types) {
15942: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
15943: $selfenrollhash{'admin'}{$type}{$item} = 1;
15944: } else {
15945: $selfenrollhash{'admin'}{$type}{$item} = 0;
15946: }
15947: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
15948: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
15949: if ($selfenrollhash{'admin'}{$type}{$item} ne
15950: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
15951: push(@{$changes{'admin'}{$type}},$item);
15952: }
15953: } else {
15954: if (!$selfenrollhash{'admin'}{$type}{$item}) {
15955: push(@{$changes{'admin'}{$type}},$item);
15956: }
15957: }
15958: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
15959: push(@{$changes{'admin'}{$type}},$item);
15960: }
15961: }
15962: }
15963: }
15964:
15965: foreach my $item (@{$ordered{'default'}}) {
15966: foreach my $type (@types) {
15967: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
15968: if ($item eq 'types') {
15969: unless (($value eq 'all') || ($value eq 'dom')) {
15970: $value = '';
15971: }
15972: } elsif ($item eq 'registered') {
15973: unless ($value eq '1') {
15974: $value = 0;
15975: }
15976: } elsif ($item eq 'approval') {
15977: unless ($value =~ /^[012]$/) {
15978: $value = 0;
15979: }
15980: } else {
15981: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15982: $value = 'none';
15983: }
15984: }
15985: $selfenrollhash{'default'}{$type}{$item} = $value;
15986: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
15987: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15988: if ($selfenrollhash{'default'}{$type}{$item} ne
15989: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
15990: push(@{$changes{'default'}{$type}},$item);
15991: }
15992: } else {
15993: push(@{$changes{'default'}{$type}},$item);
15994: }
15995: } else {
15996: push(@{$changes{'default'}{$type}},$item);
15997: }
15998: if ($item eq 'limit') {
15999: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
16000: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
16001: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
16002: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
16003: }
16004: } else {
16005: $selfenrollhash{'default'}{$type}{'cap'} = '';
16006: }
16007: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
16008: if ($selfenrollhash{'default'}{$type}{'cap'} ne
16009: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
16010: push(@{$changes{'default'}{$type}},'cap');
16011: }
16012: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
16013: push(@{$changes{'default'}{$type}},'cap');
16014: }
16015: }
16016: }
16017: }
16018:
16019: foreach my $item (@{$itemsref}) {
16020: if ($item eq 'fields') {
16021: my @changed;
16022: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
16023: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
16024: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
16025: }
16026: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
16027: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
16028: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
16029: $domconfig{'selfenrollment'}{'validation'}{$item});
16030: } else {
16031: @changed = @{$selfenrollhash{'validation'}{$item}};
16032: }
16033: } else {
16034: @changed = @{$selfenrollhash{'validation'}{$item}};
16035: }
16036: if (@changed) {
16037: if ($selfenrollhash{'validation'}{$item}) {
16038: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
16039: } else {
16040: $changes{'validation'}{$item} = &mt('None');
16041: }
16042: }
16043: } else {
16044: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
16045: if ($item eq 'markup') {
16046: if ($env{'form.selfenroll_validation_'.$item}) {
16047: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
16048: }
16049: }
16050: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
16051: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
16052: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
16053: }
16054: }
16055: }
16056: }
16057:
16058: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
16059: $dom);
16060: if ($putresult eq 'ok') {
16061: if (keys(%changes) > 0) {
16062: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16063: $resulttext = &mt('Changes made:').'<ul>';
16064: foreach my $key ('admin','default','validation') {
16065: if (ref($changes{$key}) eq 'HASH') {
16066: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
16067: if ($key eq 'validation') {
16068: foreach my $item (@{$itemsref}) {
16069: if (exists($changes{$key}{$item})) {
16070: if ($item eq 'markup') {
16071: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
16072: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
16073: } else {
16074: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
16075: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
16076: }
16077: }
16078: }
16079: } else {
16080: foreach my $type (@types) {
16081: if ($type eq 'community') {
16082: $roles{'1'} = &mt('Community personnel');
16083: } else {
16084: $roles{'1'} = &mt('Course personnel');
16085: }
16086: if (ref($changes{$key}{$type}) eq 'ARRAY') {
16087: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
16088: if ($key eq 'admin') {
16089: my @mgrdc = ();
16090: if (ref($ordered{$key}) eq 'ARRAY') {
16091: foreach my $item (@{$ordered{'admin'}}) {
16092: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
16093: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
16094: push(@mgrdc,$item);
16095: }
16096: }
16097: }
16098: if (@mgrdc) {
16099: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
16100: } else {
16101: delete($domdefaults{$type.'selfenrolladmdc'});
16102: }
16103: }
16104: } else {
16105: if (ref($ordered{$key}) eq 'ARRAY') {
16106: foreach my $item (@{$ordered{$key}}) {
16107: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
16108: $domdefaults{$type.'selfenroll'.$item} =
16109: $selfenrollhash{$key}{$type}{$item};
16110: }
16111: }
16112: }
16113: }
16114: }
16115: $resulttext .= '<li>'.$titles{$type}.'<ul>';
16116: foreach my $item (@{$ordered{$key}}) {
16117: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
16118: $resulttext .= '<li>';
16119: if ($key eq 'admin') {
16120: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
16121: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
16122: } else {
16123: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
16124: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
16125: }
16126: $resulttext .= '</li>';
16127: }
16128: }
16129: $resulttext .= '</ul></li>';
16130: }
16131: }
16132: $resulttext .= '</ul></li>';
16133: }
16134: }
1.160.6.93 raeburn 16135: }
16136: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
16137: my $cachetime = 24*60*60;
16138: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16139: if (ref($lastactref) eq 'HASH') {
16140: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 16141: }
16142: }
16143: $resulttext .= '</ul>';
16144: } else {
16145: $resulttext = &mt('No changes made to self-enrollment settings');
16146: }
16147: } else {
16148: $resulttext = '<span class="LC_error">'.
16149: &mt('An error occurred: [_1]',$putresult).'</span>';
16150: }
16151: return $resulttext;
16152: }
16153:
1.160.6.113 raeburn 16154: sub modify_wafproxy {
16155: my ($dom,$action,$lastactref,%domconfig) = @_;
16156: my %servers = &Apache::lonnet::internet_dom_servers($dom);
16157: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
16158: %wafproxy,%changes,%expirecache,%expiresaml);
16159: foreach my $server (sort(keys(%servers))) {
16160: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
16161: if ($serverhome eq $server) {
16162: my $serverdom = &Apache::lonnet::host_domain($server);
16163: if ($serverdom eq $dom) {
16164: $canset{$server} = 1;
16165: }
16166: }
16167: }
16168: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
16169: %{$values{$dom}} = ();
16170: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
16171: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
16172: }
16173: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
16174: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
16175: }
16176: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
16177: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
16178: }
16179: }
16180: my $output;
16181: if (keys(%canset)) {
16182: %{$wafproxy{'alias'}} = ();
16183: %{$wafproxy{'saml'}} = ();
16184: foreach my $key (sort(keys(%canset))) {
16185: if ($env{'form.wafproxy_'.$dom}) {
16186: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
16187: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
16188: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
16189: $changes{'alias'} = 1;
16190: }
16191: if ($env{'form.wafproxy_alias_saml_'.$key}) {
16192: $wafproxy{'saml'}{$key} = 1;
16193: }
16194: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
16195: $changes{'saml'} = 1;
16196: }
16197: } else {
16198: $wafproxy{'alias'}{$key} = '';
16199: $wafproxy{'saml'}{$key} = '';
16200: if ($curralias{$key}) {
16201: $changes{'alias'} = 1;
16202: }
16203: if ($currsaml{$key}) {
16204: $changes{'saml'} = 1;
16205: }
16206: }
16207: if ($wafproxy{'alias'}{$key} eq '') {
16208: if ($curralias{$key}) {
16209: $expirecache{$key} = 1;
16210: }
16211: delete($wafproxy{'alias'}{$key});
16212: }
16213: if ($wafproxy{'saml'}{$key} eq '') {
16214: if ($currsaml{$key}) {
16215: $expiresaml{$key} = 1;
16216: }
16217: delete($wafproxy{'saml'}{$key});
16218: }
16219: }
16220: unless (keys(%{$wafproxy{'alias'}})) {
16221: delete($wafproxy{'alias'});
16222: }
16223: unless (keys(%{$wafproxy{'saml'}})) {
16224: delete($wafproxy{'saml'});
16225: }
16226: # Localization for values in %warn occurs in &mt() calls separately.
16227: my %warn = (
16228: trusted => 'trusted IP range(s)',
16229: vpnint => 'internal IP range(s) for VPN sessions(s)',
16230: vpnext => 'IP range(s) for backend WAF connections',
16231: );
16232: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
16233: my $possible = $env{'form.wafproxy_'.$item};
16234: $possible =~ s/^\s+|\s+$//g;
16235: if ($possible ne '') {
16236: if ($item eq 'remoteip') {
16237: if ($possible =~ /^[mhn]$/) {
16238: $wafproxy{$item} = $possible;
16239: }
16240: } elsif ($item eq 'ipheader') {
16241: if ($wafproxy{'remoteip'} eq 'h') {
16242: $wafproxy{$item} = $possible;
16243: }
16244: } elsif ($item eq 'sslopt') {
16245: if ($possible =~ /^0|1$/) {
16246: $wafproxy{$item} = $possible;
16247: }
16248: } else {
16249: my (@ok,$count);
16250: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
16251: unless ($env{'form.wafproxy_vpnaccess'}) {
16252: $possible = '';
16253: }
16254: } elsif ($item eq 'trusted') {
16255: unless ($wafproxy{'remoteip'} eq 'h') {
16256: $possible = '';
16257: }
16258: }
16259: unless ($possible eq '') {
16260: $possible =~ s/[\r\n]+/\s/g;
16261: $possible =~ s/\s*-\s*/-/g;
16262: $possible =~ s/\s+/,/g;
16263: $possible =~ s/,+/,/g;
16264: }
16265: $count = 0;
16266: if ($possible ne '') {
16267: foreach my $poss (split(/\,/,$possible)) {
16268: $count ++;
16269: $poss = &validate_ip_pattern($poss);
16270: if ($poss ne '') {
16271: push(@ok,$poss);
16272: }
16273: }
16274: my $diff = $count - scalar(@ok);
16275: if ($diff) {
16276: push(@warnings,'<li>'.
16277: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
16278: $diff,$warn{$item}).
16279: '</li>');
16280: }
16281: if (@ok) {
16282: my @cidr_list;
16283: foreach my $item (@ok) {
16284: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
16285: }
16286: $wafproxy{$item} = join(',',@cidr_list);
16287: }
16288: }
16289: }
16290: if ($wafproxy{$item} ne $currvalue{$item}) {
16291: $changes{$item} = 1;
16292: }
16293: } elsif ($currvalue{$item}) {
16294: $changes{$item} = 1;
16295: }
16296: }
16297: } else {
16298: if (keys(%curralias)) {
16299: $changes{'alias'} = 1;
16300: }
16301: if (keys(%currsaml)) {
16302: $changes{'saml'} = 1;
16303: }
16304: if (keys(%currvalue)) {
16305: foreach my $key (keys(%currvalue)) {
16306: $changes{$key} = 1;
16307: }
16308: }
16309: }
16310: if (keys(%changes)) {
16311: my %defaultshash = (
16312: wafproxy => \%wafproxy,
16313: );
16314: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16315: $dom);
16316: if ($putresult eq 'ok') {
16317: my $cachetime = 24*60*60;
16318: my (%domdefaults,$updatedomdefs);
16319: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
16320: if ($changes{$item}) {
16321: unless ($updatedomdefs) {
16322: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
16323: $updatedomdefs = 1;
16324: }
16325: if ($wafproxy{$item}) {
16326: $domdefaults{'waf_'.$item} = $wafproxy{$item};
16327: } elsif (exists($domdefaults{'waf_'.$item})) {
16328: delete($domdefaults{'waf_'.$item});
16329: }
16330: }
16331: }
16332: if ($updatedomdefs) {
16333: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16334: if (ref($lastactref) eq 'HASH') {
16335: $lastactref->{'domdefaults'} = 1;
16336: }
16337: }
16338: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
16339: my %updates = %expirecache;
16340: foreach my $key (keys(%expirecache)) {
16341: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
16342: }
16343: if (ref($wafproxy{'alias'}) eq 'HASH') {
16344: my $cachetime = 24*60*60;
16345: foreach my $key (keys(%{$wafproxy{'alias'}})) {
16346: $updates{$key} = 1;
16347: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
16348: $cachetime);
16349: }
16350: }
16351: if (ref($lastactref) eq 'HASH') {
16352: $lastactref->{'proxyalias'} = \%updates;
16353: }
16354: }
16355: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
16356: my %samlupdates = %expiresaml;
16357: foreach my $key (keys(%expiresaml)) {
16358: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
16359: }
16360: if (ref($wafproxy{'saml'}) eq 'HASH') {
16361: my $cachetime = 24*60*60;
16362: foreach my $key (keys(%{$wafproxy{'saml'}})) {
16363: $samlupdates{$key} = 1;
16364: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
16365: $cachetime);
16366: }
16367: }
16368: if (ref($lastactref) eq 'HASH') {
16369: $lastactref->{'proxysaml'} = \%samlupdates;
16370: }
16371: }
16372: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
16373: foreach my $item ('alias','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
16374: if ($changes{$item}) {
16375: if ($item eq 'alias') {
16376: my $numaliased = 0;
16377: if (ref($wafproxy{'alias'}) eq 'HASH') {
16378: my $shown;
16379: if (keys(%{$wafproxy{'alias'}})) {
16380: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
16381: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
16382: &Apache::lonnet::hostname($server),
16383: $wafproxy{'alias'}{$server}).'</li>';
16384: $numaliased ++;
16385: }
16386: if ($numaliased) {
16387: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
16388: '<ul>'.$shown.'</ul>').'</li>';
16389: }
16390: }
16391: }
16392: unless ($numaliased) {
16393: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
16394: }
16395: } elsif ($item eq 'saml') {
16396: my $shown;
16397: if (ref($wafproxy{'saml'}) eq 'HASH') {
16398: if (keys(%{$wafproxy{'saml'}})) {
16399: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
16400: }
16401: }
16402: if ($shown) {
16403: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
16404: $shown).'</li>';
16405: } else {
16406: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
16407: }
16408: } else {
16409: if ($item eq 'remoteip') {
16410: my %ip_methods = &remoteip_methods();
16411: if ($wafproxy{$item} =~ /^[mh]$/) {
16412: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
16413: $ip_methods{$wafproxy{$item}}).'</li>';
16414: } else {
16415: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
16416: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
16417: '</li>';
16418: } else {
16419: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
16420: }
16421: }
16422: } elsif ($item eq 'ipheader') {
16423: if ($wafproxy{$item}) {
16424: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
16425: $wafproxy{$item}).'</li>';
16426: } else {
16427: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
16428: }
16429: } elsif ($item eq 'trusted') {
16430: if ($wafproxy{$item}) {
16431: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
16432: $wafproxy{$item}).'</li>';
16433: } else {
16434: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
16435: }
16436: } elsif ($item eq 'vpnint') {
16437: if ($wafproxy{$item}) {
16438: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
16439: $wafproxy{$item}).'</li>';
16440: } else {
16441: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
16442: }
16443: } elsif ($item eq 'vpnext') {
16444: if ($wafproxy{$item}) {
16445: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
16446: $wafproxy{$item}).'</li>';
16447: } else {
16448: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
16449: }
16450: } elsif ($item eq 'sslopt') {
16451: if ($wafproxy{$item}) {
16452: $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>';
16453: } else {
16454: $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>';
16455: }
16456: }
16457: }
16458: }
16459: }
16460: } else {
16461: $output = '<span class="LC_error">'.
16462: &mt('An error occurred: [_1]',$putresult).'</span>';
16463: }
16464: } elsif (keys(%canset)) {
16465: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
16466: }
16467: if (@warnings) {
16468: $output .= '<br />'.&mt('Warnings:').'<ul>'.
16469: join("\n",@warnings).'</ul>';
16470: }
16471: return $output;
16472: }
16473:
16474: sub validate_ip_pattern {
16475: my ($pattern) = @_;
16476: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
16477: my ($start,$end) = ($1,$2);
16478: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
16479: if (($start !~ m{/}) && ($end !~ m{/})) {
16480: return $start.'-'.$end;
16481: }
16482: }
16483: } elsif ($pattern ne '') {
16484: $pattern = &Net::CIDR::cidrvalidate($pattern);
16485: if ($pattern ne '') {
16486: return $pattern;
16487: }
16488: }
16489: return;
16490: }
16491:
1.137 raeburn 16492: sub modify_usersessions {
1.160.6.27 raeburn 16493: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 16494: my @hostingtypes = ('version','excludedomain','includedomain');
16495: my @offloadtypes = ('primary','default');
16496: my %types = (
16497: remote => \@hostingtypes,
16498: hosted => \@hostingtypes,
16499: spares => \@offloadtypes,
16500: );
16501: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 16502: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 16503: my (%by_ip,%by_location,@intdoms);
16504: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
16505: my @locations = sort(keys(%by_location));
1.137 raeburn 16506: my (%defaultshash,%changes);
16507: foreach my $prefix (@prefixes) {
16508: $defaultshash{'usersessions'}{$prefix} = {};
16509: }
1.160.6.27 raeburn 16510: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 16511: my $resulttext;
1.138 raeburn 16512: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 16513: foreach my $prefix (@prefixes) {
1.145 raeburn 16514: next if ($prefix eq 'spares');
16515: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 16516: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16517: if ($type eq 'version') {
16518: my $value = $env{'form.'.$prefix.'_'.$type};
16519: my $okvalue;
16520: if ($value ne '') {
16521: if (grep(/^\Q$value\E$/,@lcversions)) {
16522: $okvalue = $value;
16523: }
16524: }
16525: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16526: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16527: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
16528: if ($inuse == 0) {
16529: $changes{$prefix}{$type} = 1;
16530: } else {
16531: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
16532: $changes{$prefix}{$type} = 1;
16533: }
16534: if ($okvalue ne '') {
16535: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16536: }
16537: }
16538: } else {
16539: if (($inuse == 1) && ($okvalue ne '')) {
16540: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16541: $changes{$prefix}{$type} = 1;
16542: }
16543: }
16544: } else {
16545: if (($inuse == 1) && ($okvalue ne '')) {
16546: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16547: $changes{$prefix}{$type} = 1;
16548: }
16549: }
16550: } else {
16551: if (($inuse == 1) && ($okvalue ne '')) {
16552: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16553: $changes{$prefix}{$type} = 1;
16554: }
16555: }
16556: } else {
16557: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16558: my @okvals;
16559: foreach my $val (@vals) {
1.138 raeburn 16560: if ($val =~ /:/) {
16561: my @items = split(/:/,$val);
16562: foreach my $item (@items) {
16563: if (ref($by_location{$item}) eq 'ARRAY') {
16564: push(@okvals,$item);
16565: }
16566: }
16567: } else {
16568: if (ref($by_location{$val}) eq 'ARRAY') {
16569: push(@okvals,$val);
16570: }
1.137 raeburn 16571: }
16572: }
16573: @okvals = sort(@okvals);
16574: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16575: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16576: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16577: if ($inuse == 0) {
16578: $changes{$prefix}{$type} = 1;
16579: } else {
16580: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16581: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
16582: if (@changed > 0) {
16583: $changes{$prefix}{$type} = 1;
16584: }
16585: }
16586: } else {
16587: if ($inuse == 1) {
16588: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16589: $changes{$prefix}{$type} = 1;
16590: }
16591: }
16592: } else {
16593: if ($inuse == 1) {
16594: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16595: $changes{$prefix}{$type} = 1;
16596: }
16597: }
16598: } else {
16599: if ($inuse == 1) {
16600: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16601: $changes{$prefix}{$type} = 1;
16602: }
16603: }
16604: }
16605: }
16606: }
1.145 raeburn 16607:
16608: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 16609: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 16610: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
16611: my $savespares;
16612:
16613: foreach my $lonhost (sort(keys(%servers))) {
16614: my $serverhomeID =
16615: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 16616: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 16617: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
16618: my %spareschg;
16619: foreach my $type (@{$types{'spares'}}) {
16620: my @okspares;
16621: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
16622: foreach my $server (@checked) {
1.152 raeburn 16623: if (&Apache::lonnet::hostname($server) ne '') {
16624: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
16625: unless (grep(/^\Q$server\E$/,@okspares)) {
16626: push(@okspares,$server);
16627: }
1.145 raeburn 16628: }
16629: }
16630: }
16631: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
16632: my $newspare;
1.152 raeburn 16633: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
16634: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 16635: $newspare = $new;
16636: }
16637: }
1.152 raeburn 16638: my @spares;
16639: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
16640: @spares = sort(@okspares,$newspare);
16641: } else {
16642: @spares = sort(@okspares);
16643: }
16644: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 16645: if (ref($spareid{$lonhost}) eq 'HASH') {
16646: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 16647: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 16648: if (@diffs > 0) {
16649: $spareschg{$type} = 1;
16650: }
16651: }
16652: }
16653: }
16654: if (keys(%spareschg) > 0) {
16655: $changes{'spares'}{$lonhost} = \%spareschg;
16656: }
16657: }
1.160.6.61 raeburn 16658: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.160.6.105 raeburn 16659: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.160.6.61 raeburn 16660: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
16661: my @okoffload;
16662: if (@offloadnow) {
16663: foreach my $server (@offloadnow) {
16664: if (&Apache::lonnet::hostname($server) ne '') {
16665: unless (grep(/^\Q$server\E$/,@okoffload)) {
16666: push(@okoffload,$server);
16667: }
16668: }
16669: }
16670: if (@okoffload) {
16671: foreach my $lonhost (@okoffload) {
16672: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
16673: }
16674: }
16675: }
1.160.6.105 raeburn 16676: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
16677: my @okoffloadoth;
16678: if (@offloadoth) {
16679: foreach my $server (@offloadoth) {
16680: if (&Apache::lonnet::hostname($server) ne '') {
16681: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
16682: push(@okoffloadoth,$server);
16683: }
16684: }
16685: }
16686: if (@okoffloadoth) {
16687: foreach my $lonhost (@okoffloadoth) {
16688: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
16689: }
16690: }
16691: }
1.145 raeburn 16692: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16693: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
16694: if (ref($changes{'spares'}) eq 'HASH') {
16695: if (keys(%{$changes{'spares'}}) > 0) {
16696: $savespares = 1;
16697: }
16698: }
16699: } else {
16700: $savespares = 1;
16701: }
1.160.6.105 raeburn 16702: foreach my $offload ('offloadnow','offloadoth') {
16703: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
16704: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
16705: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
16706: $changes{$offload} = 1;
1.160.6.61 raeburn 16707: last;
16708: }
16709: }
1.160.6.105 raeburn 16710: unless ($changes{$offload}) {
16711: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
16712: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
16713: $changes{$offload} = 1;
16714: last;
16715: }
16716: }
16717: }
16718: } else {
16719: if (($offload eq 'offloadnow') && (@okoffload)) {
16720: $changes{'offloadnow'} = 1;
16721: }
16722: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
16723: $changes{'offloadoth'} = 1;
16724: }
1.160.6.61 raeburn 16725: }
1.160.6.105 raeburn 16726: }
16727: } else {
16728: if (@okoffload) {
1.160.6.61 raeburn 16729: $changes{'offloadnow'} = 1;
16730: }
1.160.6.105 raeburn 16731: if (@okoffloadoth) {
16732: $changes{'offloadoth'} = 1;
16733: }
1.145 raeburn 16734: }
1.147 raeburn 16735: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
16736: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 16737: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16738: $dom);
16739: if ($putresult eq 'ok') {
16740: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16741: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
16742: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
16743: }
16744: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
16745: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
16746: }
1.160.6.61 raeburn 16747: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16748: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
16749: }
1.160.6.105 raeburn 16750: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
16751: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
16752: }
1.137 raeburn 16753: }
16754: my $cachetime = 24*60*60;
16755: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 16756: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 16757: if (ref($lastactref) eq 'HASH') {
16758: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 16759: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 16760: }
1.147 raeburn 16761: if (keys(%changes) > 0) {
16762: my %lt = &usersession_titles();
16763: $resulttext = &mt('Changes made:').'<ul>';
16764: foreach my $prefix (@prefixes) {
16765: if (ref($changes{$prefix}) eq 'HASH') {
16766: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16767: if ($prefix eq 'spares') {
16768: if (ref($changes{$prefix}) eq 'HASH') {
16769: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
16770: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 16771: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 16772: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
16773: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 16774: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
16775: foreach my $type (@{$types{$prefix}}) {
16776: if ($changes{$prefix}{$lonhost}{$type}) {
16777: my $offloadto = &mt('None');
16778: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
16779: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
16780: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
16781: }
1.145 raeburn 16782: }
1.147 raeburn 16783: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 16784: }
1.137 raeburn 16785: }
16786: }
1.147 raeburn 16787: $resulttext .= '</li>';
1.137 raeburn 16788: }
16789: }
1.147 raeburn 16790: } else {
16791: foreach my $type (@{$types{$prefix}}) {
16792: if (defined($changes{$prefix}{$type})) {
16793: my $newvalue;
16794: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16795: if (ref($defaultshash{'usersessions'}{$prefix})) {
16796: if ($type eq 'version') {
16797: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
16798: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16799: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
16800: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
16801: }
1.145 raeburn 16802: }
16803: }
16804: }
1.147 raeburn 16805: if ($newvalue eq '') {
16806: if ($type eq 'version') {
16807: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
16808: } else {
16809: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16810: }
1.145 raeburn 16811: } else {
1.147 raeburn 16812: if ($type eq 'version') {
16813: $newvalue .= ' '.&mt('(or later)');
16814: }
16815: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 16816: }
1.137 raeburn 16817: }
16818: }
16819: }
1.147 raeburn 16820: $resulttext .= '</ul>';
1.137 raeburn 16821: }
16822: }
1.160.6.61 raeburn 16823: if ($changes{'offloadnow'}) {
16824: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16825: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.160.6.105 raeburn 16826: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.160.6.61 raeburn 16827: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
16828: $resulttext .= '<li>'.$lonhost.'</li>';
16829: }
16830: $resulttext .= '</ul>';
16831: } else {
1.160.6.105 raeburn 16832: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
16833: }
16834: } else {
16835: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
16836: }
16837: }
16838: if ($changes{'offloadoth'}) {
16839: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
16840: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
16841: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
16842: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
16843: $resulttext .= '<li>'.$lonhost.'</li>';
16844: }
16845: $resulttext .= '</ul>';
16846: } else {
16847: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.160.6.61 raeburn 16848: }
16849: } else {
1.160.6.105 raeburn 16850: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.160.6.61 raeburn 16851: }
16852: }
1.147 raeburn 16853: $resulttext .= '</ul>';
16854: } else {
16855: $resulttext = $nochgmsg;
1.137 raeburn 16856: }
16857: } else {
16858: $resulttext = '<span class="LC_error">'.
16859: &mt('An error occurred: [_1]',$putresult).'</span>';
16860: }
16861: } else {
1.147 raeburn 16862: $resulttext = $nochgmsg;
1.137 raeburn 16863: }
16864: return $resulttext;
16865: }
16866:
1.150 raeburn 16867: sub modify_loadbalancing {
16868: my ($dom,%domconfig) = @_;
16869: my $primary_id = &Apache::lonnet::domain($dom,'primary');
16870: my $intdom = &Apache::lonnet::internet_dom($primary_id);
16871: my ($othertitle,$usertypes,$types) =
16872: &Apache::loncommon::sorted_inst_types($dom);
16873: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 16874: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 16875: my @sparestypes = ('primary','default');
16876: my %typetitles = &sparestype_titles();
16877: my $resulttext;
1.160.6.94 raeburn 16878: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 16879: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16880: %existing = %{$domconfig{'loadbalancing'}};
16881: }
16882: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 16883: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 16884: my ($saveloadbalancing,%defaultshash,%changes);
16885: my ($alltypes,$othertypes,$titles) =
16886: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
16887: my %ruletitles = &offloadtype_text();
16888: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
16889: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
16890: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
16891: if ($balancer eq '') {
16892: next;
16893: }
16894: if (!exists($servers{$balancer})) {
16895: if (exists($currbalancer{$balancer})) {
16896: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 16897: }
1.160.6.7 raeburn 16898: next;
16899: }
16900: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
16901: push(@{$changes{'delete'}},$balancer);
16902: next;
16903: }
16904: if (!exists($currbalancer{$balancer})) {
16905: push(@{$changes{'add'}},$balancer);
16906: }
16907: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
16908: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
16909: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
16910: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16911: $saveloadbalancing = 1;
16912: }
16913: foreach my $sparetype (@sparestypes) {
16914: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
16915: my @offloadto;
16916: foreach my $target (@targets) {
16917: if (($servers{$target}) && ($target ne $balancer)) {
16918: if ($sparetype eq 'default') {
16919: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
16920: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 16921: }
16922: }
1.160.6.7 raeburn 16923: unless(grep(/^\Q$target\E$/,@offloadto)) {
16924: push(@offloadto,$target);
16925: }
1.150 raeburn 16926: }
16927: }
1.160.6.76 raeburn 16928: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
16929: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
16930: push(@offloadto,$balancer);
16931: }
16932: }
16933: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 16934: }
1.160.6.94 raeburn 16935: if ($env{'form.loadbalancing_cookie_'.$i}) {
16936: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
16937: if (exists($currbalancer{$balancer})) {
16938: unless ($currcookies{$balancer}) {
16939: $changes{'curr'}{$balancer}{'cookie'} = 1;
16940: }
16941: }
16942: } elsif (exists($currbalancer{$balancer})) {
16943: if ($currcookies{$balancer}) {
16944: $changes{'curr'}{$balancer}{'cookie'} = 1;
16945: }
16946: }
1.160.6.7 raeburn 16947: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 16948: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 16949: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
16950: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 16951: if (@targetdiffs > 0) {
1.160.6.7 raeburn 16952: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16953: }
1.160.6.7 raeburn 16954: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16955: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16956: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16957: }
16958: }
16959: }
16960: } else {
1.160.6.7 raeburn 16961: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
16962: foreach my $sparetype (@sparestypes) {
16963: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16964: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16965: $changes{'curr'}{$balancer}{'targets'} = 1;
16966: }
1.150 raeburn 16967: }
16968: }
1.160.6.7 raeburn 16969: }
1.150 raeburn 16970: }
16971: my $ishomedom;
1.160.6.7 raeburn 16972: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
16973: $ishomedom = 1;
1.150 raeburn 16974: }
16975: if (ref($alltypes) eq 'ARRAY') {
16976: foreach my $type (@{$alltypes}) {
16977: my $rule;
1.160.6.7 raeburn 16978: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 16979: (!$ishomedom)) {
1.160.6.7 raeburn 16980: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
16981: }
16982: if ($rule eq 'specific') {
1.160.6.55 raeburn 16983: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
16984: if (exists($servers{$specifiedhost})) {
16985: $rule = $specifiedhost;
16986: }
1.150 raeburn 16987: }
1.160.6.7 raeburn 16988: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
16989: if (ref($currrules{$balancer}) eq 'HASH') {
16990: if ($rule ne $currrules{$balancer}{$type}) {
16991: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16992: }
16993: } elsif ($rule ne '') {
1.160.6.7 raeburn 16994: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16995: }
16996: }
16997: }
1.160.6.7 raeburn 16998: }
16999: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
17000: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
17001: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
17002: $defaultshash{'loadbalancing'} = {};
17003: }
17004: my $putresult = &Apache::lonnet::put_dom('configuration',
17005: \%defaultshash,$dom);
17006: if ($putresult eq 'ok') {
17007: if (keys(%changes) > 0) {
1.160.6.54 raeburn 17008: my %toupdate;
1.160.6.7 raeburn 17009: if (ref($changes{'delete'}) eq 'ARRAY') {
17010: foreach my $balancer (sort(@{$changes{'delete'}})) {
17011: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 17012: $toupdate{$balancer} = 1;
1.150 raeburn 17013: }
1.160.6.7 raeburn 17014: }
17015: if (ref($changes{'add'}) eq 'ARRAY') {
17016: foreach my $balancer (sort(@{$changes{'add'}})) {
17017: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 17018: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 17019: }
17020: }
17021: if (ref($changes{'curr'}) eq 'HASH') {
17022: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 17023: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 17024: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
17025: if ($changes{'curr'}{$balancer}{'targets'}) {
17026: my %offloadstr;
17027: foreach my $sparetype (@sparestypes) {
17028: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17029: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
17030: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
17031: }
17032: }
1.150 raeburn 17033: }
1.160.6.7 raeburn 17034: if (keys(%offloadstr) == 0) {
17035: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 17036: } else {
1.160.6.7 raeburn 17037: my $showoffload;
17038: foreach my $sparetype (@sparestypes) {
17039: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
17040: if (defined($offloadstr{$sparetype})) {
17041: $showoffload .= $offloadstr{$sparetype};
17042: } else {
17043: $showoffload .= &mt('None');
17044: }
17045: $showoffload .= (' 'x3);
17046: }
17047: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 17048: }
17049: }
17050: }
1.160.6.7 raeburn 17051: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
17052: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
17053: foreach my $type (@{$alltypes}) {
17054: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
17055: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
17056: my $balancetext;
17057: if ($rule eq '') {
17058: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 17059: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 17060: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
17061: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 17062: foreach my $sparetype (@sparestypes) {
17063: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17064: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
17065: }
17066: }
1.160.6.55 raeburn 17067: foreach my $item (@{$alltypes}) {
17068: next if ($item =~ /^_LC_ipchange/);
17069: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
17070: if ($hasrule eq 'homeserver') {
17071: map { $toupdate{$_} = 1; } (keys(%libraryservers));
17072: } else {
17073: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
17074: if ($servers{$hasrule}) {
17075: $toupdate{$hasrule} = 1;
17076: }
17077: }
17078: }
17079: }
17080: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
17081: $balancetext = $ruletitles{$rule};
17082: } else {
17083: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
17084: $balancetext = $ruletitles{'particular'}.' '.$receiver;
17085: if ($receiver) {
17086: $toupdate{$receiver};
17087: }
17088: }
17089: } else {
17090: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 17091: }
1.160.6.7 raeburn 17092: } else {
17093: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
17094: }
1.160.6.26 raeburn 17095: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 17096: }
17097: }
17098: }
17099: }
1.160.6.94 raeburn 17100: if ($changes{'curr'}{$balancer}{'cookie'}) {
17101: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
17102: $balancer).'</li>';
17103: }
1.160.6.106 raeburn 17104: }
17105: }
17106: if (keys(%toupdate)) {
17107: my %thismachine;
17108: my $updatedhere;
17109: my $cachetime = 60*60*24;
17110: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
17111: foreach my $lonhost (keys(%toupdate)) {
17112: if ($thismachine{$lonhost}) {
17113: unless ($updatedhere) {
17114: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
17115: $defaultshash{'loadbalancing'},
17116: $cachetime);
17117: $updatedhere = 1;
1.160.6.54 raeburn 17118: }
1.160.6.106 raeburn 17119: } else {
17120: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
17121: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.160.6.54 raeburn 17122: }
1.150 raeburn 17123: }
1.160.6.7 raeburn 17124: }
17125: if ($resulttext ne '') {
17126: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 17127: } else {
17128: $resulttext = $nochgmsg;
17129: }
17130: } else {
1.160.6.7 raeburn 17131: $resulttext = $nochgmsg;
1.150 raeburn 17132: }
17133: } else {
1.160.6.7 raeburn 17134: $resulttext = '<span class="LC_error">'.
17135: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 17136: }
17137: } else {
1.160.6.7 raeburn 17138: $resulttext = $nochgmsg;
1.150 raeburn 17139: }
17140: return $resulttext;
17141: }
17142:
1.48 raeburn 17143: sub recurse_check {
17144: my ($chkcats,$categories,$depth,$name) = @_;
17145: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
17146: my $chg = 0;
17147: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
17148: my $category = $chkcats->[$depth]{$name}[$j];
17149: my $item;
17150: if ($category eq '') {
17151: $chg ++;
17152: } else {
17153: my $deeper = $depth + 1;
17154: $item = &escape($category).':'.&escape($name).':'.$depth;
17155: if ($chg) {
17156: $categories->{$item} -= $chg;
17157: }
17158: &recurse_check($chkcats,$categories,$deeper,$category);
17159: $deeper --;
17160: }
17161: }
17162: }
17163: return;
17164: }
17165:
17166: sub recurse_cat_deletes {
17167: my ($item,$coursecategories,$deletions) = @_;
17168: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
17169: my $subdepth = $depth + 1;
17170: if (ref($coursecategories) eq 'HASH') {
17171: foreach my $subitem (keys(%{$coursecategories})) {
17172: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
17173: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
17174: delete($coursecategories->{$subitem});
17175: $deletions->{$subitem} = 1;
17176: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 17177: }
1.48 raeburn 17178: }
17179: }
17180: return;
17181: }
17182:
1.125 raeburn 17183: sub active_dc_picker {
1.160.6.16 raeburn 17184: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 17185: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 17186: my @domcoord = keys(%domcoords);
17187: if (keys(%currhash)) {
17188: foreach my $dc (keys(%currhash)) {
17189: unless (exists($domcoords{$dc})) {
17190: push(@domcoord,$dc);
17191: }
17192: }
17193: }
17194: @domcoord = sort(@domcoord);
17195: my $numdcs = scalar(@domcoord);
17196: my $rows = 0;
17197: my $table;
1.125 raeburn 17198: if ($numdcs > 1) {
1.160.6.16 raeburn 17199: $table = '<table>';
17200: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 17201: my $rem = $i%($numinrow);
17202: if ($rem == 0) {
17203: if ($i > 0) {
1.160.6.16 raeburn 17204: $table .= '</tr>';
1.125 raeburn 17205: }
1.160.6.16 raeburn 17206: $table .= '<tr>';
17207: $rows ++;
1.125 raeburn 17208: }
1.160.6.16 raeburn 17209: my $check = '';
17210: if ($inputtype eq 'radio') {
17211: if (keys(%currhash) == 0) {
17212: if (!$i) {
17213: $check = ' checked="checked"';
17214: }
17215: } elsif (exists($currhash{$domcoord[$i]})) {
17216: $check = ' checked="checked"';
17217: }
17218: } else {
17219: if (exists($currhash{$domcoord[$i]})) {
17220: $check = ' checked="checked"';
1.125 raeburn 17221: }
17222: }
1.160.6.16 raeburn 17223: if ($i == @domcoord - 1) {
1.125 raeburn 17224: my $colsleft = $numinrow - $rem;
17225: if ($colsleft > 1) {
1.160.6.16 raeburn 17226: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 17227: } else {
1.160.6.16 raeburn 17228: $table .= '<td class="LC_left_item">';
1.125 raeburn 17229: }
17230: } else {
1.160.6.16 raeburn 17231: $table .= '<td class="LC_left_item">';
17232: }
17233: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
17234: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
17235: $table .= '<span class="LC_nobreak"><label>'.
17236: '<input type="'.$inputtype.'" name="'.$name.'"'.
17237: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
17238: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 17239: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 17240: }
1.160.6.33 raeburn 17241: $table .= '</label></span></td>';
1.125 raeburn 17242: }
1.160.6.16 raeburn 17243: $table .= '</tr></table>';
17244: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 17245: my ($dcname,$dcdom) = split(':',$domcoord[0]);
17246: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 17247: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 17248: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 17249: if ($user ne $dcname.':'.$dcdom) {
17250: $table .= ' ('.$dcname.':'.$dcdom.')';
17251: }
1.160.6.16 raeburn 17252: } else {
17253: my $check;
17254: if (exists($currhash{$domcoord[0]})) {
17255: $check = ' checked="checked"';
17256: }
1.160.6.50 raeburn 17257: $table = '<span class="LC_nobreak"><label>'.
17258: '<input type="checkbox" name="'.$name.'" '.
17259: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 17260: if ($user ne $dcname.':'.$dcdom) {
17261: $table .= ' ('.$dcname.':'.$dcdom.')';
17262: }
17263: $table .= '</label></span>';
1.160.6.16 raeburn 17264: $rows ++;
17265: }
1.125 raeburn 17266: }
1.160.6.16 raeburn 17267: return ($numdcs,$table,$rows);
1.125 raeburn 17268: }
17269:
1.137 raeburn 17270: sub usersession_titles {
17271: return &Apache::lonlocal::texthash(
17272: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
17273: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 17274: spares => 'Servers offloaded to, when busy',
1.137 raeburn 17275: version => 'LON-CAPA version requirement',
1.138 raeburn 17276: excludedomain => 'Allow all, but exclude specific domains',
17277: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 17278: primary => 'Primary (checked first)',
1.154 raeburn 17279: default => 'Default',
1.137 raeburn 17280: );
17281: }
17282:
1.152 raeburn 17283: sub id_for_thisdom {
17284: my (%servers) = @_;
17285: my %altids;
17286: foreach my $server (keys(%servers)) {
17287: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
17288: if ($serverhome ne $server) {
17289: $altids{$serverhome} = $server;
17290: }
17291: }
17292: return %altids;
17293: }
17294:
1.150 raeburn 17295: sub count_servers {
17296: my ($currbalancer,%servers) = @_;
17297: my (@spares,$numspares);
17298: foreach my $lonhost (sort(keys(%servers))) {
17299: next if ($currbalancer eq $lonhost);
17300: push(@spares,$lonhost);
17301: }
17302: if ($currbalancer) {
17303: $numspares = scalar(@spares);
17304: } else {
17305: $numspares = scalar(@spares) - 1;
17306: }
17307: return ($numspares,@spares);
17308: }
17309:
17310: sub lonbalance_targets_js {
1.160.6.7 raeburn 17311: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 17312: my $select = &mt('Select');
17313: my ($alltargets,$allishome,$allinsttypes,@alltypes);
17314: if (ref($servers) eq 'HASH') {
17315: $alltargets = join("','",sort(keys(%{$servers})));
17316: my @homedoms;
17317: foreach my $server (sort(keys(%{$servers}))) {
17318: if (&Apache::lonnet::host_domain($server) eq $dom) {
17319: push(@homedoms,'1');
17320: } else {
17321: push(@homedoms,'0');
17322: }
17323: }
17324: $allishome = join("','",@homedoms);
17325: }
17326: if (ref($types) eq 'ARRAY') {
17327: if (@{$types} > 0) {
17328: @alltypes = @{$types};
17329: }
17330: }
17331: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
17332: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 17333: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 17334: if (ref($settings) eq 'HASH') {
17335: %existing = %{$settings};
17336: }
17337: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 17338: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 17339: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 17340: return <<"END";
17341:
17342: <script type="text/javascript">
17343: // <![CDATA[
17344:
1.160.6.7 raeburn 17345: currBalancers = new Array('$balancers');
17346:
17347: function toggleTargets(balnum) {
17348: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17349: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
17350: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
17351: var prevbalancer = prevhostitem.value;
17352: var baltotal = document.getElementById('loadbalancing_total').value;
17353: prevhostitem.value = balancer;
17354: if (prevbalancer != '') {
17355: var prevIdx = currBalancers.indexOf(prevbalancer);
17356: if (prevIdx != -1) {
17357: currBalancers.splice(prevIdx,1);
17358: }
17359: }
1.150 raeburn 17360: if (balancer == '') {
1.160.6.7 raeburn 17361: hideSpares(balnum);
1.150 raeburn 17362: } else {
1.160.6.7 raeburn 17363: var currIdx = currBalancers.indexOf(balancer);
17364: if (currIdx == -1) {
17365: currBalancers.push(balancer);
17366: }
1.150 raeburn 17367: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 17368: var ishomedom = homedoms[lonhostitem.selectedIndex];
17369: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 17370: }
1.160.6.7 raeburn 17371: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 17372: return;
17373: }
17374:
1.160.6.7 raeburn 17375: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 17376: var alltargets = new Array('$alltargets');
17377: var insttypes = new Array('$allinsttypes');
1.151 raeburn 17378: var offloadtypes = new Array('primary','default');
17379:
1.160.6.7 raeburn 17380: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
17381: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 17382:
1.151 raeburn 17383: for (var i=0; i<offloadtypes.length; i++) {
17384: var count = 0;
17385: for (var j=0; j<alltargets.length; j++) {
17386: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 17387: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
17388: item.value = alltargets[j];
17389: item.style.textAlign='left';
17390: item.style.textFace='normal';
17391: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
17392: if (currBalancers.indexOf(alltargets[j]) == -1) {
17393: item.disabled = '';
17394: } else {
17395: item.disabled = 'disabled';
17396: item.checked = false;
17397: }
1.151 raeburn 17398: count ++;
17399: }
1.150 raeburn 17400: }
17401: }
1.151 raeburn 17402: for (var k=0; k<insttypes.length; k++) {
17403: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 17404: if (ishomedom == 1) {
1.160.6.7 raeburn 17405: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17406: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17407: } else {
1.160.6.7 raeburn 17408: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17409: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 17410: }
17411: } else {
1.160.6.7 raeburn 17412: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17413: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17414: }
1.151 raeburn 17415: if ((insttypes[k] != '_LC_external') &&
17416: ((insttypes[k] != '_LC_internetdom') ||
17417: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 17418: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
17419: item.options.length = 0;
17420: item.options[0] = new Option("","",true,true);
17421: var idx = 0;
1.151 raeburn 17422: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 17423: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
17424: idx ++;
17425: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 17426: }
17427: }
17428: }
17429: }
17430: return;
17431: }
17432:
1.160.6.7 raeburn 17433: function hideSpares(balnum) {
1.150 raeburn 17434: var alltargets = new Array('$alltargets');
17435: var insttypes = new Array('$allinsttypes');
17436: var offloadtypes = new Array('primary','default');
17437:
1.160.6.7 raeburn 17438: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
17439: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 17440:
17441: var total = alltargets.length - 1;
17442: for (var i=0; i<offloadtypes; i++) {
17443: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 17444: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
17445: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
17446: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 17447: }
1.150 raeburn 17448: }
17449: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 17450: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17451: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 17452: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 17453: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
17454: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 17455: }
17456: }
17457: return;
17458: }
17459:
1.160.6.7 raeburn 17460: function checkOffloads(item,balnum,type) {
1.150 raeburn 17461: var alltargets = new Array('$alltargets');
17462: var offloadtypes = new Array('primary','default');
17463: if (item.checked) {
17464: var total = alltargets.length - 1;
17465: var other;
17466: if (type == offloadtypes[0]) {
1.151 raeburn 17467: other = offloadtypes[1];
1.150 raeburn 17468: } else {
1.151 raeburn 17469: other = offloadtypes[0];
1.150 raeburn 17470: }
17471: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 17472: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 17473: if (server == item.value) {
1.160.6.7 raeburn 17474: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
17475: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 17476: }
17477: }
17478: }
17479: }
17480: return;
17481: }
17482:
1.160.6.7 raeburn 17483: function singleServerToggle(balnum,type) {
17484: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 17485: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 17486: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
17487: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17488:
17489: } else {
1.160.6.7 raeburn 17490: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
17491: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 17492: }
17493: return;
17494: }
17495:
1.160.6.7 raeburn 17496: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 17497: if (type == '_LC_external') {
1.160.6.26 raeburn 17498: return;
1.150 raeburn 17499: }
1.160.6.7 raeburn 17500: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 17501: for (var i=0; i<typesRules.length; i++) {
17502: if (formname.elements[typesRules[i]].checked) {
17503: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 17504: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
17505: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17506: } else {
1.160.6.7 raeburn 17507: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
17508: }
17509: }
17510: }
17511: return;
17512: }
17513:
17514: function balancerDeleteChange(balnum) {
17515: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17516: var baltotal = document.getElementById('loadbalancing_total').value;
17517: var addtarget;
17518: var removetarget;
17519: var action = 'delete';
17520: if (document.getElementById('loadbalancing_delete_'+balnum)) {
17521: var lonhost = hostitem.value;
17522: var currIdx = currBalancers.indexOf(lonhost);
17523: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
17524: if (currIdx != -1) {
17525: currBalancers.splice(currIdx,1);
17526: }
17527: addtarget = lonhost;
17528: } else {
17529: if (currIdx == -1) {
17530: currBalancers.push(lonhost);
17531: }
17532: removetarget = lonhost;
17533: action = 'undelete';
17534: }
17535: balancerChange(balnum,baltotal,action,addtarget,removetarget);
17536: }
17537: return;
17538: }
17539:
17540: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
17541: if (baltotal > 1) {
17542: var offloadtypes = new Array('primary','default');
17543: var alltargets = new Array('$alltargets');
17544: var insttypes = new Array('$allinsttypes');
17545: for (var i=0; i<baltotal; i++) {
17546: if (i != balnum) {
17547: for (var j=0; j<offloadtypes.length; j++) {
17548: var total = alltargets.length - 1;
17549: for (var k=0; k<total; k++) {
17550: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
17551: var server = serveritem.value;
17552: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17553: if (server == addtarget) {
17554: serveritem.disabled = '';
17555: }
17556: }
17557: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17558: if (server == removetarget) {
17559: serveritem.disabled = 'disabled';
17560: serveritem.checked = false;
17561: }
17562: }
17563: }
17564: }
17565: for (var j=0; j<insttypes.length; j++) {
17566: if (insttypes[j] != '_LC_external') {
17567: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
17568: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
17569: var currSel = singleserver.selectedIndex;
17570: var currVal = singleserver.options[currSel].value;
17571: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17572: var numoptions = singleserver.options.length;
17573: var needsnew = 1;
17574: for (var k=0; k<numoptions; k++) {
17575: if (singleserver.options[k] == addtarget) {
17576: needsnew = 0;
17577: break;
17578: }
17579: }
17580: if (needsnew == 1) {
17581: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
17582: }
17583: }
17584: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17585: singleserver.options.length = 0;
17586: if ((currVal) && (currVal != removetarget)) {
17587: singleserver.options[0] = new Option("","",false,false);
17588: } else {
17589: singleserver.options[0] = new Option("","",true,true);
17590: }
17591: var idx = 0;
17592: for (var m=0; m<alltargets.length; m++) {
17593: if (currBalancers.indexOf(alltargets[m]) == -1) {
17594: idx ++;
17595: if (currVal == alltargets[m]) {
17596: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
17597: } else {
17598: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
17599: }
17600: }
17601: }
17602: }
17603: }
17604: }
17605: }
1.150 raeburn 17606: }
17607: }
17608: }
17609: return;
17610: }
17611:
1.152 raeburn 17612: // ]]>
17613: </script>
17614:
17615: END
17616: }
17617:
17618: sub new_spares_js {
17619: my @sparestypes = ('primary','default');
17620: my $types = join("','",@sparestypes);
17621: my $select = &mt('Select');
17622: return <<"END";
17623:
17624: <script type="text/javascript">
17625: // <![CDATA[
17626:
17627: function updateNewSpares(formname,lonhost) {
17628: var types = new Array('$types');
17629: var include = new Array();
17630: var exclude = new Array();
17631: for (var i=0; i<types.length; i++) {
17632: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
17633: for (var j=0; j<spareboxes.length; j++) {
17634: if (formname.elements[spareboxes[j]].checked) {
17635: exclude.push(formname.elements[spareboxes[j]].value);
17636: } else {
17637: include.push(formname.elements[spareboxes[j]].value);
17638: }
17639: }
17640: }
17641: for (var i=0; i<types.length; i++) {
17642: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
17643: var selIdx = newSpare.selectedIndex;
17644: var currnew = newSpare.options[selIdx].value;
17645: var okSpares = new Array();
17646: for (var j=0; j<newSpare.options.length; j++) {
17647: var possible = newSpare.options[j].value;
17648: if (possible != '') {
17649: if (exclude.indexOf(possible) == -1) {
17650: okSpares.push(possible);
17651: } else {
17652: if (currnew == possible) {
17653: selIdx = 0;
17654: }
17655: }
17656: }
17657: }
17658: for (var k=0; k<include.length; k++) {
17659: if (okSpares.indexOf(include[k]) == -1) {
17660: okSpares.push(include[k]);
17661: }
17662: }
17663: okSpares.sort();
17664: newSpare.options.length = 0;
17665: if (selIdx == 0) {
17666: newSpare.options[0] = new Option("$select","",true,true);
17667: } else {
17668: newSpare.options[0] = new Option("$select","",false,false);
17669: }
17670: for (var m=0; m<okSpares.length; m++) {
17671: var idx = m+1;
17672: var selThis = 0;
17673: if (selIdx != 0) {
17674: if (okSpares[m] == currnew) {
17675: selThis = 1;
17676: }
17677: }
17678: if (selThis == 1) {
17679: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
17680: } else {
17681: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
17682: }
17683: }
17684: }
17685: return;
17686: }
17687:
17688: function checkNewSpares(lonhost,type) {
17689: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
17690: var chosen = newSpare.options[newSpare.selectedIndex].value;
17691: if (chosen != '') {
17692: var othertype;
17693: var othernewSpare;
17694: if (type == 'primary') {
17695: othernewSpare = document.getElementById('newspare_default_'+lonhost);
17696: }
17697: if (type == 'default') {
17698: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
17699: }
17700: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
17701: othernewSpare.selectedIndex = 0;
17702: }
17703: }
17704: return;
17705: }
17706:
17707: // ]]>
17708: </script>
17709:
17710: END
17711:
17712: }
17713:
17714: sub common_domprefs_js {
17715: return <<"END";
17716:
17717: <script type="text/javascript">
17718: // <![CDATA[
17719:
1.150 raeburn 17720: function getIndicesByName(formname,item) {
1.152 raeburn 17721: var group = new Array();
1.150 raeburn 17722: for (var i=0;i<formname.elements.length;i++) {
17723: if (formname.elements[i].name == item) {
1.152 raeburn 17724: group.push(formname.elements[i].id);
1.150 raeburn 17725: }
17726: }
1.152 raeburn 17727: return group;
1.150 raeburn 17728: }
17729:
17730: // ]]>
17731: </script>
17732:
17733: END
1.152 raeburn 17734:
1.150 raeburn 17735: }
17736:
1.160.6.5 raeburn 17737: sub recaptcha_js {
17738: my %lt = &captcha_phrases();
17739: return <<"END";
17740:
17741: <script type="text/javascript">
17742: // <![CDATA[
17743:
17744: function updateCaptcha(caller,context) {
17745: var privitem;
17746: var pubitem;
17747: var privtext;
17748: var pubtext;
1.160.6.69 raeburn 17749: var versionitem;
17750: var versiontext;
1.160.6.5 raeburn 17751: if (document.getElementById(context+'_recaptchapub')) {
17752: pubitem = document.getElementById(context+'_recaptchapub');
17753: } else {
17754: return;
17755: }
17756: if (document.getElementById(context+'_recaptchapriv')) {
17757: privitem = document.getElementById(context+'_recaptchapriv');
17758: } else {
17759: return;
17760: }
17761: if (document.getElementById(context+'_recaptchapubtxt')) {
17762: pubtext = document.getElementById(context+'_recaptchapubtxt');
17763: } else {
17764: return;
17765: }
17766: if (document.getElementById(context+'_recaptchaprivtxt')) {
17767: privtext = document.getElementById(context+'_recaptchaprivtxt');
17768: } else {
17769: return;
17770: }
1.160.6.69 raeburn 17771: if (document.getElementById(context+'_recaptchaversion')) {
17772: versionitem = document.getElementById(context+'_recaptchaversion');
17773: } else {
17774: return;
17775: }
17776: if (document.getElementById(context+'_recaptchavertxt')) {
17777: versiontext = document.getElementById(context+'_recaptchavertxt');
17778: } else {
17779: return;
17780: }
1.160.6.5 raeburn 17781: if (caller.checked) {
17782: if (caller.value == 'recaptcha') {
17783: pubitem.type = 'text';
17784: privitem.type = 'text';
17785: pubitem.size = '40';
17786: privitem.size = '40';
17787: pubtext.innerHTML = "$lt{'pub'}";
17788: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 17789: versionitem.type = 'text';
17790: versionitem.size = '3';
17791: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 17792: } else {
17793: pubitem.type = 'hidden';
17794: privitem.type = 'hidden';
1.160.6.69 raeburn 17795: versionitem.type = 'hidden';
1.160.6.5 raeburn 17796: pubtext.innerHTML = '';
17797: privtext.innerHTML = '';
1.160.6.69 raeburn 17798: versiontext.innerHTML = '';
1.160.6.5 raeburn 17799: }
17800: }
17801: return;
17802: }
17803:
17804: // ]]>
17805: </script>
17806:
17807: END
17808:
17809: }
17810:
1.160.6.40 raeburn 17811: sub toggle_display_js {
1.160.6.16 raeburn 17812: return <<"END";
17813:
17814: <script type="text/javascript">
17815: // <![CDATA[
17816:
1.160.6.40 raeburn 17817: function toggleDisplay(domForm,caller) {
17818: if (document.getElementById(caller)) {
17819: var divitem = document.getElementById(caller);
17820: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 17821: var checkval = 1;
17822: var dispval = 'block';
1.160.6.93 raeburn 17823: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 17824: if (caller == 'emailoptions') {
17825: optionsElement = domForm.cancreate_email;
17826: }
1.160.6.57 raeburn 17827: if (caller == 'studentsubmission') {
17828: optionsElement = domForm.postsubmit;
17829: }
1.160.6.64 raeburn 17830: if (caller == 'cloneinstcode') {
17831: optionsElement = domForm.canclone;
17832: checkval = 'instcode';
17833: }
1.160.6.93 raeburn 17834: if (selfcreateRegExp.test(caller)) {
17835: optionsElement = domForm.elements[caller];
17836: checkval = 'other';
17837: dispval = 'inline'
17838: }
1.160.6.40 raeburn 17839: if (optionsElement.length) {
1.160.6.16 raeburn 17840: var currval;
1.160.6.40 raeburn 17841: for (var i=0; i<optionsElement.length; i++) {
17842: if (optionsElement[i].checked) {
17843: currval = optionsElement[i].value;
1.160.6.16 raeburn 17844: }
17845: }
1.160.6.64 raeburn 17846: if (currval == checkval) {
17847: divitem.style.display = dispval;
1.160.6.16 raeburn 17848: } else {
1.160.6.40 raeburn 17849: divitem.style.display = 'none';
1.160.6.16 raeburn 17850: }
17851: }
17852: }
17853: return;
17854: }
17855:
17856: // ]]>
17857: </script>
17858:
17859: END
17860:
17861: }
17862:
1.160.6.5 raeburn 17863: sub captcha_phrases {
17864: return &Apache::lonlocal::texthash (
17865: priv => 'Private key',
17866: pub => 'Public key',
17867: original => 'original (CAPTCHA)',
17868: recaptcha => 'successor (ReCAPTCHA)',
17869: notused => 'unused',
1.160.6.69 raeburn 17870: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 17871: );
17872: }
17873:
1.160.6.24 raeburn 17874: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 17875: my ($dom,$cachekeys) = @_;
17876: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 17877: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17878: my %thismachine;
17879: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.98 raeburn 17880: my @posscached = ('domainconfig','domdefaults','usersessions',
1.160.6.113 raeburn 17881: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
17882: 'ipaccess');
17883: my %cache_by_lonhost;
17884: if (exists($cachekeys->{'samllanding'})) {
17885: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
17886: my %landing = %{$cachekeys->{'samllanding'}};
17887: my %domservers = &Apache::lonnet::get_servers($dom);
17888: if (keys(%domservers)) {
17889: foreach my $server (keys(%domservers)) {
17890: my @cached;
17891: next if ($thismachine{$server});
17892: if ($landing{$server}) {
17893: push(@cached,&escape('samllanding').':'.&escape($server));
17894: }
17895: if (@cached) {
17896: $cache_by_lonhost{$server} = \@cached;
17897: }
17898: }
17899: }
17900: }
17901: }
1.160.6.61 raeburn 17902: if (keys(%servers)) {
1.160.6.24 raeburn 17903: foreach my $server (keys(%servers)) {
17904: next if ($thismachine{$server});
1.160.6.27 raeburn 17905: my @cached;
17906: foreach my $name (@posscached) {
17907: if ($cachekeys->{$name}) {
1.160.6.113 raeburn 17908: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
17909: if (ref($cachekeys->{$name}) eq 'HASH') {
17910: foreach my $key (keys(%{$cachekeys->{$name}})) {
17911: push(@cached,&escape($name).':'.&escape($key));
17912: }
17913: }
17914: } else {
17915: push(@cached,&escape($name).':'.&escape($dom));
17916: }
1.160.6.27 raeburn 17917: }
17918: }
1.160.6.113 raeburn 17919: if ((exists($cache_by_lonhost{$server})) &&
17920: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
17921: push(@cached,@{$cache_by_lonhost{$server}});
17922: }
1.160.6.27 raeburn 17923: if (@cached) {
17924: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
17925: }
1.160.6.24 raeburn 17926: }
17927: }
17928: return;
17929: }
17930:
1.3 raeburn 17931: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>