Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.122
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.122! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.121 2022/01/19 20:56:06 raeburn Exp $
1.160.6.40 raeburn 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.160.6.78 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
30: ##############################################################
31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.160.6.13 raeburn 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.160.6.27 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.160.6.5 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.160.6.20 raeburn 98: used by course owners to request creation of a course, and to display/store
1.160.6.34 raeburn 99: default quota sizes for Authoring Spaces.
1.160.6.20 raeburn 100:
1.101 raeburn 101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.160.6.30 raeburn 107: (official, unofficial, community, and textbook). In each case the radio buttons
108: allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.160.6.37 raeburn 168: use Apache::lonuserutils();
1.160.6.39 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.9 raeburn 173: use File::Copy;
1.43 raeburn 174: use Locale::Language;
1.62 raeburn 175: use DateTime::TimeZone;
1.68 raeburn 176: use DateTime::Locale;
1.160.6.113 raeburn 177: use Net::CIDR;
1.1 raeburn 178:
1.155 raeburn 179: my $registered_cleanup;
180: my $modified_urls;
181:
1.1 raeburn 182: sub handler {
183: my $r=shift;
184: if ($r->header_only) {
185: &Apache::loncommon::content_type($r,'text/html');
186: $r->send_http_header;
187: return OK;
188: }
189:
1.91 raeburn 190: my $context = 'domain';
1.1 raeburn 191: my $dom = $env{'request.role.domain'};
1.5 albertel 192: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 193: if (&Apache::lonnet::allowed('mau',$dom)) {
194: &Apache::loncommon::content_type($r,'text/html');
195: $r->send_http_header;
196: } else {
197: $env{'user.error.msg'}=
198: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
199: return HTTP_NOT_ACCEPTABLE;
200: }
1.155 raeburn 201:
202: $registered_cleanup=0;
203: @{$modified_urls}=();
204:
1.1 raeburn 205: &Apache::lonhtmlcommon::clear_breadcrumbs();
206: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 207: ['phase','actions']);
1.30 raeburn 208: my $phase = 'pickactions';
1.3 raeburn 209: if ( exists($env{'form.phase'}) ) {
210: $phase = $env{'form.phase'};
211: }
1.150 raeburn 212: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 213: my %domconfig =
1.6 raeburn 214: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 215: 'quotas','autoenroll','autoupdate','autocreate',
216: 'directorysrch','usercreation','usermodification',
217: 'contacts','defaults','scantron','coursecategories',
1.160.6.73 raeburn 218: 'serverstatuses','requestcourses','helpsettings',
219: 'coursedefaults','usersessions','loadbalancing',
1.160.6.113 raeburn 220: 'requestauthor','selfenrollment','inststatus',
221: 'passwords','wafproxy','ipaccess'],$dom);
222: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
223: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
224: 'contacts','usercreation','selfcreation','usermodification',
225: 'scantron','requestcourses','requestauthor','coursecategories',
1.160.6.73 raeburn 226: 'serverstatuses','helpsettings','coursedefaults',
227: 'selfenrollment','usersessions');
1.160.6.7 raeburn 228: my %existing;
229: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
230: %existing = %{$domconfig{'loadbalancing'}};
231: }
232: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 233: push(@prefs_order,'loadbalancing');
234: }
1.30 raeburn 235: my %prefs = (
236: 'rolecolors' =>
237: { text => 'Default color schemes',
1.67 raeburn 238: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 239: header => [{col1 => 'Student Settings',
240: col2 => '',},
241: {col1 => 'Coordinator Settings',
242: col2 => '',},
243: {col1 => 'Author Settings',
244: col2 => '',},
245: {col1 => 'Administrator Settings',
246: col2 => '',}],
1.160.6.37 raeburn 247: print => \&print_rolecolors,
248: modify => \&modify_rolecolors,
1.30 raeburn 249: },
1.110 raeburn 250: 'login' =>
1.30 raeburn 251: { text => 'Log-in page options',
1.67 raeburn 252: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 253: header => [{col1 => 'Log-in Page Items',
254: col2 => '',},
255: {col1 => 'Log-in Help',
1.160.6.56 raeburn 256: col2 => 'Value'},
257: {col1 => 'Custom HTML in document head',
1.160.6.113 raeburn 258: col2 => 'Value'},
259: {col1 => 'SSO',
260: col2 => 'Dual login: SSO and non-SSO options'},
261: ],
1.160.6.37 raeburn 262: print => \&print_login,
263: modify => \&modify_login,
1.30 raeburn 264: },
1.43 raeburn 265: 'defaults' =>
1.160.6.40 raeburn 266: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 267: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 268: header => [{col1 => 'Setting',
1.160.6.40 raeburn 269: col2 => 'Value'},
270: {col1 => 'Institutional user types',
1.160.6.122! raeburn 271: col2 => 'Name displayed'},
! 272: {col1 => 'Mapping for missing usernames via standard log-in',
! 273: col2 => 'Rules in use'}],
1.160.6.37 raeburn 274: print => \&print_defaults,
275: modify => \&modify_defaults,
1.43 raeburn 276: },
1.160.6.113 raeburn 277: 'wafproxy' =>
278: { text => 'Web Application Firewall/Reverse Proxy',
279: help => 'Domain_Configuration_WAF_Proxy',
280: header => [{col1 => 'Domain(s)',
281: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
282: },
283: {col1 => 'Domain(s)',
284: col2 => 'WAF Configuration',}],
285: print => \&print_wafproxy,
286: modify => \&modify_wafproxy,
287: },
1.160.6.98 raeburn 288: 'passwords' =>
289: { text => 'Passwords (Internal authentication)',
290: help => 'Domain_Configuration_Passwords',
291: header => [{col1 => 'Resetting Forgotten Password',
292: col2 => 'Settings'},
293: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
294: col2 => 'Settings'},
295: {col1 => 'Rules for LON-CAPA Passwords',
296: col2 => 'Settings'},
297: {col1 => 'Course Owner Changing Student Passwords',
298: col2 => 'Settings'}],
299: print => \&print_passwords,
300: modify => \&modify_passwords,
301: },
1.30 raeburn 302: 'quotas' =>
1.160.6.20 raeburn 303: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 304: help => 'Domain_Configuration_Quotas',
1.77 raeburn 305: header => [{col1 => 'User affiliation',
1.72 raeburn 306: col2 => 'Available tools',
1.160.6.28 raeburn 307: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 308: print => \&print_quotas,
309: modify => \&modify_quotas,
1.30 raeburn 310: },
311: 'autoenroll' =>
312: { text => 'Auto-enrollment settings',
1.67 raeburn 313: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 314: header => [{col1 => 'Configuration setting',
315: col2 => 'Value(s)'}],
1.160.6.37 raeburn 316: print => \&print_autoenroll,
317: modify => \&modify_autoenroll,
1.30 raeburn 318: },
319: 'autoupdate' =>
320: { text => 'Auto-update settings',
1.67 raeburn 321: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 322: header => [{col1 => 'Setting',
323: col2 => 'Value',},
1.131 raeburn 324: {col1 => 'Setting',
325: col2 => 'Affiliation'},
1.43 raeburn 326: {col1 => 'User population',
1.160.6.35 raeburn 327: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 328: print => \&print_autoupdate,
329: modify => \&modify_autoupdate,
1.30 raeburn 330: },
1.125 raeburn 331: 'autocreate' =>
332: { text => 'Auto-course creation settings',
333: help => 'Domain_Configuration_Auto_Creation',
334: header => [{col1 => 'Configuration Setting',
335: col2 => 'Value',}],
1.160.6.37 raeburn 336: print => \&print_autocreate,
337: modify => \&modify_autocreate,
1.125 raeburn 338: },
1.30 raeburn 339: 'directorysrch' =>
1.160.6.72 raeburn 340: { text => 'Directory searches',
1.67 raeburn 341: help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72 raeburn 342: header => [{col1 => 'Institutional Directory Setting',
343: col2 => 'Value',},
344: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 345: col2 => 'Value',}],
1.160.6.37 raeburn 346: print => \&print_directorysrch,
347: modify => \&modify_directorysrch,
1.30 raeburn 348: },
349: 'contacts' =>
1.160.6.78 raeburn 350: { text => 'E-mail addresses and helpform',
1.67 raeburn 351: help => 'Domain_Configuration_Contact_Info',
1.160.6.78 raeburn 352: header => [{col1 => 'Default e-mail addresses',
353: col2 => 'Value',},
354: {col1 => 'Recipient(s) for notifications',
355: col2 => 'Value',},
1.160.6.107 raeburn 356: {col1 => 'Nightly status check e-mail',
357: col2 => 'Settings',},
1.160.6.78 raeburn 358: {col1 => 'Ask helpdesk form settings',
359: col2 => 'Value',},],
1.160.6.37 raeburn 360: print => \&print_contacts,
361: modify => \&modify_contacts,
1.30 raeburn 362: },
363: 'usercreation' =>
364: { text => 'User creation',
1.67 raeburn 365: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 366: header => [{col1 => 'Format rule type',
367: col2 => 'Format rules in force'},
1.34 raeburn 368: {col1 => 'User account creation',
369: col2 => 'Usernames which may be created',},
1.30 raeburn 370: {col1 => 'Context',
1.43 raeburn 371: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 372: print => \&print_usercreation,
373: modify => \&modify_usercreation,
1.30 raeburn 374: },
1.160.6.34 raeburn 375: 'selfcreation' =>
376: { text => 'Users self-creating accounts',
377: help => 'Domain_Configuration_Self_Creation',
378: header => [{col1 => 'Self-creation with institutional username',
379: col2 => 'Enabled?'},
380: {col1 => 'Institutional user type (login/SSO self-creation)',
381: col2 => 'Information user can enter'},
1.160.6.93 raeburn 382: {col1 => 'Self-creation with e-mail verification',
1.160.6.34 raeburn 383: col2 => 'Settings'}],
1.160.6.37 raeburn 384: print => \&print_selfcreation,
385: modify => \&modify_selfcreation,
1.160.6.34 raeburn 386: },
1.69 raeburn 387: 'usermodification' =>
1.33 raeburn 388: { text => 'User modification',
1.67 raeburn 389: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 390: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 391: col2 => 'User information updatable in author context'},
1.33 raeburn 392: {col1 => 'Target user has role',
1.160.6.35 raeburn 393: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 394: print => \&print_usermodification,
395: modify => \&modify_usermodification,
1.33 raeburn 396: },
1.69 raeburn 397: 'scantron' =>
1.160.6.97 raeburn 398: { text => 'Bubblesheet format',
1.67 raeburn 399: help => 'Domain_Configuration_Scantron_Format',
1.160.6.97 raeburn 400: header => [ {col1 => 'Bubblesheet format file',
401: col2 => ''},
402: {col1 => 'Bubblesheet data upload formats',
403: col2 => 'Settings'}],
1.160.6.37 raeburn 404: print => \&print_scantron,
405: modify => \&modify_scantron,
1.46 raeburn 406: },
1.86 raeburn 407: 'requestcourses' =>
408: {text => 'Request creation of courses',
409: help => 'Domain_Configuration_Request_Courses',
410: header => [{col1 => 'User affiliation',
1.102 raeburn 411: col2 => 'Availability/Processing of requests',},
412: {col1 => 'Setting',
1.160.6.30 raeburn 413: col2 => 'Value'},
414: {col1 => 'Available textbooks',
1.160.6.39 raeburn 415: col2 => ''},
1.160.6.46 raeburn 416: {col1 => 'Available templates',
417: col2 => ''},
1.160.6.39 raeburn 418: {col1 => 'Validation (not official courses)',
419: col2 => 'Value'},],
1.160.6.37 raeburn 420: print => \&print_quotas,
421: modify => \&modify_quotas,
1.86 raeburn 422: },
1.160.6.5 raeburn 423: 'requestauthor' =>
1.160.6.34 raeburn 424: {text => 'Request Authoring Space',
1.160.6.5 raeburn 425: help => 'Domain_Configuration_Request_Author',
426: header => [{col1 => 'User affiliation',
427: col2 => 'Availability/Processing of requests',},
428: {col1 => 'Setting',
429: col2 => 'Value'}],
1.160.6.37 raeburn 430: print => \&print_quotas,
431: modify => \&modify_quotas,
1.160.6.5 raeburn 432: },
1.69 raeburn 433: 'coursecategories' =>
1.120 raeburn 434: { text => 'Cataloging of courses/communities',
1.67 raeburn 435: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 436: header => [{col1 => 'Catalog type/availability',
437: col2 => '',},
438: {col1 => 'Category settings for standard catalog',
1.57 raeburn 439: col2 => '',},
440: {col1 => 'Categories',
441: col2 => '',
442: }],
1.160.6.37 raeburn 443: print => \&print_coursecategories,
444: modify => \&modify_coursecategories,
1.69 raeburn 445: },
446: 'serverstatuses' =>
1.77 raeburn 447: {text => 'Access to server status pages',
1.69 raeburn 448: help => 'Domain_Configuration_Server_Status',
449: header => [{col1 => 'Status Page',
450: col2 => 'Other named users',
451: col3 => 'Specific IPs',
452: }],
1.160.6.37 raeburn 453: print => \&print_serverstatuses,
454: modify => \&modify_serverstatuses,
1.69 raeburn 455: },
1.160.6.73 raeburn 456: 'helpsettings' =>
457: {text => 'Support settings',
458: help => 'Domain_Configuration_Help_Settings',
459: header => [{col1 => 'Help Page Settings (logged-in users)',
460: col2 => 'Value'},
461: {col1 => 'Helpdesk Roles',
462: col2 => 'Settings'},],
463: print => \&print_helpsettings,
464: modify => \&modify_helpsettings,
465: },
1.160.6.39 raeburn 466: 'coursedefaults' =>
1.160.6.16 raeburn 467: {text => 'Course/Community defaults',
468: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 469: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
470: col2 => 'Value',},
471: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 472: col2 => 'Value',},],
1.160.6.37 raeburn 473: print => \&print_coursedefaults,
474: modify => \&modify_coursedefaults,
475: },
1.160.6.39 raeburn 476: 'selfenrollment' =>
1.160.6.37 raeburn 477: {text => 'Self-enrollment in Course/Community',
478: help => 'Domain_Configuration_Selfenrollment',
479: header => [{col1 => 'Configuration Rights',
480: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
481: {col1 => 'Defaults',
482: col2 => 'Value'},
483: {col1 => 'Self-enrollment validation (optional)',
484: col2 => 'Value'},],
485: print => \&print_selfenrollment,
486: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 487: },
1.141 raeburn 488: 'usersessions' =>
1.145 raeburn 489: {text => 'User session hosting/offloading',
1.137 raeburn 490: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 491: header => [{col1 => 'Domain server',
492: col2 => 'Servers to offload sessions to when busy'},
493: {col1 => 'Hosting of users from other domains',
1.137 raeburn 494: col2 => 'Rules'},
495: {col1 => "Hosting domain's own users elsewhere",
496: col2 => 'Rules'}],
1.160.6.37 raeburn 497: print => \&print_usersessions,
498: modify => \&modify_usersessions,
1.137 raeburn 499: },
1.160.6.78 raeburn 500: 'loadbalancing' =>
1.160.6.7 raeburn 501: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 502: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 503: header => [{col1 => 'Balancers',
1.150 raeburn 504: col2 => 'Default destinations',
1.160.6.13 raeburn 505: col3 => 'User affiliation',
1.150 raeburn 506: col4 => 'Overrides'},
507: ],
1.160.6.37 raeburn 508: print => \&print_loadbalancing,
509: modify => \&modify_loadbalancing,
1.150 raeburn 510: },
1.160.6.113 raeburn 511: 'ipaccess' =>
512: {text => 'IP-based access control',
513: help => 'Domain_Configuration_IP_Access',
514: header => [{col1 => 'Setting',
515: col2 => 'Value'},],
516: print => \&print_ipaccess,
517: modify => \&modify_ipaccess,
518: },
1.3 raeburn 519: );
1.110 raeburn 520: if (keys(%servers) > 1) {
521: $prefs{'login'} = { text => 'Log-in page options',
522: help => 'Domain_Configuration_Login_Page',
523: header => [{col1 => 'Log-in Service',
524: col2 => 'Server Setting',},
525: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 526: col2 => ''},
527: {col1 => 'Log-in Help',
1.160.6.56 raeburn 528: col2 => 'Value'},
529: {col1 => 'Custom HTML in document head',
1.160.6.113 raeburn 530: col2 => 'Value'},
531: {col1 => 'SSO',
532: col2 => 'Dual login: SSO and non-SSO options'},
533: ],
1.160.6.37 raeburn 534: print => \&print_login,
535: modify => \&modify_login,
1.110 raeburn 536: };
537: }
1.160.6.13 raeburn 538:
1.6 raeburn 539: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 540: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 541: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 542: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 543: text=>"Settings to display/modify"});
1.9 raeburn 544: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 545:
1.3 raeburn 546: if ($phase eq 'process') {
1.160.6.27 raeburn 547: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
548: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 549: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 550: $r->rflush();
1.160.6.27 raeburn 551: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 552: }
1.30 raeburn 553: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 554: my $js = &recaptcha_js().
1.160.6.40 raeburn 555: &toggle_display_js();
1.160.6.7 raeburn 556: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 557: my ($othertitle,$usertypes,$types) =
558: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 559: $js .= &lonbalance_targets_js($dom,$types,\%servers,
560: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 561: &new_spares_js().
562: &common_domprefs_js().
563: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 564: }
1.160.6.30 raeburn 565: if (grep(/^requestcourses$/,@actions)) {
566: my $javascript_validations;
567: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
568: $js .= <<END;
569: <script type="text/javascript">
570: $javascript_validations
571: </script>
572: $coursebrowserjs
573: END
1.160.6.113 raeburn 574: } elsif (grep(/^ipaccess$/,@actions)) {
575: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.160.6.30 raeburn 576: }
1.160.6.93 raeburn 577: if (grep(/^selfcreation$/,@actions)) {
578: $js .= &selfcreate_javascript();
579: }
1.160.6.78 raeburn 580: if (grep(/^contacts$/,@actions)) {
581: $js .= &contacts_javascript();
582: }
1.160.6.97 raeburn 583: if (grep(/^scantron$/,@actions)) {
584: $js .= &scantron_javascript();
585: }
1.150 raeburn 586: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 587: } else {
1.160.6.11 raeburn 588: # check if domconfig user exists for the domain.
589: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 590: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 591: &config_check($dom,$confname,$servadm);
592: unless ($configuserok eq 'ok') {
593: &Apache::lonconfigsettings::print_header($r,$phase,$context);
594: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
595: $confname).
596: '<br />'
597: );
598: if ($switchserver) {
599: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
600: '<br />'.
601: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
602: '<br />'.
603: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
604: '<br />'.
605: &mt('To do that now, use the following link: [_1]',$switchserver)
606: );
607: } else {
608: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
609: '<br />'.
610: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
611: );
612: }
613: $r->print(&Apache::loncommon::end_page());
614: return OK;
615: }
1.21 raeburn 616: if (keys(%domconfig) == 0) {
617: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 618: my @ids=&Apache::lonnet::current_machine_ids();
619: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 620: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 621: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 622: my $custom_img_count = 0;
623: foreach my $img (@loginimages) {
624: if ($designhash{$dom.'.login.'.$img} ne '') {
625: $custom_img_count ++;
626: }
627: }
628: foreach my $role (@roles) {
629: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
630: $custom_img_count ++;
631: }
632: }
633: if ($custom_img_count > 0) {
1.94 raeburn 634: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 635: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 636: $r->print(
637: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
638: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
639: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
640: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
641: if ($switch_server) {
1.30 raeburn 642: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 643: }
1.91 raeburn 644: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 645: return OK;
646: }
647: }
648: }
1.91 raeburn 649: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 650: }
651: return OK;
652: }
653:
654: sub process_changes {
1.160.6.24 raeburn 655: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 656: my %domconfig;
657: if (ref($values) eq 'HASH') {
658: %domconfig = %{$values};
659: }
1.3 raeburn 660: my $output;
661: if ($action eq 'login') {
1.160.6.24 raeburn 662: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 663: } elsif ($action eq 'rolecolors') {
1.9 raeburn 664: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 665: $lastactref,%domconfig);
1.3 raeburn 666: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 667: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 668: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 669: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 670: } elsif ($action eq 'autoupdate') {
671: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 672: } elsif ($action eq 'autocreate') {
673: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 674: } elsif ($action eq 'directorysrch') {
1.160.6.81 raeburn 675: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 676: } elsif ($action eq 'usercreation') {
1.28 raeburn 677: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 678: } elsif ($action eq 'selfcreation') {
1.160.6.93 raeburn 679: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 680: } elsif ($action eq 'usermodification') {
681: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 682: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 683: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 684: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 685: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 686: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 687: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 688: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 689: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 690: } elsif ($action eq 'serverstatuses') {
691: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 692: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 693: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 694: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 695: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 696: } elsif ($action eq 'helpsettings') {
1.160.6.77 raeburn 697: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16 raeburn 698: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 699: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 700: } elsif ($action eq 'selfenrollment') {
701: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 702: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 703: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 704: } elsif ($action eq 'loadbalancing') {
705: $output = &modify_loadbalancing($dom,%domconfig);
1.160.6.98 raeburn 706: } elsif ($action eq 'passwords') {
707: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.113 raeburn 708: } elsif ($action eq 'wafproxy') {
709: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
710: } elsif ($action eq 'ipaccess') {
711: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.3 raeburn 712: }
713: return $output;
714: }
715:
716: sub print_config_box {
1.9 raeburn 717: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 718: my $rowtotal = 0;
1.49 raeburn 719: my $output;
720: if ($action eq 'coursecategories') {
721: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 722: } elsif ($action eq 'defaults') {
723: $output = &defaults_javascript($settings);
1.160.6.98 raeburn 724: } elsif ($action eq 'passwords') {
725: $output = &passwords_javascript();
1.160.6.73 raeburn 726: } elsif ($action eq 'helpsettings') {
727: my (%privs,%levelscurrent);
728: my %full=();
729: my %levels=(
730: course => {},
731: domain => {},
732: system => {},
733: );
734: my $context = 'domain';
735: my $crstype = 'Course';
736: my $formname = 'display';
737: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
738: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
739: $output =
740: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
741: \@templateroles);
1.160.6.113 raeburn 742: } elsif ($action eq 'wafproxy') {
743: $output .= &wafproxy_javascript($dom);
744: } elsif ($action eq 'autoupdate') {
745: $output .= &autoupdate_javascript();
1.160.6.116 raeburn 746: } elsif ($action eq 'autoenroll') {
747: $output .= &autoenroll_javascript();
1.160.6.113 raeburn 748: } elsif ($action eq 'login') {
749: $output .= &saml_javascript();
750: } elsif ($action eq 'ipaccess') {
751: $output .= &ipaccess_javascript($settings);
1.91 raeburn 752: }
1.160.6.40 raeburn 753: $output .=
1.30 raeburn 754: '<table class="LC_nested_outer">
1.3 raeburn 755: <tr>
1.160.6.113 raeburn 756: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 757: &mt($item->{text}).' '.
758: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
759: '</tr>';
1.30 raeburn 760: $rowtotal ++;
1.110 raeburn 761: my $numheaders = 1;
762: if (ref($item->{'header'}) eq 'ARRAY') {
763: $numheaders = scalar(@{$item->{'header'}});
764: }
765: if ($numheaders > 1) {
1.64 raeburn 766: my $colspan = '';
1.145 raeburn 767: my $rightcolspan = '';
1.160.6.104 raeburn 768: my $leftnobr = '';
1.160.6.42 raeburn 769: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 770: ($action eq 'directorysrch') ||
1.160.6.113 raeburn 771: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 772: $colspan = ' colspan="2"';
773: }
1.145 raeburn 774: if ($action eq 'usersessions') {
775: $rightcolspan = ' colspan="3"';
776: }
1.160.6.104 raeburn 777: if ($action eq 'passwords') {
778: $leftnobr = ' LC_nobreak';
779: }
1.30 raeburn 780: $output .= '
1.3 raeburn 781: <tr>
782: <td>
783: <table class="LC_nested">
784: <tr class="LC_info_row">
1.160.6.104 raeburn 785: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 786: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 787: </tr>';
1.69 raeburn 788: $rowtotal ++;
1.160.6.37 raeburn 789: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 790: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 791: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.113 raeburn 792: ($action eq 'helpsettings') || ($action eq 'contacts') || ($action eq 'wafproxy')) {
1.160.6.37 raeburn 793: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.160.6.98 raeburn 794: } elsif ($action eq 'passwords') {
795: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 796: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 797: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.160.6.97 raeburn 798: } elsif ($action eq 'scantron') {
799: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 800: } elsif ($action eq 'login') {
1.160.6.113 raeburn 801: if ($numheaders == 5) {
1.160.6.5 raeburn 802: $colspan = ' colspan="2"';
803: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
804: } else {
805: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
806: }
1.160.6.37 raeburn 807: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 808: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 809: } elsif ($action eq 'rolecolors') {
1.30 raeburn 810: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 811: }
1.30 raeburn 812: $output .= '
1.6 raeburn 813: </table>
814: </td>
815: </tr>
816: <tr>
817: <td>
818: <table class="LC_nested">
819: <tr class="LC_info_row">
1.160.6.37 raeburn 820: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 821: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 822: </tr>';
823: $rowtotal ++;
1.160.6.37 raeburn 824: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
825: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 826: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.122! raeburn 827: ($action eq 'contacts') || ($action eq 'passwords') || ($action eq 'defaults')) {
1.160.6.42 raeburn 828: if ($action eq 'coursecategories') {
829: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
830: $colspan = ' colspan="2"';
1.160.6.98 raeburn 831: } elsif ($action eq 'passwords') {
832: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.160.6.42 raeburn 833: } else {
834: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
835: }
836: $output .= '
1.63 raeburn 837: </table>
838: </td>
839: </tr>
840: <tr>
841: <td>
842: <table class="LC_nested">
843: <tr class="LC_info_row">
1.160.6.113 raeburn 844: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 845: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 846: </tr>'."\n";
847: if ($action eq 'coursecategories') {
848: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.160.6.108 raeburn 849: } elsif (($action eq 'contacts') || ($action eq 'passwords')) {
1.160.6.107 raeburn 850: if ($action eq 'passwords') {
851: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
852: } else {
853: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
854: }
855: $output .= '
1.160.6.98 raeburn 856: </tr>
857: </table>
858: </td>
859: </tr>
860: <tr>
861: <td>
862: <table class="LC_nested">
863: <tr class="LC_info_row">
1.160.6.113 raeburn 864: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.160.6.107 raeburn 865: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1.160.6.108 raeburn 866: if ($action eq 'passwords') {
867: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
868: } else {
869: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
870: }
871: $output .= '
1.160.6.98 raeburn 872: </table>
873: </td>
874: </tr>
875: <tr>';
1.160.6.42 raeburn 876: } else {
877: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
878: }
1.63 raeburn 879: $rowtotal ++;
1.160.6.57 raeburn 880: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.122! raeburn 881: ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
! 882: ($action eq 'wafproxy')) {
1.160.6.37 raeburn 883: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.160.6.97 raeburn 884: } elsif ($action eq 'scantron') {
885: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 886: } elsif ($action eq 'login') {
1.160.6.113 raeburn 887: if ($numheaders == 5) {
1.160.6.5 raeburn 888: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
889: </table>
890: </td>
891: </tr>
892: <tr>
893: <td>
894: <table class="LC_nested">
895: <tr class="LC_info_row">
896: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 897: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 898: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
899: $rowtotal ++;
900: } else {
901: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
902: }
1.160.6.56 raeburn 903: $output .= '
904: </table>
905: </td>
906: </tr>
907: <tr>
908: <td>
909: <table class="LC_nested">
910: <tr class="LC_info_row">';
1.160.6.113 raeburn 911: if ($numheaders == 5) {
1.160.6.56 raeburn 912: $output .= '
913: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
914: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
915: </tr>';
916: } else {
917: $output .= '
918: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
919: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
920: </tr>';
921: }
922: $rowtotal ++;
1.160.6.113 raeburn 923: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
924: </table>
925: </td>
926: </tr>
927: <tr>
928: <td>
929: <table class="LC_nested">
930: <tr class="LC_info_row">';
931: if ($numheaders == 5) {
932: $output .= '
933: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
934: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
935: </tr>';
936: } else {
937: $output .= '
938: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
939: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
940: </tr>';
941: }
942: $rowtotal ++;
943: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 944: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 945: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
946: $rowtotal ++;
947: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 948: </table>
949: </td>
950: </tr>
951: <tr>
952: <td>
953: <table class="LC_nested">
954: <tr class="LC_info_row">
955: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
956: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 957: &textbookcourses_javascript($settings).
958: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
959: </table>
960: </td>
961: </tr>
962: <tr>
963: <td>
964: <table class="LC_nested">
965: <tr class="LC_info_row">
966: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
967: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
968: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 969: </table>
970: </td>
971: </tr>
972: <tr>
973: <td>
974: <table class="LC_nested">
975: <tr class="LC_info_row">
1.160.6.46 raeburn 976: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
977: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 978: </tr>'.
979: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 980: } elsif ($action eq 'requestauthor') {
981: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 982: $rowtotal ++;
1.122 jms 983: } elsif ($action eq 'rolecolors') {
1.30 raeburn 984: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 985: </table>
986: </td>
987: </tr>
988: <tr>
989: <td>
990: <table class="LC_nested">
991: <tr class="LC_info_row">
1.69 raeburn 992: <td class="LC_left_item"'.$colspan.' valign="top">'.
993: &mt($item->{'header'}->[2]->{'col1'}).'</td>
994: <td class="LC_right_item" valign="top">'.
995: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 996: </tr>'.
1.30 raeburn 997: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 998: </table>
999: </td>
1000: </tr>
1001: <tr>
1002: <td>
1003: <table class="LC_nested">
1004: <tr class="LC_info_row">
1.59 bisitz 1005: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1006: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1007: </tr>'.
1.30 raeburn 1008: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1009: $rowtotal += 2;
1.6 raeburn 1010: }
1.3 raeburn 1011: } else {
1.30 raeburn 1012: $output .= '
1.3 raeburn 1013: <tr>
1014: <td>
1015: <table class="LC_nested">
1.30 raeburn 1016: <tr class="LC_info_row">';
1.160.6.72 raeburn 1017: if ($action eq 'login') {
1.30 raeburn 1018: $output .= '
1.59 bisitz 1019: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1020: } elsif ($action eq 'serverstatuses') {
1021: $output .= '
1022: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
1023: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1024:
1.6 raeburn 1025: } else {
1.30 raeburn 1026: $output .= '
1.69 raeburn 1027: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1028: }
1.72 raeburn 1029: if (defined($item->{'header'}->[0]->{'col3'})) {
1030: $output .= '<td class="LC_left_item" valign="top">'.
1031: &mt($item->{'header'}->[0]->{'col2'});
1032: if ($action eq 'serverstatuses') {
1033: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1034: }
1.69 raeburn 1035: } else {
1036: $output .= '<td class="LC_right_item" valign="top">'.
1037: &mt($item->{'header'}->[0]->{'col2'});
1038: }
1039: $output .= '</td>';
1040: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1041: if (defined($item->{'header'}->[0]->{'col4'})) {
1042: $output .= '<td class="LC_left_item" valign="top">'.
1043: &mt($item->{'header'}->[0]->{'col3'});
1044: } else {
1045: $output .= '<td class="LC_right_item" valign="top">'.
1046: &mt($item->{'header'}->[0]->{'col3'});
1047: }
1.69 raeburn 1048: if ($action eq 'serverstatuses') {
1049: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1050: }
1051: $output .= '</td>';
1.6 raeburn 1052: }
1.150 raeburn 1053: if ($item->{'header'}->[0]->{'col4'}) {
1054: $output .= '<td class="LC_right_item" valign="top">'.
1055: &mt($item->{'header'}->[0]->{'col4'});
1056: }
1.69 raeburn 1057: $output .= '</tr>';
1.48 raeburn 1058: $rowtotal ++;
1.160.6.5 raeburn 1059: if ($action eq 'quotas') {
1.86 raeburn 1060: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 1061: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.113 raeburn 1062: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1063: ($action eq 'ipaccess')) {
1.160.6.37 raeburn 1064: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1065: }
1.3 raeburn 1066: }
1.30 raeburn 1067: $output .= '
1.3 raeburn 1068: </table>
1069: </td>
1070: </tr>
1.30 raeburn 1071: </table><br />';
1072: return ($output,$rowtotal);
1.1 raeburn 1073: }
1074:
1.3 raeburn 1075: sub print_login {
1.160.6.5 raeburn 1076: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 1077: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1078: my %choices = &login_choices();
1.160.6.113 raeburn 1079: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1080: %lt = &login_file_options();
1081: $switchserver = &check_switchserver($dom,$confname);
1082: }
1.110 raeburn 1083:
1.160.6.5 raeburn 1084: if ($caller eq 'service') {
1.149 raeburn 1085: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1086: my $choice = $choices{'disallowlogin'};
1087: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1088: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 1089: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1090: '<th>'.$choices{'server'}.'</th>'.
1091: '<th>'.$choices{'serverpath'}.'</th>'.
1092: '<th>'.$choices{'custompath'}.'</th>'.
1093: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1094: my %disallowed;
1095: if (ref($settings) eq 'HASH') {
1096: if (ref($settings->{'loginvia'}) eq 'HASH') {
1097: %disallowed = %{$settings->{'loginvia'}};
1098: }
1099: }
1100: foreach my $lonhost (sort(keys(%servers))) {
1101: my $direct = 'selected="selected"';
1.128 raeburn 1102: if (ref($disallowed{$lonhost}) eq 'HASH') {
1103: if ($disallowed{$lonhost}{'server'} ne '') {
1104: $direct = '';
1105: }
1.110 raeburn 1106: }
1.115 raeburn 1107: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1108: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1109: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1110: '</option>';
1.160.6.13 raeburn 1111: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1112: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1113: my $selected = '';
1.128 raeburn 1114: if (ref($disallowed{$lonhost}) eq 'HASH') {
1115: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1116: $selected = 'selected="selected"';
1117: }
1.110 raeburn 1118: }
1119: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1120: $servers{$hostid}.'</option>';
1121: }
1.128 raeburn 1122: $datatable .= '</select></td>'.
1123: '<td><select name="'.$lonhost.'_serverpath">';
1124: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1125: my $pathname = $path;
1126: if ($path eq 'custom') {
1127: $pathname = &mt('Custom Path').' ->';
1128: }
1129: my $selected = '';
1130: if (ref($disallowed{$lonhost}) eq 'HASH') {
1131: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1132: $selected = 'selected="selected"';
1133: }
1134: } elsif ($path eq '') {
1135: $selected = 'selected="selected"';
1136: }
1137: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1138: }
1139: $datatable .= '</select></td>';
1140: my ($custom,$exempt);
1141: if (ref($disallowed{$lonhost}) eq 'HASH') {
1142: $custom = $disallowed{$lonhost}{'custompath'};
1143: $exempt = $disallowed{$lonhost}{'exempt'};
1144: }
1145: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1146: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1147: '</tr>';
1.110 raeburn 1148: }
1149: $datatable .= '</table></td></tr>';
1150: return $datatable;
1.160.6.5 raeburn 1151: } elsif ($caller eq 'page') {
1152: my %defaultchecked = (
1153: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1154: 'helpdesk' => 'on',
1.160.6.5 raeburn 1155: 'adminmail' => 'off',
1156: 'newuser' => 'off',
1157: );
1.160.6.14 raeburn 1158: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1159: my (%checkedon,%checkedoff);
1.42 raeburn 1160: foreach my $item (@toggles) {
1.160.6.5 raeburn 1161: if ($defaultchecked{$item} eq 'on') {
1162: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1163: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1164: } elsif ($defaultchecked{$item} eq 'off') {
1165: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1166: $checkedon{$item} = ' ';
1167: }
1.1 raeburn 1168: }
1.160.6.5 raeburn 1169: my @images = ('img','logo','domlogo','login');
1.160.6.119 raeburn 1170: my @alttext = ('img','logo','domlogo');
1.160.6.5 raeburn 1171: my @logintext = ('textcol','bgcol');
1172: my @bgs = ('pgbg','mainbg','sidebg');
1173: my @links = ('link','alink','vlink');
1174: my %designhash = &Apache::loncommon::get_domainconf($dom);
1175: my %defaultdesign = %Apache::loncommon::defaultdesign;
1176: my (%is_custom,%designs);
1177: my %defaults = (
1178: font => $defaultdesign{'login.font'},
1179: );
1.6 raeburn 1180: foreach my $item (@images) {
1.160.6.5 raeburn 1181: $defaults{$item} = $defaultdesign{'login.'.$item};
1182: $defaults{'showlogo'}{$item} = 1;
1183: }
1184: foreach my $item (@bgs) {
1185: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1186: }
1.41 raeburn 1187: foreach my $item (@logintext) {
1.160.6.5 raeburn 1188: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1189: }
1.160.6.5 raeburn 1190: foreach my $item (@links) {
1191: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1192: }
1.160.6.5 raeburn 1193: if (ref($settings) eq 'HASH') {
1194: foreach my $item (@toggles) {
1195: if ($settings->{$item} eq '1') {
1196: $checkedon{$item} = ' checked="checked" ';
1197: $checkedoff{$item} = ' ';
1198: } elsif ($settings->{$item} eq '0') {
1199: $checkedoff{$item} = ' checked="checked" ';
1200: $checkedon{$item} = ' ';
1201: }
1.6 raeburn 1202: }
1.160.6.5 raeburn 1203: foreach my $item (@images) {
1204: if (defined($settings->{$item})) {
1205: $designs{$item} = $settings->{$item};
1206: $is_custom{$item} = 1;
1207: }
1208: if (defined($settings->{'showlogo'}{$item})) {
1209: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1210: }
1211: }
1.160.6.119 raeburn 1212: foreach my $item (@alttext) {
1213: if (ref($settings->{'alttext'}) eq 'HASH') {
1214: if ($settings->{'alttext'}->{$item} ne '') {
1215: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1216: }
1217: }
1218: }
1.160.6.5 raeburn 1219: foreach my $item (@logintext) {
1220: if ($settings->{$item} ne '') {
1221: $designs{'logintext'}{$item} = $settings->{$item};
1222: $is_custom{$item} = 1;
1223: }
1224: }
1225: if ($settings->{'font'} ne '') {
1226: $designs{'font'} = $settings->{'font'};
1227: $is_custom{'font'} = 1;
1228: }
1229: foreach my $item (@bgs) {
1230: if ($settings->{$item} ne '') {
1231: $designs{'bgs'}{$item} = $settings->{$item};
1232: $is_custom{$item} = 1;
1233: }
1234: }
1235: foreach my $item (@links) {
1236: if ($settings->{$item} ne '') {
1237: $designs{'links'}{$item} = $settings->{$item};
1238: $is_custom{$item} = 1;
1239: }
1240: }
1241: } else {
1242: if ($designhash{$dom.'.login.font'} ne '') {
1243: $designs{'font'} = $designhash{$dom.'.login.font'};
1244: $is_custom{'font'} = 1;
1245: }
1246: foreach my $item (@images) {
1247: if ($designhash{$dom.'.login.'.$item} ne '') {
1248: $designs{$item} = $designhash{$dom.'.login.'.$item};
1249: $is_custom{$item} = 1;
1250: }
1251: }
1252: foreach my $item (@bgs) {
1253: if ($designhash{$dom.'.login.'.$item} ne '') {
1254: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1255: $is_custom{$item} = 1;
1256: }
1257: }
1258: foreach my $item (@links) {
1259: if ($designhash{$dom.'.login.'.$item} ne '') {
1260: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1261: $is_custom{$item} = 1;
1262: }
1.6 raeburn 1263: }
1264: }
1.160.6.5 raeburn 1265: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1266: logo => 'Institution Logo',
1267: domlogo => 'Domain Logo',
1268: login => 'Login box');
1269: my $itemcount = 1;
1270: foreach my $item (@toggles) {
1271: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1272: $datatable .=
1273: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1274: '</td><td>'.
1275: '<span class="LC_nobreak"><label><input type="radio" name="'.
1276: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1277: '</label> <label><input type="radio" name="'.$item.'"'.
1278: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1279: '</tr>';
1280: $itemcount ++;
1.6 raeburn 1281: }
1.160.6.5 raeburn 1282: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1283: $datatable .= '</tr></table></td></tr>';
1284: } elsif ($caller eq 'help') {
1.160.6.113 raeburn 1285: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.160.6.5 raeburn 1286: my $itemcount = 1;
1287: $defaulturl = '/adm/loginproblems.html';
1288: $defaulttype = 'default';
1289: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1290: my @currlangs;
1291: if (ref($settings) eq 'HASH') {
1292: if (ref($settings->{'helpurl'}) eq 'HASH') {
1293: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1294: next if ($settings->{'helpurl'}{$key} eq '');
1295: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1296: $type{$key} = 'custom';
1297: unless ($key eq 'nolang') {
1298: push(@currlangs,$key);
1299: }
1300: }
1301: } elsif ($settings->{'helpurl'} ne '') {
1302: $type{'nolang'} = 'custom';
1303: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1304: }
1305: }
1.160.6.5 raeburn 1306: foreach my $lang ('nolang',sort(@currlangs)) {
1307: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1308: $datatable .= '<tr'.$css_class.'>';
1309: if ($url{$lang} eq '') {
1310: $url{$lang} = $defaulturl;
1311: }
1312: if ($type{$lang} eq '') {
1313: $type{$lang} = $defaulttype;
1314: }
1315: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1316: if ($lang eq 'nolang') {
1317: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1318: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1319: } else {
1320: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1321: $langchoices{$lang},
1322: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1323: }
1324: $datatable .= '</span></td>'."\n".
1325: '<td class="LC_left_item">';
1326: if ($type{$lang} eq 'custom') {
1327: $datatable .= '<span class="LC_nobreak"><label>'.
1328: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1329: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1330: } else {
1331: $datatable .= $lt{'upl'};
1332: }
1333: $datatable .='<br />';
1334: if ($switchserver) {
1335: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1336: } else {
1337: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1338: }
1.160.6.5 raeburn 1339: $datatable .= '</td></tr>';
1340: $itemcount ++;
1.6 raeburn 1341: }
1.160.6.5 raeburn 1342: my @addlangs;
1343: foreach my $lang (sort(keys(%langchoices))) {
1344: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1345: push(@addlangs,$lang);
1346: }
1347: if (@addlangs > 0) {
1348: my %toadd;
1349: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1350: $toadd{''} = &mt('Select');
1351: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1352: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1353: &mt('Add log-in help page for a specific language:').' '.
1354: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1355: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1356: if ($switchserver) {
1357: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1358: } else {
1359: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1360: }
1.160.6.5 raeburn 1361: $datatable .= '</td></tr>';
1362: $itemcount ++;
1.6 raeburn 1363: }
1.160.6.5 raeburn 1364: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1365: } elsif ($caller eq 'headtag') {
1366: my %domservers = &Apache::lonnet::get_servers($dom);
1367: my $choice = $choices{'headtag'};
1368: $css_class = ' class="LC_odd_row"';
1369: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1370: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1371: '<th>'.$choices{'current'}.'</th>'.
1372: '<th>'.$choices{'action'}.'</th>'.
1373: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1374: my (%currurls,%currexempt);
1375: if (ref($settings) eq 'HASH') {
1376: if (ref($settings->{'headtag'}) eq 'HASH') {
1377: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1378: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1379: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1380: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1381: }
1382: }
1383: }
1384: }
1385: foreach my $lonhost (sort(keys(%domservers))) {
1386: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1387: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1388: if ($currurls{$lonhost}) {
1389: $datatable .= '<td class="LC_right_item"><a href="'.
1390: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1391: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1392: '">'.$lt{'curr'}.'</a></td>'.
1393: '<td><span class="LC_nobreak"><label>'.
1394: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1395: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1396: } else {
1397: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1398: }
1399: $datatable .='<br />';
1400: if ($switchserver) {
1401: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1402: } else {
1403: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1404: }
1.160.6.87 raeburn 1405: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56 raeburn 1406: }
1407: $datatable .= '</table></td></tr>';
1.160.6.113 raeburn 1408: } elsif ($caller eq 'saml') {
1409: my %domservers = &Apache::lonnet::get_servers($dom);
1410: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1411: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1412: '<th>'.$choices{'samllanding'}.'</th>'.
1413: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1414: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso,%styleon,%styleoff);
1415: foreach my $lonhost (keys(%domservers)) {
1416: $samlurl{$lonhost} = '/adm/sso';
1417: $styleon{$lonhost} = 'display:none';
1418: $styleoff{$lonhost} = '';
1419: }
1420: if (ref($settings->{'saml'}) eq 'HASH') {
1421: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1422: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1423: $saml{$lonhost} = 1;
1424: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1425: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1426: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1427: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1428: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1429: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1430: $styleon{$lonhost} = '';
1431: $styleoff{$lonhost} = 'display:none';
1432: } else {
1433: $styleon{$lonhost} = 'display:none';
1434: $styleoff{$lonhost} = '';
1435: }
1436: }
1437: }
1438: my $itemcount = 1;
1439: foreach my $lonhost (sort(keys(%domservers))) {
1440: my $samlon = ' ';
1441: my $samloff = ' checked="checked" ';
1442: if ($saml{$lonhost}) {
1443: $samlon = $samloff;
1444: $samloff = ' ';
1445: }
1446: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1447: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1448: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1449: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1450: &mt('No').'</label>'.(' 'x2).
1451: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1452: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1453: &mt('Yes').'</label></span></td>'.
1454: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1455: '<table><tr><th colspan="5" align="center">'.&mt('SSO').'</th><th align="center">'.
1456: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1457: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1458: '<th>'.&mt('Alt Text').'</th><th>'.&mt('URL').'</th>'.
1459: '<th>'.&mt('Tool Tip').'</th><th>'.&mt('Text').'</th></tr>'.
1460: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="8" value="'.
1461: $samltext{$lonhost}.'" /></td><td>';
1462: if ($samlimg{$lonhost}) {
1463: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1464: '<span class="LC_nobreak"><label>'.
1465: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1466: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1467: } else {
1468: $datatable .= $lt{'upl'};
1469: }
1470: $datatable .='<br />';
1471: if ($switchserver) {
1472: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1473: } else {
1474: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1475: }
1476: $datatable .= '</td>'.
1477: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="20" '.
1478: 'value="'.$samlalt{$lonhost}.'" /></td>'.
1479: '<td><input type="text" name="saml_url_'.$lonhost.'" size="8" '.
1480: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1481: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="15">'.
1482: $samltitle{$lonhost}.'</textarea></td>'.
1483: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="8" '.
1484: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1485: '</table></td>'.
1486: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1487: $itemcount ++;
1488: }
1489: $datatable .= '</table></td></tr>';
1.1 raeburn 1490: }
1.6 raeburn 1491: return $datatable;
1492: }
1493:
1494: sub login_choices {
1495: my %choices =
1496: &Apache::lonlocal::texthash (
1.116 bisitz 1497: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1498: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1499: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1500: disallowlogin => "Login page requests redirected",
1501: hostid => "Server",
1.128 raeburn 1502: server => "Redirect to:",
1503: serverpath => "Path",
1504: custompath => "Custom",
1505: exempt => "Exempt IP(s)",
1.110 raeburn 1506: directlogin => "No redirect",
1507: newuser => "Link to create a user account",
1508: img => "Header",
1509: logo => "Main Logo",
1510: domlogo => "Domain Logo",
1511: login => "Log-in Header",
1512: textcol => "Text color",
1513: bgcol => "Box color",
1514: bgs => "Background colors",
1515: links => "Link colors",
1516: font => "Font color",
1517: pgbg => "Header",
1518: mainbg => "Page",
1519: sidebg => "Login box",
1520: link => "Link",
1521: alink => "Active link",
1522: vlink => "Visited link",
1.160.6.56 raeburn 1523: headtag => "Custom markup",
1524: action => "Action",
1525: current => "Current",
1.160.6.113 raeburn 1526: samllanding => "Dual login?",
1527: samloptions => "Options",
1.160.6.119 raeburn 1528: alttext => "Alt text",
1.6 raeburn 1529: );
1530: return %choices;
1531: }
1532:
1.160.6.113 raeburn 1533: sub login_file_options {
1534: return &Apache::lonlocal::texthash(
1535: del => 'Delete?',
1536: rep => 'Replace:',
1537: upl => 'Upload:',
1538: curr => 'View contents',
1539: default => 'Default',
1540: custom => 'Custom',
1541: none => 'None',
1542: );
1543: }
1544:
1545: sub print_ipaccess {
1546: my ($dom,$settings,$rowtotal) = @_;
1547: my $css_class;
1548: my $itemcount = 0;
1549: my $datatable;
1550: my %ordered;
1551: if (ref($settings) eq 'HASH') {
1552: foreach my $item (keys(%{$settings})) {
1553: if (ref($settings->{$item}) eq 'HASH') {
1554: my $num = $settings->{$item}{'order'};
1555: if ($num eq '') {
1556: $num = scalar(keys(%{$settings}));
1557: }
1558: $ordered{$num} = $item;
1559: }
1560: }
1561: }
1562: my $maxnum = scalar(keys(%ordered));
1563: if (keys(%ordered)) {
1564: my @items = sort { $a <=> $b } keys(%ordered);
1565: for (my $i=0; $i<@items; $i++) {
1566: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1567: my $item = $ordered{$items[$i]};
1568: my ($name,$ipranges,%commblocks,%courses);
1569: if (ref($settings->{$item}) eq 'HASH') {
1570: $name = $settings->{$item}->{'name'};
1571: $ipranges = $settings->{$item}->{'ip'};
1572: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1573: %commblocks = %{$settings->{$item}->{'commblocks'}};
1574: }
1575: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1576: %courses = %{$settings->{$item}->{'courses'}};
1577: }
1578: }
1579: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1580: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1581: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1582: for (my $k=0; $k<=$maxnum; $k++) {
1583: my $vpos = $k+1;
1584: my $selstr;
1585: if ($k == $i) {
1586: $selstr = ' selected="selected" ';
1587: }
1588: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1589: }
1590: $datatable .= '</select>'.(' 'x2).
1591: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1592: &mt('Delete?').'</label></span></td>'.
1593: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1594: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1595: '</td></tr>';
1596: $itemcount ++;
1597: }
1598: }
1599: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1600: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1601: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1602: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1603: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1604: for (my $k=0; $k<$maxnum+1; $k++) {
1605: my $vpos = $k+1;
1606: my $selstr;
1607: if ($k == $maxnum) {
1608: $selstr = ' selected="selected" ';
1609: }
1610: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1611: }
1612: $datatable .= '</select> '."\n".
1613: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1614: '<td colspan="2">'.
1615: &ipaccess_options('add',$itemcount,$dom).
1616: '</td>'."\n".
1617: '</tr>'."\n";
1618: $$rowtotal ++;
1619: return $datatable;
1620: }
1621:
1622: sub ipaccess_options {
1623: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1624: my (%currblocks,%currcourses,$output);
1625: if (ref($blocksref) eq 'HASH') {
1626: %currblocks = %{$blocksref};
1627: }
1628: if (ref($coursesref) eq 'HASH') {
1629: %currcourses = %{$coursesref};
1630: }
1631: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1632: '<span class="LC_nobreak">'.&mt('Name').': '.
1633: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1634: '</span></fieldset>'.
1635: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1636: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1637: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1638: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1639: $ipranges.'</textarea></fieldset>'.
1640: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1641: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1642: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1643: '<table>';
1644: foreach my $cid (sort(keys(%currcourses))) {
1645: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1646: $output .= '<tr><td><span class="LC_nobreak">'.
1647: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1648: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1649: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1650: }
1651: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1652: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1653: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1654: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1655: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1656: '</span></td></tr></table>'."\n".
1657: '</fieldset>';
1658: return $output;
1659: }
1660:
1661: sub blocker_checkboxes {
1662: my ($num,$blocks) = @_;
1663: my ($typeorder,$types) = &commblocktype_text();
1664: my $numinrow = 6;
1665: my $output = '<table>';
1666: for (my $i=0; $i<@{$typeorder}; $i++) {
1667: my $block = $typeorder->[$i];
1668: my $blockstatus;
1669: if (ref($blocks) eq 'HASH') {
1670: if ($blocks->{$block} eq 'on') {
1671: $blockstatus = 'checked="checked"';
1672: }
1673: }
1674: my $rem = $i%($numinrow);
1675: if ($rem == 0) {
1676: if ($i > 0) {
1677: $output .= '</tr>';
1678: }
1679: $output .= '<tr>';
1680: }
1681: if ($i == scalar(@{$typeorder})-1) {
1682: my $colsleft = $numinrow-$rem;
1683: if ($colsleft > 1) {
1684: $output .= '<td colspan="'.$colsleft.'">';
1685: } else {
1686: $output .= '<td>';
1687: }
1688: } else {
1689: $output .= '<td>';
1690: }
1691: my $item = 'ipaccess_block_'.$num;
1692: if ($blockstatus) {
1693: $blockstatus = ' '.$blockstatus;
1694: }
1695: $output .= '<span class="LC_nobreak"><label>'."\n".
1696: '<input type="checkbox" name="'.$item.'"'.
1697: $blockstatus.' value="'.$block.'"'.' />'.
1698: $types->{$block}.'</label></span>'."\n".
1699: '<br /></td>';
1700: }
1701: $output .= '</tr></table>';
1702: return $output;
1703: }
1704:
1705: sub commblocktype_text {
1706: my %types = &Apache::lonlocal::texthash(
1707: 'com' => 'Messaging',
1708: 'chat' => 'Chat Room',
1709: 'boards' => 'Discussion',
1710: 'port' => 'Portfolio',
1711: 'groups' => 'Groups',
1712: 'blogs' => 'Blogs',
1713: 'about' => 'User Information',
1714: 'printout' => 'Printouts',
1715: 'passwd' => 'Change Password',
1716: 'grades' => 'Gradebook',
1.160.6.115 raeburn 1717: 'search' => 'Course search',
1718: 'wishlist' => 'Stored links',
1719: 'annotate' => 'Annotations',
1.160.6.113 raeburn 1720: );
1.160.6.115 raeburn 1721: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.160.6.113 raeburn 1722: return ($typeorder,\%types);
1723: }
1724:
1.6 raeburn 1725: sub print_rolecolors {
1.30 raeburn 1726: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1727: my %choices = &color_font_choices();
1728: my @bgs = ('pgbg','tabbg','sidebg');
1729: my @links = ('link','alink','vlink');
1730: my @images = ('img');
1731: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1732: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1733: my %defaultdesign = %Apache::loncommon::defaultdesign;
1734: my (%is_custom,%designs);
1.160.6.22 raeburn 1735: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1736: if (ref($settings) eq 'HASH') {
1737: if (ref($settings->{$role}) eq 'HASH') {
1738: if ($settings->{$role}->{'img'} ne '') {
1739: $designs{'img'} = $settings->{$role}->{'img'};
1740: $is_custom{'img'} = 1;
1741: }
1742: if ($settings->{$role}->{'font'} ne '') {
1743: $designs{'font'} = $settings->{$role}->{'font'};
1744: $is_custom{'font'} = 1;
1745: }
1.97 tempelho 1746: if ($settings->{$role}->{'fontmenu'} ne '') {
1747: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1748: $is_custom{'fontmenu'} = 1;
1749: }
1.6 raeburn 1750: foreach my $item (@bgs) {
1751: if ($settings->{$role}->{$item} ne '') {
1752: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1753: $is_custom{$item} = 1;
1754: }
1755: }
1756: foreach my $item (@links) {
1757: if ($settings->{$role}->{$item} ne '') {
1758: $designs{'links'}{$item} = $settings->{$role}->{$item};
1759: $is_custom{$item} = 1;
1760: }
1761: }
1762: }
1763: } else {
1764: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1765: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1766: $is_custom{'img'} = 1;
1767: }
1.97 tempelho 1768: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1769: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1770: $is_custom{'fontmenu'} = 1;
1771: }
1.6 raeburn 1772: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1773: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1774: $is_custom{'font'} = 1;
1775: }
1776: foreach my $item (@bgs) {
1777: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1778: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1779: $is_custom{$item} = 1;
1780:
1781: }
1782: }
1783: foreach my $item (@links) {
1784: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1785: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1786: $is_custom{$item} = 1;
1787: }
1788: }
1789: }
1790: my $itemcount = 1;
1.30 raeburn 1791: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1792: $datatable .= '</tr></table></td></tr>';
1793: return $datatable;
1794: }
1795:
1.160.6.22 raeburn 1796: sub role_defaults {
1797: my ($role,$bgs,$links,$images,$logintext) = @_;
1798: my %defaults;
1799: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1800: return %defaults;
1801: }
1802: my %defaultdesign = %Apache::loncommon::defaultdesign;
1803: if ($role eq 'login') {
1804: %defaults = (
1805: font => $defaultdesign{$role.'.font'},
1806: );
1807: if (ref($logintext) eq 'ARRAY') {
1808: foreach my $item (@{$logintext}) {
1809: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1810: }
1811: }
1812: foreach my $item (@{$images}) {
1813: $defaults{'showlogo'}{$item} = 1;
1814: }
1815: } else {
1816: %defaults = (
1817: img => $defaultdesign{$role.'.img'},
1818: font => $defaultdesign{$role.'.font'},
1819: fontmenu => $defaultdesign{$role.'.fontmenu'},
1820: );
1821: }
1822: foreach my $item (@{$bgs}) {
1823: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1824: }
1825: foreach my $item (@{$links}) {
1826: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1827: }
1828: foreach my $item (@{$images}) {
1829: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1830: }
1831: return %defaults;
1832: }
1833:
1.6 raeburn 1834: sub display_color_options {
1.9 raeburn 1835: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1836: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1837: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1838: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1839: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1840: '<td>'.$choices->{'font'}.'</td>';
1841: if (!$is_custom->{'font'}) {
1.160.6.87 raeburn 1842: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1843: } else {
1844: $datatable .= '<td> </td>';
1845: }
1.160.6.9 raeburn 1846: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1847:
1.8 raeburn 1848: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1849: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1850: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1851: ' </span></td></tr>';
1.107 raeburn 1852: unless ($role eq 'login') {
1853: $datatable .= '<tr'.$css_class.'>'.
1854: '<td>'.$choices->{'fontmenu'}.'</td>';
1855: if (!$is_custom->{'fontmenu'}) {
1.160.6.87 raeburn 1856: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1857: } else {
1858: $datatable .= '<td> </td>';
1859: }
1.160.6.22 raeburn 1860: $current_color = $designs->{'fontmenu'} ?
1861: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1862: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1863: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1864: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1865: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1866: ' </span></td></tr>';
1.97 tempelho 1867: }
1.9 raeburn 1868: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1869: foreach my $img (@{$images}) {
1.18 albertel 1870: $itemcount ++;
1.6 raeburn 1871: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1872: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1873: '<td>'.$choices->{$img};
1.160.6.119 raeburn 1874: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 1875: if ($role eq 'login') {
1876: if ($img eq 'login') {
1877: $login_hdr_pick =
1.135 bisitz 1878: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1879: $logincolors =
1880: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1881: $designs,$defaults);
1.160.6.121 raeburn 1882: } else {
1.160.6.119 raeburn 1883: if ($img ne 'domlogo') {
1884: $datatable.= &logo_display_options($img,$defaults,$designs);
1885: }
1886: if (ref($designs->{'alttext'}) eq 'HASH') {
1887: $alttext = $designs->{'alttext'}{$img};
1888: }
1.70 raeburn 1889: }
1890: }
1891: $datatable .= '</td>';
1.6 raeburn 1892: if ($designs->{$img} ne '') {
1893: $imgfile = $designs->{$img};
1.18 albertel 1894: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1895: } else {
1896: $imgfile = $defaults->{$img};
1897: }
1898: if ($imgfile) {
1.9 raeburn 1899: my ($showfile,$fullsize);
1900: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1901: my $urldir = $1;
1902: my $filename = $2;
1903: my @info = &Apache::lonnet::stat_file($designs->{$img});
1904: if (@info) {
1905: my $thumbfile = 'tn-'.$filename;
1906: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1907: if (@thumb) {
1908: $showfile = $urldir.'/'.$thumbfile;
1909: } else {
1910: $showfile = $imgfile;
1911: }
1912: } else {
1913: $showfile = '';
1914: }
1915: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1916: $showfile = $imgfile;
1.6 raeburn 1917: my $imgdir = $1;
1918: my $filename = $2;
1.159 raeburn 1919: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1920: $showfile = "/$imgdir/tn-".$filename;
1921: } else {
1.159 raeburn 1922: my $input = $londocroot.$imgfile;
1923: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1924: if (!-e $output) {
1.9 raeburn 1925: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1926: my ($fullwidth,$fullheight) = &check_dimensions($input);
1927: if ($fullwidth ne '' && $fullheight ne '') {
1928: if ($fullwidth > $width && $fullheight > $height) {
1929: my $size = $width.'x'.$height;
1.160.6.88 raeburn 1930: my @args = ('convert','-sample',$size,$input,$output);
1931: system({$args[0]} @args);
1.159 raeburn 1932: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1933: }
1934: }
1.6 raeburn 1935: }
1936: }
1.16 raeburn 1937: }
1.6 raeburn 1938: if ($showfile) {
1.40 raeburn 1939: if ($showfile =~ m{^/(adm|res)/}) {
1940: if ($showfile =~ m{^/res/}) {
1941: my $local_showfile =
1942: &Apache::lonnet::filelocation('',$showfile);
1943: &Apache::lonnet::repcopy($local_showfile);
1944: }
1945: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1946: }
1947: if ($imgfile) {
1948: if ($imgfile =~ m{^/(adm|res)/}) {
1949: if ($imgfile =~ m{^/res/}) {
1950: my $local_imgfile =
1951: &Apache::lonnet::filelocation('',$imgfile);
1952: &Apache::lonnet::repcopy($local_imgfile);
1953: }
1954: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1955: } else {
1956: $fullsize = $imgfile;
1957: }
1958: }
1.41 raeburn 1959: $datatable .= '<td>';
1960: if ($img eq 'login') {
1.135 bisitz 1961: $datatable .= $login_hdr_pick;
1962: }
1.41 raeburn 1963: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1964: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1965: } else {
1.160.6.22 raeburn 1966: $datatable .= '<td> </td><td class="LC_left_item">'.
1967: &mt('Upload:').'<br />';
1.6 raeburn 1968: }
1969: } else {
1.160.6.22 raeburn 1970: $datatable .= '<td> </td><td class="LC_left_item">'.
1971: &mt('Upload:').'<br />';
1.6 raeburn 1972: }
1.9 raeburn 1973: if ($switchserver) {
1974: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1975: } else {
1.135 bisitz 1976: if ($img ne 'login') { # suppress file selection for Log-in header
1977: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1978: }
1.9 raeburn 1979: }
1.160.6.119 raeburn 1980: if (($role eq 'login') && ($img ne 'login')) {
1981: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
1982: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
1983: '</label></span>';
1984: }
1.9 raeburn 1985: $datatable .= '</td></tr>';
1.6 raeburn 1986: }
1987: $itemcount ++;
1988: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1989: $datatable .= '<tr'.$css_class.'>'.
1990: '<td>'.$choices->{'bgs'}.'</td>';
1991: my $bgs_def;
1992: foreach my $item (@{$bgs}) {
1993: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1994: $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 1995: }
1996: }
1997: if ($bgs_def) {
1.8 raeburn 1998: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1999: } else {
2000: $datatable .= '<td> </td>';
2001: }
2002: $datatable .= '<td class="LC_right_item">'.
2003: '<table border="0"><tr>';
1.160.6.13 raeburn 2004:
1.6 raeburn 2005: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 2006: $datatable .= '<td align="center">'.$choices->{$item};
2007: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2008: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 2009: $datatable .= ' ';
1.6 raeburn 2010: }
1.160.6.9 raeburn 2011: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2012: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2013: }
2014: $datatable .= '</tr></table></td></tr>';
2015: $itemcount ++;
2016: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2017: $datatable .= '<tr'.$css_class.'>'.
2018: '<td>'.$choices->{'links'}.'</td>';
2019: my $links_def;
2020: foreach my $item (@{$links}) {
2021: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 2022: $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 2023: }
2024: }
2025: if ($links_def) {
1.8 raeburn 2026: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2027: } else {
2028: $datatable .= '<td> </td>';
2029: }
2030: $datatable .= '<td class="LC_right_item">'.
2031: '<table border="0"><tr>';
2032: foreach my $item (@{$links}) {
1.160.6.39 raeburn 2033: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 2034: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 2035: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 2036: $datatable.=' ';
1.6 raeburn 2037: }
1.160.6.9 raeburn 2038: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2039: '" /></td>';
2040: }
1.30 raeburn 2041: $$rowtotal += $itemcount;
1.3 raeburn 2042: return $datatable;
2043: }
2044:
1.70 raeburn 2045: sub logo_display_options {
2046: my ($img,$defaults,$designs) = @_;
2047: my $checkedon;
2048: if (ref($defaults) eq 'HASH') {
2049: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2050: if ($defaults->{'showlogo'}{$img}) {
2051: $checkedon = 'checked="checked" ';
2052: }
2053: }
2054: }
2055: if (ref($designs) eq 'HASH') {
2056: if (ref($designs->{'showlogo'}) eq 'HASH') {
2057: if (defined($designs->{'showlogo'}{$img})) {
2058: if ($designs->{'showlogo'}{$img} == 0) {
2059: $checkedon = '';
2060: } elsif ($designs->{'showlogo'}{$img} == 1) {
2061: $checkedon = 'checked="checked" ';
2062: }
2063: }
2064: }
2065: }
2066: return '<br /><label> <input type="checkbox" name="'.
2067: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2068: &mt('show').'</label>'."\n";
2069: }
2070:
1.41 raeburn 2071: sub login_header_options {
1.135 bisitz 2072: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2073: my $output = '';
1.41 raeburn 2074: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2075: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2076: if (!$is_custom->{'textcol'}) {
2077: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2078: ' ';
2079: }
2080: if (!$is_custom->{'bgcol'}) {
2081: $output .= $choices->{'bgcol'}.': '.
2082: '<span id="css_'.$role.'_font" style="background-color: '.
2083: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2084: }
2085: $output .= '<br />';
2086: }
2087: $output .='<br />';
2088: return $output;
2089: }
2090:
2091: sub login_text_colors {
1.160.6.22 raeburn 2092: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2093: my $color_menu = '<table border="0"><tr>';
2094: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 2095: $color_menu .= '<td align="center">'.$choices->{$item};
2096: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2097: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2098: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2099: }
2100: $color_menu .= '</tr></table><br />';
2101: return $color_menu;
2102: }
2103:
2104: sub image_changes {
2105: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2106: my $output;
1.135 bisitz 2107: if ($img eq 'login') {
1.160.6.87 raeburn 2108: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2109: } elsif (!$is_custom) {
1.70 raeburn 2110: if ($img ne 'domlogo') {
1.160.6.87 raeburn 2111: $output = &mt('Default image:').'<br />';
1.41 raeburn 2112: } else {
1.160.6.87 raeburn 2113: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2114: }
2115: }
1.160.6.87 raeburn 2116: if ($img ne 'login') {
1.135 bisitz 2117: if ($img_import) {
2118: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2119: }
2120: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2121: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2122: if ($is_custom) {
2123: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2124: '<input type="checkbox" name="'.
2125: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2126: '</label> '.&mt('Replace:').'</span><br />';
2127: } else {
1.160.6.22 raeburn 2128: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2129: }
1.41 raeburn 2130: }
2131: return $output;
2132: }
2133:
1.3 raeburn 2134: sub print_quotas {
1.86 raeburn 2135: my ($dom,$settings,$rowtotal,$action) = @_;
2136: my $context;
2137: if ($action eq 'quotas') {
2138: $context = 'tools';
2139: } else {
2140: $context = $action;
2141: }
1.160.6.20 raeburn 2142: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2143: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2144: my $typecount = 0;
1.101 raeburn 2145: my ($css_class,%titles);
1.86 raeburn 2146: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 2147: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 2148: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2149: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2150: %titles = &courserequest_titles();
1.160.6.5 raeburn 2151: } elsif ($context eq 'requestauthor') {
2152: @usertools = ('author');
2153: @options = ('norequest','approval','automatic');
2154: %titles = &authorrequest_titles();
1.86 raeburn 2155: } else {
1.160.6.4 raeburn 2156: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 2157: %titles = &tool_titles();
1.86 raeburn 2158: }
1.26 raeburn 2159: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2160: foreach my $type (@{$types}) {
1.160.6.20 raeburn 2161: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 2162: unless (($context eq 'requestcourses') ||
2163: ($context eq 'requestauthor')) {
1.86 raeburn 2164: if (ref($settings) eq 'HASH') {
2165: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 2166: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2167: } else {
2168: $currdefquota = $settings->{$type};
2169: }
1.160.6.20 raeburn 2170: if (ref($settings->{authorquota}) eq 'HASH') {
2171: $currauthorquota = $settings->{authorquota}->{$type};
2172: }
1.78 raeburn 2173: }
1.72 raeburn 2174: }
1.3 raeburn 2175: if (defined($usertypes->{$type})) {
2176: $typecount ++;
2177: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2178: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2179: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2180: '<td class="LC_left_item">';
1.101 raeburn 2181: if ($context eq 'requestcourses') {
2182: $datatable .= '<table><tr>';
2183: }
2184: my %cell;
1.72 raeburn 2185: foreach my $item (@usertools) {
1.101 raeburn 2186: if ($context eq 'requestcourses') {
2187: my ($curroption,$currlimit);
2188: if (ref($settings) eq 'HASH') {
2189: if (ref($settings->{$item}) eq 'HASH') {
2190: $curroption = $settings->{$item}->{$type};
2191: if ($curroption =~ /^autolimit=(\d*)$/) {
2192: $currlimit = $1;
2193: }
2194: }
2195: }
2196: if (!$curroption) {
2197: $curroption = 'norequest';
2198: }
2199: $datatable .= '<th>'.$titles{$item}.'</th>';
2200: foreach my $option (@options) {
2201: my $val = $option;
2202: if ($option eq 'norequest') {
2203: $val = 0;
2204: }
2205: if ($option eq 'validate') {
2206: my $canvalidate = 0;
2207: if (ref($validations{$item}) eq 'HASH') {
2208: if ($validations{$item}{$type}) {
2209: $canvalidate = 1;
2210: }
2211: }
2212: next if (!$canvalidate);
2213: }
2214: my $checked = '';
2215: if ($option eq $curroption) {
2216: $checked = ' checked="checked"';
2217: } elsif ($option eq 'autolimit') {
2218: if ($curroption =~ /^autolimit/) {
2219: $checked = ' checked="checked"';
2220: }
2221: }
2222: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2223: '<input type="radio" name="crsreq_'.$item.
2224: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2225: $titles{$option}.'</label>';
1.101 raeburn 2226: if ($option eq 'autolimit') {
1.127 raeburn 2227: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2228: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2229: 'value="'.$currlimit.'" />';
1.101 raeburn 2230: }
1.127 raeburn 2231: $cell{$item} .= '</span> ';
1.103 raeburn 2232: if ($option eq 'autolimit') {
1.127 raeburn 2233: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2234: }
1.101 raeburn 2235: }
1.160.6.5 raeburn 2236: } elsif ($context eq 'requestauthor') {
2237: my $curroption;
2238: if (ref($settings) eq 'HASH') {
2239: $curroption = $settings->{$type};
2240: }
2241: if (!$curroption) {
2242: $curroption = 'norequest';
2243: }
2244: foreach my $option (@options) {
2245: my $val = $option;
2246: if ($option eq 'norequest') {
2247: $val = 0;
2248: }
2249: my $checked = '';
2250: if ($option eq $curroption) {
2251: $checked = ' checked="checked"';
2252: }
2253: $datatable .= '<span class="LC_nobreak"><label>'.
2254: '<input type="radio" name="authorreq_'.$type.
2255: '" value="'.$val.'"'.$checked.' />'.
2256: $titles{$option}.'</label></span> ';
2257: }
1.101 raeburn 2258: } else {
2259: my $checked = 'checked="checked" ';
2260: if (ref($settings) eq 'HASH') {
2261: if (ref($settings->{$item}) eq 'HASH') {
2262: if ($settings->{$item}->{$type} == 0) {
2263: $checked = '';
2264: } elsif ($settings->{$item}->{$type} == 1) {
2265: $checked = 'checked="checked" ';
2266: }
1.78 raeburn 2267: }
1.72 raeburn 2268: }
1.101 raeburn 2269: $datatable .= '<span class="LC_nobreak"><label>'.
2270: '<input type="checkbox" name="'.$context.'_'.$item.
2271: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2272: '</label></span> ';
1.72 raeburn 2273: }
1.101 raeburn 2274: }
2275: if ($context eq 'requestcourses') {
2276: $datatable .= '</tr><tr>';
2277: foreach my $item (@usertools) {
1.106 raeburn 2278: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2279: }
2280: $datatable .= '</tr></table>';
1.72 raeburn 2281: }
1.86 raeburn 2282: $datatable .= '</td>';
1.160.6.5 raeburn 2283: unless (($context eq 'requestcourses') ||
2284: ($context eq 'requestauthor')) {
1.86 raeburn 2285: $datatable .=
1.160.6.20 raeburn 2286: '<td class="LC_right_item">'.
2287: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2288: '<input type="text" name="quota_'.$type.
1.72 raeburn 2289: '" value="'.$currdefquota.
1.160.6.20 raeburn 2290: '" size="5" /></span>'.(' ' x 2).
2291: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2292: '<input type="text" name="authorquota_'.$type.
2293: '" value="'.$currauthorquota.
2294: '" size="5" /></span></td>';
1.86 raeburn 2295: }
2296: $datatable .= '</tr>';
1.3 raeburn 2297: }
2298: }
2299: }
1.160.6.5 raeburn 2300: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2301: $defaultquota = '20';
1.160.6.20 raeburn 2302: $authorquota = '500';
1.86 raeburn 2303: if (ref($settings) eq 'HASH') {
2304: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2305: $defaultquota = $settings->{'defaultquota'}->{'default'};
2306: } elsif (defined($settings->{'default'})) {
2307: $defaultquota = $settings->{'default'};
2308: }
1.160.6.20 raeburn 2309: if (ref($settings->{'authorquota'}) eq 'HASH') {
2310: $authorquota = $settings->{'authorquota'}->{'default'};
2311: }
1.3 raeburn 2312: }
2313: }
2314: $typecount ++;
2315: $css_class = $typecount%2?' class="LC_odd_row"':'';
2316: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2317: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2318: '<td class="LC_left_item">';
1.101 raeburn 2319: if ($context eq 'requestcourses') {
2320: $datatable .= '<table><tr>';
2321: }
2322: my %defcell;
1.72 raeburn 2323: foreach my $item (@usertools) {
1.101 raeburn 2324: if ($context eq 'requestcourses') {
2325: my ($curroption,$currlimit);
2326: if (ref($settings) eq 'HASH') {
2327: if (ref($settings->{$item}) eq 'HASH') {
2328: $curroption = $settings->{$item}->{'default'};
2329: if ($curroption =~ /^autolimit=(\d*)$/) {
2330: $currlimit = $1;
2331: }
2332: }
2333: }
2334: if (!$curroption) {
2335: $curroption = 'norequest';
2336: }
2337: $datatable .= '<th>'.$titles{$item}.'</th>';
2338: foreach my $option (@options) {
2339: my $val = $option;
2340: if ($option eq 'norequest') {
2341: $val = 0;
2342: }
2343: if ($option eq 'validate') {
2344: my $canvalidate = 0;
2345: if (ref($validations{$item}) eq 'HASH') {
2346: if ($validations{$item}{'default'}) {
2347: $canvalidate = 1;
2348: }
2349: }
2350: next if (!$canvalidate);
2351: }
2352: my $checked = '';
2353: if ($option eq $curroption) {
2354: $checked = ' checked="checked"';
2355: } elsif ($option eq 'autolimit') {
2356: if ($curroption =~ /^autolimit/) {
2357: $checked = ' checked="checked"';
2358: }
2359: }
2360: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2361: '<input type="radio" name="crsreq_'.$item.
2362: '_default" value="'.$val.'"'.$checked.' />'.
2363: $titles{$option}.'</label>';
2364: if ($option eq 'autolimit') {
1.127 raeburn 2365: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2366: $item.'_limit_default" size="1" '.
2367: 'value="'.$currlimit.'" />';
2368: }
1.127 raeburn 2369: $defcell{$item} .= '</span> ';
1.104 raeburn 2370: if ($option eq 'autolimit') {
1.127 raeburn 2371: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2372: }
1.101 raeburn 2373: }
1.160.6.5 raeburn 2374: } elsif ($context eq 'requestauthor') {
2375: my $curroption;
2376: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 2377: $curroption = $settings->{'default'};
1.160.6.5 raeburn 2378: }
2379: if (!$curroption) {
2380: $curroption = 'norequest';
2381: }
2382: foreach my $option (@options) {
2383: my $val = $option;
2384: if ($option eq 'norequest') {
2385: $val = 0;
2386: }
2387: my $checked = '';
2388: if ($option eq $curroption) {
2389: $checked = ' checked="checked"';
2390: }
2391: $datatable .= '<span class="LC_nobreak"><label>'.
2392: '<input type="radio" name="authorreq_default"'.
2393: ' value="'.$val.'"'.$checked.' />'.
2394: $titles{$option}.'</label></span> ';
2395: }
1.101 raeburn 2396: } else {
2397: my $checked = 'checked="checked" ';
2398: if (ref($settings) eq 'HASH') {
2399: if (ref($settings->{$item}) eq 'HASH') {
2400: if ($settings->{$item}->{'default'} == 0) {
2401: $checked = '';
2402: } elsif ($settings->{$item}->{'default'} == 1) {
2403: $checked = 'checked="checked" ';
2404: }
1.78 raeburn 2405: }
1.72 raeburn 2406: }
1.101 raeburn 2407: $datatable .= '<span class="LC_nobreak"><label>'.
2408: '<input type="checkbox" name="'.$context.'_'.$item.
2409: '" value="default" '.$checked.'/>'.$titles{$item}.
2410: '</label></span> ';
2411: }
2412: }
2413: if ($context eq 'requestcourses') {
2414: $datatable .= '</tr><tr>';
2415: foreach my $item (@usertools) {
1.106 raeburn 2416: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2417: }
1.101 raeburn 2418: $datatable .= '</tr></table>';
1.72 raeburn 2419: }
1.86 raeburn 2420: $datatable .= '</td>';
1.160.6.5 raeburn 2421: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2422: $datatable .= '<td class="LC_right_item">'.
2423: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2424: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2425: $defaultquota.'" size="5" /></span>'.(' ' x2).
2426: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2427: '<input type="text" name="authorquota" value="'.
2428: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2429: }
2430: $datatable .= '</tr>';
1.72 raeburn 2431: $typecount ++;
2432: $css_class = $typecount%2?' class="LC_odd_row"':'';
2433: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2434: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2435: if ($context eq 'requestcourses') {
1.109 raeburn 2436: $datatable .= &mt('(overrides affiliation, if set)').
2437: '</td>'.
2438: '<td class="LC_left_item">'.
2439: '<table><tr>';
1.101 raeburn 2440: } else {
1.109 raeburn 2441: $datatable .= &mt('(overrides affiliation, if checked)').
2442: '</td>'.
2443: '<td class="LC_left_item" colspan="2">'.
2444: '<br />';
1.101 raeburn 2445: }
2446: my %advcell;
1.72 raeburn 2447: foreach my $item (@usertools) {
1.101 raeburn 2448: if ($context eq 'requestcourses') {
2449: my ($curroption,$currlimit);
2450: if (ref($settings) eq 'HASH') {
2451: if (ref($settings->{$item}) eq 'HASH') {
2452: $curroption = $settings->{$item}->{'_LC_adv'};
2453: if ($curroption =~ /^autolimit=(\d*)$/) {
2454: $currlimit = $1;
2455: }
2456: }
2457: }
2458: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2459: my $checked = '';
2460: if ($curroption eq '') {
2461: $checked = ' checked="checked"';
2462: }
2463: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2464: '<input type="radio" name="crsreq_'.$item.
2465: '__LC_adv" value=""'.$checked.' />'.
2466: &mt('No override set').'</label></span> ';
1.101 raeburn 2467: foreach my $option (@options) {
2468: my $val = $option;
2469: if ($option eq 'norequest') {
2470: $val = 0;
2471: }
2472: if ($option eq 'validate') {
2473: my $canvalidate = 0;
2474: if (ref($validations{$item}) eq 'HASH') {
2475: if ($validations{$item}{'_LC_adv'}) {
2476: $canvalidate = 1;
2477: }
2478: }
2479: next if (!$canvalidate);
2480: }
2481: my $checked = '';
1.104 raeburn 2482: if ($val eq $curroption) {
1.101 raeburn 2483: $checked = ' checked="checked"';
2484: } elsif ($option eq 'autolimit') {
2485: if ($curroption =~ /^autolimit/) {
2486: $checked = ' checked="checked"';
2487: }
2488: }
2489: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2490: '<input type="radio" name="crsreq_'.$item.
2491: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2492: $titles{$option}.'</label>';
2493: if ($option eq 'autolimit') {
1.127 raeburn 2494: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2495: $item.'_limit__LC_adv" size="1" '.
2496: 'value="'.$currlimit.'" />';
2497: }
1.127 raeburn 2498: $advcell{$item} .= '</span> ';
1.104 raeburn 2499: if ($option eq 'autolimit') {
1.127 raeburn 2500: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2501: }
1.101 raeburn 2502: }
1.160.6.5 raeburn 2503: } elsif ($context eq 'requestauthor') {
2504: my $curroption;
2505: if (ref($settings) eq 'HASH') {
2506: $curroption = $settings->{'_LC_adv'};
2507: }
2508: my $checked = '';
2509: if ($curroption eq '') {
2510: $checked = ' checked="checked"';
2511: }
2512: $datatable .= '<span class="LC_nobreak"><label>'.
2513: '<input type="radio" name="authorreq__LC_adv"'.
2514: ' value=""'.$checked.' />'.
2515: &mt('No override set').'</label></span> ';
2516: foreach my $option (@options) {
2517: my $val = $option;
2518: if ($option eq 'norequest') {
2519: $val = 0;
2520: }
2521: my $checked = '';
2522: if ($val eq $curroption) {
2523: $checked = ' checked="checked"';
2524: }
2525: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2526: '<input type="radio" name="authorreq__LC_adv"'.
2527: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2528: $titles{$option}.'</label></span> ';
2529: }
1.101 raeburn 2530: } else {
2531: my $checked = 'checked="checked" ';
2532: if (ref($settings) eq 'HASH') {
2533: if (ref($settings->{$item}) eq 'HASH') {
2534: if ($settings->{$item}->{'_LC_adv'} == 0) {
2535: $checked = '';
2536: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2537: $checked = 'checked="checked" ';
2538: }
1.79 raeburn 2539: }
1.72 raeburn 2540: }
1.101 raeburn 2541: $datatable .= '<span class="LC_nobreak"><label>'.
2542: '<input type="checkbox" name="'.$context.'_'.$item.
2543: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2544: '</label></span> ';
2545: }
2546: }
2547: if ($context eq 'requestcourses') {
2548: $datatable .= '</tr><tr>';
2549: foreach my $item (@usertools) {
1.106 raeburn 2550: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2551: }
1.101 raeburn 2552: $datatable .= '</tr></table>';
1.72 raeburn 2553: }
1.98 raeburn 2554: $datatable .= '</td></tr>';
1.30 raeburn 2555: $$rowtotal += $typecount;
1.3 raeburn 2556: return $datatable;
2557: }
2558:
1.160.6.5 raeburn 2559: sub print_requestmail {
1.160.6.93 raeburn 2560: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25 raeburn 2561: my ($now,$datatable,%currapp);
1.102 raeburn 2562: $now = time;
2563: if (ref($settings) eq 'HASH') {
2564: if (ref($settings->{'notify'}) eq 'HASH') {
2565: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2566: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2567: }
2568: }
2569: }
1.160.6.16 raeburn 2570: my $numinrow = 2;
1.160.6.34 raeburn 2571: my $css_class;
1.160.6.93 raeburn 2572: if ($$rowtotal%2) {
2573: $css_class = 'LC_odd_row';
2574: }
2575: if ($customcss) {
2576: $css_class .= " $customcss";
2577: }
2578: $css_class =~ s/^\s+//;
2579: if ($css_class) {
2580: $css_class = ' class="'.$css_class.'"';
2581: }
2582: if ($rowstyle) {
2583: $css_class .= ' style="'.$rowstyle.'"';
2584: }
1.160.6.5 raeburn 2585: my $text;
2586: if ($action eq 'requestcourses') {
2587: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2588: } elsif ($action eq 'requestauthor') {
2589: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2590: } else {
1.160.6.34 raeburn 2591: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2592: }
1.160.6.34 raeburn 2593: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2594: ' <td>'.$text.'</td>'.
1.102 raeburn 2595: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2596: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2597: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2598: if ($numdc > 0) {
2599: $datatable .= $table;
1.102 raeburn 2600: } else {
2601: $datatable .= &mt('There are no active Domain Coordinators');
2602: }
2603: $datatable .='</td></tr>';
2604: return $datatable;
2605: }
2606:
1.160.6.30 raeburn 2607: sub print_studentcode {
2608: my ($settings,$rowtotal) = @_;
2609: my $rownum = 0;
2610: my ($output,%current);
2611: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2612: if (ref($settings) eq 'HASH') {
2613: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2614: foreach my $type (@crstypes) {
2615: $current{$type} = $settings->{'uniquecode'}{$type};
2616: }
1.160.6.30 raeburn 2617: }
2618: }
2619: $output .= '<tr>'.
2620: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2621: '<td class="LC_left_item">';
2622: foreach my $type (@crstypes) {
2623: my $check = ' ';
2624: if ($current{$type}) {
2625: $check = ' checked="checked" ';
2626: }
2627: $output .= '<span class="LC_nobreak"><label>'.
2628: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2629: &mt($type).'</label></span>'.(' 'x2).' ';
2630: }
2631: $output .= '</td></tr>';
2632: $$rowtotal ++;
2633: return $output;
2634: }
2635:
2636: sub print_textbookcourses {
1.160.6.46 raeburn 2637: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2638: my $rownum = 0;
2639: my $css_class;
2640: my $itemcount = 1;
2641: my $maxnum = 0;
2642: my $bookshash;
2643: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2644: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2645: }
2646: my %ordered;
2647: if (ref($bookshash) eq 'HASH') {
2648: foreach my $item (keys(%{$bookshash})) {
2649: if (ref($bookshash->{$item}) eq 'HASH') {
2650: my $num = $bookshash->{$item}{'order'};
2651: $ordered{$num} = $item;
2652: }
2653: }
2654: }
2655: my $confname = $dom.'-domainconfig';
2656: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2657: my $maxnum = scalar(keys(%ordered));
2658: my $datatable;
1.160.6.30 raeburn 2659: if (keys(%ordered)) {
2660: my @items = sort { $a <=> $b } keys(%ordered);
2661: for (my $i=0; $i<@items; $i++) {
2662: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2663: my $key = $ordered{$items[$i]};
2664: my %coursehash=&Apache::lonnet::coursedescription($key);
2665: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2666: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2667: if (ref($bookshash->{$key}) eq 'HASH') {
2668: $subject = $bookshash->{$key}->{'subject'};
2669: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2670: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2671: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2672: $author = $bookshash->{$key}->{'author'};
2673: $image = $bookshash->{$key}->{'image'};
2674: if ($image ne '') {
2675: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2676: my $imagethumb = "$path/tn-".$imagefile;
2677: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2678: }
1.160.6.30 raeburn 2679: }
2680: }
1.160.6.46 raeburn 2681: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2682: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2683: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2684: for (my $k=0; $k<=$maxnum; $k++) {
2685: my $vpos = $k+1;
2686: my $selstr;
2687: if ($k == $i) {
2688: $selstr = ' selected="selected" ';
2689: }
2690: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2691: }
2692: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2693: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2694: &mt('Delete?').'</label></span></td>'.
2695: '<td colspan="2">'.
1.160.6.46 raeburn 2696: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2697: (' 'x2).
1.160.6.46 raeburn 2698: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2699: if ($type eq 'textbooks') {
2700: $datatable .= (' 'x2).
1.160.6.47 raeburn 2701: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2702: (' 'x2).
1.160.6.46 raeburn 2703: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2704: (' 'x2).
2705: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2706: if ($image) {
1.160.6.114 raeburn 2707: $datatable .= $imgsrc.
1.160.6.46 raeburn 2708: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2709: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2710: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2711: }
2712: if ($switchserver) {
2713: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2714: } else {
2715: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2716: }
1.160.6.30 raeburn 2717: }
1.160.6.46 raeburn 2718: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2719: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2720: $coursetitle.'</span></td></tr>'."\n";
2721: $itemcount ++;
2722: }
2723: }
2724: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2725: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2726: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2727: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2728: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2729: for (my $k=0; $k<$maxnum+1; $k++) {
2730: my $vpos = $k+1;
2731: my $selstr;
2732: if ($k == $maxnum) {
2733: $selstr = ' selected="selected" ';
2734: }
2735: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2736: }
2737: $datatable .= '</select> '."\n".
1.160.6.87 raeburn 2738: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2739: '<td colspan="2">'.
1.160.6.46 raeburn 2740: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2741: (' 'x2).
1.160.6.46 raeburn 2742: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2743: (' 'x2);
2744: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2745: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2746: (' 'x2).
2747: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2748: (' 'x2).
2749: '<span class="LC_nobreak">'.&mt('Image:').' ';
2750: if ($switchserver) {
2751: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2752: } else {
2753: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2754: }
1.160.6.87 raeburn 2755: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2756: }
1.160.6.87 raeburn 2757: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2758: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2759: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2760: &Apache::loncommon::selectcourse_link
1.160.6.87 raeburn 2761: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2762: '</span></td>'."\n".
2763: '</tr>'."\n";
2764: $itemcount ++;
2765: return $datatable;
2766: }
2767:
2768: sub textbookcourses_javascript {
1.160.6.46 raeburn 2769: my ($settings) = @_;
2770: return unless(ref($settings) eq 'HASH');
2771: my (%ordered,%total,%jstext);
2772: foreach my $type ('textbooks','templates') {
2773: $total{$type} = 0;
2774: if (ref($settings->{$type}) eq 'HASH') {
2775: foreach my $item (keys(%{$settings->{$type}})) {
2776: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2777: my $num = $settings->{$type}->{$item}{'order'};
2778: $ordered{$type}{$num} = $item;
2779: }
2780: }
2781: $total{$type} = scalar(keys(%{$settings->{$type}}));
2782: }
2783: my @jsarray = ();
2784: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2785: push(@jsarray,$ordered{$type}{$item});
2786: }
2787: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2788: }
2789: return <<"ENDSCRIPT";
2790: <script type="text/javascript">
2791: // <![CDATA[
1.160.6.46 raeburn 2792: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2793: var changedVal;
1.160.6.46 raeburn 2794: $jstext{'textbooks'};
2795: $jstext{'templates'};
2796: var newpos;
2797: var maxh;
2798: if (caller == 'textbooks') {
2799: newpos = 'textbooks_addbook_pos';
2800: maxh = 1 + $total{'textbooks'};
2801: } else {
2802: newpos = 'templates_addbook_pos';
2803: maxh = 1 + $total{'templates'};
2804: }
1.160.6.30 raeburn 2805: var current = new Array;
2806: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2807: if (item == newpos) {
2808: changedVal = newitemVal;
2809: } else {
2810: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2811: current[newitemVal] = newpos;
2812: }
1.160.6.46 raeburn 2813: if (caller == 'textbooks') {
2814: for (var i=0; i<textbooks.length; i++) {
2815: var elementName = 'textbooks_'+textbooks[i];
2816: if (elementName != item) {
2817: if (form.elements[elementName]) {
2818: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2819: current[currVal] = elementName;
2820: }
2821: }
2822: }
2823: }
2824: if (caller == 'templates') {
2825: for (var i=0; i<templates.length; i++) {
2826: var elementName = 'templates_'+templates[i];
2827: if (elementName != item) {
2828: if (form.elements[elementName]) {
2829: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2830: current[currVal] = elementName;
2831: }
1.160.6.30 raeburn 2832: }
2833: }
2834: }
2835: var oldVal;
2836: for (var j=0; j<maxh; j++) {
2837: if (current[j] == undefined) {
2838: oldVal = j;
2839: }
2840: }
2841: if (oldVal < changedVal) {
2842: for (var k=oldVal+1; k<=changedVal ; k++) {
2843: var elementName = current[k];
2844: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2845: }
2846: } else {
2847: for (var k=changedVal; k<oldVal; k++) {
2848: var elementName = current[k];
2849: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2850: }
2851: }
2852: return;
2853: }
2854:
2855: // ]]>
2856: </script>
2857:
2858: ENDSCRIPT
2859: }
2860:
1.160.6.113 raeburn 2861: sub wafproxy_javascript {
2862: my ($dom) = @_;
2863: return <<"ENDSCRIPT";
2864: <script type="text/javascript">
2865: // <![CDATA[
2866: function updateWAF() {
2867: if (document.getElementById('wafproxy_remoteip')) {
2868: var wafremote = 0;
2869: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
2870: wafremote = 1;
2871: }
2872: var fields = new Array('header','trust');
2873: for (var i=0; i<fields.length; i++) {
2874: if (document.getElementById('wafproxy_'+fields[i])) {
2875: if (wafremote == 1) {
2876: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
2877: }
2878: else {
2879: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
2880: }
2881: }
2882: }
2883: if (document.getElementById('wafproxyranges_$dom')) {
2884: if (wafremote == 1) {
2885: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
2886: } else {
2887: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
2888: if (document.display.wafproxy_vpnaccess[i].checked) {
2889: if (document.display.wafproxy_vpnaccess[i].value == 0) {
2890: document.getElementById('wafproxyranges_$dom').style.display = 'none';
2891: }
2892: }
2893: }
2894: }
2895: }
2896: }
2897: return;
2898: }
2899:
2900: function checkWAF() {
2901: if (document.getElementById('wafproxy_remoteip')) {
2902: var wafvpn = 0;
2903: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
2904: if (document.display.wafproxy_vpnaccess[i].checked) {
2905: if (document.display.wafproxy_vpnaccess[i].value == 1) {
2906: wafvpn = 1;
2907: }
2908: break;
2909: }
2910: }
2911: var vpn = new Array('vpnint','vpnext');
2912: for (var i=0; i<vpn.length; i++) {
2913: if (document.getElementById('wafproxy_show_'+vpn[i])) {
2914: if (wafvpn == 1) {
2915: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
2916: }
2917: else {
2918: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
2919: }
2920: }
2921: }
2922: if (document.getElementById('wafproxyranges_$dom')) {
2923: if (wafvpn == 1) {
2924: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
2925: }
2926: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
2927: document.getElementById('wafproxyranges_$dom').style.display = 'none';
2928: }
2929: }
2930: }
2931: return;
2932: }
2933:
2934: function toggleWAF() {
2935: if (document.getElementById('wafproxy_table')) {
2936: var wafproxy = 0;
2937: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
2938: if (document.display.wafproxy_${dom}[i].checked) {
2939: if (document.display.wafproxy_${dom}[i].value == 1) {
2940: wafproxy = 1;
2941: break;
2942: }
2943: }
2944: }
2945: if (wafproxy == 1) {
2946: document.getElementById('wafproxy_table').style.display='inline';
2947: }
2948: else {
2949: document.getElementById('wafproxy_table').style.display='none';
2950: }
2951: if (document.getElementById('wafproxyrow_${dom}')) {
2952: if (wafproxy == 1) {
2953: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
2954: }
2955: else {
2956: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
2957: }
2958: }
2959: if (document.getElementById('nowafproxyrow_$dom')) {
2960: if (wafproxy == 1) {
2961: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
2962: }
2963: else {
2964: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
2965: }
2966: }
2967: }
2968: return;
2969: }
2970: // ]]>
2971: </script>
2972:
2973: ENDSCRIPT
2974: }
2975:
2976: sub autoupdate_javascript {
2977: return <<"ENDSCRIPT";
2978: <script type="text/javascript">
2979: // <![CDATA[
2980: function toggleLastActiveDays(form) {
2981: var radioname = 'lastactive';
2982: var divid = 'lastactive_div';
2983: var num = form.elements[radioname].length;
2984: if (num) {
2985: var setvis = '';
2986: for (var i=0; i<num; i++) {
2987: if (form.elements[radioname][i].checked) {
2988: if (form.elements[radioname][i].value == '1') {
2989: if (document.getElementById(divid)) {
2990: document.getElementById(divid).style.display = 'inline-block';
2991: }
2992: setvis = 1;
2993: }
2994: break;
2995: }
2996: }
2997: if (!setvis) {
2998: if (document.getElementById(divid)) {
2999: document.getElementById(divid).style.display = 'none';
3000: }
3001: }
3002: }
3003: return;
3004: }
3005: // ]]>
3006: </script>
3007:
3008: ENDSCRIPT
3009: }
3010:
1.160.6.116 raeburn 3011: sub autoenroll_javascript {
3012: return <<"ENDSCRIPT";
3013: <script type="text/javascript">
3014: // <![CDATA[
3015: function toggleFailsafe(form) {
3016: var radioname = 'autoenroll_failsafe';
3017: var divid = 'autoenroll_failsafe_div';
3018: var num = form.elements[radioname].length;
3019: if (num) {
3020: var setvis = '';
3021: for (var i=0; i<num; i++) {
3022: if (form.elements[radioname][i].checked) {
3023: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3024: if (document.getElementById(divid)) {
3025: document.getElementById(divid).style.display = 'inline-block';
3026: }
3027: setvis = 1;
3028: }
3029: break;
3030: }
3031: }
3032: if (!setvis) {
3033: if (document.getElementById(divid)) {
3034: document.getElementById(divid).style.display = 'none';
3035: }
3036: }
3037: }
3038: return;
3039: }
3040: // ]]>
3041: </script>
3042:
3043: ENDSCRIPT
3044: }
3045:
1.160.6.113 raeburn 3046: sub saml_javascript {
3047: return <<"ENDSCRIPT";
3048: <script type="text/javascript">
3049: // <![CDATA[
3050: function toggleSamlOptions(form,hostid) {
3051: var radioname = 'saml_'+hostid;
3052: var tablecellon = 'samloptionson_'+hostid;
3053: var tablecelloff = 'samloptionsoff_'+hostid;
3054: var num = form.elements[radioname].length;
3055: if (num) {
3056: var setvis = '';
3057: for (var i=0; i<num; i++) {
3058: if (form.elements[radioname][i].checked) {
3059: if (form.elements[radioname][i].value == '1') {
3060: if (document.getElementById(tablecellon)) {
3061: document.getElementById(tablecellon).style.display='';
3062: }
3063: if (document.getElementById(tablecelloff)) {
3064: document.getElementById(tablecelloff).style.display='none';
3065: }
3066: setvis = 1;
3067: }
3068: break;
3069: }
3070: }
3071: if (!setvis) {
3072: if (document.getElementById(tablecellon)) {
3073: document.getElementById(tablecellon).style.display='none';
3074: }
3075: if (document.getElementById(tablecelloff)) {
3076: document.getElementById(tablecelloff).style.display='';
3077: }
3078: }
3079: }
3080: return;
3081: }
3082: // ]]>
3083: </script>
3084:
3085: ENDSCRIPT
3086: }
3087:
3088: sub ipaccess_javascript {
3089: my ($settings) = @_;
3090: my (%ordered,$total,%jstext);
3091: $total = 0;
3092: if (ref($settings) eq 'HASH') {
3093: foreach my $item (keys(%{$settings})) {
3094: if (ref($settings->{$item}) eq 'HASH') {
3095: my $num = $settings->{$item}{'order'};
3096: $ordered{$num} = $item;
3097: }
3098: }
3099: $total = scalar(keys(%{$settings}));
3100: }
3101: my @jsarray = ();
3102: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3103: push(@jsarray,$ordered{$item});
3104: }
3105: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3106: return <<"ENDSCRIPT";
3107: <script type="text/javascript">
3108: // <![CDATA[
3109: function reorderIPaccess(form,item) {
3110: var changedVal;
3111: $jstext
3112: var newpos = 'ipaccess_pos_add';
3113: var maxh = 1 + $total;
3114: var current = new Array;
3115: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3116: if (item == newpos) {
3117: changedVal = newitemVal;
3118: } else {
3119: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3120: current[newitemVal] = newpos;
3121: }
3122: for (var i=0; i<ipaccess.length; i++) {
3123: var elementName = 'ipaccess_pos_'+ipaccess[i];
3124: if (elementName != item) {
3125: if (form.elements[elementName]) {
3126: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3127: current[currVal] = elementName;
3128: }
3129: }
3130: }
3131: var oldVal;
3132: for (var j=0; j<maxh; j++) {
3133: if (current[j] == undefined) {
3134: oldVal = j;
3135: }
3136: }
3137: if (oldVal < changedVal) {
3138: for (var k=oldVal+1; k<=changedVal ; k++) {
3139: var elementName = current[k];
3140: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3141: }
3142: } else {
3143: for (var k=changedVal; k<oldVal; k++) {
3144: var elementName = current[k];
3145: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3146: }
3147: }
3148: return;
3149: }
3150: // ]]>
3151: </script>
3152:
3153: ENDSCRIPT
3154: }
3155:
1.3 raeburn 3156: sub print_autoenroll {
1.30 raeburn 3157: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3158: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.116 raeburn 3159: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3160: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3161: $failsafesty = 'none';
3162: %failsafechecked = (
3163: off => ' checked="checked"',
3164: );
1.3 raeburn 3165: if (ref($settings) eq 'HASH') {
3166: if (exists($settings->{'run'})) {
3167: if ($settings->{'run'} eq '0') {
3168: $runoff = ' checked="checked" ';
3169: $runon = ' ';
3170: } else {
3171: $runon = ' checked="checked" ';
3172: $runoff = ' ';
3173: }
3174: } else {
3175: if ($autorun) {
3176: $runon = ' checked="checked" ';
3177: $runoff = ' ';
3178: } else {
3179: $runoff = ' checked="checked" ';
3180: $runon = ' ';
3181: }
3182: }
1.129 raeburn 3183: if (exists($settings->{'co-owners'})) {
3184: if ($settings->{'co-owners'} eq '0') {
3185: $coownersoff = ' checked="checked" ';
3186: $coownerson = ' ';
3187: } else {
3188: $coownerson = ' checked="checked" ';
3189: $coownersoff = ' ';
3190: }
3191: } else {
3192: $coownersoff = ' checked="checked" ';
3193: $coownerson = ' ';
3194: }
1.3 raeburn 3195: if (exists($settings->{'sender_domain'})) {
3196: $defdom = $settings->{'sender_domain'};
3197: }
1.160.6.116 raeburn 3198: if (exists($settings->{'failsafe'})) {
3199: $failsafe = $settings->{'failsafe'};
3200: if ($failsafe eq 'zero') {
3201: $failsafechecked{'zero'} = ' checked="checked"';
3202: $failsafechecked{'off'} = '';
3203: $failsafesty = 'inline-block';
3204: } elsif ($failsafe eq 'any') {
3205: $failsafechecked{'any'} = ' checked="checked"';
3206: $failsafechecked{'off'} = '';
3207: }
3208: $autofailsafe = $settings->{'autofailsafe'};
3209: } elsif (exists($settings->{'autofailsafe'})) {
3210: $autofailsafe = $settings->{'autofailsafe'};
3211: if ($autofailsafe ne '') {
3212: $failsafechecked{'zero'} = ' checked="checked"';
3213: $failsafe = 'zero';
3214: $failsafechecked{'off'} = '';
3215: }
1.160.6.68 raeburn 3216: }
1.14 raeburn 3217: } else {
3218: if ($autorun) {
3219: $runon = ' checked="checked" ';
3220: $runoff = ' ';
3221: } else {
3222: $runoff = ' checked="checked" ';
3223: $runon = ' ';
3224: }
1.3 raeburn 3225: }
3226: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3227: my $notif_sender;
3228: if (ref($settings) eq 'HASH') {
3229: $notif_sender = $settings->{'sender_uname'};
3230: }
1.3 raeburn 3231: my $datatable='<tr class="LC_odd_row">'.
3232: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3233: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3234: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3235: $runon.' value="1" />'.&mt('Yes').'</label> '.
3236: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3237: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3238: '</tr><tr>'.
3239: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3240: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3241: &mt('username').': '.
3242: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3243: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3244: ': '.$domform.'</span></td></tr>'.
3245: '<tr class="LC_odd_row">'.
3246: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3247: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3248: '<input type="radio" name="autoassign_coowners"'.
3249: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3250: '<label><input type="radio" name="autoassign_coowners"'.
3251: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 3252: '</tr><tr>'.
3253: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.160.6.116 raeburn 3254: '<td class="LC_left_item"><span class="LC_nobreak">'.
3255: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="off" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'off'}.' />'.&mt('Not in use').'</label></span> '.
3256: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="zero" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'zero'}.' />'.&mt('Retrieved section enrollment is zero').'</label></span><br />'.
3257: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="any" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'any'}.' />'.&mt('Retrieved section enrollment is zero or greater').'</label></span>'.
3258: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
3259: '<span class="LC_nobreak">'.
3260: &mt('Threshold for number of students in section to drop: [_1]',
3261: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
3262: '</span></div></td></tr>';
1.160.6.68 raeburn 3263: $$rowtotal += 4;
1.3 raeburn 3264: return $datatable;
3265: }
3266:
3267: sub print_autoupdate {
1.30 raeburn 3268: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 3269: my ($enable,$datatable);
1.3 raeburn 3270: if ($position eq 'top') {
1.160.6.113 raeburn 3271: my %choices = &Apache::lonlocal::texthash (
3272: run => 'Auto-update active?',
3273: classlists => 'Update information in classlists?',
3274: unexpired => 'Skip updates for users without active or future roles?',
3275: lastactive => 'Skip updates for inactive users?',
3276: );
3277: my $itemcount = 0;
1.3 raeburn 3278: my $updateon = ' ';
3279: my $updateoff = ' checked="checked" ';
3280: if (ref($settings) eq 'HASH') {
3281: if ($settings->{'run'} eq '1') {
3282: $updateon = $updateoff;
3283: $updateoff = ' ';
3284: }
3285: }
1.160.6.113 raeburn 3286: $enable = '<tr class="LC_odd_row">'.
3287: '<td>'.&mt($choices{'run'}).'</td>'.
3288: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3289: '<input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3290: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 3291: '<label><input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3292: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 3293: '</tr>';
1.160.6.113 raeburn 3294: my @toggles = ('classlists','unexpired');
3295: my %defaultchecked = ('classlists' => 'off',
3296: 'unexpired' => 'off'
3297: );
3298: $$rowtotal ++;
3299: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3300: \%choices,$itemcount,'','','left','no');
3301: $datatable = $enable.$datatable;
3302: $$rowtotal += $itemcount;
3303: my $lastactiveon = ' ';
3304: my $lastactiveoff = ' checked="checked" ';
3305: my $lastactivestyle = 'none';
3306: my $lastactivedays;
3307: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
3308: if (ref($settings) eq 'HASH') {
3309: if ($settings->{'lastactive'} =~ /^\d+$/) {
3310: $lastactiveon = $lastactiveoff;
3311: $lastactiveoff = ' ';
3312: $lastactivestyle = 'inline-block';
3313: $lastactivedays = $settings->{'lastactive'};
3314: }
3315: }
3316: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3317: $datatable .= '<tr'.$css_class.'>'.
3318: '<td>'.$choices{'lastactive'}.'</td>'.
3319: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3320: '<input type="radio" name="lastactive"'.
3321: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
3322: ' <label>'.
3323: '<input type="radio" name="lastactive"'.
3324: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
3325: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
3326: ': '.&mt('inactive = no activity in last [_1] days',
3327: '<input type="text" size="5" name="lastactivedays" value="'.
3328: $lastactivedays.'" />').
3329: '</span></td>'.
3330: '</tr>';
3331: $$rowtotal ++;
1.131 raeburn 3332: } elsif ($position eq 'middle') {
3333: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3334: my $numinrow = 3;
3335: my $locknamesettings;
3336: $datatable .= &insttypes_row($settings,$types,$usertypes,
3337: $dom,$numinrow,$othertitle,
1.160.6.93 raeburn 3338: 'lockablenames',$rowtotal);
1.131 raeburn 3339: $$rowtotal ++;
1.3 raeburn 3340: } else {
1.44 raeburn 3341: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3342: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3343: 'permanentemail','id');
1.33 raeburn 3344: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3345: my $numrows = 0;
1.26 raeburn 3346: if (ref($types) eq 'ARRAY') {
3347: if (@{$types} > 0) {
3348: $datatable =
3349: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3350: \@fields,$types,\$numrows);
1.30 raeburn 3351: $$rowtotal += @{$types};
1.26 raeburn 3352: }
1.3 raeburn 3353: }
3354: $datatable .=
3355: &usertype_update_row($settings,{'default' => $othertitle},
3356: \%fieldtitles,\@fields,['default'],
3357: \$numrows);
1.30 raeburn 3358: $$rowtotal ++;
1.3 raeburn 3359: }
3360: return $datatable;
3361: }
3362:
1.125 raeburn 3363: sub print_autocreate {
3364: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3365: my (%createon,%createoff,%currhash);
1.125 raeburn 3366: my @types = ('xml','req');
3367: if (ref($settings) eq 'HASH') {
3368: foreach my $item (@types) {
3369: $createoff{$item} = ' checked="checked" ';
3370: $createon{$item} = ' ';
3371: if (exists($settings->{$item})) {
3372: if ($settings->{$item}) {
3373: $createon{$item} = ' checked="checked" ';
3374: $createoff{$item} = ' ';
3375: }
3376: }
3377: }
1.160.6.16 raeburn 3378: if ($settings->{'xmldc'} ne '') {
3379: $currhash{$settings->{'xmldc'}} = 1;
3380: }
1.125 raeburn 3381: } else {
3382: foreach my $item (@types) {
3383: $createoff{$item} = ' checked="checked" ';
3384: $createon{$item} = ' ';
3385: }
3386: }
3387: $$rowtotal += 2;
1.160.6.16 raeburn 3388: my $numinrow = 2;
1.125 raeburn 3389: my $datatable='<tr class="LC_odd_row">'.
3390: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3391: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3392: '<input type="radio" name="autocreate_xml"'.
3393: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3394: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3395: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3396: '</td></tr><tr>'.
3397: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3398: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3399: '<input type="radio" name="autocreate_req"'.
3400: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3401: '<label><input type="radio" name="autocreate_req"'.
3402: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 3403: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3404: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 3405: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3406: if ($numdc > 1) {
1.160.6.50 raeburn 3407: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3408: '</td><td class="LC_left_item">';
1.125 raeburn 3409: } else {
1.160.6.50 raeburn 3410: $datatable .= &mt('Course creation processed as:').
3411: '</td><td class="LC_right_item">';
1.125 raeburn 3412: }
1.160.6.50 raeburn 3413: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 3414: $$rowtotal += $rows;
1.125 raeburn 3415: return $datatable;
3416: }
3417:
1.23 raeburn 3418: sub print_directorysrch {
1.160.6.72 raeburn 3419: my ($position,$dom,$settings,$rowtotal) = @_;
3420: my $datatable;
3421: if ($position eq 'top') {
3422: my $instsrchon = ' ';
3423: my $instsrchoff = ' checked="checked" ';
3424: my ($exacton,$containson,$beginson);
3425: my $instlocalon = ' ';
3426: my $instlocaloff = ' checked="checked" ';
3427: if (ref($settings) eq 'HASH') {
3428: if ($settings->{'available'} eq '1') {
3429: $instsrchon = $instsrchoff;
3430: $instsrchoff = ' ';
3431: }
3432: if ($settings->{'localonly'} eq '1') {
3433: $instlocalon = $instlocaloff;
3434: $instlocaloff = ' ';
3435: }
3436: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3437: foreach my $type (@{$settings->{'searchtypes'}}) {
3438: if ($type eq 'exact') {
3439: $exacton = ' checked="checked" ';
3440: } elsif ($type eq 'contains') {
3441: $containson = ' checked="checked" ';
3442: } elsif ($type eq 'begins') {
3443: $beginson = ' checked="checked" ';
3444: }
3445: }
3446: } else {
3447: if ($settings->{'searchtypes'} eq 'exact') {
3448: $exacton = ' checked="checked" ';
3449: } elsif ($settings->{'searchtypes'} eq 'contains') {
3450: $containson = ' checked="checked" ';
3451: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3452: $exacton = ' checked="checked" ';
3453: $containson = ' checked="checked" ';
3454: }
3455: }
1.23 raeburn 3456: }
1.160.6.72 raeburn 3457: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3458: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 3459:
1.160.6.72 raeburn 3460: my $numinrow = 4;
3461: my $cansrchrow = 0;
3462: $datatable='<tr class="LC_odd_row">'.
3463: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3464: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3465: '<input type="radio" name="dirsrch_available"'.
3466: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3467: '<label><input type="radio" name="dirsrch_available"'.
3468: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3469: '</tr><tr>'.
3470: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3471: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3472: '<input type="radio" name="dirsrch_instlocalonly"'.
3473: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3474: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3475: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3476: '</tr>';
3477: $$rowtotal += 2;
3478: if (ref($usertypes) eq 'HASH') {
3479: if (keys(%{$usertypes}) > 0) {
3480: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93 raeburn 3481: $numinrow,$othertitle,'cansearch',
3482: $rowtotal);
1.160.6.72 raeburn 3483: $cansrchrow = 1;
3484: }
1.26 raeburn 3485: }
1.160.6.72 raeburn 3486: if ($cansrchrow) {
3487: $$rowtotal ++;
3488: $datatable .= '<tr>';
3489: } else {
3490: $datatable .= '<tr class="LC_odd_row">';
3491: }
3492: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3493: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3494: foreach my $title (@{$titleorder}) {
3495: if (defined($searchtitles->{$title})) {
3496: my $check = ' ';
3497: if (ref($settings) eq 'HASH') {
3498: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3499: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3500: $check = ' checked="checked" ';
3501: }
1.39 raeburn 3502: }
1.25 raeburn 3503: }
1.160.6.72 raeburn 3504: $datatable .= '<td class="LC_left_item">'.
3505: '<span class="LC_nobreak"><label>'.
3506: '<input type="checkbox" name="searchby" '.
3507: 'value="'.$title.'"'.$check.'/>'.
3508: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3509: }
3510: }
1.160.6.72 raeburn 3511: $datatable .= '</tr></table></td></tr>';
3512: $$rowtotal ++;
3513: if ($cansrchrow) {
3514: $datatable .= '<tr class="LC_odd_row">';
3515: } else {
3516: $datatable .= '<tr>';
3517: }
3518: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3519: '<td class="LC_left_item" colspan="2">'.
3520: '<span class="LC_nobreak"><label>'.
3521: '<input type="checkbox" name="searchtypes" '.
3522: $exacton.' value="exact" />'.&mt('Exact match').
3523: '</label> '.
3524: '<label><input type="checkbox" name="searchtypes" '.
3525: $beginson.' value="begins" />'.&mt('Begins with').
3526: '</label> '.
3527: '<label><input type="checkbox" name="searchtypes" '.
3528: $containson.' value="contains" />'.&mt('Contains').
3529: '</label></span></td></tr>';
3530: $$rowtotal ++;
1.26 raeburn 3531: } else {
1.160.6.72 raeburn 3532: my $domsrchon = ' checked="checked" ';
3533: my $domsrchoff = ' ';
3534: my $domlocalon = ' ';
3535: my $domlocaloff = ' checked="checked" ';
3536: if (ref($settings) eq 'HASH') {
3537: if ($settings->{'lclocalonly'} eq '1') {
3538: $domlocalon = $domlocaloff;
3539: $domlocaloff = ' ';
3540: }
3541: if ($settings->{'lcavailable'} eq '0') {
3542: $domsrchoff = $domsrchon;
3543: $domsrchon = ' ';
3544: }
3545: }
3546: $datatable='<tr class="LC_odd_row">'.
3547: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3548: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3549: '<input type="radio" name="dirsrch_domavailable"'.
3550: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3551: '<label><input type="radio" name="dirsrch_domavailable"'.
3552: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3553: '</tr><tr>'.
3554: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3555: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3556: '<input type="radio" name="dirsrch_domlocalonly"'.
3557: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3558: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3559: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3560: '</tr>';
3561: $$rowtotal += 2;
1.26 raeburn 3562: }
1.25 raeburn 3563: return $datatable;
3564: }
3565:
1.28 raeburn 3566: sub print_contacts {
1.160.6.78 raeburn 3567: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3568: my $datatable;
3569: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 3570: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.160.6.107 raeburn 3571: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.160.6.78 raeburn 3572: if ($position eq 'top') {
3573: if (ref($settings) eq 'HASH') {
3574: foreach my $item (@contacts) {
3575: if (exists($settings->{$item})) {
3576: $to{$item} = $settings->{$item};
3577: }
1.28 raeburn 3578: }
3579: }
1.160.6.78 raeburn 3580: } elsif ($position eq 'middle') {
3581: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91 raeburn 3582: 'updatesmail','idconflictsmail','hostipmail');
1.28 raeburn 3583: foreach my $type (@mailings) {
1.160.6.78 raeburn 3584: $otheremails{$type} = '';
3585: }
1.160.6.107 raeburn 3586: } elsif ($position eq 'lower') {
3587: if (ref($settings) eq 'HASH') {
3588: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3589: %lonstatus = %{$settings->{'lonstatus'}};
3590: }
3591: }
1.160.6.78 raeburn 3592: } else {
3593: @mailings = ('helpdeskmail','otherdomsmail');
3594: foreach my $type (@mailings) {
3595: $otheremails{$type} = '';
3596: }
3597: $bccemails{'helpdeskmail'} = '';
3598: $bccemails{'otherdomsmail'} = '';
3599: $includestr{'helpdeskmail'} = '';
3600: $includestr{'otherdomsmail'} = '';
3601: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3602: }
3603: if (ref($settings) eq 'HASH') {
1.160.6.107 raeburn 3604: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 3605: foreach my $type (@mailings) {
3606: if (exists($settings->{$type})) {
3607: if (ref($settings->{$type}) eq 'HASH') {
3608: foreach my $item (@contacts) {
3609: if ($settings->{$type}{$item}) {
3610: $checked{$type}{$item} = ' checked="checked" ';
3611: }
1.28 raeburn 3612: }
1.160.6.78 raeburn 3613: $otheremails{$type} = $settings->{$type}{'others'};
3614: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3615: $bccemails{$type} = $settings->{$type}{'bcc'};
3616: if ($settings->{$type}{'include'} ne '') {
3617: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3618: $includestr{$type} = &unescape($includestr{$type});
3619: }
3620: }
3621: }
3622: } elsif ($type eq 'lonstatusmail') {
3623: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3624: }
3625: }
3626: }
3627: if ($position eq 'bottom') {
3628: foreach my $type (@mailings) {
3629: $bccemails{$type} = $settings->{$type}{'bcc'};
3630: if ($settings->{$type}{'include'} ne '') {
3631: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3632: $includestr{$type} = &unescape($includestr{$type});
3633: }
3634: }
3635: if (ref($settings->{'helpform'}) eq 'HASH') {
3636: if (ref($fields) eq 'ARRAY') {
3637: foreach my $field (@{$fields}) {
3638: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3639: }
1.160.6.78 raeburn 3640: }
3641: if (exists($settings->{'helpform'}{'maxsize'})) {
3642: $maxsize = $settings->{'helpform'}{'maxsize'};
3643: } else {
3644: $maxsize = '1.0';
3645: }
3646: } else {
3647: if (ref($fields) eq 'ARRAY') {
3648: foreach my $field (@{$fields}) {
3649: $currfield{$field} = 'yes';
1.134 raeburn 3650: }
1.28 raeburn 3651: }
1.160.6.78 raeburn 3652: $maxsize = '1.0';
1.28 raeburn 3653: }
3654: }
3655: } else {
1.160.6.78 raeburn 3656: if ($position eq 'top') {
3657: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3658: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3659: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3660: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
3661: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3662: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3663: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3664: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91 raeburn 3665: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78 raeburn 3666: } elsif ($position eq 'bottom') {
3667: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3668: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3669: if (ref($fields) eq 'ARRAY') {
3670: foreach my $field (@{$fields}) {
3671: $currfield{$field} = 'yes';
3672: }
3673: }
3674: $maxsize = '1.0';
3675: }
1.28 raeburn 3676: }
3677: my ($titles,$short_titles) = &contact_titles();
3678: my $rownum = 0;
3679: my $css_class;
1.160.6.78 raeburn 3680: if ($position eq 'top') {
3681: foreach my $item (@contacts) {
3682: $css_class = $rownum%2?' class="LC_odd_row"':'';
3683: $datatable .= '<tr'.$css_class.'>'.
3684: '<td><span class="LC_nobreak">'.$titles->{$item}.
3685: '</span></td><td class="LC_right_item">'.
3686: '<input type="text" name="'.$item.'" value="'.
3687: $to{$item}.'" /></td></tr>';
3688: $rownum ++;
3689: }
1.160.6.101 raeburn 3690: } elsif ($position eq 'bottom') {
3691: $css_class = $rownum%2?' class="LC_odd_row"':'';
3692: $datatable .= '<tr'.$css_class.'>'.
3693: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3694: &mt('(e-mail, subject, and description always shown)').
3695: '</td><td class="LC_left_item">';
3696: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3697: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3698: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3699: foreach my $field (@{$fields}) {
3700: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3701: if (($field eq 'screenshot') || ($field eq 'cc')) {
3702: $datatable .= ' '.&mt('(logged-in users)');
3703: }
3704: $datatable .='</td><td>';
3705: my $clickaction;
3706: if ($field eq 'screenshot') {
3707: $clickaction = ' onclick="screenshotSize(this);"';
3708: }
3709: if (ref($possoptions->{$field}) eq 'ARRAY') {
3710: foreach my $option (@{$possoptions->{$field}}) {
3711: my $checked;
3712: if ($currfield{$field} eq $option) {
3713: $checked = ' checked="checked"';
3714: }
3715: $datatable .= '<span class="LC_nobreak"><label>'.
3716: '<input type="radio" name="helpform_'.$field.'" '.
3717: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3718: '</label></span>'.(' 'x2);
3719: }
3720: }
3721: if ($field eq 'screenshot') {
3722: my $display;
3723: if ($currfield{$field} eq 'no') {
3724: $display = ' style="display:none"';
3725: }
3726: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
3727: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3728: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3729: }
3730: $datatable .= '</td></tr>';
3731: }
3732: $datatable .= '</table>';
3733: }
3734: $datatable .= '</td></tr>'."\n";
3735: $rownum ++;
3736: }
1.160.6.107 raeburn 3737: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 3738: foreach my $type (@mailings) {
3739: $css_class = $rownum%2?' class="LC_odd_row"':'';
3740: $datatable .= '<tr'.$css_class.'>'.
3741: '<td><span class="LC_nobreak">'.
3742: $titles->{$type}.': </span></td>'.
3743: '<td class="LC_left_item">';
3744: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3745: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3746: }
3747: $datatable .= '<span class="LC_nobreak">';
3748: foreach my $item (@contacts) {
3749: $datatable .= '<label>'.
3750: '<input type="checkbox" name="'.$type.'"'.
3751: $checked{$type}{$item}.
3752: ' value="'.$item.'" />'.$short_titles->{$item}.
3753: '</label> ';
3754: }
3755: $datatable .= '</span><br />'.&mt('Others').': '.
3756: '<input type="text" name="'.$type.'_others" '.
3757: 'value="'.$otheremails{$type}.'" />';
3758: my %locchecked;
3759: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3760: foreach my $loc ('s','b') {
3761: if ($includeloc{$type} eq $loc) {
3762: $locchecked{$loc} = ' checked="checked"';
3763: last;
3764: }
3765: }
3766: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3767: '<input type="text" name="'.$type.'_bcc" '.
3768: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3769: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3770: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 3771: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 3772: '<span class="LC_nobreak">'.&mt('Location:').' '.
3773: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3774: (' 'x2).
3775: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3776: '</span></fieldset>';
3777: }
3778: $datatable .= '</td></tr>'."\n";
3779: $rownum ++;
3780: }
1.28 raeburn 3781: }
1.160.6.78 raeburn 3782: if ($position eq 'middle') {
3783: my %choices;
1.160.6.107 raeburn 3784: my $corelink = &core_link_msu();
3785: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.160.6.78 raeburn 3786: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.160.6.107 raeburn 3787: $corelink);
3788: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
3789: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.160.6.78 raeburn 3790: my %defaultchecked = ('reporterrors' => 'on',
1.160.6.107 raeburn 3791: 'reportupdates' => 'on',
3792: 'reportstatus' => 'on');
1.160.6.78 raeburn 3793: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3794: \%choices,$rownum);
3795: $datatable .= $reports;
1.160.6.107 raeburn 3796: } elsif ($position eq 'lower') {
1.160.6.109 raeburn 3797: my (%current,%excluded,%weights);
1.160.6.107 raeburn 3798: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
3799: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.160.6.109 raeburn 3800: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.160.6.107 raeburn 3801: } else {
1.160.6.109 raeburn 3802: $current{'errorthreshold'} = $defaults->{'threshold'};
1.160.6.107 raeburn 3803: }
3804: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.160.6.109 raeburn 3805: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.160.6.107 raeburn 3806: } else {
1.160.6.109 raeburn 3807: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.160.6.107 raeburn 3808: }
3809: if (ref($lonstatus{'weights'}) eq 'HASH') {
3810: foreach my $type ('E','W','N','U') {
3811: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
3812: $weights{$type} = $lonstatus{'weights'}{$type};
3813: } else {
3814: $weights{$type} = $defaults->{$type};
3815: }
3816: }
3817: } else {
3818: foreach my $type ('E','W','N','U') {
3819: $weights{$type} = $defaults->{$type};
3820: }
3821: }
3822: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
3823: if (@{$lonstatus{'excluded'}} > 0) {
3824: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
3825: }
3826: }
1.160.6.109 raeburn 3827: foreach my $item ('errorthreshold','errorsysmail') {
3828: $css_class = $rownum%2?' class="LC_odd_row"':'';
3829: $datatable .= '<tr'.$css_class.'>'.
3830: '<td class="LC_left_item"><span class="LC_nobreak">'.
3831: $titles->{$item}.
3832: '</span></td><td class="LC_left_item">'.
3833: '<input type="text" name="'.$item.'" value="'.
3834: $current{$item}.'" size="5" /></td></tr>';
3835: $rownum ++;
3836: }
1.160.6.107 raeburn 3837: $css_class = $rownum%2?' class="LC_odd_row"':'';
3838: $datatable .= '<tr'.$css_class.'>'.
3839: '<td class="LC_left_item">'.
3840: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
3841: '</span></td><td class="LC_left_item"><table><tr>';
3842: foreach my $type ('E','W','N','U') {
3843: $datatable .= '<td>'.$names->{$type}.'<br />'.
3844: '<input type="text" name="errorweights_'.$type.'" value="'.
3845: $weights{$type}.'" size="5" /></td>';
3846: }
3847: $datatable .= '</tr></table></tr>';
3848: $rownum ++;
3849: $css_class = $rownum%2?' class="LC_odd_row"':'';
3850: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
3851: $titles->{'errorexcluded'}.'</td>'.
3852: '<td class="LC_left_item"><table>';
3853: my $numinrow = 4;
3854: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
3855: for (my $i=0; $i<@ids; $i++) {
3856: my $rem = $i%($numinrow);
3857: if ($rem == 0) {
3858: if ($i > 0) {
3859: $datatable .= '</tr>';
3860: }
3861: $datatable .= '<tr>';
3862: }
3863: my $check;
3864: if ($excluded{$ids[$i]}) {
3865: $check = ' checked="checked" ';
3866: }
3867: $datatable .= '<td class="LC_left_item">'.
3868: '<span class="LC_nobreak"><label>'.
3869: '<input type="checkbox" name="errorexcluded" '.
3870: 'value="'.$ids[$i].'"'.$check.' />'.
3871: $ids[$i].'</label></span></td>';
3872: }
3873: my $colsleft = $numinrow - @ids%($numinrow);
3874: if ($colsleft > 1 ) {
3875: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3876: ' </td>';
3877: } elsif ($colsleft == 1) {
3878: $datatable .= '<td class="LC_left_item"> </td>';
3879: }
3880: $datatable .= '</tr></table></td></tr>';
3881: $rownum ++;
1.160.6.78 raeburn 3882: } elsif ($position eq 'bottom') {
1.160.6.101 raeburn 3883: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3884: my (@posstypes,%usertypeshash);
3885: if (ref($types) eq 'ARRAY') {
3886: @posstypes = @{$types};
3887: }
3888: if (@posstypes) {
3889: if (ref($usertypes) eq 'HASH') {
3890: %usertypeshash = %{$usertypes};
3891: }
3892: my @overridden;
3893: my $numinrow = 4;
3894: if (ref($settings) eq 'HASH') {
3895: if (ref($settings->{'overrides'}) eq 'HASH') {
3896: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3897: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3898: push(@overridden,$key);
3899: foreach my $item (@contacts) {
3900: if ($settings->{'overrides'}{$key}{$item}) {
3901: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3902: }
3903: }
3904: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3905: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3906: $includeloc{'override_'.$key} = '';
3907: $includestr{'override_'.$key} = '';
3908: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3909: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3910: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3911: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3912: }
1.160.6.78 raeburn 3913: }
3914: }
3915: }
1.160.6.101 raeburn 3916: }
3917: my $customclass = 'LC_helpdesk_override';
3918: my $optionsprefix = 'LC_options_helpdesk_';
3919:
3920: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3921:
3922: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3923: $numinrow,$othertitle,'overrides',
3924: \$rownum,$onclicktypes,$customclass);
3925: $rownum ++;
3926: $usertypeshash{'default'} = $othertitle;
3927: foreach my $status (@posstypes) {
3928: my $css_class;
3929: if ($rownum%2) {
3930: $css_class = 'LC_odd_row ';
3931: }
3932: $css_class .= $customclass;
3933: my $rowid = $optionsprefix.$status;
3934: my $hidden = 1;
3935: my $currstyle = 'display:none';
3936: if (grep(/^\Q$status\E$/,@overridden)) {
3937: $currstyle = 'display:table-row';
3938: $hidden = 0;
3939: }
3940: my $key = 'override_'.$status;
3941: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3942: $includeloc{$key},$includestr{$key},$status,$rowid,
3943: $usertypeshash{$status},$css_class,$currstyle,
3944: \@contacts,$short_titles);
3945: unless ($hidden) {
3946: $rownum ++;
1.160.6.78 raeburn 3947: }
3948: }
1.134 raeburn 3949: }
1.28 raeburn 3950: }
1.30 raeburn 3951: $$rowtotal += $rownum;
1.28 raeburn 3952: return $datatable;
3953: }
3954:
1.160.6.107 raeburn 3955: sub core_link_msu {
3956: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3957: &mt('LON-CAPA core group - MSU'),600,500);
3958: }
3959:
1.160.6.101 raeburn 3960: sub overridden_helpdesk {
3961: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3962: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3963: my $class = 'LC_left_item';
3964: if ($css_class) {
3965: $css_class = ' class="'.$css_class.'"';
3966: }
3967: if ($rowid) {
3968: $rowid = ' id="'.$rowid.'"';
3969: }
3970: if ($rowstyle) {
3971: $rowstyle = ' style="'.$rowstyle.'"';
3972: }
3973: my ($output,$description);
3974: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3975: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3976: "<td>$description</td>\n".
3977: '<td class="'.$class.'" colspan="2">'.
3978: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3979: '<span class="LC_nobreak">';
3980: if (ref($contacts) eq 'ARRAY') {
3981: foreach my $item (@{$contacts}) {
3982: my $check;
3983: if (ref($checked) eq 'HASH') {
3984: $check = $checked->{$item};
3985: }
3986: my $title;
3987: if (ref($short_titles) eq 'HASH') {
3988: $title = $short_titles->{$item};
3989: }
3990: $output .= '<label>'.
3991: '<input type="checkbox" name="override_'.$type.'"'.$check.
3992: ' value="'.$item.'" />'.$title.'</label> ';
3993: }
3994: }
3995: $output .= '</span><br />'.&mt('Others').': '.
3996: '<input type="text" name="override_'.$type.'_others" '.
3997: 'value="'.$otheremails.'" />';
3998: my %locchecked;
3999: foreach my $loc ('s','b') {
4000: if ($includeloc eq $loc) {
4001: $locchecked{$loc} = ' checked="checked"';
4002: last;
4003: }
4004: }
4005: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4006: '<input type="text" name="override_'.$type.'_bcc" '.
4007: 'value="'.$bccemails.'" /></fieldset>'.
4008: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4009: &mt('Text automatically added to e-mail:').' '.
4010: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
4011: '<span class="LC_nobreak">'.&mt('Location:').' '.
4012: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4013: (' 'x2).
4014: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4015: '</span></fieldset>'.
4016: '</td></tr>'."\n";
4017: return $output;
4018: }
4019:
1.160.6.78 raeburn 4020: sub contacts_javascript {
4021: return <<"ENDSCRIPT";
4022:
4023: <script type="text/javascript">
4024: // <![CDATA[
4025:
4026: function screenshotSize(field) {
4027: if (document.getElementById('help_screenshotsize')) {
4028: if (field.value == 'no') {
4029: document.getElementById('help_screenshotsize').style.display="none";
4030: } else {
4031: document.getElementById('help_screenshotsize').style.display="";
4032: }
4033: }
4034: return;
4035: }
4036:
1.160.6.101 raeburn 4037: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4038: if (form.elements[checkbox].length != undefined) {
4039: var count = 0;
4040: if (docount) {
4041: for (var i=0; i<form.elements[checkbox].length; i++) {
4042: if (form.elements[checkbox][i].checked) {
4043: count ++;
4044: }
4045: }
4046: }
4047: for (var i=0; i<form.elements[checkbox].length; i++) {
4048: var type = form.elements[checkbox][i].value;
4049: if (document.getElementById(prefix+type)) {
4050: if (form.elements[checkbox][i].checked) {
4051: document.getElementById(prefix+type).style.display = 'table-row';
4052: if (count % 2 == 1) {
4053: document.getElementById(prefix+type).className = target+' LC_odd_row';
4054: } else {
4055: document.getElementById(prefix+type).className = target;
4056: }
4057: count ++;
4058: } else {
4059: document.getElementById(prefix+type).style.display = 'none';
4060: }
4061: }
4062: }
4063: }
4064: return;
4065: }
4066:
1.160.6.78 raeburn 4067: // ]]>
4068: </script>
4069:
4070: ENDSCRIPT
4071: }
4072:
1.118 jms 4073: sub print_helpsettings {
1.160.6.73 raeburn 4074: my ($position,$dom,$settings,$rowtotal) = @_;
4075: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 4076: my $formname = 'display';
1.160.6.5 raeburn 4077: my ($datatable,$itemcount);
1.160.6.73 raeburn 4078: if ($position eq 'top') {
4079: $itemcount = 1;
4080: my (%choices,%defaultchecked,@toggles);
4081: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4082: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4083: &mt('LON-CAPA bug tracker'),600,500));
4084: %defaultchecked = ('submitbugs' => 'on');
4085: @toggles = ('submitbugs');
4086: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4087: \%choices,$itemcount);
4088: $$rowtotal ++;
4089: } else {
4090: my $css_class;
4091: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 4092: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 4093: if (ref($settings) eq 'HASH') {
4094: if (ref($settings->{'adhoc'}) eq 'HASH') {
4095: %current = %{$settings->{'adhoc'}};
4096: }
1.160.6.77 raeburn 4097: }
4098: my $count = 0;
4099: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 4100: if ($key=~/^rolesdef\_(\w+)$/) {
4101: my $rolename = $1;
1.160.6.77 raeburn 4102: my (%privs,$order);
1.160.6.73 raeburn 4103: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4104: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 4105: if (ref($current{$rolename}) eq 'HASH') {
4106: $order = $current{$rolename}{'order'};
4107: }
4108: if ($order eq '') {
4109: $order = $count;
4110: }
4111: $ordered{$order} = $rolename;
4112: $count++;
1.160.6.73 raeburn 4113: }
4114: }
1.160.6.77 raeburn 4115: my $maxnum = scalar(keys(%ordered));
4116: my @roles_by_num = ();
4117: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4118: push(@roles_by_num,$item);
4119: }
4120: my $context = 'domprefs';
4121: my $crstype = 'Course';
4122: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 4123: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 4124: my ($numstatustypes,@jsarray);
4125: if (ref($types) eq 'ARRAY') {
4126: if (@{$types} > 0) {
4127: $numstatustypes = scalar(@{$types});
4128: push(@accesstypes,'status');
4129: @jsarray = ('bystatus');
4130: }
4131: }
1.160.6.86 raeburn 4132: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 4133: if (keys(%domhelpdesk)) {
4134: push(@accesstypes,('inc','exc'));
4135: push(@jsarray,('notinc','notexc'));
4136: }
4137: my $hiddenstr = join("','",@jsarray);
4138: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 4139: my $context = 'domprefs';
4140: my $crstype = 'Course';
1.160.6.77 raeburn 4141: my $prefix = 'helproles_';
4142: my $add_class = 'LC_hidden';
4143: foreach my $num (@roles_by_num) {
4144: my $role = $ordered{$num};
4145: my ($desc,$access,@statuses);
4146: if (ref($current{$role}) eq 'HASH') {
4147: $desc = $current{$role}{'desc'};
4148: $access = $current{$role}{'access'};
4149: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4150: @statuses = @{$current{$role}{'insttypes'}};
4151: }
4152: }
4153: if ($desc eq '') {
4154: $desc = $role;
4155: }
4156: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 4157: my %full=();
4158: my %levels= (
4159: course => {},
4160: domain => {},
4161: system => {},
4162: );
4163: my %levelscurrent=(
4164: course => {},
4165: domain => {},
4166: system => {},
4167: );
4168: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4169: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4170: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 4171: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
4172: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
4173: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4174: for (my $k=0; $k<=$maxnum; $k++) {
4175: my $vpos = $k+1;
4176: my $selstr;
4177: if ($k == $num) {
4178: $selstr = ' selected="selected" ';
4179: }
4180: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4181: }
4182: $datatable .= '</select>'.(' 'x2).
4183: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4184: '</td>'.
4185: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4186: &mt('Name shown to users:').
4187: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4188: '</fieldset>'.
4189: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4190: $othertitle,$usertypes,$types,\%domhelpdesk).
4191: '<fieldset>'.
4192: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 4193: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 4194: \%levelscurrent,$identifier,
4195: 'LC_hidden',$prefix.$num.'_privs').
4196: '</fieldset></td>';
1.160.6.73 raeburn 4197: $itemcount ++;
4198: }
4199: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4200: my $newcust = 'custhelp'.$count;
4201: my (%privs,%levelscurrent);
4202: my %full=();
4203: my %levels= (
4204: course => {},
4205: domain => {},
4206: system => {},
4207: );
4208: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4209: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 4210: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
4211: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
4212: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4213: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4214: for (my $k=0; $k<$maxnum+1; $k++) {
4215: my $vpos = $k+1;
4216: my $selstr;
4217: if ($k == $maxnum) {
4218: $selstr = ' selected="selected" ';
4219: }
4220: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4221: }
4222: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 4223: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4224: '</label></span></td>'.
1.160.6.77 raeburn 4225: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4226: '<span class="LC_nobreak">'.
4227: &mt('Internal name:').
4228: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4229: '</span>'.(' 'x4).
4230: '<span class="LC_nobreak">'.
4231: &mt('Name shown to users:').
4232: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4233: '</span></fieldset>'.
4234: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4235: $usertypes,$types,\%domhelpdesk).
4236: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 4237: &Apache::lonuserutils::custom_role_header($context,$crstype,
4238: \@templateroles,$newcust).
4239: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4240: \%levelscurrent,$newcust).
1.160.6.87 raeburn 4241: '</fieldset>'.
4242: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4243: '</td></tr>';
1.160.6.73 raeburn 4244: $count ++;
4245: $$rowtotal += $count;
4246: }
1.160.6.5 raeburn 4247: return $datatable;
1.121 raeburn 4248: }
4249:
1.160.6.77 raeburn 4250: sub adhocbutton {
4251: my ($prefix,$num,$field,$visibility) = @_;
4252: my %lt = &Apache::lonlocal::texthash(
4253: show => 'Show details',
4254: hide => 'Hide details',
4255: );
4256: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4257: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4258: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4259: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4260: }
4261:
4262: sub helpsettings_javascript {
4263: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4264: return unless(ref($roles_by_num) eq 'ARRAY');
4265: my %html_js_lt = &Apache::lonlocal::texthash(
4266: show => 'Show details',
4267: hide => 'Hide details',
4268: );
4269: &html_escape(\%html_js_lt);
4270: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4271: return <<"ENDSCRIPT";
4272: <script type="text/javascript">
4273: // <![CDATA[
4274:
4275: function reorderHelpRoles(form,item) {
4276: var changedVal;
4277: $jstext
4278: var newpos = 'helproles_${total}_pos';
4279: var maxh = 1 + $total;
4280: var current = new Array();
4281: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4282: if (item == newpos) {
4283: changedVal = newitemVal;
4284: } else {
4285: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4286: current[newitemVal] = newpos;
4287: }
4288: for (var i=0; i<helproles.length; i++) {
4289: var elementName = 'helproles_'+helproles[i]+'_pos';
4290: if (elementName != item) {
4291: if (form.elements[elementName]) {
4292: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4293: current[currVal] = elementName;
4294: }
4295: }
4296: }
4297: var oldVal;
4298: for (var j=0; j<maxh; j++) {
4299: if (current[j] == undefined) {
4300: oldVal = j;
4301: }
4302: }
4303: if (oldVal < changedVal) {
4304: for (var k=oldVal+1; k<=changedVal ; k++) {
4305: var elementName = current[k];
4306: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4307: }
4308: } else {
4309: for (var k=changedVal; k<oldVal; k++) {
4310: var elementName = current[k];
4311: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4312: }
4313: }
4314: return;
4315: }
4316:
4317: function helpdeskAccess(num) {
4318: var curraccess = null;
4319: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4320: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4321: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4322: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4323: }
4324: }
4325: }
4326: var shown = Array();
4327: var hidden = Array();
4328: if (curraccess == 'none') {
4329: hidden = Array('$hiddenstr');
4330: } else {
4331: if (curraccess == 'status') {
4332: shown = Array('bystatus');
4333: hidden = Array('notinc','notexc');
4334: } else {
4335: if (curraccess == 'exc') {
4336: shown = Array('notexc');
4337: hidden = Array('notinc','bystatus');
4338: }
4339: if (curraccess == 'inc') {
4340: shown = Array('notinc');
4341: hidden = Array('notexc','bystatus');
4342: }
1.160.6.79 raeburn 4343: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 4344: hidden = Array('notinc','notexc','bystatus');
4345: }
4346: }
4347: }
4348: if (hidden.length > 0) {
4349: for (var i=0; i<hidden.length; i++) {
4350: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4351: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4352: }
4353: }
4354: }
4355: if (shown.length > 0) {
4356: for (var i=0; i<shown.length; i++) {
4357: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4358: if (shown[i] == 'privs') {
4359: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4360: } else {
4361: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4362: }
4363: }
4364: }
4365: }
4366: return;
4367: }
4368:
4369: function toggleHelpdeskItem(num,field) {
4370: if (document.getElementById('helproles_'+num+'_'+field)) {
4371: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
4372: document.getElementById('helproles_'+num+'_'+field).className =
4373: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4374: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4375: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4376: }
4377: } else {
4378: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4379: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4380: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4381: }
4382: }
4383: }
4384: return;
4385: }
4386:
4387: // ]]>
4388: </script>
4389:
4390: ENDSCRIPT
4391: }
4392:
4393: sub helpdeskroles_access {
4394: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4395: $usertypes,$types,$domhelpdesk) = @_;
4396: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4397: my %lt = &Apache::lonlocal::texthash(
4398: 'rou' => 'Role usage',
4399: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 4400: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4401: 'dh' => 'All with domain helpdesk role',
4402: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 4403: 'none' => 'None',
4404: 'status' => 'Determined based on institutional status',
4405: 'inc' => 'Include all, but exclude specific personnel',
4406: 'exc' => 'Exclude all, but include specific personnel',
4407: );
4408: my %usecheck = (
4409: all => ' checked="checked"',
4410: );
4411: my %displaydiv = (
4412: status => 'none',
4413: inc => 'none',
4414: exc => 'none',
4415: priv => 'block',
4416: );
4417: my $output;
4418: if (ref($current) eq 'HASH') {
4419: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4420: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4421: $usecheck{$current->{access}} = $usecheck{'all'};
4422: delete($usecheck{'all'});
4423: if ($current->{access} =~ /^(status|inc|exc)$/) {
4424: my $access = $1;
4425: $displaydiv{$access} = 'inline';
4426: } elsif ($current->{access} eq 'none') {
4427: $displaydiv{'priv'} = 'none';
4428: }
4429: }
4430: }
4431: }
4432: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4433: '<p>'.$lt{'whi'}.'</p>';
4434: foreach my $access (@{$accesstypes}) {
4435: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4436: ' onclick="helpdeskAccess('."'$num'".');" />'.
4437: $lt{$access}.'</label>';
4438: if ($access eq 'status') {
4439: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4440: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4441: $othertitle,$usertypes,$types).
4442: '</div>';
4443: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4444: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4445: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4446: '</div>';
4447: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4448: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4449: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4450: '</div>';
4451: }
4452: $output .= '</p>';
4453: }
4454: $output .= '</fieldset>';
4455: return $output;
4456: }
4457:
1.121 raeburn 4458: sub radiobutton_prefs {
1.160.6.16 raeburn 4459: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.113 raeburn 4460: $additional,$align,$firstval) = @_;
1.121 raeburn 4461: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4462: (ref($choices) eq 'HASH'));
4463:
4464: my (%checkedon,%checkedoff,$datatable,$css_class);
4465:
4466: foreach my $item (@{$toggles}) {
4467: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4468: $checkedon{$item} = ' checked="checked" ';
4469: $checkedoff{$item} = ' ';
1.121 raeburn 4470: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4471: $checkedoff{$item} = ' checked="checked" ';
4472: $checkedon{$item} = ' ';
4473: }
4474: }
4475: if (ref($settings) eq 'HASH') {
1.121 raeburn 4476: foreach my $item (@{$toggles}) {
1.118 jms 4477: if ($settings->{$item} eq '1') {
4478: $checkedon{$item} = ' checked="checked" ';
4479: $checkedoff{$item} = ' ';
4480: } elsif ($settings->{$item} eq '0') {
4481: $checkedoff{$item} = ' checked="checked" ';
4482: $checkedon{$item} = ' ';
4483: }
4484: }
1.121 raeburn 4485: }
1.160.6.16 raeburn 4486: if ($onclick) {
4487: $onclick = ' onclick="'.$onclick.'"';
4488: }
1.121 raeburn 4489: foreach my $item (@{$toggles}) {
1.118 jms 4490: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4491: $datatable .=
1.160.6.16 raeburn 4492: '<tr'.$css_class.'><td valign="top">'.
4493: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 4494: '</span></td>';
4495: if ($align eq 'left') {
4496: $datatable .= '<td class="LC_left_item">';
4497: } else {
4498: $datatable .= '<td class="LC_right_item">';
4499: }
1.160.6.113 raeburn 4500: $datatable .= '<span class="LC_nobreak">';
4501: if ($firstval eq 'no') {
4502: $datatable .=
4503: '<label><input type="radio" name="'.
4504: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
4505: '</label> <label><input type="radio" name="'.$item.'" '.
4506: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
4507: } else {
4508: $datatable .=
1.118 jms 4509: '<label><input type="radio" name="'.
1.160.6.16 raeburn 4510: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4511: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.113 raeburn 4512: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
4513: }
4514: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 4515: $itemcount ++;
1.121 raeburn 4516: }
4517: return ($datatable,$itemcount);
4518: }
4519:
4520: sub print_coursedefaults {
1.139 raeburn 4521: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 4522: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4523: my $itemcount = 1;
1.160.6.16 raeburn 4524: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 4525: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 4526: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4527: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 4528: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4529: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.115 raeburn 4530: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.160.6.90 raeburn 4531: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 4532: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 4533: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 4534: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 4535: );
1.160.6.21 raeburn 4536: my %staticdefaults = (
4537: anonsurvey_threshold => 10,
4538: uploadquota => 500,
1.160.6.57 raeburn 4539: postsubmit => 60,
1.160.6.70 raeburn 4540: mysqltables => 172800,
1.160.6.21 raeburn 4541: );
1.139 raeburn 4542: if ($position eq 'top') {
1.160.6.57 raeburn 4543: %defaultchecked = (
4544: 'uselcmath' => 'on',
4545: 'usejsme' => 'on',
1.160.6.115 raeburn 4546: 'inline_chem' => 'on',
1.160.6.64 raeburn 4547: 'canclone' => 'none',
1.160.6.57 raeburn 4548: );
1.160.6.115 raeburn 4549: @toggles = ('uselcmath','usejsme','inline_chem');
1.160.6.90 raeburn 4550: my $deftex = $Apache::lonnet::deftex;
4551: if (ref($settings) eq 'HASH') {
4552: if ($settings->{'texengine'}) {
4553: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
4554: $deftex = $settings->{'texengine'};
4555: }
4556: }
4557: }
4558: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4559: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
4560: '<span class="LC_nobreak">'.$choices{'texengine'}.
4561: '</span></td><td class="LC_right_item">'.
4562: '<select name="texengine">'."\n";
4563: my %texoptions = (
4564: MathJax => 'MathJax',
4565: mimetex => &mt('Convert to Images'),
4566: tth => &mt('TeX to HTML'),
4567: );
4568: foreach my $renderer ('MathJax','mimetex','tth') {
4569: my $selected = '';
4570: if ($renderer eq $deftex) {
4571: $selected = ' selected="selected"';
4572: }
4573: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
4574: }
4575: $mathdisp .= '</select></td></tr>'."\n";
4576: $itemcount ++;
1.139 raeburn 4577: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4578: \%choices,$itemcount);
1.160.6.90 raeburn 4579: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 4580: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4581: $datatable .=
4582: '<tr'.$css_class.'><td valign="top">'.
4583: '<span class="LC_nobreak">'.$choices{'canclone'}.
4584: '</span></td><td class="LC_left_item">';
4585: my $currcanclone = 'none';
4586: my $onclick;
4587: my @cloneoptions = ('none','domain');
1.160.6.111 raeburn 4588: my %clonetitles = &Apache::lonlocal::texthash (
1.160.6.64 raeburn 4589: none => 'No additional course requesters',
4590: domain => "Any course requester in course's domain",
4591: instcode => 'Course requests for official courses ...',
4592: );
4593: my (%codedefaults,@code_order,@posscodes);
4594: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4595: \@code_order) eq 'ok') {
4596: if (@code_order > 0) {
4597: push(@cloneoptions,'instcode');
4598: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4599: }
4600: }
4601: if (ref($settings) eq 'HASH') {
4602: if ($settings->{'canclone'}) {
4603: if (ref($settings->{'canclone'}) eq 'HASH') {
4604: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4605: if (@code_order > 0) {
4606: $currcanclone = 'instcode';
4607: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4608: }
4609: }
4610: } elsif ($settings->{'canclone'} eq 'domain') {
4611: $currcanclone = $settings->{'canclone'};
4612: }
4613: }
4614: }
4615: foreach my $option (@cloneoptions) {
4616: my ($checked,$additional);
4617: if ($currcanclone eq $option) {
4618: $checked = ' checked="checked"';
4619: }
4620: if ($option eq 'instcode') {
4621: if (@code_order) {
4622: my $show = 'none';
4623: if ($checked) {
4624: $show = 'block';
4625: }
4626: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4627: &mt('Institutional codes for new and cloned course have identical:').
4628: '<br />';
4629: foreach my $item (@code_order) {
4630: my $codechk;
4631: if ($checked) {
4632: if (grep(/^\Q$item\E$/,@posscodes)) {
4633: $codechk = ' checked="checked"';
4634: }
4635: }
4636: $additional .= '<label>'.
4637: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4638: $item.'</label>';
4639: }
4640: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4641: }
4642: }
4643: $datatable .=
4644: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4645: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4646: '</label> '.$additional.'</span><br />';
4647: }
4648: $datatable .= '</td>'.
4649: '</tr>';
4650: $itemcount ++;
1.139 raeburn 4651: } else {
4652: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 4653: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 4654: my $currusecredits = 0;
1.160.6.57 raeburn 4655: my $postsubmitclient = 1;
1.160.6.30 raeburn 4656: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 4657: if (ref($settings) eq 'HASH') {
4658: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 4659: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4660: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4661: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4662: }
4663: }
1.160.6.16 raeburn 4664: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 4665: foreach my $type (@types) {
4666: next if ($type eq 'community');
4667: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4668: if ($defcredits{$type} ne '') {
4669: $currusecredits = 1;
4670: }
4671: }
4672: }
4673: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4674: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4675: $postsubmitclient = 0;
4676: foreach my $type (@types) {
4677: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4678: }
4679: } else {
4680: foreach my $type (@types) {
4681: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4682: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
4683: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
4684: } else {
4685: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4686: }
4687: } else {
4688: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4689: }
4690: }
4691: }
4692: } else {
4693: foreach my $type (@types) {
4694: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 4695: }
4696: }
1.160.6.70 raeburn 4697: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4698: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4699: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4700: }
4701: } else {
4702: foreach my $type (@types) {
4703: $currmysql{$type} = $staticdefaults{'mysqltables'};
4704: }
4705: }
1.160.6.58 raeburn 4706: } else {
4707: foreach my $type (@types) {
4708: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4709: }
1.139 raeburn 4710: }
4711: if (!$currdefresponder) {
1.160.6.21 raeburn 4712: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4713: } elsif ($currdefresponder < 1) {
4714: $currdefresponder = 1;
4715: }
1.160.6.21 raeburn 4716: foreach my $type (@types) {
4717: if ($curruploadquota{$type} eq '') {
4718: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4719: }
4720: }
1.139 raeburn 4721: $datatable .=
1.160.6.16 raeburn 4722: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4723: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4724: '</span></td>'.
4725: '<td class="LC_right_item"><span class="LC_nobreak">'.
4726: '<input type="text" name="anonsurvey_threshold"'.
4727: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 4728: '</td></tr>'."\n";
4729: $itemcount ++;
4730: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4731: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4732: $choices{'uploadquota'}.
4733: '</span></td>'.
4734: '<td align="right" class="LC_right_item">'.
4735: '<table><tr>';
1.160.6.21 raeburn 4736: foreach my $type (@types) {
4737: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4738: '<input type="text" name="uploadquota_'.$type.'"'.
4739: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4740: }
4741: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 4742: $itemcount ++;
1.160.6.40 raeburn 4743: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 4744: my $display = 'none';
4745: if ($currusecredits) {
4746: $display = 'block';
4747: }
4748: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 4749: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4750: foreach my $type (@types) {
4751: next if ($type eq 'community');
4752: $additional .= '<td align="center">'.&mt($type).'<br />'.
4753: '<input type="text" name="'.$type.'_credits"'.
4754: ' value="'.$defcredits{$type}.'" size="3" /></td>';
4755: }
4756: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 4757: %defaultchecked = ('coursecredits' => 'off');
4758: @toggles = ('coursecredits');
4759: my $current = {
4760: 'coursecredits' => $currusecredits,
4761: };
4762: (my $table,$itemcount) =
4763: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4764: \%choices,$itemcount,$onclick,$additional,'left');
4765: $datatable .= $table;
4766: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4767: my $display = 'none';
4768: if ($postsubmitclient) {
4769: $display = 'block';
4770: }
4771: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 4772: &mt('Number of seconds submit is disabled').'<br />'.
4773: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4774: '<table><tr>';
1.160.6.57 raeburn 4775: foreach my $type (@types) {
4776: $additional .= '<td align="center">'.&mt($type).'<br />'.
4777: '<input type="text" name="'.$type.'_timeout" value="'.
4778: $deftimeout{$type}.'" size="5" /></td>';
4779: }
4780: $additional .= '</tr></table></div>'."\n";
4781: %defaultchecked = ('postsubmit' => 'on');
4782: @toggles = ('postsubmit');
1.160.6.70 raeburn 4783: $current = {
4784: 'postsubmit' => $postsubmitclient,
4785: };
1.160.6.57 raeburn 4786: ($table,$itemcount) =
4787: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4788: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 4789: $datatable .= $table;
1.160.6.70 raeburn 4790: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4791: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4792: $choices{'mysqltables'}.
4793: '</span></td>'.
4794: '<td align="right" class="LC_right_item">'.
4795: '<table><tr>';
4796: foreach my $type (@types) {
4797: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4798: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 4799: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 4800: }
4801: $datatable .= '</tr></table></td></tr>'."\n";
4802: $itemcount ++;
4803:
1.160.6.37 raeburn 4804: }
4805: $$rowtotal += $itemcount;
4806: return $datatable;
4807: }
4808:
4809: sub print_selfenrollment {
4810: my ($position,$dom,$settings,$rowtotal) = @_;
4811: my ($css_class,$datatable);
4812: my $itemcount = 1;
4813: my @types = ('official','unofficial','community','textbook');
4814: if (($position eq 'top') || ($position eq 'middle')) {
4815: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4816: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
4817: my @rows;
4818: my $key;
4819: if ($position eq 'top') {
4820: $key = 'admin';
4821: if (ref($rowsref) eq 'ARRAY') {
4822: @rows = @{$rowsref};
4823: }
4824: } elsif ($position eq 'middle') {
4825: $key = 'default';
4826: @rows = ('types','registered','approval','limit');
4827: }
4828: foreach my $row (@rows) {
4829: if (defined($titlesref->{$row})) {
4830: $itemcount ++;
4831: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4832: $datatable .= '<tr'.$css_class.'>'.
4833: '<td>'.$titlesref->{$row}.'</td>'.
4834: '<td class="LC_left_item">'.
4835: '<table><tr>';
4836: my (%current,%currentcap);
4837: if (ref($settings) eq 'HASH') {
4838: if (ref($settings->{$key}) eq 'HASH') {
4839: foreach my $type (@types) {
4840: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4841: $current{$type} = $settings->{$key}->{$type}->{$row};
4842: }
4843: if (($row eq 'limit') && ($key eq 'default')) {
4844: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4845: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4846: }
4847: }
4848: }
4849: }
4850: }
4851: my %roles = (
4852: '0' => &Apache::lonnet::plaintext('dc'),
4853: );
4854:
4855: foreach my $type (@types) {
4856: unless (($row eq 'registered') && ($key eq 'default')) {
4857: $datatable .= '<th>'.&mt($type).'</th>';
4858: }
4859: }
4860: unless (($row eq 'registered') && ($key eq 'default')) {
4861: $datatable .= '</tr><tr>';
4862: }
4863: foreach my $type (@types) {
4864: if ($type eq 'community') {
4865: $roles{'1'} = &mt('Community personnel');
4866: } else {
4867: $roles{'1'} = &mt('Course personnel');
4868: }
4869: $datatable .= '<td style="vertical-align: top">';
4870: if ($position eq 'top') {
4871: my %checked;
4872: if ($current{$type} eq '0') {
4873: $checked{'0'} = ' checked="checked"';
4874: } else {
4875: $checked{'1'} = ' checked="checked"';
4876: }
4877: foreach my $role ('1','0') {
4878: $datatable .= '<span class="LC_nobreak"><label>'.
4879: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4880: 'value="'.$role.'"'.$checked{$role}.' />'.
4881: $roles{$role}.'</label></span> ';
4882: }
4883: } else {
4884: if ($row eq 'types') {
4885: my %checked;
4886: if ($current{$type} =~ /^(all|dom)$/) {
4887: $checked{$1} = ' checked="checked"';
4888: } else {
4889: $checked{''} = ' checked="checked"';
4890: }
4891: foreach my $val ('','dom','all') {
4892: $datatable .= '<span class="LC_nobreak"><label>'.
4893: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4894: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4895: }
4896: } elsif ($row eq 'registered') {
4897: my %checked;
4898: if ($current{$type} eq '1') {
4899: $checked{'1'} = ' checked="checked"';
4900: } else {
4901: $checked{'0'} = ' checked="checked"';
4902: }
4903: foreach my $val ('0','1') {
4904: $datatable .= '<span class="LC_nobreak"><label>'.
4905: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4906: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4907: }
4908: } elsif ($row eq 'approval') {
4909: my %checked;
4910: if ($current{$type} =~ /^([12])$/) {
4911: $checked{$1} = ' checked="checked"';
4912: } else {
4913: $checked{'0'} = ' checked="checked"';
4914: }
4915: for my $val (0..2) {
4916: $datatable .= '<span class="LC_nobreak"><label>'.
4917: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4918: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4919: }
4920: } elsif ($row eq 'limit') {
4921: my %checked;
4922: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4923: $checked{$1} = ' checked="checked"';
4924: } else {
4925: $checked{'none'} = ' checked="checked"';
4926: }
4927: my $cap;
4928: if ($currentcap{$type} =~ /^\d+$/) {
4929: $cap = $currentcap{$type};
4930: }
4931: foreach my $val ('none','allstudents','selfenrolled') {
4932: $datatable .= '<span class="LC_nobreak"><label>'.
4933: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4934: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4935: }
4936: $datatable .= '<br />'.
4937: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4938: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4939: '</span>';
4940: }
4941: }
4942: $datatable .= '</td>';
4943: }
4944: $datatable .= '</tr>';
4945: }
4946: $datatable .= '</table></td></tr>';
4947: }
4948: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 4949: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4950: }
4951: $$rowtotal += $itemcount;
4952: return $datatable;
4953: }
4954:
4955: sub print_validation_rows {
4956: my ($caller,$dom,$settings,$rowtotal) = @_;
4957: my ($itemsref,$namesref,$fieldsref);
4958: if ($caller eq 'selfenroll') {
4959: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4960: } elsif ($caller eq 'requestcourses') {
4961: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4962: }
4963: my %currvalidation;
4964: if (ref($settings) eq 'HASH') {
4965: if (ref($settings->{'validation'}) eq 'HASH') {
4966: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 4967: }
1.160.6.39 raeburn 4968: }
4969: my $datatable;
4970: my $itemcount = 0;
4971: foreach my $item (@{$itemsref}) {
4972: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4973: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4974: $namesref->{$item}.
4975: '</span></td>'.
4976: '<td class="LC_left_item">';
4977: if (($item eq 'url') || ($item eq 'button')) {
4978: $datatable .= '<span class="LC_nobreak">'.
4979: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4980: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4981: } elsif ($item eq 'fields') {
4982: my @currfields;
4983: if (ref($currvalidation{$item}) eq 'ARRAY') {
4984: @currfields = @{$currvalidation{$item}};
4985: }
4986: foreach my $field (@{$fieldsref}) {
4987: my $check = '';
4988: if (grep(/^\Q$field\E$/,@currfields)) {
4989: $check = ' checked="checked"';
4990: }
4991: $datatable .= '<span class="LC_nobreak"><label>'.
4992: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4993: ' value="'.$field.'"'.$check.' />'.$field.
4994: '</label></span> ';
4995: }
4996: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 4997: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 4998: $currvalidation{$item}.
1.160.6.37 raeburn 4999: '</textarea>';
1.160.6.39 raeburn 5000: }
5001: $datatable .= '</td></tr>'."\n";
5002: if (ref($rowtotal)) {
1.160.6.37 raeburn 5003: $itemcount ++;
5004: }
1.139 raeburn 5005: }
1.160.6.39 raeburn 5006: if ($caller eq 'requestcourses') {
5007: my %currhash;
1.160.6.51 raeburn 5008: if (ref($settings) eq 'HASH') {
5009: if (ref($settings->{'validation'}) eq 'HASH') {
5010: if ($settings->{'validation'}{'dc'} ne '') {
5011: $currhash{$settings->{'validation'}{'dc'}} = 1;
5012: }
1.160.6.39 raeburn 5013: }
5014: }
5015: my $numinrow = 2;
5016: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5017: 'validationdc',%currhash);
1.160.6.50 raeburn 5018: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 5019: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 5020: if ($numdc > 1) {
1.160.6.50 raeburn 5021: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 5022: } else {
1.160.6.50 raeburn 5023: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 5024: }
1.160.6.50 raeburn 5025: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 5026: $itemcount ++;
5027: }
5028: if (ref($rowtotal)) {
5029: $$rowtotal += $itemcount;
5030: }
1.121 raeburn 5031: return $datatable;
1.118 jms 5032: }
5033:
1.160.6.98 raeburn 5034: sub print_passwords {
5035: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
5036: my ($datatable,$css_class);
5037: my $itemcount = 0;
5038: my %titles = &Apache::lonlocal::texthash (
5039: captcha => '"Forgot Password" CAPTCHA validation',
5040: link => 'Reset link expiration (hours)',
5041: case => 'Case-sensitive usernames/e-mail',
5042: prelink => 'Information required (form 1)',
5043: postlink => 'Information required (form 2)',
5044: emailsrc => 'LON-CAPA e-mail address type(s)',
5045: customtext => 'Domain specific text (HTML)',
5046: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
5047: intauth_check => 'Check bcrypt cost if authenticated',
5048: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
5049: permanent => 'Permanent e-mail address',
5050: critical => 'Critical notification address',
5051: notify => 'Notification address',
5052: min => 'Minimum password length',
5053: max => 'Maximum password length',
5054: chars => 'Required characters',
5055: numsaved => 'Number of previous passwords to save and disallow reuse',
5056: );
5057: if ($position eq 'top') {
5058: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5059: my $shownlinklife = 2;
5060: my $prelink = 'both';
5061: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
5062: if (ref($settings) eq 'HASH') {
5063: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
5064: $shownlinklife = $settings->{resetlink};
5065: }
5066: if (ref($settings->{resetcase}) eq 'ARRAY') {
5067: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
5068: }
5069: if ($settings->{resetprelink} =~ /^(both|either)$/) {
5070: $prelink = $settings->{resetprelink};
5071: }
5072: if (ref($settings->{resetpostlink}) eq 'HASH') {
5073: %postlink = %{$settings->{resetpostlink}};
5074: }
5075: if (ref($settings->{resetemail}) eq 'ARRAY') {
5076: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
5077: }
5078: if ($settings->{resetremove}) {
5079: $nostdtext = 1;
5080: }
5081: if ($settings->{resetcustom}) {
5082: $customurl = $settings->{resetcustom};
5083: }
5084: } else {
5085: if (ref($types) eq 'ARRAY') {
5086: foreach my $item (@{$types}) {
5087: $casesens{$item} = 1;
5088: $postlink{$item} = ['username','email'];
5089: }
5090: }
5091: $casesens{'default'} = 1;
5092: $postlink{'default'} = ['username','email'];
5093: $prelink = 'both';
5094: %emailsrc = (
5095: permanent => 1,
5096: critical => 1,
5097: notify => 1,
5098: );
5099: }
5100: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
5101: $itemcount ++;
5102: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5103: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
5104: '<td class="LC_left_item">'.
5105: '<input type="textbox" value="'.$shownlinklife.'" '.
5106: 'name="passwords_link" size="3" /></td></tr>';
5107: $itemcount ++;
5108: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5109: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
5110: '<td class="LC_left_item">';
5111: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5112: foreach my $item (@{$types}) {
5113: my $checkedcase;
5114: if ($casesens{$item}) {
5115: $checkedcase = ' checked="checked"';
5116: }
5117: $datatable .= '<span class="LC_nobreak"><label>'.
5118: '<input type="checkbox" name="passwords_case_sensitive" value="'.
5119: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.160.6.104 raeburn 5120: '</span> ';
1.160.6.98 raeburn 5121: }
5122: }
5123: my $checkedcase;
5124: if ($casesens{'default'}) {
5125: $checkedcase = ' checked="checked"';
5126: }
5127: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5128: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
5129: $othertitle.'</label></span></td>';
5130: $itemcount ++;
5131: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5132: my %checkedpre = (
5133: both => ' checked="checked"',
5134: either => '',
5135: );
5136: if ($prelink eq 'either') {
5137: $checkedpre{either} = ' checked="checked"';
5138: $checkedpre{both} = '';
5139: }
5140: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
5141: '<td class="LC_left_item"><span class="LC_nobreak">'.
5142: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
5143: &mt('Both username and e-mail address').'</label></span> '.
5144: '<span class="LC_nobreak"><label>'.
5145: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
5146: &mt('Either username or e-mail address').'</label></span></td></tr>';
5147: $itemcount ++;
5148: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5149: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
5150: '<td class="LC_left_item">';
5151: my %postlinked;
5152: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5153: foreach my $item (@{$types}) {
5154: undef(%postlinked);
5155: $datatable .= '<fieldset style="display: inline-block;">'.
5156: '<legend>'.$usertypes->{$item}.'</legend>';
5157: if (ref($postlink{$item}) eq 'ARRAY') {
5158: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
5159: }
5160: foreach my $field ('email','username') {
5161: my $checked;
5162: if ($postlinked{$field}) {
5163: $checked = ' checked="checked"';
5164: }
5165: $datatable .= '<span class="LC_nobreak"><label>'.
5166: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
5167: $field.'"'.$checked.' />'.$field.'</label>'.
5168: '<span> ';
5169: }
5170: $datatable .= '</fieldset>';
5171: }
5172: }
5173: if (ref($postlink{'default'}) eq 'ARRAY') {
5174: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
5175: }
5176: $datatable .= '<fieldset style="display: inline-block;">'.
5177: '<legend>'.$othertitle.'</legend>';
5178: foreach my $field ('email','username') {
5179: my $checked;
5180: if ($postlinked{$field}) {
5181: $checked = ' checked="checked"';
5182: }
5183: $datatable .= '<span class="LC_nobreak"><label>'.
5184: '<input type="checkbox" name="passwords_postlink_default" value="'.
5185: $field.'"'.$checked.' />'.$field.'</label>'.
5186: '<span> ';
5187: }
5188: $datatable .= '</fieldset></td></tr>';
5189: $itemcount ++;
5190: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5191: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
5192: '<td class="LC_left_item">';
5193: foreach my $type ('permanent','critical','notify') {
5194: my $checkedemail;
5195: if ($emailsrc{$type}) {
5196: $checkedemail = ' checked="checked"';
5197: }
5198: $datatable .= '<span class="LC_nobreak"><label>'.
5199: '<input type="checkbox" name="passwords_emailsrc" value="'.
5200: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
5201: '<span> ';
5202: }
5203: $datatable .= '</td></tr>';
5204: $itemcount ++;
5205: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5206: my $switchserver = &check_switchserver($dom,$confname);
5207: my ($showstd,$noshowstd);
5208: if ($nostdtext) {
5209: $noshowstd = ' checked="checked"';
5210: } else {
5211: $showstd = ' checked="checked"';
5212: }
5213: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
5214: '<td class="LC_left_item"><span class="LC_nobreak">'.
5215: &mt('Retain standard text:').
5216: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
5217: &mt('Yes').'</label>'.' '.
5218: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
5219: &mt('No').'</label></span><br />'.
5220: '<span class="LC_fontsize_small">'.
5221: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
5222: &mt('Include custom text:');
5223: if ($customurl) {
1.160.6.104 raeburn 5224: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.160.6.98 raeburn 5225: undef,undef,undef,undef,'background-color:#ffffff');
5226: $datatable .= '<span class="LC_nobreak"> '.$link.
5227: '<label><input type="checkbox" name="passwords_custom_del"'.
5228: ' value="1" />'.&mt('Delete?').'</label></span>'.
5229: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
5230: }
5231: if ($switchserver) {
5232: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
5233: } else {
5234: $datatable .='<span class="LC_nobreak"> '.
5235: '<input type="file" name="passwords_customfile" /></span>';
5236: }
5237: $datatable .= '</td></tr>';
5238: } elsif ($position eq 'middle') {
5239: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
5240: my @items = ('intauth_cost','intauth_check','intauth_switch');
5241: my %defaults;
5242: if (ref($domconf{'defaults'}) eq 'HASH') {
5243: %defaults = %{$domconf{'defaults'}};
5244: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
5245: $defaults{'intauth_cost'} = 10;
5246: }
5247: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
5248: $defaults{'intauth_check'} = 0;
5249: }
5250: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
5251: $defaults{'intauth_switch'} = 0;
5252: }
5253: } else {
5254: %defaults = (
5255: 'intauth_cost' => 10,
5256: 'intauth_check' => 0,
5257: 'intauth_switch' => 0,
5258: );
5259: }
5260: foreach my $item (@items) {
5261: if ($itemcount%2) {
5262: $css_class = '';
5263: } else {
5264: $css_class = ' class="LC_odd_row" ';
5265: }
5266: $datatable .= '<tr'.$css_class.'>'.
5267: '<td><span class="LC_nobreak">'.$titles{$item}.
5268: '</span></td><td class="LC_left_item" colspan="3">';
5269: if ($item eq 'intauth_switch') {
5270: my @options = (0,1,2);
5271: my %optiondesc = &Apache::lonlocal::texthash (
5272: 0 => 'No',
5273: 1 => 'Yes',
5274: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
5275: );
5276: $datatable .= '<table width="100%">';
5277: foreach my $option (@options) {
5278: my $checked = ' ';
5279: if ($defaults{$item} eq $option) {
5280: $checked = ' checked="checked"';
5281: }
5282: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5283: '<label><input type="radio" name="'.$item.
5284: '" value="'.$option.'"'.$checked.' />'.
5285: $optiondesc{$option}.'</label></span></td></tr>';
5286: }
5287: $datatable .= '</table>';
5288: } elsif ($item eq 'intauth_check') {
5289: my @options = (0,1,2);
5290: my %optiondesc = &Apache::lonlocal::texthash (
5291: 0 => 'No',
5292: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
5293: 2 => 'Yes, disallow login if stored cost is less than domain default',
5294: );
5295: $datatable .= '<table width="100%">';
5296: foreach my $option (@options) {
5297: my $checked = ' ';
5298: my $onclick;
5299: if ($defaults{$item} eq $option) {
5300: $checked = ' checked="checked"';
5301: }
5302: if ($option == 2) {
5303: $onclick = ' onclick="javascript:warnIntAuth(this);"';
5304: }
5305: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5306: '<label><input type="radio" name="'.$item.
5307: '" value="'.$option.'"'.$checked.$onclick.' />'.
5308: $optiondesc{$option}.'</label></span></td></tr>';
5309: }
5310: $datatable .= '</table>';
5311: } else {
5312: $datatable .= '<input type="text" name="'.$item.'" value="'.
5313: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
5314: }
5315: $datatable .= '</td></tr>';
5316: $itemcount ++;
5317: }
5318: } elsif ($position eq 'lower') {
5319: my ($min,$max,%chars,$numsaved);
1.160.6.99 raeburn 5320: $min = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 5321: if (ref($settings) eq 'HASH') {
5322: if ($settings->{min}) {
5323: $min = $settings->{min};
5324: }
5325: if ($settings->{max}) {
5326: $max = $settings->{max};
5327: }
5328: if (ref($settings->{chars}) eq 'ARRAY') {
5329: map { $chars{$_} = 1; } (@{$settings->{chars}});
5330: }
5331: if ($settings->{numsaved}) {
5332: $numsaved = $settings->{numsaved};
5333: }
5334: }
5335: my %rulenames = &Apache::lonlocal::texthash(
5336: uc => 'At least one upper case letter',
5337: lc => 'At least one lower case letter',
5338: num => 'At least one number',
5339: spec => 'At least one non-alphanumeric',
5340: );
5341: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5342: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
5343: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 5344: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
5345: 'onblur="javascript:warnIntPass(this);" />'.
5346: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.160.6.98 raeburn 5347: '</span></td></tr>';
5348: $itemcount ++;
5349: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5350: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
5351: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 5352: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
5353: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 5354: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
5355: '</span></td></tr>';
5356: $itemcount ++;
5357: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5358: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
5359: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
5360: '</span></td>';
5361: my $numinrow = 2;
5362: my @possrules = ('uc','lc','num','spec');
5363: $datatable .= '<td class="LC_left_item"><table>';
5364: for (my $i=0; $i<@possrules; $i++) {
5365: my ($rem,$checked);
5366: if ($chars{$possrules[$i]}) {
5367: $checked = ' checked="checked"';
5368: }
5369: $rem = $i%($numinrow);
5370: if ($rem == 0) {
5371: if ($i > 0) {
5372: $datatable .= '</tr>';
5373: }
5374: $datatable .= '<tr>';
5375: }
5376: $datatable .= '<td><span class="LC_nobreak"><label>'.
5377: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
5378: $rulenames{$possrules[$i]}.'</label></span></td>';
5379: }
5380: my $rem = @possrules%($numinrow);
5381: my $colsleft = $numinrow - $rem;
5382: if ($colsleft > 1 ) {
5383: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5384: ' </td>';
5385: } elsif ($colsleft == 1) {
5386: $datatable .= '<td class="LC_left_item"> </td>';
5387: }
5388: $datatable .='</table></td></tr>';
5389: $itemcount ++;
5390: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5391: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
5392: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.100 raeburn 5393: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
1.160.6.99 raeburn 5394: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 5395: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
5396: '</span></td></tr>';
5397: } else {
5398: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5399: my %ownerchg = (
5400: by => {},
5401: for => {},
5402: );
5403: my %ownertitles = &Apache::lonlocal::texthash (
5404: by => 'Course owner status(es) allowed',
5405: for => 'Student status(es) allowed',
5406: );
5407: if (ref($settings) eq 'HASH') {
5408: if (ref($settings->{crsownerchg}) eq 'HASH') {
5409: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
5410: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
5411: }
5412: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
5413: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
5414: }
5415: }
5416: }
5417: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5418: $datatable .= '<tr '.$css_class.'>'.
5419: '<td>'.
5420: &mt('Requirements').'<ul>'.
5421: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
5422: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
5423: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
5424: '<li>'.&mt('User, course, and student share same domain').'</li>'.
5425: '</ul>'.
5426: '</td>'.
5427: '<td class="LC_left_item">';
5428: foreach my $item ('by','for') {
5429: $datatable .= '<fieldset style="display: inline-block;">'.
5430: '<legend>'.$ownertitles{$item}.'</legend>';
5431: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5432: foreach my $type (@{$types}) {
5433: my $checked;
5434: if ($ownerchg{$item}{$type}) {
5435: $checked = ' checked="checked"';
5436: }
5437: $datatable .= '<span class="LC_nobreak"><label>'.
5438: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
5439: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.160.6.104 raeburn 5440: '</span> ';
1.160.6.98 raeburn 5441: }
5442: }
5443: my $checked;
5444: if ($ownerchg{$item}{'default'}) {
5445: $checked = ' checked="checked"';
5446: }
5447: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5448: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
5449: $othertitle.'</label></span></fieldset>';
5450: }
5451: $datatable .= '</td></tr>';
5452: }
5453: return $datatable;
5454: }
5455:
1.160.6.113 raeburn 5456: sub print_wafproxy {
5457: my ($position,$dom,$settings,$rowtotal) = @_;
5458: my $css_class;
5459: my $itemcount = 0;
5460: my $datatable;
5461: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5462: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
5463: my %lt = &wafproxy_titles();
5464: foreach my $server (sort(keys(%servers))) {
5465: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
5466: next if ($serverhome eq '');
5467: my $serverdom;
5468: if ($serverhome ne $server) {
5469: $serverdom = &Apache::lonnet::host_domain($serverhome);
5470: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
5471: $othercontrol{$server} = $serverdom;
5472: }
5473: } else {
5474: $serverdom = &Apache::lonnet::host_domain($server);
5475: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
5476: if ($serverdom ne $dom) {
5477: $othercontrol{$server} = $serverdom;
5478: } else {
5479: $setdom = 1;
5480: if (ref($settings) eq 'HASH') {
5481: if (ref($settings->{'alias'}) eq 'HASH') {
5482: $aliases{$dom} = $settings->{'alias'};
5483: if ($aliases{$dom} ne '') {
5484: $showdom = 1;
5485: }
5486: }
5487: if (ref($settings->{'saml'}) eq 'HASH') {
5488: $saml{$dom} = $settings->{'saml'};
5489: }
5490: }
5491: }
5492: }
5493: }
5494: if ($setdom) {
5495: %{$values{$dom}} = ();
5496: if (ref($settings) eq 'HASH') {
5497: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
5498: $values{$dom}{$item} = $settings->{$item};
5499: }
5500: }
5501: }
5502: if (keys(%othercontrol)) {
5503: %otherdoms = reverse(%othercontrol);
5504: foreach my $domain (keys(%otherdoms)) {
5505: %{$values{$domain}} = ();
5506: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
5507: if (ref($config{'wafproxy'}) eq 'HASH') {
5508: $aliases{$domain} = $config{'wafproxy'}{'alias'};
5509: if (exists($config{'wafproxy'}{'saml'})) {
5510: $saml{$domain} = $config{'wafproxy'}{'saml'};
5511: }
5512: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
5513: $values{$domain}{$item} = $config{'wafproxy'}{$item};
5514: }
5515: }
5516: }
5517: }
5518: if ($position eq 'top') {
5519: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5520: my %aliasinfo;
5521: foreach my $server (sort(keys(%servers))) {
5522: $itemcount ++;
5523: my $dom_in_effect;
5524: my $aliasrows = '<tr>'.
5525: '<td class="LC_left_item" style="vertical-align: baseline;">'.
5526: &mt('Hostname').': '.
5527: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
5528: if ($othercontrol{$server}) {
5529: $dom_in_effect = $othercontrol{$server};
5530: my ($current,$forsaml);
5531: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
5532: $current = $aliases{$dom_in_effect}{$server};
5533: }
5534: if (ref($saml{$dom_in_effect}) eq 'HASH') {
5535: if ($saml{$dom_in_effect}{$server}) {
5536: $forsaml = 1;
5537: }
5538: }
5539: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
5540: &mt('Alias').': ';
5541: if ($current) {
5542: $aliasrows .= $current;
5543: if ($forsaml) {
5544: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
5545: }
5546: } else {
5547: $aliasrows .= &mt('None');
5548: }
5549: $aliasrows .= ' <span class="LC_small">('.
5550: &mt('controlled by domain: [_1]',
5551: '<b>'.$dom_in_effect.'</b>').')</span></td>';
5552: } else {
5553: $dom_in_effect = $dom;
5554: my ($current,$samlon,$samloff);
5555: $samloff = ' checked="checked"';
5556: if (ref($aliases{$dom}) eq 'HASH') {
5557: if ($aliases{$dom}{$server}) {
5558: $current = $aliases{$dom}{$server};
5559: }
5560: }
5561: if (ref($saml{$dom}) eq 'HASH') {
5562: if ($saml{$dom}{$server}) {
5563: $samlon = $samloff;
5564: undef($samloff);
5565: }
5566: }
5567: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
5568: &mt('Alias').': '.
5569: '<input type="text" name="wafproxy_alias_'.$server.'" '.
5570: 'value="'.$current.'" size="30" />'.
5571: (' 'x2).'<span class="LC_nobreak">'.
5572: &mt('Alias used for SSO Auth').': <label>'.
5573: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
5574: &mt('No').'</label> <label>'.
5575: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
5576: &mt('Yes').'</label></span>'.
5577: '</td>';
5578: }
5579: $aliasrows .= '</tr>';
5580: $aliasinfo{$dom_in_effect} .= $aliasrows;
5581: }
5582: if ($aliasinfo{$dom}) {
5583: my ($onclick,$wafon,$wafoff,$showtable);
5584: $onclick = ' onclick="javascript:toggleWAF();"';
5585: $wafoff = ' checked="checked"';
5586: $showtable = ' style="display:none";';
5587: if ($showdom) {
5588: $wafon = $wafoff;
5589: $wafoff = '';
5590: $showtable = ' style="display:inline;"';
5591: }
5592: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5593: $datatable = '<tr'.$css_class.'>'.
5594: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
5595: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
5596: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
5597: &mt('Yes').'</label>'.(' 'x2).'<label>'.
5598: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
5599: &mt('No').'</label></span></td>'.
5600: '<td class="LC_left_item">'.
5601: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
5602: '</table></td></tr>';
5603: $itemcount++;
5604: }
5605: if (keys(%otherdoms)) {
5606: foreach my $key (sort(keys(%otherdoms))) {
5607: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5608: $datatable .= '<tr'.$css_class.'>'.
5609: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
5610: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
5611: '</table></td></tr>';
5612: $itemcount++;
5613: }
5614: }
5615: } else {
5616: my %ip_methods = &remoteip_methods();
5617: if ($setdom) {
5618: $itemcount ++;
5619: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5620: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
5621: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
5622: $wafstyle = ' style="display:none;"';
5623: $nowafstyle = ' style="display:table-row;"';
5624: $currwafdisplay = ' style="display: none"';
5625: $wafrangestyle = ' style="display: none"';
5626: $curr_remotip = 'n';
5627: $ssltossl = ' checked="checked"';
5628: if ($showdom) {
5629: $wafstyle = ' style="display:table-row;"';
5630: $nowafstyle = ' style="display:none;"';
5631: if (keys(%{$values{$dom}})) {
5632: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
5633: $curr_remotip = $values{$dom}{remoteip};
5634: }
5635: if ($curr_remotip eq 'h') {
5636: $currwafdisplay = ' style="display:table-row"';
5637: $wafrangestyle = ' style="display:inline-block;"';
5638: }
5639: if ($values{$dom}{'sslopt'}) {
5640: $alltossl = ' checked="checked"';
5641: $ssltossl = '';
5642: }
5643: }
5644: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
5645: $vpndircheck = ' checked="checked"';
5646: $currwafvpn = ' style="display:table-row;"';
5647: $wafrangestyle = ' style="display:inline-block;"';
5648: } else {
5649: $vpnaliascheck = ' checked="checked"';
5650: $currwafvpn = ' style="display:none;"';
5651: }
5652: }
5653: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
5654: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
5655: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
5656: '</tr>'.
5657: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
5658: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
5659: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
5660: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
5661: &mt('Range(s) stored in CIDR notation').'</div></td>'.
5662: '<td class="LC_left_item"><table>'.
5663: '<tr>'.
5664: '<td valign="top">'.$lt{'remoteip'}.': '.
5665: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
5666: foreach my $option ('m','h','n') {
5667: my $sel;
1.160.6.114 raeburn 5668: if ($option eq $curr_remotip) {
5669: $sel = ' selected="selected"';
5670: }
5671: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
5672: $ip_methods{$option}.'</option>';
5673: }
5674: $datatable .= '</select></td></tr>'."\n".
5675: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
5676: $lt{'ipheader'}.': '.
5677: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
5678: 'name="wafproxy_ipheader" />'.
5679: '</td></tr>'."\n".
5680: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
5681: $lt{'trusted'}.':<br />'.
5682: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
5683: $values{$dom}{'trusted'}.'</textarea>'.
5684: '</td></tr>'."\n".
5685: '<tr><td><hr /></td></tr>'."\n".
5686: '<tr>'.
1.160.6.113 raeburn 5687: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
5688: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
5689: $lt{'vpndirect'}.'</label>'.(' 'x2).
5690: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
5691: $lt{'vpnaliased'}.'</label></span></td></tr>';
5692: foreach my $item ('vpnint','vpnext') {
5693: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
5694: '<td valign="top">'.$lt{$item}.':<br />'.
5695: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
5696: $values{$dom}{$item}.'</textarea>'.
5697: '</td></tr>'."\n";
5698: }
5699: $datatable .= '<tr><td><hr /></td></tr>'."\n".
5700: '<tr>'.
5701: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
5702: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
5703: $lt{'alltossl'}.'</label>'.(' 'x2).
5704: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
5705: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
5706: '</table></td></tr>';
5707: }
5708: if (keys(%otherdoms)) {
5709: foreach my $domain (sort(keys(%otherdoms))) {
5710: $itemcount ++;
5711: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5712: $datatable .= '<tr'.$css_class.'>'.
5713: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
5714: '<td class="LC_left_item"><table>';
5715: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
5716: my $showval = &mt('None');
5717: if ($item eq 'ssl') {
5718: $showval = $lt{'ssltossl'};
5719: }
5720: if ($values{$domain}{$item}) {
5721: $showval = $values{$domain}{$item};
5722: if ($item eq 'ssl') {
5723: $showval = $lt{'alltossl'};
5724: } elsif ($item eq 'remoteip') {
5725: $showval = $ip_methods{$values{$domain}{$item}};
5726: }
5727: }
5728: $datatable .= '<tr>'.
5729: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
5730: }
5731: $datatable .= '</table></td></tr>';
5732: }
5733: }
5734: }
5735: $$rowtotal += $itemcount;
5736: return $datatable;
5737: }
5738:
5739: sub wafproxy_titles {
5740: return &Apache::lonlocal::texthash(
5741: remoteip => "Method for determining user's IP",
5742: ipheader => 'Request header containing remote IP',
5743: trusted => 'Trusted IP range(s)',
5744: vpnaccess => 'Access from institutional VPN',
5745: vpndirect => 'via regular hostname (no WAF)',
5746: vpnaliased => 'via aliased hostname (WAF)',
5747: vpnint => 'Internal IP Range(s) for VPN sessions',
5748: vpnext => 'IP Range(s) for backend WAF connections',
5749: sslopt => 'Forwarding http/https',
5750: alltossl => 'WAF forwards both http and https requests to https',
5751: ssltossl => 'WAF forwards http requests to http and https to https',
5752: );
5753: }
5754:
5755: sub remoteip_methods {
5756: return &Apache::lonlocal::texthash(
5757: m => 'Use Apache mod_remoteip',
5758: h => 'Use headers parsed by LON-CAPA',
5759: n => 'Not in use',
5760: );
5761: }
5762:
1.137 raeburn 5763: sub print_usersessions {
5764: my ($position,$dom,$settings,$rowtotal) = @_;
5765: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 5766: my (%by_ip,%by_location,@intdoms);
5767: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 5768:
5769: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 5770: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 5771: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 5772: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 5773: my $itemcount = 1;
5774: if ($position eq 'top') {
1.152 raeburn 5775: if (keys(%serverhomes) > 1) {
1.145 raeburn 5776: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.105 raeburn 5777: my ($curroffloadnow,$curroffloadoth);
1.160.6.61 raeburn 5778: if (ref($settings) eq 'HASH') {
5779: if (ref($settings->{'offloadnow'}) eq 'HASH') {
5780: $curroffloadnow = $settings->{'offloadnow'};
5781: }
1.160.6.105 raeburn 5782: if (ref($settings->{'offloadoth'}) eq 'HASH') {
5783: $curroffloadoth = $settings->{'offloadoth'};
5784: }
1.160.6.61 raeburn 5785: }
1.160.6.105 raeburn 5786: my $other_insts = scalar(keys(%by_location));
5787: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
5788: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 5789: } else {
1.140 raeburn 5790: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 5791: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 5792: }
1.137 raeburn 5793: } else {
1.145 raeburn 5794: if (keys(%by_location) == 0) {
5795: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 5796: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 5797: } else {
5798: my %lt = &usersession_titles();
5799: my $numinrow = 5;
5800: my $prefix;
5801: my @types;
5802: if ($position eq 'bottom') {
5803: $prefix = 'remote';
5804: @types = ('version','excludedomain','includedomain');
5805: } else {
5806: $prefix = 'hosted';
5807: @types = ('excludedomain','includedomain');
5808: }
5809: my (%current,%checkedon,%checkedoff);
5810: my @lcversions = &Apache::lonnet::all_loncaparevs();
5811: my @locations = sort(keys(%by_location));
5812: foreach my $type (@types) {
5813: $checkedon{$type} = '';
5814: $checkedoff{$type} = ' checked="checked"';
5815: }
5816: if (ref($settings) eq 'HASH') {
5817: if (ref($settings->{$prefix}) eq 'HASH') {
5818: foreach my $key (keys(%{$settings->{$prefix}})) {
5819: $current{$key} = $settings->{$prefix}{$key};
5820: if ($key eq 'version') {
5821: if ($current{$key} ne '') {
5822: $checkedon{$key} = ' checked="checked"';
5823: $checkedoff{$key} = '';
5824: }
5825: } elsif (ref($current{$key}) eq 'ARRAY') {
5826: $checkedon{$key} = ' checked="checked"';
5827: $checkedoff{$key} = '';
5828: }
1.137 raeburn 5829: }
5830: }
5831: }
1.145 raeburn 5832: foreach my $type (@types) {
5833: next if ($type ne 'version' && !@locations);
5834: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5835: $datatable .= '<tr'.$css_class.'>
5836: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
5837: <span class="LC_nobreak">
5838: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
5839: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
5840: if ($type eq 'version') {
5841: my $selector = '<select name="'.$prefix.'_version">';
5842: foreach my $version (@lcversions) {
5843: my $selected = '';
5844: if ($current{'version'} eq $version) {
5845: $selected = ' selected="selected"';
5846: }
5847: $selector .= ' <option value="'.$version.'"'.
5848: $selected.'>'.$version.'</option>';
5849: }
5850: $selector .= '</select> ';
5851: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
5852: } else {
5853: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
5854: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
5855: ' />'.(' 'x2).
5856: '<input type="button" value="'.&mt('uncheck all').'" '.
5857: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
5858: "\n".
5859: '</div><div><table>';
5860: my $rem;
5861: for (my $i=0; $i<@locations; $i++) {
5862: my ($showloc,$value,$checkedtype);
5863: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
5864: my $ip = $by_location{$locations[$i]}->[0];
5865: if (ref($by_ip{$ip}) eq 'ARRAY') {
5866: $value = join(':',@{$by_ip{$ip}});
5867: $showloc = join(', ',@{$by_ip{$ip}});
5868: if (ref($current{$type}) eq 'ARRAY') {
5869: foreach my $loc (@{$by_ip{$ip}}) {
5870: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
5871: $checkedtype = ' checked="checked"';
5872: last;
5873: }
5874: }
1.138 raeburn 5875: }
5876: }
5877: }
1.145 raeburn 5878: $rem = $i%($numinrow);
5879: if ($rem == 0) {
5880: if ($i > 0) {
5881: $datatable .= '</tr>';
5882: }
5883: $datatable .= '<tr>';
5884: }
5885: $datatable .= '<td class="LC_left_item">'.
5886: '<span class="LC_nobreak"><label>'.
5887: '<input type="checkbox" name="'.$prefix.'_'.$type.
5888: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
5889: '</label></span></td>';
1.137 raeburn 5890: }
1.145 raeburn 5891: $rem = @locations%($numinrow);
5892: my $colsleft = $numinrow - $rem;
5893: if ($colsleft > 1 ) {
5894: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5895: ' </td>';
5896: } elsif ($colsleft == 1) {
5897: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 5898: }
1.145 raeburn 5899: $datatable .= '</tr></table>';
1.137 raeburn 5900: }
1.145 raeburn 5901: $datatable .= '</td></tr>';
5902: $itemcount ++;
1.137 raeburn 5903: }
5904: }
5905: }
5906: $$rowtotal += $itemcount;
5907: return $datatable;
5908: }
5909:
1.138 raeburn 5910: sub build_location_hashes {
5911: my ($intdoms,$by_ip,$by_location) = @_;
5912: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
5913: (ref($by_location) eq 'HASH'));
5914: my %iphost = &Apache::lonnet::get_iphost();
5915: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
5916: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
5917: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
5918: foreach my $id (@{$iphost{$primary_ip}}) {
5919: my $intdom = &Apache::lonnet::internet_dom($id);
5920: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
5921: push(@{$intdoms},$intdom);
5922: }
5923: }
5924: }
5925: foreach my $ip (keys(%iphost)) {
5926: if (ref($iphost{$ip}) eq 'ARRAY') {
5927: foreach my $id (@{$iphost{$ip}}) {
5928: my $location = &Apache::lonnet::internet_dom($id);
5929: if ($location) {
5930: next if (grep(/^\Q$location\E$/,@{$intdoms}));
5931: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5932: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
5933: push(@{$by_ip->{$ip}},$location);
5934: }
5935: } else {
5936: $by_ip->{$ip} = [$location];
5937: }
5938: }
5939: }
5940: }
5941: }
5942: foreach my $ip (sort(keys(%{$by_ip}))) {
5943: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5944: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
5945: my $first = $by_ip->{$ip}->[0];
5946: if (ref($by_location->{$first}) eq 'ARRAY') {
5947: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
5948: push(@{$by_location->{$first}},$ip);
5949: }
5950: } else {
5951: $by_location->{$first} = [$ip];
5952: }
5953: }
5954: }
5955: return;
5956: }
5957:
1.145 raeburn 5958: sub current_offloads_to {
5959: my ($dom,$settings,$servers) = @_;
5960: my (%spareid,%otherdomconfigs);
1.152 raeburn 5961: if (ref($servers) eq 'HASH') {
1.145 raeburn 5962: foreach my $lonhost (sort(keys(%{$servers}))) {
5963: my $gotspares;
1.152 raeburn 5964: if (ref($settings) eq 'HASH') {
5965: if (ref($settings->{'spares'}) eq 'HASH') {
5966: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
5967: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
5968: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
5969: $gotspares = 1;
5970: }
1.145 raeburn 5971: }
5972: }
5973: unless ($gotspares) {
5974: my $gotspares;
5975: my $serverhomeID =
5976: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
5977: my $serverhomedom =
5978: &Apache::lonnet::host_domain($serverhomeID);
5979: if ($serverhomedom ne $dom) {
5980: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
5981: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5982: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5983: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5984: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5985: $gotspares = 1;
5986: }
5987: }
5988: } else {
5989: $otherdomconfigs{$serverhomedom} =
5990: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
5991: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
5992: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5993: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5994: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
5995: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5996: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5997: $gotspares = 1;
5998: }
5999: }
6000: }
6001: }
6002: }
6003: }
6004: }
6005: unless ($gotspares) {
6006: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
6007: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6008: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6009: } else {
6010: my $server_hostname = &Apache::lonnet::hostname($lonhost);
6011: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
6012: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
6013: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6014: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6015: } else {
1.150 raeburn 6016: my %what = (
6017: spareid => 1,
6018: );
6019: my ($result,$returnhash) =
6020: &Apache::lonnet::get_remote_globals($lonhost,\%what);
6021: if ($result eq 'ok') {
6022: if (ref($returnhash) eq 'HASH') {
6023: if (ref($returnhash->{'spareid'}) eq 'HASH') {
6024: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
6025: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
6026: }
6027: }
1.145 raeburn 6028: }
6029: }
6030: }
6031: }
6032: }
6033: }
6034: return %spareid;
6035: }
6036:
6037: sub spares_row {
1.160.6.105 raeburn 6038: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
6039: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 6040: my $css_class;
6041: my $numinrow = 4;
6042: my $itemcount = 1;
6043: my $datatable;
1.152 raeburn 6044: my %typetitles = &sparestype_titles();
6045: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 6046: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 6047: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
6048: my ($othercontrol,$serverdom);
6049: if ($serverhome ne $server) {
6050: $serverdom = &Apache::lonnet::host_domain($serverhome);
6051: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6052: } else {
6053: $serverdom = &Apache::lonnet::host_domain($server);
6054: if ($serverdom ne $dom) {
6055: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6056: }
6057: }
6058: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.105 raeburn 6059: my ($checkednow,$checkedoth);
1.160.6.61 raeburn 6060: if (ref($curroffloadnow) eq 'HASH') {
6061: if ($curroffloadnow->{$server}) {
6062: $checkednow = ' checked="checked"';
6063: }
6064: }
1.160.6.105 raeburn 6065: if (ref($curroffloadoth) eq 'HASH') {
6066: if ($curroffloadoth->{$server}) {
6067: $checkedoth = ' checked="checked"';
6068: }
6069: }
1.145 raeburn 6070: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6071: $datatable .= '<tr'.$css_class.'>
6072: <td rowspan="2">
1.160.6.13 raeburn 6073: <span class="LC_nobreak">'.
6074: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 6075: ,'<b>'.$server.'</b>').'</span><br />'.
6076: '<span class="LC_nobreak">'."\n".
6077: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.160.6.105 raeburn 6078: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.160.6.13 raeburn 6079: "\n";
1.160.6.105 raeburn 6080: if ($other_insts) {
6081: $datatable .= '<br />'.
6082: '<span class="LC_nobreak">'."\n".
6083: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
6084: ' '.&mt('Switch other institutions on next access').'</label></span>'.
6085: "\n";
6086: }
1.145 raeburn 6087: my (%current,%canselect);
1.152 raeburn 6088: my @choices =
6089: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6090: foreach my $type ('primary','default') {
6091: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 6092: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6093: my @spares = @{$spareid->{$server}{$type}};
6094: if (@spares > 0) {
1.152 raeburn 6095: if ($othercontrol) {
6096: $current{$type} = join(', ',@spares);
6097: } else {
6098: $current{$type} .= '<table>';
6099: my $numspares = scalar(@spares);
6100: for (my $i=0; $i<@spares; $i++) {
6101: my $rem = $i%($numinrow);
6102: if ($rem == 0) {
6103: if ($i > 0) {
6104: $current{$type} .= '</tr>';
6105: }
6106: $current{$type} .= '<tr>';
1.145 raeburn 6107: }
1.152 raeburn 6108: $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'".');" /> '.
6109: $spareid->{$server}{$type}[$i].
6110: '</label></td>'."\n";
6111: }
6112: my $rem = @spares%($numinrow);
6113: my $colsleft = $numinrow - $rem;
6114: if ($colsleft > 1 ) {
6115: $current{$type} .= '<td colspan="'.$colsleft.
6116: '" class="LC_left_item">'.
6117: ' </td>';
6118: } elsif ($colsleft == 1) {
6119: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 6120: }
1.152 raeburn 6121: $current{$type} .= '</tr></table>';
1.150 raeburn 6122: }
1.145 raeburn 6123: }
6124: }
6125: if ($current{$type} eq '') {
6126: $current{$type} = &mt('None specified');
6127: }
1.152 raeburn 6128: if ($othercontrol) {
6129: if ($type eq 'primary') {
6130: $canselect{$type} = $othercontrol;
6131: }
6132: } else {
6133: $canselect{$type} =
6134: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
6135: '<select name="newspare_'.$type.'_'.$server.'" '.
6136: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
6137: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
6138: if (@choices > 0) {
6139: foreach my $lonhost (@choices) {
6140: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
6141: }
6142: }
6143: $canselect{$type} .= '</select>'."\n";
6144: }
6145: } else {
6146: $current{$type} = &mt('Could not be determined');
6147: if ($type eq 'primary') {
6148: $canselect{$type} = $othercontrol;
6149: }
1.145 raeburn 6150: }
1.152 raeburn 6151: if ($type eq 'default') {
6152: $datatable .= '<tr'.$css_class.'>';
6153: }
6154: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
6155: '<td>'.$current{$type}.'</td>'."\n".
6156: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 6157: }
6158: $itemcount ++;
6159: }
6160: }
6161: $$rowtotal += $itemcount;
6162: return $datatable;
6163: }
6164:
1.152 raeburn 6165: sub possible_newspares {
6166: my ($server,$currspares,$serverhomes,$altids) = @_;
6167: my $serverhostname = &Apache::lonnet::hostname($server);
6168: my %excluded;
6169: if ($serverhostname ne '') {
6170: %excluded = (
6171: $serverhostname => 1,
6172: );
6173: }
6174: if (ref($currspares) eq 'HASH') {
6175: foreach my $type (keys(%{$currspares})) {
6176: if (ref($currspares->{$type}) eq 'ARRAY') {
6177: if (@{$currspares->{$type}} > 0) {
6178: foreach my $curr (@{$currspares->{$type}}) {
6179: my $hostname = &Apache::lonnet::hostname($curr);
6180: $excluded{$hostname} = 1;
6181: }
6182: }
6183: }
6184: }
6185: }
6186: my @choices;
6187: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
6188: if (keys(%{$serverhomes}) > 1) {
6189: foreach my $name (sort(keys(%{$serverhomes}))) {
6190: unless ($excluded{$name}) {
6191: if (exists($altids->{$serverhomes->{$name}})) {
6192: push(@choices,$altids->{$serverhomes->{$name}});
6193: } else {
6194: push(@choices,$serverhomes->{$name});
1.145 raeburn 6195: }
6196: }
6197: }
6198: }
6199: }
1.152 raeburn 6200: return sort(@choices);
1.145 raeburn 6201: }
6202:
1.150 raeburn 6203: sub print_loadbalancing {
6204: my ($dom,$settings,$rowtotal) = @_;
6205: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6206: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6207: my $numinrow = 1;
6208: my $datatable;
6209: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 6210: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 6211: if (ref($settings) eq 'HASH') {
6212: %existing = %{$settings};
6213: }
6214: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
6215: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 6216: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 6217: } else {
6218: return;
6219: }
6220: my ($othertitle,$usertypes,$types) =
6221: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 6222: my $rownum = 8;
1.150 raeburn 6223: if (ref($types) eq 'ARRAY') {
6224: $rownum += scalar(@{$types});
6225: }
1.160.6.7 raeburn 6226: my @css_class = ('LC_odd_row','LC_even_row');
6227: my $balnum = 0;
6228: my $islast;
6229: my (@toshow,$disabledtext);
6230: if (keys(%currbalancer) > 0) {
6231: @toshow = sort(keys(%currbalancer));
6232: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
6233: push(@toshow,'');
6234: }
6235: } else {
6236: @toshow = ('');
6237: $disabledtext = &mt('No existing load balancer');
6238: }
6239: foreach my $lonhost (@toshow) {
6240: if ($balnum == scalar(@toshow)-1) {
6241: $islast = 1;
6242: } else {
6243: $islast = 0;
6244: }
6245: my $cssidx = $balnum%2;
6246: my $targets_div_style = 'display: none';
6247: my $disabled_div_style = 'display: block';
6248: my $homedom_div_style = 'display: none';
6249: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
6250: '<td rowspan="'.$rownum.'" valign="top">'.
6251: '<p>';
6252: if ($lonhost eq '') {
6253: $datatable .= '<span class="LC_nobreak">';
6254: if (keys(%currbalancer) > 0) {
6255: $datatable .= &mt('Add balancer:');
6256: } else {
6257: $datatable .= &mt('Enable balancer:');
6258: }
6259: $datatable .= ' '.
6260: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
6261: ' id="loadbalancing_lonhost_'.$balnum.'"'.
6262: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
6263: '<option value="" selected="selected">'.&mt('None').
6264: '</option>'."\n";
6265: foreach my $server (sort(keys(%servers))) {
6266: next if ($currbalancer{$server});
6267: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
6268: }
6269: $datatable .=
6270: '</select>'."\n".
6271: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
6272: } else {
6273: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
6274: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
6275: &mt('Stop balancing').'</label>'.
6276: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
6277: $targets_div_style = 'display: block';
6278: $disabled_div_style = 'display: none';
6279: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
6280: $homedom_div_style = 'display: block';
6281: }
6282: }
6283: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
6284: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
6285: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
6286: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
6287: my ($numspares,@spares) = &count_servers($lonhost,%servers);
6288: my @sparestypes = ('primary','default');
6289: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 6290: my %hostherechecked = (
6291: no => ' checked="checked"',
6292: );
1.160.6.94 raeburn 6293: my %balcookiechecked = (
6294: no => ' checked="checked"',
6295: );
1.160.6.7 raeburn 6296: foreach my $sparetype (@sparestypes) {
6297: my $targettable;
6298: for (my $i=0; $i<$numspares; $i++) {
6299: my $checked;
6300: if (ref($currtargets{$lonhost}) eq 'HASH') {
6301: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6302: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6303: $checked = ' checked="checked"';
6304: }
6305: }
6306: }
6307: my ($chkboxval,$disabled);
6308: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
6309: $chkboxval = $spares[$i];
6310: }
6311: if (exists($currbalancer{$spares[$i]})) {
6312: $disabled = ' disabled="disabled"';
6313: }
6314: $targettable .=
1.160.6.55 raeburn 6315: '<td><span class="LC_nobreak"><label>'.
6316: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 6317: $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 6318: '</span></label></span></td>';
1.160.6.7 raeburn 6319: my $rem = $i%($numinrow);
6320: if ($rem == 0) {
6321: if (($i > 0) && ($i < $numspares-1)) {
6322: $targettable .= '</tr>';
6323: }
6324: if ($i < $numspares-1) {
6325: $targettable .= '<tr>';
1.150 raeburn 6326: }
6327: }
6328: }
1.160.6.7 raeburn 6329: if ($targettable ne '') {
6330: my $rem = $numspares%($numinrow);
6331: my $colsleft = $numinrow - $rem;
6332: if ($colsleft > 1 ) {
6333: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6334: ' </td>';
6335: } elsif ($colsleft == 1) {
6336: $targettable .= '<td class="LC_left_item"> </td>';
6337: }
6338: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
6339: '<table><tr>'.$targettable.'</tr></table><br />';
6340: }
1.160.6.76 raeburn 6341: $hostherechecked{$sparetype} = '';
6342: if (ref($currtargets{$lonhost}) eq 'HASH') {
6343: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6344: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6345: $hostherechecked{$sparetype} = ' checked="checked"';
6346: $hostherechecked{'no'} = '';
6347: }
6348: }
6349: }
6350: }
1.160.6.94 raeburn 6351: if ($currcookies{$lonhost}) {
6352: %balcookiechecked = (
6353: yes => ' checked="checked"',
6354: );
6355: }
1.160.6.76 raeburn 6356: $datatable .= &mt('Hosting on balancer itself').'<br />'.
6357: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
6358: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
6359: foreach my $sparetype (@sparestypes) {
6360: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
6361: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
6362: '</i></label><br />';
1.160.6.7 raeburn 6363: }
1.160.6.94 raeburn 6364: $datatable .= &mt('Use balancer cookie').'<br />'.
6365: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
6366: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
6367: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
6368: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
6369: '</div></td></tr>'.
1.160.6.7 raeburn 6370: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
6371: $othertitle,$usertypes,$types,\%servers,
6372: \%currbalancer,$lonhost,
6373: $targets_div_style,$homedom_div_style,
6374: $css_class[$cssidx],$balnum,$islast);
6375: $$rowtotal += $rownum;
6376: $balnum ++;
6377: }
6378: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
6379: return $datatable;
6380: }
6381:
6382: sub get_loadbalancers_config {
1.160.6.94 raeburn 6383: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 6384: return unless ((ref($servers) eq 'HASH') &&
6385: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 6386: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
6387: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 6388: if (keys(%{$existing}) > 0) {
6389: my $oldlonhost;
6390: foreach my $key (sort(keys(%{$existing}))) {
6391: if ($key eq 'lonhost') {
6392: $oldlonhost = $existing->{'lonhost'};
6393: $currbalancer->{$oldlonhost} = 1;
6394: } elsif ($key eq 'targets') {
6395: if ($oldlonhost) {
6396: $currtargets->{$oldlonhost} = $existing->{'targets'};
6397: }
6398: } elsif ($key eq 'rules') {
6399: if ($oldlonhost) {
6400: $currrules->{$oldlonhost} = $existing->{'rules'};
6401: }
6402: } elsif (ref($existing->{$key}) eq 'HASH') {
6403: $currbalancer->{$key} = 1;
6404: $currtargets->{$key} = $existing->{$key}{'targets'};
6405: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 6406: if ($existing->{$key}{'cookie'}) {
6407: $currcookies->{$key} = 1;
6408: }
1.150 raeburn 6409: }
6410: }
1.160.6.7 raeburn 6411: } else {
6412: my ($balancerref,$targetsref) =
6413: &Apache::lonnet::get_lonbalancer_config($servers);
6414: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
6415: foreach my $server (sort(keys(%{$balancerref}))) {
6416: $currbalancer->{$server} = 1;
6417: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 6418: }
6419: }
6420: }
1.160.6.7 raeburn 6421: return;
1.150 raeburn 6422: }
6423:
6424: sub loadbalancing_rules {
6425: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 6426: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
6427: $css_class,$balnum,$islast) = @_;
1.150 raeburn 6428: my $output;
1.160.6.7 raeburn 6429: my $num = 0;
6430: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 6431: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
6432: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
6433: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 6434: $num ++;
1.150 raeburn 6435: my $current;
6436: if (ref($currrules) eq 'HASH') {
6437: $current = $currrules->{$type};
6438: }
1.160.6.55 raeburn 6439: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 6440: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 6441: $current = '';
6442: }
6443: }
6444: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 6445: $servers,$currbalancer,$lonhost,$dom,
6446: $targets_div_style,$homedom_div_style,
6447: $css_class,$balnum,$num,$islast);
1.150 raeburn 6448: }
6449: }
6450: return $output;
6451: }
6452:
6453: sub loadbalancing_titles {
6454: my ($dom,$intdom,$usertypes,$types) = @_;
6455: my %othertypes = (
6456: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
6457: '_LC_author' => &mt('Users from [_1] with author role',$dom),
6458: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
6459: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 6460: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
6461: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 6462: );
1.160.6.26 raeburn 6463: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 6464: my @available;
1.150 raeburn 6465: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 6466: @available = @{$types};
1.150 raeburn 6467: }
1.160.6.89 raeburn 6468: unless (grep(/^default$/,@available)) {
6469: push(@available,'default');
6470: }
6471: unshift(@alltypes,@available);
1.150 raeburn 6472: my %titles;
6473: foreach my $type (@alltypes) {
6474: if ($type =~ /^_LC_/) {
6475: $titles{$type} = $othertypes{$type};
6476: } elsif ($type eq 'default') {
6477: $titles{$type} = &mt('All users from [_1]',$dom);
6478: if (ref($types) eq 'ARRAY') {
6479: if (@{$types} > 0) {
6480: $titles{$type} = &mt('Other users from [_1]',$dom);
6481: }
6482: }
6483: } elsif (ref($usertypes) eq 'HASH') {
6484: $titles{$type} = $usertypes->{$type};
6485: }
6486: }
6487: return (\@alltypes,\%othertypes,\%titles);
6488: }
6489:
6490: sub loadbalance_rule_row {
1.160.6.7 raeburn 6491: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
6492: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 6493: my @rulenames;
1.150 raeburn 6494: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 6495: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 6496: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 6497: } else {
1.160.6.26 raeburn 6498: @rulenames = ('default','homeserver');
6499: if ($type eq '_LC_external') {
6500: push(@rulenames,'externalbalancer');
6501: } else {
6502: push(@rulenames,'specific');
6503: }
6504: push(@rulenames,'none');
1.150 raeburn 6505: }
6506: my $style = $targets_div_style;
1.160.6.55 raeburn 6507: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 6508: $style = $homedom_div_style;
6509: }
1.160.6.7 raeburn 6510: my $space;
6511: if ($islast && $num == 1) {
6512: $space = '<div display="inline-block"> </div>';
6513: }
6514: my $output =
6515: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
6516: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
6517: '<td valaign="top">'.$space.
6518: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 6519: for (my $i=0; $i<@rulenames; $i++) {
6520: my $rule = $rulenames[$i];
6521: my ($checked,$extra);
6522: if ($rulenames[$i] eq 'default') {
6523: $rule = '';
6524: }
6525: if ($rulenames[$i] eq 'specific') {
6526: if (ref($servers) eq 'HASH') {
6527: my $default;
6528: if (($current ne '') && (exists($servers->{$current}))) {
6529: $checked = ' checked="checked"';
6530: }
6531: unless ($checked) {
6532: $default = ' selected="selected"';
6533: }
1.160.6.7 raeburn 6534: $extra =
6535: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
6536: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
6537: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
6538: '<option value=""'.$default.'></option>'."\n";
6539: foreach my $server (sort(keys(%{$servers}))) {
6540: if (ref($currbalancer) eq 'HASH') {
6541: next if (exists($currbalancer->{$server}));
6542: }
1.150 raeburn 6543: my $selected;
1.160.6.7 raeburn 6544: if ($server eq $current) {
1.150 raeburn 6545: $selected = ' selected="selected"';
6546: }
1.160.6.7 raeburn 6547: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 6548: }
6549: $extra .= '</select>';
6550: }
6551: } elsif ($rule eq $current) {
6552: $checked = ' checked="checked"';
6553: }
6554: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 6555: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
6556: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
6557: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 6558: ')"'.$checked.' /> ';
1.160.6.56 raeburn 6559: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 6560: $output .= $ruletitles{'particular'};
6561: } else {
6562: $output .= $ruletitles{$rulenames[$i]};
6563: }
6564: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 6565: }
6566: $output .= '</div></td></tr>'."\n";
6567: return $output;
6568: }
6569:
6570: sub offloadtype_text {
6571: my %ruletitles = &Apache::lonlocal::texthash (
6572: 'default' => 'Offloads to default destinations',
6573: 'homeserver' => "Offloads to user's home server",
6574: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
6575: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 6576: 'none' => 'No offload',
1.160.6.26 raeburn 6577: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
6578: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 6579: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 6580: );
6581: return %ruletitles;
6582: }
6583:
6584: sub sparestype_titles {
6585: my %typestitles = &Apache::lonlocal::texthash (
6586: 'primary' => 'primary',
6587: 'default' => 'default',
6588: );
6589: return %typestitles;
6590: }
6591:
1.28 raeburn 6592: sub contact_titles {
6593: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 6594: 'supportemail' => 'Support E-mail address',
6595: 'adminemail' => 'Default Server Admin E-mail address',
6596: 'errormail' => 'Error reports to be e-mailed to',
6597: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.101 raeburn 6598: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
6599: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 6600: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
6601: 'requestsmail' => 'E-mail from course requests requiring approval',
6602: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 6603: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 6604: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.160.6.109 raeburn 6605: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
6606: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.160.6.107 raeburn 6607: 'errorweights' => 'Weights used to compute error count',
6608: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 6609: );
6610: my %short_titles = &Apache::lonlocal::texthash (
6611: adminemail => 'Admin E-mail address',
6612: supportemail => 'Support E-mail',
6613: );
6614: return (\%titles,\%short_titles);
6615: }
6616:
1.160.6.78 raeburn 6617: sub helpform_fields {
6618: my %titles = &Apache::lonlocal::texthash (
6619: 'username' => 'Name',
6620: 'user' => 'Username/domain',
6621: 'phone' => 'Phone',
6622: 'cc' => 'Cc e-mail',
6623: 'course' => 'Course Details',
6624: 'section' => 'Sections',
6625: 'screenshot' => 'File upload',
6626: );
6627: my @fields = ('username','phone','user','course','section','cc','screenshot');
6628: my %possoptions = (
6629: username => ['yes','no','req'],
6630: phone => ['yes','no','req'],
6631: user => ['yes','no'],
6632: cc => ['yes','no'],
6633: course => ['yes','no'],
6634: section => ['yes','no'],
6635: screenshot => ['yes','no'],
6636: );
6637: my %fieldoptions = &Apache::lonlocal::texthash (
6638: 'yes' => 'Optional',
6639: 'req' => 'Required',
6640: 'no' => "Not shown",
6641: );
6642: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
6643: }
6644:
1.72 raeburn 6645: sub tool_titles {
6646: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 6647: aboutme => 'Personal web page',
1.86 raeburn 6648: blog => 'Blog',
1.160.6.4 raeburn 6649: webdav => 'WebDAV',
1.86 raeburn 6650: portfolio => 'Portfolio',
1.88 bisitz 6651: official => 'Official courses (with institutional codes)',
6652: unofficial => 'Unofficial courses',
1.98 raeburn 6653: community => 'Communities',
1.160.6.30 raeburn 6654: textbook => 'Textbook courses',
1.86 raeburn 6655: );
1.72 raeburn 6656: return %titles;
6657: }
6658:
1.101 raeburn 6659: sub courserequest_titles {
6660: my %titles = &Apache::lonlocal::texthash (
6661: official => 'Official',
6662: unofficial => 'Unofficial',
6663: community => 'Communities',
1.160.6.30 raeburn 6664: textbook => 'Textbook',
1.101 raeburn 6665: norequest => 'Not allowed',
1.104 raeburn 6666: approval => 'Approval by Dom. Coord.',
1.101 raeburn 6667: validate => 'With validation',
6668: autolimit => 'Numerical limit',
1.103 raeburn 6669: unlimited => '(blank for unlimited)',
1.101 raeburn 6670: );
6671: return %titles;
6672: }
6673:
1.160.6.5 raeburn 6674: sub authorrequest_titles {
6675: my %titles = &Apache::lonlocal::texthash (
6676: norequest => 'Not allowed',
6677: approval => 'Approval by Dom. Coord.',
6678: automatic => 'Automatic approval',
6679: );
6680: return %titles;
6681: }
6682:
1.101 raeburn 6683: sub courserequest_conditions {
6684: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 6685: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 6686: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 6687: );
6688: return %conditions;
6689: }
6690:
6691:
1.27 raeburn 6692: sub print_usercreation {
1.30 raeburn 6693: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 6694: my $numinrow = 4;
1.28 raeburn 6695: my $datatable;
6696: if ($position eq 'top') {
1.30 raeburn 6697: $$rowtotal ++;
1.34 raeburn 6698: my $rowcount = 0;
1.32 raeburn 6699: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 6700: if (ref($rules) eq 'HASH') {
6701: if (keys(%{$rules}) > 0) {
1.32 raeburn 6702: $datatable .= &user_formats_row('username',$settings,$rules,
6703: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 6704: $$rowtotal ++;
1.32 raeburn 6705: $rowcount ++;
6706: }
6707: }
6708: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
6709: if (ref($idrules) eq 'HASH') {
6710: if (keys(%{$idrules}) > 0) {
6711: $datatable .= &user_formats_row('id',$settings,$idrules,
6712: $idruleorder,$numinrow,$rowcount);
6713: $$rowtotal ++;
6714: $rowcount ++;
1.28 raeburn 6715: }
6716: }
1.39 raeburn 6717: if ($rowcount == 0) {
6718: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
6719: $$rowtotal ++;
6720: $rowcount ++;
6721: }
1.34 raeburn 6722: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 6723: my @creators = ('author','course','requestcrs');
1.37 raeburn 6724: my ($rules,$ruleorder) =
6725: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 6726: my %lt = &usercreation_types();
6727: my %checked;
6728: if (ref($settings) eq 'HASH') {
6729: if (ref($settings->{'cancreate'}) eq 'HASH') {
6730: foreach my $item (@creators) {
6731: $checked{$item} = $settings->{'cancreate'}{$item};
6732: }
6733: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
6734: foreach my $item (@creators) {
6735: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
6736: $checked{$item} = 'none';
6737: }
6738: }
6739: }
6740: }
6741: my $rownum = 0;
6742: foreach my $item (@creators) {
6743: $rownum ++;
1.160.6.34 raeburn 6744: if ($checked{$item} eq '') {
6745: $checked{$item} = 'any';
1.34 raeburn 6746: }
6747: my $css_class;
6748: if ($rownum%2) {
6749: $css_class = '';
6750: } else {
6751: $css_class = ' class="LC_odd_row" ';
6752: }
6753: $datatable .= '<tr'.$css_class.'>'.
6754: '<td><span class="LC_nobreak">'.$lt{$item}.
6755: '</span></td><td align="right">';
1.160.6.34 raeburn 6756: my @options = ('any');
6757: if (ref($rules) eq 'HASH') {
6758: if (keys(%{$rules}) > 0) {
6759: push(@options,('official','unofficial'));
1.37 raeburn 6760: }
6761: }
1.160.6.34 raeburn 6762: push(@options,'none');
1.37 raeburn 6763: foreach my $option (@options) {
1.50 raeburn 6764: my $type = 'radio';
1.34 raeburn 6765: my $check = ' ';
1.160.6.34 raeburn 6766: if ($checked{$item} eq $option) {
6767: $check = ' checked="checked" ';
1.34 raeburn 6768: }
6769: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 6770: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 6771: $item.'" value="'.$option.'"'.$check.'/> '.
6772: $lt{$option}.'</label> </span>';
6773: }
6774: $datatable .= '</td></tr>';
6775: }
1.28 raeburn 6776: } else {
6777: my @contexts = ('author','course','domain');
6778: my @authtypes = ('int','krb4','krb5','loc');
6779: my %checked;
6780: if (ref($settings) eq 'HASH') {
6781: if (ref($settings->{'authtypes'}) eq 'HASH') {
6782: foreach my $item (@contexts) {
6783: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
6784: foreach my $auth (@authtypes) {
6785: if ($settings->{'authtypes'}{$item}{$auth}) {
6786: $checked{$item}{$auth} = ' checked="checked" ';
6787: }
6788: }
6789: }
6790: }
1.27 raeburn 6791: }
1.35 raeburn 6792: } else {
6793: foreach my $item (@contexts) {
1.36 raeburn 6794: foreach my $auth (@authtypes) {
1.35 raeburn 6795: $checked{$item}{$auth} = ' checked="checked" ';
6796: }
6797: }
1.27 raeburn 6798: }
1.28 raeburn 6799: my %title = &context_names();
6800: my %authname = &authtype_names();
6801: my $rownum = 0;
6802: my $css_class;
6803: foreach my $item (@contexts) {
6804: if ($rownum%2) {
6805: $css_class = '';
6806: } else {
6807: $css_class = ' class="LC_odd_row" ';
6808: }
1.30 raeburn 6809: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 6810: '<td>'.$title{$item}.
6811: '</td><td class="LC_left_item">'.
6812: '<span class="LC_nobreak">';
6813: foreach my $auth (@authtypes) {
6814: $datatable .= '<label>'.
6815: '<input type="checkbox" name="'.$item.'_auth" '.
6816: $checked{$item}{$auth}.' value="'.$auth.'" />'.
6817: $authname{$auth}.'</label> ';
6818: }
6819: $datatable .= '</span></td></tr>';
6820: $rownum ++;
1.27 raeburn 6821: }
1.30 raeburn 6822: $$rowtotal += $rownum;
1.27 raeburn 6823: }
6824: return $datatable;
6825: }
6826:
1.160.6.34 raeburn 6827: sub print_selfcreation {
6828: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 6829: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
6830: $emaildomain,$datatable);
1.160.6.34 raeburn 6831: if (ref($settings) eq 'HASH') {
6832: if (ref($settings->{'cancreate'}) eq 'HASH') {
6833: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 6834: if (ref($createsettings) eq 'HASH') {
6835: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
6836: @selfcreate = @{$createsettings->{'selfcreate'}};
6837: } elsif ($createsettings->{'selfcreate'} ne '') {
6838: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
6839: @selfcreate = ('email','login','sso');
6840: } elsif ($createsettings->{'selfcreate'} ne 'none') {
6841: @selfcreate = ($createsettings->{'selfcreate'});
6842: }
6843: }
6844: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
6845: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 6846: }
1.160.6.93 raeburn 6847: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
6848: $emailoptions = $createsettings->{'emailoptions'};
6849: }
6850: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
6851: $emailverified = $createsettings->{'emailverified'};
6852: }
6853: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
6854: $emaildomain = $createsettings->{'emaildomain'};
6855: }
1.160.6.34 raeburn 6856: }
6857: }
6858: }
6859: my %radiohash;
6860: my $numinrow = 4;
6861: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 6862: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 6863: if ($position eq 'top') {
6864: my %choices = &Apache::lonlocal::texthash (
6865: cancreate_login => 'Institutional Login',
6866: cancreate_sso => 'Institutional Single Sign On',
6867: );
6868: my @toggles = sort(keys(%choices));
6869: my %defaultchecked = (
6870: 'cancreate_login' => 'off',
6871: 'cancreate_sso' => 'off',
6872: );
1.160.6.35 raeburn 6873: my ($onclick,$itemcount);
1.160.6.34 raeburn 6874: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6875: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 6876: $$rowtotal += $itemcount;
1.160.6.34 raeburn 6877:
6878: if (ref($usertypes) eq 'HASH') {
6879: if (keys(%{$usertypes}) > 0) {
6880: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
6881: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 6882: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 6883: $$rowtotal ++;
6884: }
6885: }
1.160.6.44 raeburn 6886: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
6887: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6888: $fieldtitles{'inststatus'} = &mt('Institutional status');
6889: my $rem;
6890: my $numperrow = 2;
6891: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
6892: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 6893: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 6894: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 6895: '<table>'."\n";
1.160.6.44 raeburn 6896: for (my $i=0; $i<@fields; $i++) {
6897: $rem = $i%($numperrow);
6898: if ($rem == 0) {
6899: if ($i > 0) {
6900: $datatable .= '</tr>';
6901: }
6902: $datatable .= '<tr>';
6903: }
6904: my $currval;
1.160.6.51 raeburn 6905: if (ref($createsettings) eq 'HASH') {
6906: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
6907: $currval = $createsettings->{'shibenv'}{$fields[$i]};
6908: }
1.160.6.44 raeburn 6909: }
6910: $datatable .= '<td class="LC_left_item">'.
6911: '<span class="LC_nobreak">'.
6912: '<input type="text" name="shibenv_'.$fields[$i].'" '.
6913: 'value="'.$currval.'" size="10" /> '.
6914: $fieldtitles{$fields[$i]}.'</span></td>';
6915: }
6916: my $colsleft = $numperrow - $rem;
6917: if ($colsleft > 1 ) {
6918: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6919: ' </td>';
6920: } elsif ($colsleft == 1) {
6921: $datatable .= '<td class="LC_left_item"> </td>';
6922: }
6923: $datatable .= '</tr></table></td></tr>';
6924: $$rowtotal ++;
1.160.6.34 raeburn 6925: } elsif ($position eq 'middle') {
6926: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 6927: my @posstypes;
1.160.6.34 raeburn 6928: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 6929: @posstypes = @{$types};
6930: }
6931: unless (grep(/^default$/,@posstypes)) {
6932: push(@posstypes,'default');
6933: }
6934: my %usertypeshash;
6935: if (ref($usertypes) eq 'HASH') {
6936: %usertypeshash = %{$usertypes};
6937: }
6938: $usertypeshash{'default'} = $othertitle;
6939: foreach my $status (@posstypes) {
6940: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
6941: $numinrow,$$rowtotal,\%usertypeshash);
6942: $$rowtotal ++;
1.160.6.34 raeburn 6943: }
6944: } else {
1.160.6.40 raeburn 6945: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 6946: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 6947: );
6948: my @toggles = sort(keys(%choices));
6949: my %defaultchecked = (
6950: 'cancreate_email' => 'off',
6951: );
1.160.6.93 raeburn 6952: my $customclass = 'LC_selfcreate_email';
6953: my $classprefix = 'LC_canmodify_emailusername_';
6954: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 6955: my $display = 'none';
1.160.6.93 raeburn 6956: my $rowstyle = 'display:none';
1.160.6.40 raeburn 6957: if (grep(/^\Qemail\E$/,@selfcreate)) {
6958: $display = 'block';
1.160.6.93 raeburn 6959: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 6960: }
1.160.6.93 raeburn 6961: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
6962: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6963: \%choices,$$rowtotal,$onclick);
6964: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
6965: $rowstyle);
6966: $$rowtotal ++;
6967: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
6968: $rowstyle);
6969: $$rowtotal ++;
6970: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 6971: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 6972: my ($emailrules,$emailruleorder) =
6973: &Apache::lonnet::inst_userrules($dom,'email');
6974: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6975: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6976: if (ref($types) eq 'ARRAY') {
6977: @posstypes = @{$types};
6978: }
6979: if (@posstypes) {
6980: unless (grep(/^default$/,@posstypes)) {
6981: push(@posstypes,'default');
1.160.6.89 raeburn 6982: }
6983: if (ref($usertypes) eq 'HASH') {
6984: %usertypeshash = %{$usertypes};
6985: }
1.160.6.93 raeburn 6986: my $currassign;
6987: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
6988: $currassign = {
6989: selfassign => $domdefaults{'inststatusguest'},
6990: };
6991: @ordered = @{$domdefaults{'inststatusguest'}};
6992: } else {
6993: $currassign = { selfassign => [] };
6994: }
6995: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
6996: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
6997: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
6998: $numinrow,$othertitle,'selfassign',
6999: $rowtotal,$onclicktypes,$customclass,
7000: $rowstyle);
7001: $$rowtotal ++;
1.160.6.89 raeburn 7002: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 7003: foreach my $status (@posstypes) {
7004: my $css_class;
7005: if ($$rowtotal%2) {
7006: $css_class = 'LC_odd_row ';
7007: }
7008: $css_class .= $customclass;
7009: my $rowid = $optionsprefix.$status;
7010: my $hidden = 1;
7011: my $currstyle = 'display:none';
7012: if (grep(/^\Q$status\E$/,@ordered)) {
7013: $currstyle = $rowstyle;
7014: $hidden = 0;
7015: }
7016: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7017: $emailrules,$emailruleorder,$settings,$status,$rowid,
7018: $usertypeshash{$status},$css_class,$currstyle,$intdom);
7019: unless ($hidden) {
7020: $$rowtotal ++;
7021: }
1.160.6.89 raeburn 7022: }
7023: } else {
1.160.6.93 raeburn 7024: my $css_class;
7025: if ($$rowtotal%2) {
7026: $css_class = 'LC_odd_row ';
7027: }
7028: $css_class .= $customclass;
1.160.6.89 raeburn 7029: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 7030: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7031: $emailrules,$emailruleorder,$settings,'default','',
7032: $othertitle,$css_class,$rowstyle,$intdom);
7033: $$rowtotal ++;
1.160.6.34 raeburn 7034: }
1.160.6.35 raeburn 7035: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
7036: $numinrow = 1;
1.160.6.93 raeburn 7037: if (@posstypes) {
7038: foreach my $status (@posstypes) {
7039: my $rowid = $classprefix.$status;
7040: my $datarowstyle = 'display:none';
7041: if (grep(/^\Q$status\E$/,@ordered)) {
7042: $datarowstyle = $rowstyle;
7043: }
7044: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
7045: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7046: $infotitles,$rowid,$customclass,$datarowstyle);
7047: unless ($datarowstyle eq 'display:none') {
7048: $$rowtotal ++;
7049: }
1.160.6.34 raeburn 7050: }
1.160.6.93 raeburn 7051: } else {
7052: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
7053: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7054: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 7055: }
7056: }
7057: return $datatable;
7058: }
7059:
1.160.6.93 raeburn 7060: sub selfcreate_javascript {
7061: return <<"ENDSCRIPT";
7062:
7063: <script type="text/javascript">
7064: // <![CDATA[
7065:
7066: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
7067: var x = document.getElementsByClassName(target);
7068: var insttypes = 0;
7069: var insttypeRegExp = new RegExp(prefix);
7070: if ((x.length != undefined) && (x.length > 0)) {
7071: if (form.elements[radio].length != undefined) {
7072: for (var i=0; i<form.elements[radio].length; i++) {
7073: if (form.elements[radio][i].checked) {
7074: if (form.elements[radio][i].value == 1) {
7075: for (var j=0; j<x.length; j++) {
7076: if (x[j].id == 'undefined') {
7077: x[j].style.display = 'table-row';
7078: } else if (insttypeRegExp.test(x[j].id)) {
7079: insttypes ++;
7080: } else {
7081: x[j].style.display = 'table-row';
7082: }
7083: }
7084: } else {
7085: for (var j=0; j<x.length; j++) {
7086: x[j].style.display = 'none';
7087: }
1.160.6.40 raeburn 7088: }
1.160.6.93 raeburn 7089: break;
7090: }
7091: }
7092: if (insttypes > 0) {
7093: toggleDataRow(form,checkbox,target,altprefix);
7094: toggleDataRow(form,checkbox,target,prefix,1);
7095: }
7096: }
7097: }
7098: return;
7099: }
7100:
7101: function toggleDataRow(form,checkbox,target,prefix,docount) {
7102: if (form.elements[checkbox].length != undefined) {
7103: var count = 0;
7104: if (docount) {
7105: for (var i=0; i<form.elements[checkbox].length; i++) {
7106: if (form.elements[checkbox][i].checked) {
7107: count ++;
7108: }
7109: }
7110: }
7111: for (var i=0; i<form.elements[checkbox].length; i++) {
7112: var type = form.elements[checkbox][i].value;
7113: if (document.getElementById(prefix+type)) {
7114: if (form.elements[checkbox][i].checked) {
7115: document.getElementById(prefix+type).style.display = 'table-row';
7116: if (count % 2 == 1) {
7117: document.getElementById(prefix+type).className = target+' LC_odd_row';
7118: } else {
7119: document.getElementById(prefix+type).className = target;
7120: }
7121: count ++;
1.160.6.40 raeburn 7122: } else {
1.160.6.93 raeburn 7123: document.getElementById(prefix+type).style.display = 'none';
7124: }
7125: }
7126: }
7127: }
7128: return;
7129: }
7130:
7131: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
7132: var caller = radio+'_'+status;
7133: if (form.elements[caller].length != undefined) {
7134: for (var i=0; i<form.elements[caller].length; i++) {
7135: if (form.elements[caller][i].checked) {
7136: if (document.getElementById(altprefix+'_inst_'+status)) {
7137: var curr = form.elements[caller][i].value;
7138: if (prefix) {
7139: document.getElementById(prefix+'_'+status).style.display = 'none';
7140: }
7141: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
7142: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
7143: if (curr == 'custom') {
7144: if (prefix) {
7145: document.getElementById(prefix+'_'+status).style.display = 'inline';
7146: }
7147: } else if (curr == 'inst') {
7148: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
7149: } else if (curr == 'noninst') {
7150: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 7151: }
1.160.6.93 raeburn 7152: break;
1.160.6.40 raeburn 7153: }
1.160.6.93 raeburn 7154: }
7155: }
7156: }
7157: }
7158:
7159: // ]]>
7160: </script>
7161:
7162: ENDSCRIPT
7163: }
7164:
7165: sub noninst_users {
7166: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
7167: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
7168: my $class = 'LC_left_item';
7169: if ($css_class) {
7170: $css_class = ' class="'.$css_class.'"';
7171: }
7172: if ($rowid) {
7173: $rowid = ' id="'.$rowid.'"';
7174: }
7175: if ($rowstyle) {
7176: $rowstyle = ' style="'.$rowstyle.'"';
7177: }
7178: my ($output,$description);
7179: if ($type eq 'default') {
7180: $description = &mt('Requests for: [_1]',$typetitle);
7181: } else {
7182: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
7183: }
7184: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
7185: "<td>$description</td>\n".
7186: '<td class="'.$class.'" colspan="2">'.
7187: '<table><tr>';
7188: my %headers = &Apache::lonlocal::texthash(
7189: approve => 'Processing',
7190: email => 'E-mail',
7191: username => 'Username',
7192: );
7193: foreach my $item ('approve','email','username') {
7194: $output .= '<th>'.$headers{$item}.'</th>';
7195: }
7196: $output .= '</tr><tr>';
7197: foreach my $item ('approve','email','username') {
7198: $output .= '<td valign="top">';
7199: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
7200: if ($item eq 'approve') {
7201: %choices = &Apache::lonlocal::texthash (
7202: automatic => 'Automatically approved',
7203: approval => 'Queued for approval',
7204: );
7205: @options = ('automatic','approval');
7206: $hashref = $processing;
7207: $defoption = 'automatic';
7208: $name = 'cancreate_emailprocess_'.$type;
7209: } elsif ($item eq 'email') {
7210: %choices = &Apache::lonlocal::texthash (
7211: any => 'Any e-mail',
7212: inst => 'Institutional only',
7213: noninst => 'Non-institutional only',
7214: custom => 'Custom restrictions',
7215: );
7216: @options = ('any','inst','noninst');
7217: my $showcustom;
7218: if (ref($emailrules) eq 'HASH') {
7219: if (keys(%{$emailrules}) > 0) {
7220: push(@options,'custom');
7221: $showcustom = 'cancreate_emailrule';
7222: if (ref($settings) eq 'HASH') {
7223: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
7224: foreach my $rule (@{$settings->{'email_rule'}}) {
7225: if (exists($emailrules->{$rule})) {
7226: $hascustom ++;
7227: }
7228: }
7229: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
7230: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
7231: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
7232: if (exists($emailrules->{$rule})) {
7233: $hascustom ++;
7234: }
7235: }
7236: }
7237: }
7238: }
7239: }
7240: }
7241: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
7242: "'cancreate_emaildomain','$type'".');"';
7243: $hashref = $emailoptions;
7244: $defoption = 'any';
7245: $name = 'cancreate_emailoptions_'.$type;
7246: } elsif ($item eq 'username') {
7247: %choices = &Apache::lonlocal::texthash (
7248: all => 'Same as e-mail',
7249: first => 'Omit @domain',
7250: free => 'Free to choose',
7251: );
7252: @options = ('all','first','free');
7253: $hashref = $emailverified;
7254: $defoption = 'all';
7255: $name = 'cancreate_usernameoptions_'.$type;
7256: }
7257: foreach my $option (@options) {
7258: my $checked;
7259: if (ref($hashref) eq 'HASH') {
7260: if ($type eq '') {
7261: if (!exists($hashref->{'default'})) {
7262: if ($option eq $defoption) {
7263: $checked = ' checked="checked"';
7264: }
7265: } else {
7266: if ($hashref->{'default'} eq $option) {
7267: $checked = ' checked="checked"';
7268: }
1.160.6.40 raeburn 7269: }
7270: } else {
1.160.6.93 raeburn 7271: if (!exists($hashref->{$type})) {
7272: if ($option eq $defoption) {
7273: $checked = ' checked="checked"';
7274: }
7275: } else {
7276: if ($hashref->{$type} eq $option) {
7277: $checked = ' checked="checked"';
7278: }
1.160.6.40 raeburn 7279: }
7280: }
1.160.6.93 raeburn 7281: } elsif (($item eq 'email') && ($hascustom)) {
7282: if ($option eq 'custom') {
7283: $checked = ' checked="checked"';
7284: }
7285: } elsif ($option eq $defoption) {
7286: $checked = ' checked="checked"';
7287: }
7288: $output .= '<span class="LC_nobreak"><label>'.
7289: '<input type="radio" name="'.$name.'"'.
7290: $checked.' value="'.$option.'"'.$onclick.' />'.
7291: $choices{$option}.'</label></span><br />';
7292: if ($item eq 'email') {
7293: if ($option eq 'custom') {
7294: my $id = 'cancreate_emailrule_'.$type;
7295: my $display = 'none';
7296: if ($checked) {
7297: $display = 'inline';
7298: }
7299: my $numinrow = 2;
7300: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
7301: '<legend>'.&mt('Disallow').'</legend><table>'.
7302: &user_formats_row('email',$settings,$emailrules,
7303: $emailruleorder,$numinrow,'',$type);
7304: '</table></fieldset>';
7305: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
7306: my %text = &Apache::lonlocal::texthash (
7307: inst => 'must end:',
7308: noninst => 'cannot end:',
7309: );
7310: my $value;
7311: if (ref($emaildomain) eq 'HASH') {
7312: if (ref($emaildomain->{$type}) eq 'HASH') {
7313: $value = $emaildomain->{$type}->{$option};
7314: }
7315: }
7316: if ($value eq '') {
7317: $value = '@'.$intdom;
7318: }
7319: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
7320: my $display = 'none';
7321: if ($checked) {
7322: $display = 'inline';
7323: }
7324: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
7325: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
7326: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
7327: '</div>';
7328: }
1.160.6.40 raeburn 7329: }
7330: }
1.160.6.93 raeburn 7331: $output .= '</td>'."\n";
1.160.6.40 raeburn 7332: }
1.160.6.93 raeburn 7333: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 7334: return $output;
7335: }
7336:
1.160.6.5 raeburn 7337: sub captcha_choice {
1.160.6.93 raeburn 7338: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 7339: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
7340: $vertext,$currver);
1.160.6.5 raeburn 7341: my %lt = &captcha_phrases();
7342: $keyentry = 'hidden';
1.160.6.98 raeburn 7343: my $colspan=2;
1.160.6.5 raeburn 7344: if ($context eq 'cancreate') {
1.160.6.34 raeburn 7345: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 7346: } elsif ($context eq 'login') {
7347: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98 raeburn 7348: } elsif ($context eq 'passwords') {
7349: $rowname = &mt('"Forgot Password" CAPTCHA validation');
7350: $colspan=1;
1.160.6.5 raeburn 7351: }
7352: if (ref($settings) eq 'HASH') {
7353: if ($settings->{'captcha'}) {
7354: $checked{$settings->{'captcha'}} = ' checked="checked"';
7355: } else {
7356: $checked{'original'} = ' checked="checked"';
7357: }
7358: if ($settings->{'captcha'} eq 'recaptcha') {
7359: $pubtext = $lt{'pub'};
7360: $privtext = $lt{'priv'};
7361: $keyentry = 'text';
1.160.6.69 raeburn 7362: $vertext = $lt{'ver'};
7363: $currver = $settings->{'recaptchaversion'};
7364: if ($currver ne '2') {
7365: $currver = 1;
7366: }
1.160.6.5 raeburn 7367: }
7368: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
7369: $currpub = $settings->{'recaptchakeys'}{'public'};
7370: $currpriv = $settings->{'recaptchakeys'}{'private'};
7371: }
7372: } else {
7373: $checked{'original'} = ' checked="checked"';
7374: }
1.160.6.93 raeburn 7375: my $css_class;
7376: if ($itemcount%2) {
7377: $css_class = 'LC_odd_row';
7378: }
7379: if ($customcss) {
7380: $css_class .= " $customcss";
7381: }
7382: $css_class =~ s/^\s+//;
7383: if ($css_class) {
7384: $css_class = ' class="'.$css_class.'"';
7385: }
7386: if ($rowstyle) {
7387: $css_class .= ' style="'.$rowstyle.'"';
7388: }
1.160.6.5 raeburn 7389: my $output = '<tr'.$css_class.'>'.
1.160.6.98 raeburn 7390: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 7391: '<table><tr><td>'."\n";
7392: foreach my $option ('original','recaptcha','notused') {
7393: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
7394: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
7395: $lt{$option}.'</label></span>';
7396: unless ($option eq 'notused') {
7397: $output .= (' 'x2)."\n";
7398: }
7399: }
7400: #
7401: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
7402: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
7403: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
7404: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
7405: #
7406: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 7407: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 7408: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
7409: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
7410: $currpub.'" size="40" /></span><br />'."\n".
7411: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
7412: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 7413: $currpriv.'" size="40" /></span><br />'.
7414: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
7415: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
7416: $currver.'" size="3" /></span><br />'.
7417: '</td></tr></table>'."\n".
1.160.6.5 raeburn 7418: '</td></tr>';
7419: return $output;
7420: }
7421:
1.32 raeburn 7422: sub user_formats_row {
1.160.6.93 raeburn 7423: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 7424: my $output;
7425: my %text = (
7426: 'username' => 'new usernames',
7427: 'id' => 'IDs',
7428: );
1.160.6.122! raeburn 7429: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.160.6.93 raeburn 7430: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7431: $output = '<tr '.$css_class.'>'.
7432: '<td><span class="LC_nobreak">'.
7433: &mt("Format rules to check for $text{$type}: ").
7434: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 7435: }
1.27 raeburn 7436: my $rem;
7437: if (ref($ruleorder) eq 'ARRAY') {
7438: for (my $i=0; $i<@{$ruleorder}; $i++) {
7439: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
7440: my $rem = $i%($numinrow);
7441: if ($rem == 0) {
7442: if ($i > 0) {
7443: $output .= '</tr>';
7444: }
7445: $output .= '<tr>';
7446: }
7447: my $check = ' ';
1.39 raeburn 7448: if (ref($settings) eq 'HASH') {
7449: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
7450: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
7451: $check = ' checked="checked" ';
7452: }
1.160.6.93 raeburn 7453: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
7454: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
7455: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
7456: $check = ' checked="checked" ';
7457: }
7458: }
1.27 raeburn 7459: }
7460: }
1.160.6.93 raeburn 7461: my $name = $type.'_rule';
7462: if ($type eq 'email') {
7463: $name .= '_'.$status;
7464: }
1.27 raeburn 7465: $output .= '<td class="LC_left_item">'.
7466: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 7467: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 7468: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
7469: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
7470: }
7471: }
7472: $rem = @{$ruleorder}%($numinrow);
7473: }
1.160.6.93 raeburn 7474: my $colsleft;
7475: if ($rem) {
7476: $colsleft = $numinrow - $rem;
7477: }
1.27 raeburn 7478: if ($colsleft > 1 ) {
7479: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7480: ' </td>';
7481: } elsif ($colsleft == 1) {
7482: $output .= '<td class="LC_left_item"> </td>';
7483: }
1.160.6.122! raeburn 7484: $output .= '</tr>';
! 7485: unless (($type eq 'email') || ($type eq 'unamemap')) {
! 7486: $output .= '</table></td></tr>';
1.160.6.93 raeburn 7487: }
1.27 raeburn 7488: return $output;
7489: }
7490:
1.34 raeburn 7491: sub usercreation_types {
7492: my %lt = &Apache::lonlocal::texthash (
7493: author => 'When adding a co-author',
7494: course => 'When adding a user to a course',
1.100 raeburn 7495: requestcrs => 'When requesting a course',
1.34 raeburn 7496: any => 'Any',
7497: official => 'Institutional only ',
7498: unofficial => 'Non-institutional only',
7499: none => 'None',
7500: );
7501: return %lt;
1.48 raeburn 7502: }
1.34 raeburn 7503:
1.160.6.34 raeburn 7504: sub selfcreation_types {
7505: my %lt = &Apache::lonlocal::texthash (
7506: selfcreate => 'User creates own account',
7507: any => 'Any',
7508: official => 'Institutional only ',
7509: unofficial => 'Non-institutional only',
7510: email => 'E-mail address',
7511: login => 'Institutional Login',
7512: sso => 'SSO',
7513: );
7514: }
7515:
1.28 raeburn 7516: sub authtype_names {
7517: my %lt = &Apache::lonlocal::texthash(
7518: int => 'Internal',
7519: krb4 => 'Kerberos 4',
7520: krb5 => 'Kerberos 5',
7521: loc => 'Local',
7522: );
7523: return %lt;
7524: }
7525:
7526: sub context_names {
7527: my %context_title = &Apache::lonlocal::texthash(
7528: author => 'Creating users when an Author',
7529: course => 'Creating users when in a course',
7530: domain => 'Creating users when a Domain Coordinator',
7531: );
7532: return %context_title;
7533: }
7534:
1.33 raeburn 7535: sub print_usermodification {
7536: my ($position,$dom,$settings,$rowtotal) = @_;
7537: my $numinrow = 4;
7538: my ($context,$datatable,$rowcount);
7539: if ($position eq 'top') {
7540: $rowcount = 0;
7541: $context = 'author';
7542: foreach my $role ('ca','aa') {
7543: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7544: $numinrow,$rowcount);
7545: $$rowtotal ++;
7546: $rowcount ++;
7547: }
1.160.6.37 raeburn 7548: } elsif ($position eq 'bottom') {
1.33 raeburn 7549: $context = 'course';
7550: $rowcount = 0;
7551: foreach my $role ('st','ep','ta','in','cr') {
7552: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7553: $numinrow,$rowcount);
7554: $$rowtotal ++;
7555: $rowcount ++;
7556: }
7557: }
7558: return $datatable;
7559: }
7560:
1.43 raeburn 7561: sub print_defaults {
1.160.6.40 raeburn 7562: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 7563: my $rownum = 0;
1.160.6.80 raeburn 7564: my ($datatable,$css_class,$titles);
7565: unless ($position eq 'bottom') {
7566: $titles = &defaults_titles($dom);
7567: }
1.160.6.40 raeburn 7568: if ($position eq 'top') {
7569: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
7570: 'datelocale_def','portal_def');
7571: my %defaults;
7572: if (ref($settings) eq 'HASH') {
7573: %defaults = %{$settings};
1.43 raeburn 7574: } else {
1.160.6.40 raeburn 7575: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7576: foreach my $item (@items) {
7577: $defaults{$item} = $domdefaults{$item};
7578: }
1.43 raeburn 7579: }
1.160.6.40 raeburn 7580: foreach my $item (@items) {
7581: if ($rownum%2) {
7582: $css_class = '';
7583: } else {
7584: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 7585: }
1.160.6.40 raeburn 7586: $datatable .= '<tr'.$css_class.'>'.
7587: '<td><span class="LC_nobreak">'.$titles->{$item}.
7588: '</span></td><td class="LC_right_item" colspan="3">';
7589: if ($item eq 'auth_def') {
7590: my @authtypes = ('internal','krb4','krb5','localauth');
7591: my %shortauth = (
7592: internal => 'int',
7593: krb4 => 'krb4',
7594: krb5 => 'krb5',
7595: localauth => 'loc'
7596: );
7597: my %authnames = &authtype_names();
7598: foreach my $auth (@authtypes) {
7599: my $checked = ' ';
7600: if ($defaults{$item} eq $auth) {
7601: $checked = ' checked="checked" ';
7602: }
7603: $datatable .= '<label><input type="radio" name="'.$item.
7604: '" value="'.$auth.'"'.$checked.'/>'.
7605: $authnames{$shortauth{$auth}}.'</label> ';
7606: }
7607: } elsif ($item eq 'timezone_def') {
7608: my $includeempty = 1;
7609: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
7610: } elsif ($item eq 'datelocale_def') {
1.160.6.98 raeburn 7611: my $includeempty = 1;
7612: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
7613: } elsif ($item eq 'lang_def') {
7614: my $includeempty = 1;
7615: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.80 raeburn 7616: } else {
1.160.6.98 raeburn 7617: my $size;
7618: if ($item eq 'portal_def') {
7619: $size = ' size="25"';
7620: }
1.160.6.80 raeburn 7621: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.98 raeburn 7622: $defaults{$item}.'"'.$size.' />';
1.160.6.80 raeburn 7623: }
7624: $datatable .= '</td></tr>';
7625: $rownum ++;
7626: }
1.160.6.122! raeburn 7627: } elsif ($position eq 'middle') {
1.160.6.80 raeburn 7628: my %defaults;
1.160.6.40 raeburn 7629: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 7630: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 7631: my $maxnum = @{$settings->{'inststatusorder'}};
7632: for (my $i=0; $i<$maxnum; $i++) {
7633: $css_class = $rownum%2?' class="LC_odd_row"':'';
7634: my $item = $settings->{'inststatusorder'}->[$i];
7635: my $title = $settings->{'inststatustypes'}->{$item};
7636: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
7637: $datatable .= '<tr'.$css_class.'>'.
7638: '<td><span class="LC_nobreak">'.
7639: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
7640: for (my $k=0; $k<=$maxnum; $k++) {
7641: my $vpos = $k+1;
7642: my $selstr;
7643: if ($k == $i) {
7644: $selstr = ' selected="selected" ';
7645: }
7646: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7647: }
7648: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
7649: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
7650: &mt('delete').'</span></td>'.
1.160.6.112 raeburn 7651: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.160.6.40 raeburn 7652: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 7653: '</span></td></tr>';
1.160.6.40 raeburn 7654: }
7655: $css_class = $rownum%2?' class="LC_odd_row"':'';
7656: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
7657: $datatable .= '<tr '.$css_class.'>'.
7658: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
7659: for (my $k=0; $k<=$maxnum; $k++) {
7660: my $vpos = $k+1;
7661: my $selstr;
7662: if ($k == $maxnum) {
7663: $selstr = ' selected="selected" ';
7664: }
7665: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7666: }
7667: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 7668: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 7669: ' '.&mt('(new)').
7670: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.112 raeburn 7671: &mt('Name displayed').':'.
1.160.6.40 raeburn 7672: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
7673: '</tr>'."\n";
7674: $rownum ++;
1.141 raeburn 7675: }
1.43 raeburn 7676: }
1.160.6.122! raeburn 7677: } else {
! 7678: my ($unamemaprules,$ruleorder) =
! 7679: &Apache::lonnet::inst_userrules($dom,'unamemap');
! 7680: $css_class = $rownum%2?' class="LC_odd_row"':'';
! 7681: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
! 7682: my $numinrow = 2;
! 7683: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
! 7684: &user_formats_row('unamemap',$settings,$unamemaprules,
! 7685: $ruleorder,$numinrow).
! 7686: '</table></td></tr>';
! 7687: }
! 7688: if ($datatable eq '') {
! 7689: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
! 7690: &mt('No rules set for domain in customized localenroll.pm').
! 7691: '</td></tr>';
! 7692: }
1.43 raeburn 7693: }
7694: $$rowtotal += $rownum;
7695: return $datatable;
7696: }
7697:
1.160.6.5 raeburn 7698: sub get_languages_hash {
7699: my %langchoices;
7700: foreach my $id (&Apache::loncommon::languageids()) {
7701: my $code = &Apache::loncommon::supportedlanguagecode($id);
7702: if ($code ne '') {
7703: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
7704: }
7705: }
7706: return %langchoices;
7707: }
7708:
1.43 raeburn 7709: sub defaults_titles {
1.141 raeburn 7710: my ($dom) = @_;
1.43 raeburn 7711: my %titles = &Apache::lonlocal::texthash (
7712: 'auth_def' => 'Default authentication type',
7713: 'auth_arg_def' => 'Default authentication argument',
7714: 'lang_def' => 'Default language',
1.54 raeburn 7715: 'timezone_def' => 'Default timezone',
1.68 raeburn 7716: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 7717: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 7718: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
7719: 'intauth_check' => 'Check bcrypt cost if authenticated',
7720: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 7721: );
1.141 raeburn 7722: if ($dom) {
7723: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
7724: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
7725: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
7726: $protocol = 'http' if ($protocol ne 'https');
7727: if ($uint_dom) {
7728: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
7729: $uint_dom);
7730: }
7731: }
1.43 raeburn 7732: return (\%titles);
7733: }
7734:
1.160.6.97 raeburn 7735: sub print_scantron {
7736: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
7737: if ($position eq 'top') {
7738: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
7739: } else {
7740: return &print_scantronconfig($dom,$settings,\$rowtotal);
7741: }
7742: }
7743:
7744: sub scantron_javascript {
7745: return <<"ENDSCRIPT";
7746:
7747: <script type="text/javascript">
7748: // <![CDATA[
7749:
7750: function toggleScantron(form) {
7751: var csvfieldset = new Array();
7752: if (document.getElementById('scantroncsv_cols')) {
7753: csvfieldset.push(document.getElementById('scantroncsv_cols'));
7754: }
7755: if (document.getElementById('scantroncsv_options')) {
7756: csvfieldset.push(document.getElementById('scantroncsv_options'));
7757: }
7758: if (csvfieldset.length) {
7759: if (document.getElementById('scantronconfcsv')) {
7760: var scantroncsv = document.getElementById('scantronconfcsv');
7761: if (scantroncsv.checked) {
7762: for (var i=0; i<csvfieldset.length; i++) {
7763: csvfieldset[i].style.display = 'block';
7764: }
7765: } else {
7766: for (var i=0; i<csvfieldset.length; i++) {
7767: csvfieldset[i].style.display = 'none';
7768: }
7769: var csvselects = document.getElementsByClassName('scantronconfig_csv');
7770: if (csvselects.length) {
7771: for (var j=0; j<csvselects.length; j++) {
7772: csvselects[j].selectedIndex = 0;
7773: }
7774: }
7775: }
7776: }
7777: }
7778: return;
7779: }
7780: // ]]>
7781: </script>
7782:
7783: ENDSCRIPT
7784:
7785: }
7786:
1.46 raeburn 7787: sub print_scantronformat {
7788: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
7789: my $itemcount = 1;
1.60 raeburn 7790: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
7791: %confhash);
1.46 raeburn 7792: my $switchserver = &check_switchserver($dom,$confname);
7793: my %lt = &Apache::lonlocal::texthash (
1.95 www 7794: default => 'Default bubblesheet format file error',
7795: custom => 'Custom bubblesheet format file error',
1.46 raeburn 7796: );
7797: my %scantronfiles = (
7798: default => 'default.tab',
7799: custom => 'custom.tab',
7800: );
7801: foreach my $key (keys(%scantronfiles)) {
7802: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
7803: .$scantronfiles{$key};
7804: }
7805: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
7806: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
7807: if (!$switchserver) {
7808: my $servadm = $r->dir_config('lonAdmEMail');
7809: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
7810: if ($configuserok eq 'ok') {
7811: if ($author_ok eq 'ok') {
7812: my %legacyfile = (
1.160.6.97 raeburn 7813: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
7814: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 7815: );
7816: my %md5chk;
7817: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7818: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
7819: chomp($md5chk{$type});
1.46 raeburn 7820: }
7821: if ($md5chk{'default'} ne $md5chk{'custom'}) {
7822: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 7823: ($scantronurls{$type},my $error) =
1.46 raeburn 7824: &legacy_scantronformat($r,$dom,$confname,
7825: $type,$legacyfile{$type},
7826: $scantronurls{$type},
7827: $scantronfiles{$type});
1.60 raeburn 7828: if ($error ne '') {
7829: $error{$type} = $error;
7830: }
7831: }
7832: if (keys(%error) == 0) {
7833: $is_custom = 1;
1.160.6.97 raeburn 7834: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 7835: $scantronurls{'custom'};
1.160.6.97 raeburn 7836: my $putresult =
1.60 raeburn 7837: &Apache::lonnet::put_dom('configuration',
7838: \%confhash,$dom);
7839: if ($putresult ne 'ok') {
1.160.6.97 raeburn 7840: $error{'custom'} =
1.60 raeburn 7841: '<span class="LC_error">'.
7842: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7843: }
1.46 raeburn 7844: }
7845: } else {
1.60 raeburn 7846: ($scantronurls{'default'},my $error) =
1.46 raeburn 7847: &legacy_scantronformat($r,$dom,$confname,
7848: 'default',$legacyfile{'default'},
7849: $scantronurls{'default'},
7850: $scantronfiles{'default'});
1.60 raeburn 7851: if ($error eq '') {
7852: $confhash{'scantron'}{'scantronformat'} = '';
7853: my $putresult =
7854: &Apache::lonnet::put_dom('configuration',
7855: \%confhash,$dom);
7856: if ($putresult ne 'ok') {
7857: $error{'default'} =
7858: '<span class="LC_error">'.
7859: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7860: }
7861: } else {
7862: $error{'default'} = $error;
7863: }
1.46 raeburn 7864: }
7865: }
7866: }
7867: } else {
1.95 www 7868: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 7869: }
7870: }
7871: if (ref($settings) eq 'HASH') {
7872: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
7873: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
7874: if ((!@info) || ($info[0] eq 'no_such_dir')) {
7875: $scantronurl = '';
7876: } else {
7877: $scantronurl = $settings->{'scantronformat'};
7878: }
7879: $is_custom = 1;
7880: } else {
7881: $scantronurl = $scantronurls{'default'};
7882: }
7883: } else {
1.60 raeburn 7884: if ($is_custom) {
7885: $scantronurl = $scantronurls{'custom'};
7886: } else {
7887: $scantronurl = $scantronurls{'default'};
7888: }
1.46 raeburn 7889: }
7890: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7891: $datatable .= '<tr'.$css_class.'>';
7892: if (!$is_custom) {
1.65 raeburn 7893: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
7894: '<span class="LC_nobreak">';
1.46 raeburn 7895: if ($scantronurl) {
1.160.6.21 raeburn 7896: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
7897: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 7898: } else {
7899: $datatable = &mt('File unavailable for display');
7900: }
1.65 raeburn 7901: $datatable .= '</span></td>';
1.60 raeburn 7902: if (keys(%error) == 0) {
7903: $datatable .= '<td valign="bottom">';
7904: if (!$switchserver) {
7905: $datatable .= &mt('Upload:').'<br />';
7906: }
7907: } else {
7908: my $errorstr;
7909: foreach my $key (sort(keys(%error))) {
7910: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7911: }
7912: $datatable .= '<td>'.$errorstr;
7913: }
1.46 raeburn 7914: } else {
7915: if (keys(%error) > 0) {
7916: my $errorstr;
7917: foreach my $key (sort(keys(%error))) {
7918: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7919: }
1.60 raeburn 7920: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 7921: } elsif ($scantronurl) {
1.160.6.26 raeburn 7922: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 7923: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 7924: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 7925: $link.
7926: '<label><input type="checkbox" name="scantronformat_del"'.
7927: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 7928: '<td><span class="LC_nobreak"> '.
7929: &mt('Replace:').'</span><br />';
1.46 raeburn 7930: }
7931: }
7932: if (keys(%error) == 0) {
7933: if ($switchserver) {
7934: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
7935: } else {
1.65 raeburn 7936: $datatable .='<span class="LC_nobreak"> '.
7937: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 7938: }
7939: }
7940: $datatable .= '</td></tr>';
7941: $$rowtotal ++;
7942: return $datatable;
7943: }
7944:
7945: sub legacy_scantronformat {
7946: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
7947: my ($url,$error);
7948: my @statinfo = &Apache::lonnet::stat_file($newurl);
7949: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
7950: (my $result,$url) =
7951: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
7952: '','',$newfile);
7953: if ($result ne 'ok') {
1.130 raeburn 7954: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 7955: }
7956: }
7957: return ($url,$error);
7958: }
1.43 raeburn 7959:
1.160.6.97 raeburn 7960: sub print_scantronconfig {
7961: my ($dom,$settings,$rowtotal) = @_;
7962: my $itemcount = 2;
7963: my $is_checked = ' checked="checked"';
7964: my %optionson = (
7965: hdr => ' checked="checked"',
7966: pad => ' checked="checked"',
7967: rem => ' checked="checked"',
7968: );
7969: my %optionsoff = (
7970: hdr => '',
7971: pad => '',
7972: rem => '',
7973: );
7974: my $currcsvsty = 'none';
7975: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
7976: my @fields = &scantroncsv_fields();
7977: my %titles = &scantronconfig_titles();
7978: if (ref($settings) eq 'HASH') {
7979: if (ref($settings->{config}) eq 'HASH') {
7980: if ($settings->{config}->{dat}) {
7981: $checked{'dat'} = $is_checked;
7982: }
7983: if (ref($settings->{config}->{csv}) eq 'HASH') {
7984: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
7985: %csvfields = %{$settings->{config}->{csv}->{fields}};
7986: if (keys(%csvfields) > 0) {
7987: $checked{'csv'} = $is_checked;
7988: $currcsvsty = 'block';
7989: }
7990: }
7991: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
7992: %csvoptions = %{$settings->{config}->{csv}->{options}};
7993: foreach my $option (keys(%optionson)) {
7994: unless ($csvoptions{$option}) {
7995: $optionsoff{$option} = $optionson{$option};
7996: $optionson{$option} = '';
7997: }
7998: }
7999: }
8000: }
8001: } else {
8002: $checked{'dat'} = $is_checked;
8003: }
8004: } else {
8005: $checked{'dat'} = $is_checked;
8006: }
8007: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
8008: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8009: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
8010: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
8011: foreach my $item ('dat','csv') {
8012: my $id;
8013: if ($item eq 'csv') {
8014: $id = 'id="scantronconfcsv" ';
8015: }
8016: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
8017: $titles{$item}.'</label>'.(' 'x3);
8018: if ($item eq 'csv') {
8019: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
8020: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
8021: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
8022: foreach my $col (@fields) {
8023: my $selnone;
8024: if ($csvfields{$col} eq '') {
8025: $selnone = ' selected="selected"';
8026: }
8027: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
8028: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
8029: '<option value=""'.$selnone.'></option>';
8030: for (my $i=0; $i<20; $i++) {
8031: my $shown = $i+1;
8032: my $sel;
8033: unless ($selnone) {
8034: if (exists($csvfields{$col})) {
8035: if ($csvfields{$col} == $i) {
8036: $sel = ' selected="selected"';
8037: }
8038: }
8039: }
8040: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
8041: }
8042: $datatable .= '</select></td></tr>';
8043: }
8044: $datatable .= '</table></fieldset>'.
8045: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
8046: '<legend>'.&mt('CSV Options').'</legend>';
8047: foreach my $option ('hdr','pad','rem') {
8048: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
8049: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
8050: &mt('Yes').'</label>'.(' 'x2)."\n".
8051: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
8052: }
8053: $datatable .= '</fieldset>';
8054: $itemcount ++;
8055: }
8056: }
8057: $datatable .= '</td></tr>';
8058: $$rowtotal ++;
8059: return $datatable;
8060: }
8061:
8062: sub scantronconfig_titles {
8063: return &Apache::lonlocal::texthash(
8064: dat => 'Standard format (.dat)',
8065: csv => 'Comma separated values (.csv)',
8066: hdr => 'Remove first line in file (contains column titles)',
8067: pad => 'Prepend 0s to PaperID',
8068: rem => 'Remove leading spaces (except Question Response columns)',
8069: CODE => 'CODE',
8070: ID => 'Student ID',
8071: PaperID => 'Paper ID',
8072: FirstName => 'First Name',
8073: LastName => 'Last Name',
8074: FirstQuestion => 'First Question Response',
8075: Section => 'Section',
8076: );
8077: }
8078:
8079: sub scantroncsv_fields {
8080: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
8081: }
8082:
1.49 raeburn 8083: sub print_coursecategories {
1.57 raeburn 8084: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
8085: my $datatable;
8086: if ($position eq 'top') {
1.160.6.42 raeburn 8087: my (%checked);
8088: my @catitems = ('unauth','auth');
8089: my @cattypes = ('std','domonly','codesrch','none');
8090: $checked{'unauth'} = 'std';
8091: $checked{'auth'} = 'std';
8092: if (ref($settings) eq 'HASH') {
8093: foreach my $type (@cattypes) {
8094: if ($type eq $settings->{'unauth'}) {
8095: $checked{'unauth'} = $type;
8096: }
8097: if ($type eq $settings->{'auth'}) {
8098: $checked{'auth'} = $type;
8099: }
8100: }
8101: }
8102: my %lt = &Apache::lonlocal::texthash (
8103: unauth => 'Catalog type for unauthenticated users',
8104: auth => 'Catalog type for authenticated users',
8105: none => 'No catalog',
8106: std => 'Standard catalog',
8107: domonly => 'Domain-only catalog',
8108: codesrch => "Code search form",
8109: );
8110: my $itemcount = 0;
8111: foreach my $item (@catitems) {
8112: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8113: $datatable .= '<tr '.$css_class.'>'.
8114: '<td>'.$lt{$item}.'</td>'.
8115: '<td class="LC_right_item"><span class="LC_nobreak">';
8116: foreach my $type (@cattypes) {
8117: my $ischecked;
8118: if ($checked{$item} eq $type) {
8119: $ischecked=' checked="checked"';
8120: }
8121: $datatable .= '<label>'.
8122: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
8123: ' />'.$lt{$type}.'</label> ';
8124: }
1.160.6.87 raeburn 8125: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 8126: $itemcount ++;
8127: }
8128: $$rowtotal += $itemcount;
8129: } elsif ($position eq 'middle') {
1.57 raeburn 8130: my $toggle_cats_crs = ' ';
8131: my $toggle_cats_dom = ' checked="checked" ';
8132: my $can_cat_crs = ' ';
8133: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 8134: my $toggle_catscomm_comm = ' ';
8135: my $toggle_catscomm_dom = ' checked="checked" ';
8136: my $can_catcomm_comm = ' ';
8137: my $can_catcomm_dom = ' checked="checked" ';
8138:
1.57 raeburn 8139: if (ref($settings) eq 'HASH') {
8140: if ($settings->{'togglecats'} eq 'crs') {
8141: $toggle_cats_crs = $toggle_cats_dom;
8142: $toggle_cats_dom = ' ';
8143: }
8144: if ($settings->{'categorize'} eq 'crs') {
8145: $can_cat_crs = $can_cat_dom;
8146: $can_cat_dom = ' ';
8147: }
1.120 raeburn 8148: if ($settings->{'togglecatscomm'} eq 'comm') {
8149: $toggle_catscomm_comm = $toggle_catscomm_dom;
8150: $toggle_catscomm_dom = ' ';
8151: }
8152: if ($settings->{'categorizecomm'} eq 'comm') {
8153: $can_catcomm_comm = $can_catcomm_dom;
8154: $can_catcomm_dom = ' ';
8155: }
1.57 raeburn 8156: }
8157: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 8158: togglecats => 'Show/Hide a course in catalog',
8159: togglecatscomm => 'Show/Hide a community in catalog',
8160: categorize => 'Assign a category to a course',
8161: categorizecomm => 'Assign a category to a community',
1.57 raeburn 8162: );
8163: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 8164: dom => 'Set in Domain',
8165: crs => 'Set in Course',
8166: comm => 'Set in Community',
1.57 raeburn 8167: );
8168: $datatable = '<tr class="LC_odd_row">'.
8169: '<td>'.$title{'togglecats'}.'</td>'.
8170: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8171: '<input type="radio" name="togglecats"'.
8172: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8173: '<label><input type="radio" name="togglecats"'.
8174: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
8175: '</tr><tr>'.
8176: '<td>'.$title{'categorize'}.'</td>'.
8177: '<td class="LC_right_item"><span class="LC_nobreak">'.
8178: '<label><input type="radio" name="categorize"'.
8179: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8180: '<label><input type="radio" name="categorize"'.
8181: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 8182: '</tr><tr class="LC_odd_row">'.
8183: '<td>'.$title{'togglecatscomm'}.'</td>'.
8184: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8185: '<input type="radio" name="togglecatscomm"'.
8186: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8187: '<label><input type="radio" name="togglecatscomm"'.
8188: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
8189: '</tr><tr>'.
8190: '<td>'.$title{'categorizecomm'}.'</td>'.
8191: '<td class="LC_right_item"><span class="LC_nobreak">'.
8192: '<label><input type="radio" name="categorizecomm"'.
8193: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8194: '<label><input type="radio" name="categorizecomm"'.
8195: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 8196: '</tr>';
1.120 raeburn 8197: $$rowtotal += 4;
1.57 raeburn 8198: } else {
8199: my $css_class;
8200: my $itemcount = 1;
8201: my $cathash;
8202: if (ref($settings) eq 'HASH') {
8203: $cathash = $settings->{'cats'};
8204: }
8205: if (ref($cathash) eq 'HASH') {
8206: my (@cats,@trails,%allitems,%idx,@jsarray);
8207: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
8208: \%allitems,\%idx,\@jsarray);
8209: my $maxdepth = scalar(@cats);
8210: my $colattrib = '';
8211: if ($maxdepth > 2) {
8212: $colattrib = ' colspan="2" ';
8213: }
8214: my @path;
8215: if (@cats > 0) {
8216: if (ref($cats[0]) eq 'ARRAY') {
8217: my $numtop = @{$cats[0]};
8218: my $maxnum = $numtop;
1.120 raeburn 8219: my %default_names = (
8220: instcode => &mt('Official courses'),
8221: communities => &mt('Communities'),
8222: );
8223:
8224: if ((!grep(/^instcode$/,@{$cats[0]})) ||
8225: ($cathash->{'instcode::0'} eq '') ||
8226: (!grep(/^communities$/,@{$cats[0]})) ||
8227: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 8228: $maxnum ++;
8229: }
8230: my $lastidx;
8231: for (my $i=0; $i<$numtop; $i++) {
8232: my $parent = $cats[0][$i];
8233: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8234: my $item = &escape($parent).'::0';
8235: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
8236: $lastidx = $idx{$item};
8237: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8238: .'<select name="'.$item.'"'.$chgstr.'>';
8239: for (my $k=0; $k<=$maxnum; $k++) {
8240: my $vpos = $k+1;
8241: my $selstr;
8242: if ($k == $i) {
8243: $selstr = ' selected="selected" ';
8244: }
8245: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8246: }
1.160.6.29 raeburn 8247: $datatable .= '</select></span></td><td>';
1.120 raeburn 8248: if ($parent eq 'instcode' || $parent eq 'communities') {
8249: $datatable .= '<span class="LC_nobreak">'
8250: .$default_names{$parent}.'</span>';
8251: if ($parent eq 'instcode') {
8252: $datatable .= '<br /><span class="LC_nobreak">('
8253: .&mt('with institutional codes')
8254: .')</span></td><td'.$colattrib.'>';
8255: } else {
8256: $datatable .= '<table><tr><td>';
8257: }
8258: $datatable .= '<span class="LC_nobreak">'
8259: .'<label><input type="radio" name="'
8260: .$parent.'" value="1" checked="checked" />'
8261: .&mt('Display').'</label>';
8262: if ($parent eq 'instcode') {
8263: $datatable .= ' ';
8264: } else {
8265: $datatable .= '</span></td></tr><tr><td>'
8266: .'<span class="LC_nobreak">';
8267: }
8268: $datatable .= '<label><input type="radio" name="'
8269: .$parent.'" value="0" />'
8270: .&mt('Do not display').'</label></span>';
8271: if ($parent eq 'communities') {
8272: $datatable .= '</td></tr></table>';
8273: }
8274: $datatable .= '</td>';
1.57 raeburn 8275: } else {
8276: $datatable .= $parent
1.160.6.29 raeburn 8277: .' <span class="LC_nobreak"><label>'
8278: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 8279: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
8280: }
8281: my $depth = 1;
8282: push(@path,$parent);
8283: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
8284: pop(@path);
8285: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8286: $itemcount ++;
8287: }
1.48 raeburn 8288: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 8289: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
8290: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 8291: for (my $k=0; $k<=$maxnum; $k++) {
8292: my $vpos = $k+1;
8293: my $selstr;
1.57 raeburn 8294: if ($k == $numtop) {
1.48 raeburn 8295: $selstr = ' selected="selected" ';
8296: }
8297: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8298: }
1.59 bisitz 8299: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 8300: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
8301: .'</tr>'."\n";
1.48 raeburn 8302: $itemcount ++;
1.120 raeburn 8303: foreach my $default ('instcode','communities') {
8304: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
8305: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8306: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
8307: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
8308: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
8309: for (my $k=0; $k<=$maxnum; $k++) {
8310: my $vpos = $k+1;
8311: my $selstr;
8312: if ($k == $maxnum) {
8313: $selstr = ' selected="selected" ';
8314: }
8315: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 8316: }
1.120 raeburn 8317: $datatable .= '</select></span></td>'.
8318: '<td><span class="LC_nobreak">'.
8319: $default_names{$default}.'</span>';
8320: if ($default eq 'instcode') {
8321: $datatable .= '<br /><span class="LC_nobreak">('
8322: .&mt('with institutional codes').')</span>';
8323: }
8324: $datatable .= '</td>'
8325: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
8326: .&mt('Display').'</label> '
8327: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
8328: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 8329: }
8330: }
8331: }
1.57 raeburn 8332: } else {
8333: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 8334: }
8335: } else {
1.160.6.87 raeburn 8336: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 8337: .&initialize_categories($itemcount);
1.48 raeburn 8338: }
1.57 raeburn 8339: $$rowtotal += $itemcount;
1.48 raeburn 8340: }
8341: return $datatable;
8342: }
8343:
1.69 raeburn 8344: sub print_serverstatuses {
8345: my ($dom,$settings,$rowtotal) = @_;
8346: my $datatable;
8347: my @pages = &serverstatus_pages();
8348: my (%namedaccess,%machineaccess);
8349: foreach my $type (@pages) {
8350: $namedaccess{$type} = '';
8351: $machineaccess{$type}= '';
8352: }
8353: if (ref($settings) eq 'HASH') {
8354: foreach my $type (@pages) {
8355: if (exists($settings->{$type})) {
8356: if (ref($settings->{$type}) eq 'HASH') {
8357: foreach my $key (keys(%{$settings->{$type}})) {
8358: if ($key eq 'namedusers') {
8359: $namedaccess{$type} = $settings->{$type}->{$key};
8360: } elsif ($key eq 'machines') {
8361: $machineaccess{$type} = $settings->{$type}->{$key};
8362: }
8363: }
8364: }
8365: }
8366: }
8367: }
1.81 raeburn 8368: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8369: my $rownum = 0;
8370: my $css_class;
8371: foreach my $type (@pages) {
8372: $rownum ++;
8373: $css_class = $rownum%2?' class="LC_odd_row"':'';
8374: $datatable .= '<tr'.$css_class.'>'.
8375: '<td><span class="LC_nobreak">'.
8376: $titles->{$type}.'</span></td>'.
8377: '<td class="LC_left_item">'.
8378: '<input type="text" name="'.$type.'_namedusers" '.
8379: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
8380: '<td class="LC_right_item">'.
8381: '<span class="LC_nobreak">'.
8382: '<input type="text" name="'.$type.'_machines" '.
8383: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 8384: '</span></td></tr>'."\n";
1.69 raeburn 8385: }
8386: $$rowtotal += $rownum;
8387: return $datatable;
8388: }
8389:
8390: sub serverstatus_pages {
8391: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 8392: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 8393: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 8394: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 8395: }
8396:
1.160.6.40 raeburn 8397: sub defaults_javascript {
8398: my ($settings) = @_;
1.160.6.98 raeburn 8399: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 8400: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8401: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
8402: if ($maxnum eq '') {
8403: $maxnum = 0;
8404: }
8405: $maxnum ++;
1.160.6.51 raeburn 8406: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 8407: return <<"ENDSCRIPT";
8408: <script type="text/javascript">
8409: // <![CDATA[
8410: function reorderTypes(form,caller) {
8411: var changedVal;
8412: $jstext
8413: var newpos = 'addinststatus_pos';
8414: var current = new Array;
8415: var maxh = $maxnum;
8416: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8417: var oldVal;
8418: if (caller == newpos) {
8419: changedVal = newitemVal;
8420: } else {
8421: var curritem = 'inststatus_pos_'+caller;
8422: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
8423: current[newitemVal] = newpos;
8424: }
8425: for (var i=0; i<inststatuses.length; i++) {
8426: if (inststatuses[i] != caller) {
8427: var elementName = 'inststatus_pos_'+inststatuses[i];
8428: if (form.elements[elementName]) {
8429: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8430: current[currVal] = elementName;
8431: }
8432: }
8433: }
8434: for (var j=0; j<maxh; j++) {
8435: if (current[j] == undefined) {
8436: oldVal = j;
8437: }
8438: }
8439: if (oldVal < changedVal) {
8440: for (var k=oldVal+1; k<=changedVal ; k++) {
8441: var elementName = current[k];
8442: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8443: }
8444: } else {
8445: for (var k=changedVal; k<oldVal; k++) {
8446: var elementName = current[k];
8447: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8448: }
8449: }
8450: return;
8451: }
8452:
8453: // ]]>
8454: </script>
8455:
8456: ENDSCRIPT
8457: }
8458: }
8459:
1.160.6.98 raeburn 8460: sub passwords_javascript {
1.160.6.99 raeburn 8461: my %intalert = &Apache::lonlocal::texthash (
8462: 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.',
8463: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
8464: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
8465: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
8466: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
8467: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
8468: );
8469: &js_escape(\%intalert);
8470: my $defmin = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 8471: my $intauthjs = <<"ENDSCRIPT";
8472:
8473: function warnIntAuth(field) {
8474: if (field.name == 'intauth_check') {
8475: if (field.value == '2') {
1.160.6.99 raeburn 8476: alert('$intalert{authcheck}');
1.160.6.98 raeburn 8477: }
8478: }
8479: if (field.name == 'intauth_cost') {
8480: field.value.replace(/\s/g,'');
8481: if (field.value != '') {
8482: var regexdigit=/^\\d+\$/;
8483: if (!regexdigit.test(field.value)) {
1.160.6.99 raeburn 8484: alert('$intalert{authcost}');
8485: }
8486: }
8487: }
8488: return;
8489: }
8490:
8491: function warnIntPass(field) {
8492: field.value.replace(/^\s+/,'');
8493: field.value.replace(/\s+\$/,'');
8494: var regexdigit=/^\\d+\$/;
8495: if (field.name == 'passwords_min') {
8496: if (field.value == '') {
8497: alert('$intalert{passmin}');
8498: field.value = '$defmin';
8499: } else {
8500: if (!regexdigit.test(field.value)) {
8501: alert('$intalert{passmin}');
8502: field.value = '$defmin';
8503: }
8504: var minval = parseInt(field.value,10);
8505: if (minval < $defmin) {
8506: alert('$intalert{passmin}');
8507: field.value = '$defmin';
8508: }
8509: }
8510: } else {
8511: if (field.value == '0') {
8512: field.value = '';
8513: }
8514: if (field.value != '') {
8515: if (field.name == 'passwords_expire') {
8516: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
8517: if (!regexpposnum.test(field.value)) {
8518: alert('$intalert{passexp}');
8519: field.value = '';
8520: } else {
8521: var expval = parseFloat(field.value);
8522: if (expval == 0) {
8523: alert('$intalert{passexp}');
8524: field.value = '';
8525: }
8526: }
8527: } else {
8528: if (!regexdigit.test(field.value)) {
8529: if (field.name == 'passwords_max') {
8530: alert('$intalert{passmax}');
8531: } else {
8532: if (field.name == 'passwords_numsaved') {
8533: alert('$intalert{passnum}');
8534: }
8535: }
1.160.6.104 raeburn 8536: field.value = '';
1.160.6.99 raeburn 8537: }
1.160.6.98 raeburn 8538: }
8539: }
8540: }
8541: return;
8542: }
8543:
8544: ENDSCRIPT
8545: return &Apache::lonhtmlcommon::scripttag($intauthjs);
8546: }
8547:
1.49 raeburn 8548: sub coursecategories_javascript {
8549: my ($settings) = @_;
1.57 raeburn 8550: my ($output,$jstext,$cathash);
1.49 raeburn 8551: if (ref($settings) eq 'HASH') {
1.57 raeburn 8552: $cathash = $settings->{'cats'};
8553: }
8554: if (ref($cathash) eq 'HASH') {
1.49 raeburn 8555: my (@cats,@jsarray,%idx);
1.57 raeburn 8556: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 8557: if (@jsarray > 0) {
8558: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
8559: for (my $i=0; $i<@jsarray; $i++) {
8560: if (ref($jsarray[$i]) eq 'ARRAY') {
8561: my $catstr = join('","',@{$jsarray[$i]});
8562: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
8563: }
8564: }
8565: }
8566: } else {
8567: $jstext = ' var categories = Array(1);'."\n".
8568: ' categories[0] = Array("instcode_pos");'."\n";
8569: }
1.160.6.42 raeburn 8570: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
8571: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 8572: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
8573: &js_escape(\$instcode_reserved);
8574: &js_escape(\$communities_reserved);
8575: &js_escape(\$choose_again);
1.49 raeburn 8576: $output = <<"ENDSCRIPT";
8577: <script type="text/javascript">
1.109 raeburn 8578: // <![CDATA[
1.49 raeburn 8579: function reorderCats(form,parent,item,idx) {
8580: var changedVal;
8581: $jstext
8582: var newpos = 'addcategory_pos';
8583: if (parent == '') {
8584: var has_instcode = 0;
8585: var maxtop = categories[idx].length;
8586: for (var j=0; j<maxtop; j++) {
8587: if (categories[idx][j] == 'instcode::0') {
8588: has_instcode == 1;
8589: }
8590: }
8591: if (has_instcode == 0) {
8592: categories[idx][maxtop] = 'instcode_pos';
8593: }
8594: } else {
8595: newpos += '_'+parent;
8596: }
8597: var maxh = 1 + categories[idx].length;
8598: var current = new Array;
8599: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8600: if (item == newpos) {
8601: changedVal = newitemVal;
8602: } else {
8603: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
8604: current[newitemVal] = newpos;
8605: }
8606: for (var i=0; i<categories[idx].length; i++) {
8607: var elementName = categories[idx][i];
8608: if (elementName != item) {
8609: if (form.elements[elementName]) {
8610: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8611: current[currVal] = elementName;
8612: }
8613: }
8614: }
8615: var oldVal;
8616: for (var j=0; j<maxh; j++) {
8617: if (current[j] == undefined) {
8618: oldVal = j;
8619: }
8620: }
8621: if (oldVal < changedVal) {
8622: for (var k=oldVal+1; k<=changedVal ; k++) {
8623: var elementName = current[k];
8624: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8625: }
8626: } else {
8627: for (var k=changedVal; k<oldVal; k++) {
8628: var elementName = current[k];
8629: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8630: }
8631: }
8632: return;
8633: }
1.120 raeburn 8634:
8635: function categoryCheck(form) {
8636: if (form.elements['addcategory_name'].value == 'instcode') {
8637: alert('$instcode_reserved\\n$choose_again');
8638: return false;
8639: }
8640: if (form.elements['addcategory_name'].value == 'communities') {
8641: alert('$communities_reserved\\n$choose_again');
8642: return false;
8643: }
8644: return true;
8645: }
8646:
1.109 raeburn 8647: // ]]>
1.49 raeburn 8648: </script>
8649:
8650: ENDSCRIPT
8651: return $output;
8652: }
8653:
1.48 raeburn 8654: sub initialize_categories {
8655: my ($itemcount) = @_;
1.120 raeburn 8656: my ($datatable,$css_class,$chgstr);
1.160.6.111 raeburn 8657: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 8658: instcode => 'Official courses (with institutional codes)',
8659: communities => 'Communities',
8660: );
8661: my $select0 = ' selected="selected"';
8662: my $select1 = '';
8663: foreach my $default ('instcode','communities') {
8664: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 8665: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 8666: if ($default eq 'communities') {
8667: $select1 = $select0;
8668: $select0 = '';
8669: }
8670: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8671: .'<select name="'.$default.'_pos">'
8672: .'<option value="0"'.$select0.'>1</option>'
8673: .'<option value="1"'.$select1.'>2</option>'
8674: .'<option value="2">3</option></select> '
8675: .$default_names{$default}
8676: .'</span></td><td><span class="LC_nobreak">'
8677: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
8678: .&mt('Display').'</label> <label>'
8679: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 8680: .'</label></span></td></tr>';
1.120 raeburn 8681: $itemcount ++;
8682: }
1.48 raeburn 8683: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 8684: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 8685: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 8686: .'<select name="addcategory_pos"'.$chgstr.'>'
8687: .'<option value="0">1</option>'
8688: .'<option value="1">2</option>'
8689: .'<option value="2" selected="selected">3</option></select> '
1.160.6.103 raeburn 8690: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
1.160.6.87 raeburn 8691: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
8692: .'</td></tr>';
1.48 raeburn 8693: return $datatable;
8694: }
8695:
8696: sub build_category_rows {
1.49 raeburn 8697: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
8698: my ($text,$name,$item,$chgstr);
1.48 raeburn 8699: if (ref($cats) eq 'ARRAY') {
8700: my $maxdepth = scalar(@{$cats});
8701: if (ref($cats->[$depth]) eq 'HASH') {
8702: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8703: my $numchildren = @{$cats->[$depth]{$parent}};
8704: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 8705: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 8706: my ($idxnum,$parent_name,$parent_item);
8707: my $higher = $depth - 1;
8708: if ($higher == 0) {
8709: $parent_name = &escape($parent).'::'.$higher;
8710: } else {
8711: if (ref($path) eq 'ARRAY') {
8712: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8713: }
8714: }
8715: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 8716: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 8717: if ($j < $numchildren) {
1.48 raeburn 8718: $name = $cats->[$depth]{$parent}[$j];
8719: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 8720: $idxnum = $idx->{$item};
8721: } else {
8722: $name = $parent_name;
8723: $item = $parent_item;
1.48 raeburn 8724: }
1.49 raeburn 8725: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8726: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 8727: for (my $i=0; $i<=$numchildren; $i++) {
8728: my $vpos = $i+1;
8729: my $selstr;
8730: if ($j == $i) {
8731: $selstr = ' selected="selected" ';
8732: }
8733: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8734: }
8735: $text .= '</select> ';
8736: if ($j < $numchildren) {
8737: my $deeper = $depth+1;
8738: $text .= $name.' '
8739: .'<label><input type="checkbox" name="deletecategory" value="'
8740: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8741: if(ref($path) eq 'ARRAY') {
8742: push(@{$path},$name);
1.49 raeburn 8743: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 8744: pop(@{$path});
8745: }
8746: } else {
1.160.6.87 raeburn 8747: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 8748: if ($j == $numchildren) {
8749: $text .= $name;
8750: } else {
8751: $text .= $item;
8752: }
8753: $text .= '" value="" />';
8754: }
8755: $text .= '</td></tr>';
8756: }
8757: $text .= '</table></td>';
8758: } else {
8759: my $higher = $depth-1;
8760: if ($higher == 0) {
8761: $name = &escape($parent).'::'.$higher;
8762: } else {
8763: if (ref($path) eq 'ARRAY') {
8764: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8765: }
8766: }
8767: my $colspan;
8768: if ($parent ne 'instcode') {
8769: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 8770: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 8771: }
8772: }
8773: }
8774: }
8775: return $text;
8776: }
8777:
1.33 raeburn 8778: sub modifiable_userdata_row {
1.160.6.93 raeburn 8779: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
8780: $rowid,$customcss,$rowstyle) = @_;
1.160.6.35 raeburn 8781: my ($role,$rolename,$statustype);
8782: $role = $item;
1.160.6.34 raeburn 8783: if ($context eq 'cancreate') {
1.160.6.93 raeburn 8784: if ($item =~ /^(emailusername)_(.+)$/) {
8785: $role = $1;
8786: $statustype = $2;
1.160.6.35 raeburn 8787: if (ref($usertypes) eq 'HASH') {
8788: if ($usertypes->{$statustype}) {
8789: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
8790: } else {
8791: $rolename = &mt('Data provided by user');
8792: }
8793: }
1.160.6.34 raeburn 8794: }
8795: } elsif ($context eq 'selfcreate') {
1.63 raeburn 8796: if (ref($usertypes) eq 'HASH') {
8797: $rolename = $usertypes->{$role};
8798: } else {
8799: $rolename = $role;
8800: }
1.33 raeburn 8801: } else {
1.63 raeburn 8802: if ($role eq 'cr') {
8803: $rolename = &mt('Custom role');
8804: } else {
8805: $rolename = &Apache::lonnet::plaintext($role);
8806: }
1.33 raeburn 8807: }
1.160.6.34 raeburn 8808: my (@fields,%fieldtitles);
8809: if (ref($fieldsref) eq 'ARRAY') {
8810: @fields = @{$fieldsref};
8811: } else {
8812: @fields = ('lastname','firstname','middlename','generation',
8813: 'permanentemail','id');
8814: }
8815: if ((ref($titlesref) eq 'HASH')) {
8816: %fieldtitles = %{$titlesref};
8817: } else {
8818: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8819: }
1.33 raeburn 8820: my $output;
1.160.6.93 raeburn 8821: my $css_class;
8822: if ($rowcount%2) {
8823: $css_class = 'LC_odd_row';
8824: }
8825: if ($customcss) {
8826: $css_class .= " $customcss";
8827: }
8828: $css_class =~ s/^\s+//;
8829: if ($css_class) {
8830: $css_class = ' class="'.$css_class.'"';
8831: }
8832: if ($rowstyle) {
8833: $css_class .= ' style="'.$rowstyle.'"';
8834: }
8835: if ($rowid) {
8836: $rowid = ' id="'.$rowid.'"';
8837: }
8838:
8839: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 8840: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
8841: '<td class="LC_left_item" colspan="2"><table>';
8842: my $rem;
8843: my %checks;
8844: if (ref($settings) eq 'HASH') {
8845: if (ref($settings->{$context}) eq 'HASH') {
8846: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 8847: my $hashref = $settings->{$context}->{$role};
8848: if ($role eq 'emailusername') {
8849: if ($statustype) {
8850: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
8851: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 8852: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 8853: foreach my $field (@fields) {
8854: if ($hashref->{$field}) {
8855: $checks{$field} = $hashref->{$field};
8856: }
8857: }
8858: }
8859: }
8860: }
8861: } else {
8862: if (ref($hashref) eq 'HASH') {
8863: foreach my $field (@fields) {
8864: if ($hashref->{$field}) {
8865: $checks{$field} = ' checked="checked" ';
8866: }
8867: }
1.33 raeburn 8868: }
8869: }
8870: }
8871: }
8872: }
1.160.6.93 raeburn 8873:
8874: my $total = scalar(@fields);
8875: for (my $i=0; $i<$total; $i++) {
8876: $rem = $i%($numinrow);
1.33 raeburn 8877: if ($rem == 0) {
8878: if ($i > 0) {
8879: $output .= '</tr>';
8880: }
8881: $output .= '<tr>';
8882: }
8883: my $check = ' ';
1.160.6.35 raeburn 8884: unless ($role eq 'emailusername') {
8885: if (exists($checks{$fields[$i]})) {
1.160.6.98 raeburn 8886: $check = $checks{$fields[$i]};
1.160.6.35 raeburn 8887: } else {
8888: if ($role eq 'st') {
8889: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 8890: $check = ' checked="checked" ';
1.160.6.35 raeburn 8891: }
1.33 raeburn 8892: }
8893: }
8894: }
8895: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 8896: '<span class="LC_nobreak">';
8897: if ($role eq 'emailusername') {
8898: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
8899: $checks{$fields[$i]} = 'omit';
8900: }
8901: foreach my $option ('required','optional','omit') {
8902: my $checked='';
8903: if ($checks{$fields[$i]} eq $option) {
8904: $checked='checked="checked" ';
8905: }
8906: $output .= '<label>'.
8907: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
8908: &mt($option).'</label>'.(' ' x2);
8909: }
8910: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
8911: } else {
8912: $output .= '<label>'.
8913: '<input type="checkbox" name="canmodify_'.$role.'" '.
8914: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
8915: '</label>';
8916: }
8917: $output .= '</span></td>';
1.33 raeburn 8918: }
1.160.6.93 raeburn 8919: $rem = $total%$numinrow;
8920: my $colsleft;
8921: if ($rem) {
8922: $colsleft = $numinrow - $rem;
8923: }
8924: if ($colsleft > 1) {
1.33 raeburn 8925: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8926: ' </td>';
8927: } elsif ($colsleft == 1) {
8928: $output .= '<td class="LC_left_item"> </td>';
8929: }
8930: $output .= '</tr></table></td></tr>';
8931: return $output;
8932: }
1.28 raeburn 8933:
1.93 raeburn 8934: sub insttypes_row {
1.160.6.93 raeburn 8935: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
8936: $customcss,$rowstyle) = @_;
1.93 raeburn 8937: my %lt = &Apache::lonlocal::texthash (
8938: cansearch => 'Users allowed to search',
8939: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 8940: lockablenames => 'User preference to lock name',
1.160.6.93 raeburn 8941: selfassign => 'Self-reportable affiliations',
1.160.6.101 raeburn 8942: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 8943: );
8944: my $showdom;
8945: if ($context eq 'cansearch') {
8946: $showdom = ' ('.$dom.')';
8947: }
1.160.6.5 raeburn 8948: my $class = 'LC_left_item';
8949: if ($context eq 'statustocreate') {
8950: $class = 'LC_right_item';
8951: }
1.160.6.93 raeburn 8952: my $css_class;
8953: if ($$rowtotal%2) {
8954: $css_class = 'LC_odd_row';
8955: }
8956: if ($customcss) {
8957: $css_class .= ' '.$customcss;
8958: }
8959: $css_class =~ s/^\s+//;
8960: if ($css_class) {
8961: $css_class = ' class="'.$css_class.'"';
8962: }
8963: if ($rowstyle) {
8964: $css_class .= ' style="'.$rowstyle.'"';
8965: }
8966: if ($onclick) {
8967: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 8968: }
8969: my $output = '<tr'.$css_class.'>'.
8970: '<td>'.$lt{$context}.$showdom.
8971: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 8972: my $rem;
8973: if (ref($types) eq 'ARRAY') {
8974: for (my $i=0; $i<@{$types}; $i++) {
8975: if (defined($usertypes->{$types->[$i]})) {
8976: my $rem = $i%($numinrow);
8977: if ($rem == 0) {
8978: if ($i > 0) {
8979: $output .= '</tr>';
8980: }
8981: $output .= '<tr>';
1.23 raeburn 8982: }
1.26 raeburn 8983: my $check = ' ';
1.99 raeburn 8984: if (ref($settings) eq 'HASH') {
8985: if (ref($settings->{$context}) eq 'ARRAY') {
8986: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
8987: $check = ' checked="checked" ';
8988: }
1.160.6.101 raeburn 8989: } elsif (ref($settings->{$context}) eq 'HASH') {
8990: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
8991: $check = ' checked="checked" ';
8992: }
1.99 raeburn 8993: } elsif ($context eq 'statustocreate') {
1.26 raeburn 8994: $check = ' checked="checked" ';
8995: }
1.23 raeburn 8996: }
1.26 raeburn 8997: $output .= '<td class="LC_left_item">'.
8998: '<span class="LC_nobreak"><label>'.
1.93 raeburn 8999: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 9000: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
1.26 raeburn 9001: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 9002: }
9003: }
1.26 raeburn 9004: $rem = @{$types}%($numinrow);
1.23 raeburn 9005: }
9006: my $colsleft = $numinrow - $rem;
1.160.6.101 raeburn 9007: if ($context eq 'overrides') {
9008: if ($colsleft > 1) {
9009: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9010: } else {
9011: $output .= '<td class="LC_left_item">';
9012: }
9013: $output .= ' ';
1.23 raeburn 9014: } else {
1.160.6.101 raeburn 9015: if ($rem == 0) {
9016: $output .= '<tr>';
9017: }
9018: if ($colsleft > 1) {
9019: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9020: } else {
9021: $output .= '<td class="LC_left_item">';
9022: }
9023: my $defcheck = ' ';
9024: if (ref($settings) eq 'HASH') {
9025: if (ref($settings->{$context}) eq 'ARRAY') {
9026: if (grep(/^default$/,@{$settings->{$context}})) {
9027: $defcheck = ' checked="checked" ';
9028: }
9029: } elsif ($context eq 'statustocreate') {
1.99 raeburn 9030: $defcheck = ' checked="checked" ';
9031: }
1.26 raeburn 9032: }
1.160.6.101 raeburn 9033: $output .= '<span class="LC_nobreak"><label>'.
9034: '<input type="checkbox" name="'.$context.'" '.
9035: 'value="default"'.$defcheck.$onclick.' />'.
9036: $othertitle.'</label></span>';
1.23 raeburn 9037: }
1.160.6.101 raeburn 9038: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 9039: return $output;
1.23 raeburn 9040: }
9041:
9042: sub sorted_searchtitles {
9043: my %searchtitles = &Apache::lonlocal::texthash(
9044: 'uname' => 'username',
9045: 'lastname' => 'last name',
9046: 'lastfirst' => 'last name, first name',
9047: );
9048: my @titleorder = ('uname','lastname','lastfirst');
9049: return (\%searchtitles,\@titleorder);
9050: }
9051:
1.25 raeburn 9052: sub sorted_searchtypes {
9053: my %srchtypes_desc = (
9054: exact => 'is exact match',
9055: contains => 'contains ..',
9056: begins => 'begins with ..',
9057: );
9058: my @srchtypeorder = ('exact','begins','contains');
9059: return (\%srchtypes_desc,\@srchtypeorder);
9060: }
9061:
1.3 raeburn 9062: sub usertype_update_row {
9063: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
9064: my $datatable;
9065: my $numinrow = 4;
9066: foreach my $type (@{$types}) {
9067: if (defined($usertypes->{$type})) {
9068: $$rownums ++;
9069: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
9070: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
9071: '</td><td class="LC_left_item"><table>';
9072: for (my $i=0; $i<@{$fields}; $i++) {
9073: my $rem = $i%($numinrow);
9074: if ($rem == 0) {
9075: if ($i > 0) {
9076: $datatable .= '</tr>';
9077: }
9078: $datatable .= '<tr>';
9079: }
9080: my $check = ' ';
1.39 raeburn 9081: if (ref($settings) eq 'HASH') {
9082: if (ref($settings->{'fields'}) eq 'HASH') {
9083: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
9084: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
9085: $check = ' checked="checked" ';
9086: }
1.3 raeburn 9087: }
9088: }
9089: }
9090:
9091: if ($i == @{$fields}-1) {
9092: my $colsleft = $numinrow - $rem;
9093: if ($colsleft > 1) {
9094: $datatable .= '<td colspan="'.$colsleft.'">';
9095: } else {
9096: $datatable .= '<td>';
9097: }
9098: } else {
9099: $datatable .= '<td>';
9100: }
1.8 raeburn 9101: $datatable .= '<span class="LC_nobreak"><label>'.
9102: '<input type="checkbox" name="updateable_'.$type.
9103: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
9104: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 9105: }
9106: $datatable .= '</tr></table></td></tr>';
9107: }
9108: }
9109: return $datatable;
1.1 raeburn 9110: }
9111:
9112: sub modify_login {
1.160.6.24 raeburn 9113: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 9114: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.160.6.113 raeburn 9115: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
9116: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso);
1.160.6.5 raeburn 9117: %title = ( coursecatalog => 'Display course catalog',
9118: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 9119: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 9120: newuser => 'Link for visitors to create a user account',
1.160.6.113 raeburn 9121: loginheader => 'Log-in box header',
9122: saml => 'Dual SSO and non-SSO login');
1.160.6.5 raeburn 9123: @offon = ('off','on');
1.112 raeburn 9124: if (ref($domconfig{login}) eq 'HASH') {
9125: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
9126: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
9127: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
9128: }
9129: }
1.160.6.113 raeburn 9130: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
9131: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
9132: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
9133: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
9134: $saml{$lonhost} = 1;
9135: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
9136: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
9137: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
9138: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
9139: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
9140: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
9141: }
9142: }
9143: }
1.112 raeburn 9144: }
1.9 raeburn 9145: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
9146: \%domconfig,\%loginhash);
1.160.6.14 raeburn 9147: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9148: foreach my $item (@toggles) {
9149: $loginhash{login}{$item} = $env{'form.'.$item};
9150: }
1.41 raeburn 9151: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 9152: if (ref($colchanges{'login'}) eq 'HASH') {
9153: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
9154: \%loginhash);
9155: }
1.110 raeburn 9156:
1.149 raeburn 9157: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 9158: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 9159: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 9160: if (keys(%servers) > 1) {
9161: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 9162: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
9163: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
9164: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
9165: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
9166: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
9167: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9168: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9169: $changes{'loginvia'}{$lonhost} = 1;
9170: } else {
9171: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
9172: $changes{'loginvia'}{$lonhost} = 1;
9173: }
9174: } else {
9175: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9176: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9177: $changes{'loginvia'}{$lonhost} = 1;
9178: }
9179: }
9180: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
9181: foreach my $item (@loginvia_attribs) {
9182: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
9183: }
9184: } else {
9185: foreach my $item (@loginvia_attribs) {
9186: my $new = $env{'form.'.$lonhost.'_'.$item};
9187: if (($item eq 'serverpath') && ($new eq 'custom')) {
9188: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
9189: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9190: $new = '/';
9191: }
9192: }
9193: if (($item eq 'custompath') &&
9194: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9195: $new = '';
9196: }
9197: if ($new ne $curr_loginvia{$lonhost}{$item}) {
9198: $changes{'loginvia'}{$lonhost} = 1;
9199: }
9200: if ($item eq 'exempt') {
1.160.6.56 raeburn 9201: $new = &check_exempt_addresses($new);
1.128 raeburn 9202: }
9203: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9204: }
9205: }
1.112 raeburn 9206: } else {
1.128 raeburn 9207: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9208: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 9209: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 9210: foreach my $item (@loginvia_attribs) {
9211: my $new = $env{'form.'.$lonhost.'_'.$item};
9212: if (($item eq 'serverpath') && ($new eq 'custom')) {
9213: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9214: $new = '/';
9215: }
9216: }
9217: if (($item eq 'custompath') &&
9218: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9219: $new = '';
9220: }
9221: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9222: }
1.110 raeburn 9223: }
9224: }
9225: }
9226: }
1.119 raeburn 9227:
1.160.6.5 raeburn 9228: my $servadm = $r->dir_config('lonAdmEMail');
9229: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
9230: if (ref($domconfig{'login'}) eq 'HASH') {
9231: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
9232: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
9233: if ($lang eq 'nolang') {
9234: push(@currlangs,$lang);
9235: } elsif (defined($langchoices{$lang})) {
9236: push(@currlangs,$lang);
9237: } else {
9238: next;
9239: }
9240: }
9241: }
9242: }
9243: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
9244: if (@currlangs > 0) {
9245: foreach my $lang (@currlangs) {
9246: if (grep(/^\Q$lang\E$/,@delurls)) {
9247: $changes{'helpurl'}{$lang} = 1;
9248: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
9249: $changes{'helpurl'}{$lang} = 1;
9250: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
9251: push(@newlangs,$lang);
9252: } else {
9253: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9254: }
9255: }
9256: }
9257: unless (grep(/^nolang$/,@currlangs)) {
9258: if ($env{'form.loginhelpurl_nolang.filename'}) {
9259: $changes{'helpurl'}{'nolang'} = 1;
9260: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
9261: push(@newlangs,'nolang');
9262: }
9263: }
9264: if ($env{'form.loginhelpurl_add_lang'}) {
9265: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
9266: ($env{'form.loginhelpurl_add_file.filename'})) {
9267: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
9268: $addedfile = $env{'form.loginhelpurl_add_lang'};
9269: }
9270: }
9271: if ((@newlangs > 0) || ($addedfile)) {
9272: my $error;
9273: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9274: if ($configuserok eq 'ok') {
9275: if ($switchserver) {
9276: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
9277: } elsif ($author_ok eq 'ok') {
9278: my @allnew = @newlangs;
9279: if ($addedfile ne '') {
9280: push(@allnew,$addedfile);
9281: }
9282: foreach my $lang (@allnew) {
9283: my $formelem = 'loginhelpurl_'.$lang;
9284: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
9285: $formelem = 'loginhelpurl_add_file';
9286: }
9287: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9288: "help/$lang",'','',$newfile{$lang});
9289: if ($result eq 'ok') {
9290: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
9291: $changes{'helpurl'}{$lang} = 1;
9292: } else {
9293: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
9294: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9295: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
9296: (!grep(/^\Q$lang\E$/,@delurls))) {
9297: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9298: }
9299: }
9300: }
9301: } else {
9302: $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);
9303: }
9304: } else {
9305: $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);
9306: }
9307: if ($error) {
9308: &Apache::lonnet::logthis($error);
9309: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9310: }
9311: }
1.160.6.56 raeburn 9312:
9313: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
9314: if (ref($domconfig{'login'}) eq 'HASH') {
9315: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
9316: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
9317: if ($domservers{$lonhost}) {
9318: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9319: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 9320: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 9321: }
9322: }
9323: }
9324: }
9325: }
9326: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
9327: foreach my $lonhost (sort(keys(%domservers))) {
9328: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9329: $changes{'headtag'}{$lonhost} = 1;
9330: } else {
9331: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
9332: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
9333: }
9334: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
9335: push(@newhosts,$lonhost);
9336: } elsif ($currheadtagurls{$lonhost}) {
9337: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
9338: if ($currexempt{$lonhost}) {
9339: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
9340: $changes{'headtag'}{$lonhost} = 1;
9341: }
9342: } elsif ($possexempt{$lonhost}) {
9343: $changes{'headtag'}{$lonhost} = 1;
9344: }
9345: if ($possexempt{$lonhost}) {
9346: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9347: }
9348: }
9349: }
9350: }
9351: if (@newhosts) {
9352: my $error;
9353: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9354: if ($configuserok eq 'ok') {
9355: if ($switchserver) {
9356: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
9357: } elsif ($author_ok eq 'ok') {
9358: foreach my $lonhost (@newhosts) {
9359: my $formelem = 'loginheadtag_'.$lonhost;
9360: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9361: "login/headtag/$lonhost",'','',
9362: $env{'form.loginheadtag_'.$lonhost.'.filename'});
9363: if ($result eq 'ok') {
1.160.6.113 raeburn 9364: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
9365: $changes{'headtag'}{$lonhost} = 1;
9366: if ($possexempt{$lonhost}) {
9367: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9368: }
9369: } else {
9370: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
9371: $newheadtagurls{$lonhost},$result);
9372: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9373: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
9374: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
9375: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
9376: }
9377: }
9378: }
9379: } else {
9380: $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);
9381: }
9382: } else {
9383: $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);
9384: }
9385: if ($error) {
9386: &Apache::lonnet::logthis($error);
9387: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9388: }
9389: }
9390: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
9391: my @newsamlimgs;
9392: foreach my $lonhost (keys(%domservers)) {
9393: if ($env{'form.saml_'.$lonhost}) {
9394: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
9395: push(@newsamlimgs,$lonhost);
9396: }
9397: foreach my $item ('text','alt','url','title','notsso') {
9398: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
9399: }
9400: if ($saml{$lonhost}) {
9401: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
9402: #FIXME Need to obsolete published image
9403: delete($currsaml{$lonhost}{'img'});
9404: $changes{'saml'}{$lonhost} = 1;
9405: }
9406: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
9407: $changes{'saml'}{$lonhost} = 1;
9408: }
9409: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
9410: $changes{'saml'}{$lonhost} = 1;
9411: }
9412: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
9413: $changes{'saml'}{$lonhost} = 1;
9414: }
9415: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
9416: $changes{'saml'}{$lonhost} = 1;
9417: }
9418: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
9419: $changes{'saml'}{$lonhost} = 1;
9420: }
9421: } else {
9422: $changes{'saml'}{$lonhost} = 1;
9423: }
9424: foreach my $item ('text','alt','url','title','notsso') {
9425: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
9426: }
9427: } else {
9428: if ($saml{$lonhost}) {
9429: $changes{'saml'}{$lonhost} = 1;
9430: delete($currsaml{$lonhost});
9431: }
9432: }
9433: }
9434: foreach my $posshost (keys(%currsaml)) {
9435: unless (exists($domservers{$posshost})) {
9436: delete($currsaml{$posshost});
9437: }
9438: }
9439: %{$loginhash{'login'}{'saml'}} = %currsaml;
9440: if (@newsamlimgs) {
9441: my $error;
9442: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9443: if ($configuserok eq 'ok') {
9444: if ($switchserver) {
9445: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
9446: } elsif ($author_ok eq 'ok') {
9447: foreach my $lonhost (@newsamlimgs) {
9448: my $formelem = 'saml_img_'.$lonhost;
9449: my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9450: "login/saml/$lonhost",'','',
9451: $env{'form.saml_img_'.$lonhost.'.filename'});
9452: if ($result eq 'ok') {
9453: $currsaml{$lonhost}{'img'} = $imgurl;
9454: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
9455: $changes{'saml'}{$lonhost} = 1;
1.160.6.56 raeburn 9456: } else {
1.160.6.113 raeburn 9457: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
9458: $lonhost,$result);
1.160.6.56 raeburn 9459: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9460: }
9461: }
9462: } else {
1.160.6.113 raeburn 9463: $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 9464: }
9465: } else {
1.160.6.113 raeburn 9466: $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 9467: }
9468: if ($error) {
9469: &Apache::lonnet::logthis($error);
9470: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9471: }
9472: }
1.160.6.5 raeburn 9473: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
9474:
9475: my $defaulthelpfile = '/adm/loginproblems.html';
9476: my $defaulttext = &mt('Default in use');
9477:
1.1 raeburn 9478: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
9479: $dom);
9480: if ($putresult eq 'ok') {
1.160.6.14 raeburn 9481: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9482: my %defaultchecked = (
9483: 'coursecatalog' => 'on',
1.160.6.14 raeburn 9484: 'helpdesk' => 'on',
1.42 raeburn 9485: 'adminmail' => 'off',
1.43 raeburn 9486: 'newuser' => 'off',
1.42 raeburn 9487: );
1.55 raeburn 9488: if (ref($domconfig{'login'}) eq 'HASH') {
9489: foreach my $item (@toggles) {
9490: if ($defaultchecked{$item} eq 'on') {
9491: if (($domconfig{'login'}{$item} eq '0') &&
9492: ($env{'form.'.$item} eq '1')) {
9493: $changes{$item} = 1;
9494: } elsif (($domconfig{'login'}{$item} eq '' ||
9495: $domconfig{'login'}{$item} eq '1') &&
9496: ($env{'form.'.$item} eq '0')) {
9497: $changes{$item} = 1;
9498: }
9499: } elsif ($defaultchecked{$item} eq 'off') {
9500: if (($domconfig{'login'}{$item} eq '1') &&
9501: ($env{'form.'.$item} eq '0')) {
9502: $changes{$item} = 1;
9503: } elsif (($domconfig{'login'}{$item} eq '' ||
9504: $domconfig{'login'}{$item} eq '0') &&
9505: ($env{'form.'.$item} eq '1')) {
9506: $changes{$item} = 1;
9507: }
1.42 raeburn 9508: }
9509: }
1.41 raeburn 9510: }
1.6 raeburn 9511: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 9512: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.113 raeburn 9513: if (exists($changes{'saml'})) {
9514: my $hostid_in_use;
9515: my @hosts = &Apache::lonnet::current_machine_ids();
9516: if (@hosts > 1) {
9517: foreach my $hostid (@hosts) {
9518: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
9519: $hostid_in_use = $hostid;
9520: last;
9521: }
9522: }
9523: } else {
9524: $hostid_in_use = $r->dir_config('lonHostID');
9525: }
9526: if (($hostid_in_use) &&
9527: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
9528: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
9529: }
9530: if (ref($lastactref) eq 'HASH') {
9531: if (ref($changes{'saml'}) eq 'HASH') {
9532: my %updates;
9533: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
9534: $lastactref->{'samllanding'} = \%updates;
9535: }
9536: }
9537: }
1.160.6.27 raeburn 9538: if (ref($lastactref) eq 'HASH') {
9539: $lastactref->{'domainconfig'} = 1;
9540: }
1.1 raeburn 9541: $resulttext = &mt('Changes made:').'<ul>';
9542: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 9543: if ($item eq 'loginvia') {
1.112 raeburn 9544: if (ref($changes{$item}) eq 'HASH') {
9545: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
9546: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 9547: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
9548: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
9549: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
9550: $protocol = 'http' if ($protocol ne 'https');
9551: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
9552:
9553: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
9554: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
9555: } else {
9556: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
9557: }
9558: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
9559: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
9560: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
9561: }
9562: $resulttext .= '</li>';
9563: } else {
9564: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
9565: }
1.112 raeburn 9566: } else {
1.128 raeburn 9567: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 9568: }
9569: }
1.128 raeburn 9570: $resulttext .= '</ul></li>';
1.112 raeburn 9571: }
1.160.6.5 raeburn 9572: } elsif ($item eq 'helpurl') {
9573: if (ref($changes{$item}) eq 'HASH') {
9574: foreach my $lang (sort(keys(%{$changes{$item}}))) {
9575: if (grep(/^\Q$lang\E$/,@delurls)) {
9576: my ($chg,$link);
9577: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
9578: if ($lang eq 'nolang') {
9579: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
9580: } else {
9581: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
9582: }
9583: $resulttext .= '<li>'.$chg.'</li>';
9584: } else {
9585: my $chg;
9586: if ($lang eq 'nolang') {
9587: $chg = &mt('custom log-in help file for no preferred language');
9588: } else {
9589: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
9590: }
9591: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
9592: $loginhash{'login'}{'helpurl'}{$lang}.
9593: '?inhibitmenu=yes',$chg,600,500).
9594: '</li>';
9595: }
9596: }
9597: }
1.160.6.56 raeburn 9598: } elsif ($item eq 'headtag') {
9599: if (ref($changes{$item}) eq 'HASH') {
9600: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9601: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9602: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
9603: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9604: $resulttext .= '<li><a href="'.
9605: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
9606: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
9607: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
9608: if ($possexempt{$lonhost}) {
9609: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
9610: } else {
9611: $resulttext .= &mt('included for any client IP');
9612: }
9613: $resulttext .= '</li>';
9614: }
9615: }
9616: }
1.160.6.113 raeburn 9617: } elsif ($item eq 'saml') {
9618: if (ref($changes{$item}) eq 'HASH') {
9619: my %notlt = (
9620: text => 'Text for log-in by SSO',
9621: img => 'SSO button image',
9622: alt => 'Alt text for button image',
9623: url => 'SSO URL',
9624: title => 'Tooltip for SSO link',
9625: notsso => 'Text for non-SSO log-in',
9626: );
9627: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9628: if (ref($currsaml{$lonhost}) eq 'HASH') {
9629: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
9630: '<ul>';
9631: foreach my $key ('text','img','alt','url','title','notsso') {
9632: if ($currsaml{$lonhost}{$key} eq '') {
9633: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
9634: } else {
9635: my $value = "'$currsaml{$lonhost}{$key}'";
9636: if ($key eq 'img') {
9637: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
9638: }
9639: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
9640: $value).'</li>';
9641: }
9642: }
9643: $resulttext .= '</ul></li>';
9644: } else {
9645: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
9646: }
9647: }
9648: }
1.160.6.5 raeburn 9649: } elsif ($item eq 'captcha') {
9650: if (ref($loginhash{'login'}) eq 'HASH') {
9651: my $chgtxt;
9652: if ($loginhash{'login'}{$item} eq 'notused') {
9653: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
9654: } else {
9655: my %captchas = &captcha_phrases();
9656: if ($captchas{$loginhash{'login'}{$item}}) {
9657: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
9658: } else {
9659: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
9660: }
9661: }
9662: $resulttext .= '<li>'.$chgtxt.'</li>';
9663: }
9664: } elsif ($item eq 'recaptchakeys') {
9665: if (ref($loginhash{'login'}) eq 'HASH') {
9666: my ($privkey,$pubkey);
9667: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
9668: $pubkey = $loginhash{'login'}{$item}{'public'};
9669: $privkey = $loginhash{'login'}{$item}{'private'};
9670: }
9671: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
9672: if (!$pubkey) {
9673: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
9674: } else {
9675: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9676: }
9677: if (!$privkey) {
9678: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
9679: } else {
1.160.6.53 raeburn 9680: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 9681: }
9682: $chgtxt .= '</ul>';
9683: $resulttext .= '<li>'.$chgtxt.'</li>';
9684: }
1.160.6.69 raeburn 9685: } elsif ($item eq 'recaptchaversion') {
9686: if (ref($loginhash{'login'}) eq 'HASH') {
9687: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
9688: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
9689: '</li>';
9690: }
9691: }
1.41 raeburn 9692: } else {
9693: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
9694: }
1.1 raeburn 9695: }
1.6 raeburn 9696: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 9697: } else {
9698: $resulttext = &mt('No changes made to log-in page settings');
9699: }
9700: } else {
1.11 albertel 9701: $resulttext = '<span class="LC_error">'.
9702: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9703: }
1.6 raeburn 9704: if ($errors) {
1.9 raeburn 9705: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 9706: $errors.'</ul>';
9707: }
9708: return $resulttext;
9709: }
9710:
1.160.6.56 raeburn 9711: sub check_exempt_addresses {
9712: my ($iplist) = @_;
9713: $iplist =~ s/^\s+//;
9714: $iplist =~ s/\s+$//;
9715: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
9716: my (@okips,$new);
9717: foreach my $ip (@poss_ips) {
9718: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
9719: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
9720: push(@okips,$ip);
9721: }
9722: }
9723: }
9724: if (@okips > 0) {
9725: $new = join(',',@okips);
9726: } else {
9727: $new = '';
9728: }
9729: return $new;
9730: }
9731:
1.6 raeburn 9732: sub color_font_choices {
9733: my %choices =
9734: &Apache::lonlocal::texthash (
9735: img => "Header",
9736: bgs => "Background colors",
9737: links => "Link colors",
1.55 raeburn 9738: images => "Images",
1.6 raeburn 9739: font => "Font color",
1.160.6.22 raeburn 9740: fontmenu => "Font menu",
1.76 raeburn 9741: pgbg => "Page",
1.6 raeburn 9742: tabbg => "Header",
9743: sidebg => "Border",
9744: link => "Link",
9745: alink => "Active link",
9746: vlink => "Visited link",
9747: );
9748: return %choices;
9749: }
9750:
1.160.6.113 raeburn 9751: sub modify_ipaccess {
9752: my ($dom,$lastactref,%domconfig) = @_;
9753: my (@allpos,%changes,%confhash,$errors,$resulttext);
9754: my (@items,%deletions,%itemids,@warnings);
9755: my ($typeorder,$types) = &commblocktype_text();
9756: if ($env{'form.ipaccess_add'}) {
9757: my $name = $env{'form.ipaccess_name_add'};
9758: my ($newid,$error) = &get_ipaccess_id($dom,$name);
9759: if ($newid) {
9760: $itemids{'add'} = $newid;
9761: push(@items,'add');
9762: $changes{$newid} = 1;
9763: } else {
9764: $error = &mt('Failed to acquire unique ID for new IP access control item');
9765: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9766: }
9767: }
9768: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
9769: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
9770: if (@todelete) {
9771: map { $deletions{$_} = 1; } @todelete;
9772: }
9773: my $maxnum = $env{'form.ipaccess_maxnum'};
9774: for (my $i=0; $i<$maxnum; $i++) {
9775: my $itemid = $env{'form.ipaccess_id_'.$i};
9776: $itemid =~ s/\D+//g;
9777: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
9778: if ($deletions{$itemid}) {
9779: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
9780: } else {
9781: push(@items,$i);
9782: $itemids{$i} = $itemid;
9783: }
9784: }
9785: }
9786: }
9787: foreach my $idx (@items) {
9788: my $itemid = $itemids{$idx};
9789: next unless ($itemid);
9790: my %current;
9791: unless ($idx eq 'add') {
9792: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
9793: %current = %{$domconfig{'ipaccess'}{$itemid}};
9794: }
9795: }
9796: my $position = $env{'form.ipaccess_pos_'.$itemid};
9797: $position =~ s/\D+//g;
9798: if ($position ne '') {
9799: $allpos[$position] = $itemid;
9800: }
9801: my $name = $env{'form.ipaccess_name_'.$idx};
9802: $name =~ s/^\s+|\s+$//g;
9803: $confhash{$itemid}{'name'} = $name;
9804: my $possrange = $env{'form.ipaccess_range_'.$idx};
9805: $possrange =~ s/^\s+|\s+$//g;
9806: unless ($possrange eq '') {
9807: $possrange =~ s/[\r\n]+/\s/g;
9808: $possrange =~ s/\s*-\s*/-/g;
9809: $possrange =~ s/\s+/,/g;
9810: $possrange =~ s/,+/,/g;
9811: if ($possrange ne '') {
9812: my (@ok,$count);
9813: $count = 0;
9814: foreach my $poss (split(/\,/,$possrange)) {
9815: $count ++;
9816: $poss = &validate_ip_pattern($poss);
9817: if ($poss ne '') {
9818: push(@ok,$poss);
9819: }
9820: }
9821: my $diff = $count - scalar(@ok);
9822: if ($diff) {
9823: $errors .= '<li><span class="LC_error">'.
9824: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
9825: $diff,$name).
9826: '</span></li>';
9827: }
9828: if (@ok) {
9829: my @cidr_list;
9830: foreach my $item (@ok) {
9831: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
9832: }
9833: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
9834: }
9835: }
9836: }
9837: foreach my $field ('name','ip') {
9838: unless (($idx eq 'add') || ($changes{$itemid})) {
9839: if ($current{$field} ne $confhash{$itemid}{$field}) {
9840: $changes{$itemid} = 1;
9841: last;
9842: }
9843: }
9844: }
9845: $confhash{$itemid}{'commblocks'} = {};
9846:
9847: my %commblocks;
9848: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
9849: foreach my $type (@{$typeorder}) {
9850: if ($commblocks{$type}) {
9851: $confhash{$itemid}{'commblocks'}{$type} = 'on';
9852: }
9853: unless (($idx eq 'add') || ($changes{$itemid})) {
9854: if (ref($current{'commblocks'}) eq 'HASH') {
9855: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
9856: $changes{$itemid} = 1;
9857: }
9858: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
9859: $changes{$itemid} = 1;
9860: }
9861: }
9862: }
9863: $confhash{$itemid}{'courses'} = {};
9864: my %crsdeletions;
9865: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
9866: if (@delcrs) {
9867: map { $crsdeletions{$_} = 1; } @delcrs;
9868: }
9869: if (ref($current{'courses'}) eq 'HASH') {
9870: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
9871: if ($crsdeletions{$cid}) {
9872: $changes{$itemid} = 1;
9873: } else {
9874: $confhash{$itemid}{'courses'}{$cid} = 1;
9875: }
9876: }
9877: }
9878: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
9879: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
9880: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
9881: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
9882: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
9883: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
9884: $errors .= '<li><span class="LC_error">'.
9885: &mt('Invalid courseID [_1] omitted from list of allowed courses',
9886: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
9887: '</span></li>';
9888: } else {
9889: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
9890: $changes{$itemid} = 1;
9891: }
9892: }
9893: }
9894: if (@allpos > 0) {
9895: my $idx = 0;
9896: foreach my $itemid (@allpos) {
9897: if ($itemid ne '') {
9898: $confhash{$itemid}{'order'} = $idx;
9899: unless ($changes{$itemid}) {
9900: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
9901: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
9902: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
9903: $changes{$itemid} = 1;
9904: }
9905: }
9906: }
9907: }
9908: $idx ++;
9909: }
9910: }
9911: }
9912: if (keys(%changes)) {
9913: my %defaultshash = (
9914: ipaccess => \%confhash,
9915: );
9916: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
9917: $dom);
9918: if ($putresult eq 'ok') {
9919: my $cachetime = 1800;
9920: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
9921: if (ref($lastactref) eq 'HASH') {
9922: $lastactref->{'ipaccess'} = 1;
9923: }
9924: $resulttext = &mt('Changes made:').'<ul>';
9925: my %bynum;
9926: foreach my $itemid (sort(keys(%changes))) {
9927: if (ref($confhash{$itemid}) eq 'HASH') {
9928: my $position = $confhash{$itemid}{'order'};
9929: if ($position =~ /^\d+$/) {
9930: $bynum{$position} = $itemid;
9931: }
9932: }
9933: }
9934: if (keys(%deletions)) {
9935: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
9936: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
9937: }
9938: }
9939: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
9940: my $itemid = $bynum{$pos};
9941: if (ref($confhash{$itemid}) eq 'HASH') {
9942: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
9943: my $position = $pos + 1;
9944: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
9945: if ($confhash{$itemid}{'ip'} eq '') {
9946: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
9947: } else {
9948: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
9949: }
9950: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
9951: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
9952: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
9953: '</li>';
9954: } else {
9955: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
9956: }
9957: if (keys(%{$confhash{$itemid}{'courses'}})) {
9958: my @courses;
9959: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
9960: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
9961: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
9962: }
9963: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
9964: join('</li><li>',@courses).'</li></ul>';
9965: } else {
9966: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
9967: }
9968: $resulttext .= '</ul></li>';
9969: }
9970: }
9971: $resulttext .= '</ul>';
9972: } else {
9973: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9974: }
9975: } else {
9976: $resulttext = &mt('No changes made');
9977: }
9978: if ($errors) {
9979: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
9980: $errors.'</ul></p>';
9981: }
9982: return $resulttext;
9983: }
9984:
9985: sub get_ipaccess_id {
9986: my ($domain,$location) = @_;
9987: # get lock on ipaccess db
9988: my $lockhash = {
9989: lock => $env{'user.name'}.
9990: ':'.$env{'user.domain'},
9991: };
9992: my $tries = 0;
9993: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
9994: my ($id,$error);
9995:
9996: while (($gotlock ne 'ok') && ($tries<10)) {
9997: $tries ++;
9998: sleep (0.1);
9999: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
10000: }
10001: if ($gotlock eq 'ok') {
10002: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
10003: if ($currids{'lock'}) {
10004: delete($currids{'lock'});
10005: if (keys(%currids)) {
10006: my @curr = sort { $a <=> $b } keys(%currids);
10007: if ($curr[-1] =~ /^\d+$/) {
10008: $id = 1 + $curr[-1];
10009: }
10010: } else {
10011: $id = 1;
10012: }
10013: if ($id) {
10014: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
10015: $error = 'nostore';
10016: }
10017: } else {
10018: $error = 'nonumber';
10019: }
10020: }
10021: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
10022: } else {
10023: $error = 'nolock';
10024: }
10025: return ($id,$error);
10026: }
10027:
1.6 raeburn 10028: sub modify_rolecolors {
1.160.6.24 raeburn 10029: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 10030: my ($resulttext,%rolehash);
10031: $rolehash{'rolecolors'} = {};
1.55 raeburn 10032: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
10033: if ($domconfig{'rolecolors'} eq '') {
10034: $domconfig{'rolecolors'} = {};
10035: }
10036: }
1.9 raeburn 10037: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 10038: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
10039: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
10040: $dom);
10041: if ($putresult eq 'ok') {
10042: if (keys(%changes) > 0) {
1.41 raeburn 10043: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10044: if (ref($lastactref) eq 'HASH') {
10045: $lastactref->{'domainconfig'} = 1;
10046: }
1.6 raeburn 10047: $resulttext = &display_colorchgs($dom,\%changes,$roles,
10048: $rolehash{'rolecolors'});
10049: } else {
10050: $resulttext = &mt('No changes made to default color schemes');
10051: }
10052: } else {
1.11 albertel 10053: $resulttext = '<span class="LC_error">'.
10054: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 10055: }
10056: if ($errors) {
10057: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10058: $errors.'</ul>';
10059: }
10060: return $resulttext;
10061: }
10062:
10063: sub modify_colors {
1.9 raeburn 10064: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 10065: my (%changes,%choices);
1.51 raeburn 10066: my @bgs;
1.6 raeburn 10067: my @links = ('link','alink','vlink');
1.41 raeburn 10068: my @logintext;
1.6 raeburn 10069: my @images;
10070: my $servadm = $r->dir_config('lonAdmEMail');
10071: my $errors;
1.160.6.22 raeburn 10072: my %defaults;
1.6 raeburn 10073: foreach my $role (@{$roles}) {
10074: if ($role eq 'login') {
1.12 raeburn 10075: %choices = &login_choices();
1.41 raeburn 10076: @logintext = ('textcol','bgcol');
1.12 raeburn 10077: } else {
10078: %choices = &color_font_choices();
10079: }
10080: if ($role eq 'login') {
1.41 raeburn 10081: @images = ('img','logo','domlogo','login');
1.51 raeburn 10082: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 10083: } else {
10084: @images = ('img');
1.160.6.22 raeburn 10085: @bgs = ('pgbg','tabbg','sidebg');
10086: }
10087: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
10088: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
10089: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
10090: }
10091: if ($role eq 'login') {
10092: foreach my $item (@logintext) {
1.160.6.39 raeburn 10093: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10094: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10095: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10096: }
10097: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 10098: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10099: }
10100: }
10101: } else {
1.160.6.39 raeburn 10102: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
10103: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
10104: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
10105: }
10106: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 10107: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
10108: }
1.6 raeburn 10109: }
1.160.6.22 raeburn 10110: foreach my $item (@bgs) {
1.160.6.39 raeburn 10111: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10112: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10113: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10114: }
10115: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 10116: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10117: }
10118: }
10119: foreach my $item (@links) {
1.160.6.39 raeburn 10120: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10121: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10122: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10123: }
10124: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 10125: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10126: }
1.6 raeburn 10127: }
1.46 raeburn 10128: my ($configuserok,$author_ok,$switchserver) =
10129: &config_check($dom,$confname,$servadm);
1.9 raeburn 10130: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 10131: if (ref($domconfig->{$role}) ne 'HASH') {
10132: $domconfig->{$role} = {};
10133: }
1.8 raeburn 10134: foreach my $img (@images) {
1.160.6.119 raeburn 10135: if ($role eq 'login') {
10136: if (($img eq 'img') || ($img eq 'logo')) {
10137: if (defined($env{'form.login_showlogo_'.$img})) {
10138: $confhash->{$role}{'showlogo'}{$img} = 1;
10139: } else {
10140: $confhash->{$role}{'showlogo'}{$img} = 0;
10141: }
1.70 raeburn 10142: }
1.160.6.119 raeburn 10143: if ($env{'form.login_alt_'.$img} ne '') {
10144: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
10145: }
10146: }
1.18 albertel 10147: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
10148: && !defined($domconfig->{$role}{$img})
10149: && !$env{'form.'.$role.'_del_'.$img}
10150: && $env{'form.'.$role.'_import_'.$img}) {
10151: # import the old configured image from the .tab setting
10152: # if they haven't provided a new one
10153: $domconfig->{$role}{$img} =
10154: $env{'form.'.$role.'_import_'.$img};
10155: }
1.6 raeburn 10156: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 10157: my $error;
1.6 raeburn 10158: if ($configuserok eq 'ok') {
1.9 raeburn 10159: if ($switchserver) {
1.12 raeburn 10160: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 10161: } else {
10162: if ($author_ok eq 'ok') {
10163: my ($result,$logourl) =
10164: &publishlogo($r,'upload',$role.'_'.$img,
10165: $dom,$confname,$img,$width,$height);
10166: if ($result eq 'ok') {
10167: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 10168: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10169: } else {
1.12 raeburn 10170: $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 10171: }
10172: } else {
1.46 raeburn 10173: $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 10174: }
10175: }
10176: } else {
1.46 raeburn 10177: $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 10178: }
10179: if ($error) {
1.8 raeburn 10180: &Apache::lonnet::logthis($error);
1.11 albertel 10181: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 10182: }
10183: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 10184: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
10185: my $error;
10186: if ($configuserok eq 'ok') {
10187: # is confname an author?
10188: if ($switchserver eq '') {
10189: if ($author_ok eq 'ok') {
10190: my ($result,$logourl) =
10191: &publishlogo($r,'copy',$domconfig->{$role}{$img},
10192: $dom,$confname,$img,$width,$height);
10193: if ($result eq 'ok') {
10194: $confhash->{$role}{$img} = $logourl;
1.18 albertel 10195: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10196: }
10197: }
10198: }
10199: }
1.6 raeburn 10200: }
10201: }
10202: }
10203: if (ref($domconfig) eq 'HASH') {
10204: if (ref($domconfig->{$role}) eq 'HASH') {
10205: foreach my $img (@images) {
10206: if ($domconfig->{$role}{$img} ne '') {
10207: if ($env{'form.'.$role.'_del_'.$img}) {
10208: $confhash->{$role}{$img} = '';
1.12 raeburn 10209: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10210: } else {
1.9 raeburn 10211: if ($confhash->{$role}{$img} eq '') {
10212: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
10213: }
1.6 raeburn 10214: }
10215: } else {
10216: if ($env{'form.'.$role.'_del_'.$img}) {
10217: $confhash->{$role}{$img} = '';
1.12 raeburn 10218: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10219: }
10220: }
1.160.6.119 raeburn 10221: if ($role eq 'login') {
10222: if (($img eq 'logo') || ($img eq 'img')) {
10223: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
10224: if ($confhash->{$role}{'showlogo'}{$img} ne
10225: $domconfig->{$role}{'showlogo'}{$img}) {
10226: $changes{$role}{'showlogo'}{$img} = 1;
10227: }
10228: } else {
10229: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10230: $changes{$role}{'showlogo'}{$img} = 1;
10231: }
1.70 raeburn 10232: }
1.160.6.119 raeburn 10233: }
10234: if ($img ne 'login') {
10235: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
10236: if ($confhash->{$role}{'alttext'}{$img} ne
10237: $domconfig->{$role}{'alttext'}{$img}) {
10238: $changes{$role}{'alttext'}{$img} = 1;
10239: }
10240: } else {
10241: if ($confhash->{$role}{'alttext'}{$img} ne '') {
10242: $changes{$role}{'alttext'}{$img} = 1;
10243: }
1.70 raeburn 10244: }
10245: }
10246: }
10247: }
1.6 raeburn 10248: if ($domconfig->{$role}{'font'} ne '') {
10249: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
10250: $changes{$role}{'font'} = 1;
10251: }
10252: } else {
10253: if ($confhash->{$role}{'font'}) {
10254: $changes{$role}{'font'} = 1;
10255: }
10256: }
1.107 raeburn 10257: if ($role ne 'login') {
10258: if ($domconfig->{$role}{'fontmenu'} ne '') {
10259: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
10260: $changes{$role}{'fontmenu'} = 1;
10261: }
10262: } else {
10263: if ($confhash->{$role}{'fontmenu'}) {
10264: $changes{$role}{'fontmenu'} = 1;
10265: }
1.97 tempelho 10266: }
10267: }
1.6 raeburn 10268: foreach my $item (@bgs) {
10269: if ($domconfig->{$role}{$item} ne '') {
10270: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10271: $changes{$role}{'bgs'}{$item} = 1;
10272: }
10273: } else {
10274: if ($confhash->{$role}{$item}) {
10275: $changes{$role}{'bgs'}{$item} = 1;
10276: }
10277: }
10278: }
10279: foreach my $item (@links) {
10280: if ($domconfig->{$role}{$item} ne '') {
10281: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10282: $changes{$role}{'links'}{$item} = 1;
10283: }
10284: } else {
10285: if ($confhash->{$role}{$item}) {
10286: $changes{$role}{'links'}{$item} = 1;
10287: }
10288: }
10289: }
1.41 raeburn 10290: foreach my $item (@logintext) {
10291: if ($domconfig->{$role}{$item} ne '') {
10292: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10293: $changes{$role}{'logintext'}{$item} = 1;
10294: }
10295: } else {
10296: if ($confhash->{$role}{$item}) {
10297: $changes{$role}{'logintext'}{$item} = 1;
10298: }
10299: }
10300: }
1.6 raeburn 10301: } else {
10302: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10303: \@logintext,$confhash,\%changes);
1.6 raeburn 10304: }
10305: } else {
10306: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10307: \@logintext,$confhash,\%changes);
1.6 raeburn 10308: }
10309: }
10310: return ($errors,%changes);
10311: }
10312:
1.46 raeburn 10313: sub config_check {
10314: my ($dom,$confname,$servadm) = @_;
10315: my ($configuserok,$author_ok,$switchserver,%currroles);
10316: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
10317: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
10318: $confname,$servadm);
10319: if ($configuserok eq 'ok') {
10320: $switchserver = &check_switchserver($dom,$confname);
10321: if ($switchserver eq '') {
10322: $author_ok = &check_authorstatus($dom,$confname,%currroles);
10323: }
10324: }
10325: return ($configuserok,$author_ok,$switchserver);
10326: }
10327:
1.6 raeburn 10328: sub default_change_checker {
1.41 raeburn 10329: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 10330: foreach my $item (@{$links}) {
10331: if ($confhash->{$role}{$item}) {
10332: $changes->{$role}{'links'}{$item} = 1;
10333: }
10334: }
10335: foreach my $item (@{$bgs}) {
10336: if ($confhash->{$role}{$item}) {
10337: $changes->{$role}{'bgs'}{$item} = 1;
10338: }
10339: }
1.41 raeburn 10340: foreach my $item (@{$logintext}) {
10341: if ($confhash->{$role}{$item}) {
10342: $changes->{$role}{'logintext'}{$item} = 1;
10343: }
10344: }
1.6 raeburn 10345: foreach my $img (@{$images}) {
10346: if ($env{'form.'.$role.'_del_'.$img}) {
10347: $confhash->{$role}{$img} = '';
1.12 raeburn 10348: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 10349: }
1.70 raeburn 10350: if ($role eq 'login') {
10351: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10352: $changes->{$role}{'showlogo'}{$img} = 1;
10353: }
1.160.6.119 raeburn 10354: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
10355: if ($confhash->{$role}{'alttext'}{$img} ne '') {
10356: $changes->{$role}{'alttext'}{$img} = 1;
10357: }
10358: }
1.70 raeburn 10359: }
1.6 raeburn 10360: }
10361: if ($confhash->{$role}{'font'}) {
10362: $changes->{$role}{'font'} = 1;
10363: }
1.48 raeburn 10364: }
1.6 raeburn 10365:
10366: sub display_colorchgs {
10367: my ($dom,$changes,$roles,$confhash) = @_;
10368: my (%choices,$resulttext);
10369: if (!grep(/^login$/,@{$roles})) {
10370: $resulttext = &mt('Changes made:').'<br />';
10371: }
10372: foreach my $role (@{$roles}) {
10373: if ($role eq 'login') {
10374: %choices = &login_choices();
10375: } else {
10376: %choices = &color_font_choices();
10377: }
10378: if (ref($changes->{$role}) eq 'HASH') {
10379: if ($role ne 'login') {
10380: $resulttext .= '<h4>'.&mt($role).'</h4>';
10381: }
10382: foreach my $key (sort(keys(%{$changes->{$role}}))) {
10383: if ($role ne 'login') {
10384: $resulttext .= '<ul>';
10385: }
10386: if (ref($changes->{$role}{$key}) eq 'HASH') {
10387: if ($role ne 'login') {
10388: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
10389: }
10390: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 10391: if (($role eq 'login') && ($key eq 'showlogo')) {
10392: if ($confhash->{$role}{$key}{$item}) {
10393: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
10394: } else {
10395: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
10396: }
1.160.6.119 raeburn 10397: } elsif (($role eq 'login') && ($key eq 'alttext')) {
10398: if ($confhash->{$role}{$key}{$item} ne '') {
1.160.6.120 raeburn 10399: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.160.6.119 raeburn 10400: $confhash->{$role}{$key}{$item}).'</li>';
10401: } else {
10402: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
10403: }
1.70 raeburn 10404: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 10405: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
10406: } else {
1.12 raeburn 10407: my $newitem = $confhash->{$role}{$item};
10408: if ($key eq 'images') {
10409: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
10410: }
10411: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 10412: }
10413: }
10414: if ($role ne 'login') {
10415: $resulttext .= '</ul></li>';
10416: }
10417: } else {
10418: if ($confhash->{$role}{$key} eq '') {
10419: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
10420: } else {
10421: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
10422: }
10423: }
10424: if ($role ne 'login') {
10425: $resulttext .= '</ul>';
10426: }
10427: }
10428: }
10429: }
1.3 raeburn 10430: return $resulttext;
1.1 raeburn 10431: }
10432:
1.9 raeburn 10433: sub thumb_dimensions {
10434: return ('200','50');
10435: }
10436:
1.16 raeburn 10437: sub check_dimensions {
10438: my ($inputfile) = @_;
10439: my ($fullwidth,$fullheight);
10440: if ($inputfile =~ m|^[/\w.\-]+$|) {
10441: if (open(PIPE,"identify $inputfile 2>&1 |")) {
10442: my $imageinfo = <PIPE>;
10443: if (!close(PIPE)) {
10444: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
10445: }
10446: chomp($imageinfo);
10447: my ($fullsize) =
1.21 raeburn 10448: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 10449: if ($fullsize) {
10450: ($fullwidth,$fullheight) = split(/x/,$fullsize);
10451: }
10452: }
10453: }
10454: return ($fullwidth,$fullheight);
10455: }
10456:
1.9 raeburn 10457: sub check_configuser {
10458: my ($uhome,$dom,$confname,$servadm) = @_;
10459: my ($configuserok,%currroles);
10460: if ($uhome eq 'no_host') {
10461: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98 raeburn 10462: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 10463: $configuserok =
10464: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
10465: $configpass,'','','','','',undef,$servadm);
10466: } else {
10467: $configuserok = 'ok';
10468: %currroles =
10469: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
10470: }
10471: return ($configuserok,%currroles);
10472: }
10473:
10474: sub check_authorstatus {
10475: my ($dom,$confname,%currroles) = @_;
10476: my $author_ok;
1.40 raeburn 10477: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 10478: my $start = time;
10479: my $end = 0;
10480: $author_ok =
10481: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 10482: 'au',$end,$start,'','','domconfig');
1.9 raeburn 10483: } else {
10484: $author_ok = 'ok';
10485: }
10486: return $author_ok;
10487: }
10488:
10489: sub publishlogo {
1.46 raeburn 10490: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 10491: my ($output,$fname,$logourl);
10492: if ($action eq 'upload') {
10493: $fname=$env{'form.'.$formname.'.filename'};
10494: chop($env{'form.'.$formname});
10495: } else {
10496: ($fname) = ($formname =~ /([^\/]+)$/);
10497: }
1.46 raeburn 10498: if ($savefileas ne '') {
10499: $fname = $savefileas;
10500: }
1.9 raeburn 10501: $fname=&Apache::lonnet::clean_filename($fname);
10502: # See if there is anything left
10503: unless ($fname) { return ('error: no uploaded file'); }
10504: $fname="$subdir/$fname";
1.160.6.5 raeburn 10505: my $docroot=$r->dir_config('lonDocRoot');
10506: my $filepath="$docroot/priv";
10507: my $relpath = "$dom/$confname";
1.9 raeburn 10508: my ($fnamepath,$file,$fetchthumb);
10509: $file=$fname;
10510: if ($fname=~m|/|) {
10511: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
10512: }
1.160.6.26 raeburn 10513: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 10514: my $count;
1.160.6.5 raeburn 10515: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 10516: $filepath.="/$parts[$count]";
10517: if ((-e $filepath)!=1) {
10518: mkdir($filepath,02770);
10519: }
10520: }
10521: # Check for bad extension and disallow upload
10522: if ($file=~/\.(\w+)$/ &&
10523: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
10524: $output =
1.160.6.25 raeburn 10525: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 10526: } elsif ($file=~/\.(\w+)$/ &&
10527: !defined(&Apache::loncommon::fileembstyle($1))) {
10528: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
10529: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 10530: $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 10531: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 10532: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 10533: } else {
10534: my $source = $filepath.'/'.$file;
10535: my $logfile;
1.160.6.88 raeburn 10536: if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 10537: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 10538: }
10539: print $logfile
10540: "\n================= Publish ".localtime()." ================\n".
10541: $env{'user.name'}.':'.$env{'user.domain'}."\n";
10542: # Save the file
1.160.6.88 raeburn 10543: if (!open(FH,">",$source)) {
1.9 raeburn 10544: &Apache::lonnet::logthis('Failed to create '.$source);
10545: return (&mt('Failed to create file'));
10546: }
10547: if ($action eq 'upload') {
10548: if (!print FH ($env{'form.'.$formname})) {
10549: &Apache::lonnet::logthis('Failed to write to '.$source);
10550: return (&mt('Failed to write file'));
10551: }
10552: } else {
10553: my $original = &Apache::lonnet::filelocation('',$formname);
10554: if(!copy($original,$source)) {
10555: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
10556: return (&mt('Failed to write file'));
10557: }
10558: }
10559: close(FH);
10560: chmod(0660, $source); # Permissions to rw-rw---.
10561:
10562: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
10563: my $copyfile=$targetdir.'/'.$file;
10564:
10565: my @parts=split(/\//,$targetdir);
10566: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
10567: for (my $count=5;$count<=$#parts;$count++) {
10568: $path.="/$parts[$count]";
10569: if (!-e $path) {
10570: print $logfile "\nCreating directory ".$path;
10571: mkdir($path,02770);
10572: }
10573: }
10574: my $versionresult;
10575: if (-e $copyfile) {
10576: $versionresult = &logo_versioning($targetdir,$file,$logfile);
10577: } else {
10578: $versionresult = 'ok';
10579: }
10580: if ($versionresult eq 'ok') {
10581: if (copy($source,$copyfile)) {
10582: print $logfile "\nCopied original source to ".$copyfile."\n";
10583: $output = 'ok';
10584: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 10585: push(@{$modified_urls},[$copyfile,$source]);
10586: my $metaoutput =
10587: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
10588: unless ($registered_cleanup) {
10589: my $handlers = $r->get_handlers('PerlCleanupHandler');
10590: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10591: $registered_cleanup=1;
10592: }
1.9 raeburn 10593: } else {
10594: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
10595: $output = &mt('Failed to copy file to RES space').", $!";
10596: }
10597: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
10598: my $inputfile = $filepath.'/'.$file;
10599: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 10600: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
10601: if ($fullwidth ne '' && $fullheight ne '') {
10602: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
10603: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88 raeburn 10604: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
10605: system({$args[0]} @args);
1.16 raeburn 10606: chmod(0660, $filepath.'/tn-'.$file);
10607: if (-e $outfile) {
10608: my $copyfile=$targetdir.'/tn-'.$file;
10609: if (copy($outfile,$copyfile)) {
10610: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 10611: my $thumb_metaoutput =
10612: &write_metadata($dom,$confname,$formname,
10613: $targetdir,'tn-'.$file,$logfile);
10614: push(@{$modified_urls},[$copyfile,$outfile]);
10615: unless ($registered_cleanup) {
10616: my $handlers = $r->get_handlers('PerlCleanupHandler');
10617: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10618: $registered_cleanup=1;
10619: }
1.16 raeburn 10620: } else {
10621: print $logfile "\nUnable to write ".$copyfile.
10622: ':'.$!."\n";
10623: }
10624: }
1.9 raeburn 10625: }
10626: }
10627: }
10628: } else {
10629: $output = $versionresult;
10630: }
10631: }
10632: return ($output,$logourl);
10633: }
10634:
10635: sub logo_versioning {
10636: my ($targetdir,$file,$logfile) = @_;
10637: my $target = $targetdir.'/'.$file;
10638: my ($maxversion,$fn,$extn,$output);
10639: $maxversion = 0;
10640: if ($file =~ /^(.+)\.(\w+)$/) {
10641: $fn=$1;
10642: $extn=$2;
10643: }
10644: opendir(DIR,$targetdir);
10645: while (my $filename=readdir(DIR)) {
10646: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
10647: $maxversion=($1>$maxversion)?$1:$maxversion;
10648: }
10649: }
10650: $maxversion++;
10651: print $logfile "\nCreating old version ".$maxversion."\n";
10652: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
10653: if (copy($target,$copyfile)) {
10654: print $logfile "Copied old target to ".$copyfile."\n";
10655: $copyfile=$copyfile.'.meta';
10656: if (copy($target.'.meta',$copyfile)) {
10657: print $logfile "Copied old target metadata to ".$copyfile."\n";
10658: $output = 'ok';
10659: } else {
10660: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
10661: $output = &mt('Failed to copy old meta').", $!, ";
10662: }
10663: } else {
10664: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
10665: $output = &mt('Failed to copy old target').", $!, ";
10666: }
10667: return $output;
10668: }
10669:
10670: sub write_metadata {
10671: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
10672: my (%metadatafields,%metadatakeys,$output);
10673: $metadatafields{'title'}=$formname;
10674: $metadatafields{'creationdate'}=time;
10675: $metadatafields{'lastrevisiondate'}=time;
10676: $metadatafields{'copyright'}='public';
10677: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
10678: $env{'user.domain'};
10679: $metadatafields{'authorspace'}=$confname.':'.$dom;
10680: $metadatafields{'domain'}=$dom;
10681: {
10682: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
10683: my $mfh;
1.160.6.88 raeburn 10684: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 10685: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 10686: unless ($_=~/\./) {
10687: my $unikey=$_;
10688: $unikey=~/^([A-Za-z]+)/;
10689: my $tag=$1;
10690: $tag=~tr/A-Z/a-z/;
10691: print $mfh "\n\<$tag";
10692: foreach (split(/\,/,$metadatakeys{$unikey})) {
10693: my $value=$metadatafields{$unikey.'.'.$_};
10694: $value=~s/\"/\'\'/g;
10695: print $mfh ' '.$_.'="'.$value.'"';
10696: }
10697: print $mfh '>'.
10698: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
10699: .'</'.$tag.'>';
10700: }
10701: }
10702: $output = 'ok';
10703: print $logfile "\nWrote metadata";
10704: close($mfh);
10705: } else {
10706: print $logfile "\nFailed to open metadata file";
1.9 raeburn 10707: $output = &mt('Could not write metadata');
10708: }
10709: }
1.155 raeburn 10710: return $output;
10711: }
10712:
10713: sub notifysubscribed {
10714: foreach my $targetsource (@{$modified_urls}){
10715: next unless (ref($targetsource) eq 'ARRAY');
10716: my ($target,$source)=@{$targetsource};
10717: if ($source ne '') {
1.160.6.88 raeburn 10718: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 10719: print $logfh "\nCleanup phase: Notifications\n";
10720: my @subscribed=&subscribed_hosts($target);
10721: foreach my $subhost (@subscribed) {
10722: print $logfh "\nNotifying host ".$subhost.':';
10723: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
10724: print $logfh $reply;
10725: }
10726: my @subscribedmeta=&subscribed_hosts("$target.meta");
10727: foreach my $subhost (@subscribedmeta) {
10728: print $logfh "\nNotifying host for metadata only ".$subhost.':';
10729: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
10730: $subhost);
10731: print $logfh $reply;
10732: }
10733: print $logfh "\n============ Done ============\n";
1.160 raeburn 10734: close($logfh);
1.155 raeburn 10735: }
10736: }
10737: }
10738: return OK;
10739: }
10740:
10741: sub subscribed_hosts {
10742: my ($target) = @_;
10743: my @subscribed;
1.160.6.88 raeburn 10744: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 10745: while (my $subline=<$fh>) {
10746: if ($subline =~ /^($match_lonid):/) {
10747: my $host = $1;
10748: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
10749: unless (grep(/^\Q$host\E$/,@subscribed)) {
10750: push(@subscribed,$host);
10751: }
10752: }
10753: }
10754: }
10755: }
10756: return @subscribed;
1.9 raeburn 10757: }
10758:
10759: sub check_switchserver {
10760: my ($dom,$confname) = @_;
10761: my ($allowed,$switchserver);
10762: my $home = &Apache::lonnet::homeserver($confname,$dom);
10763: if ($home eq 'no_host') {
10764: $home = &Apache::lonnet::domain($dom,'primary');
10765: }
10766: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 10767: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
10768: if (!$allowed) {
1.160.6.11 raeburn 10769: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 10770: }
10771: return $switchserver;
10772: }
10773:
1.1 raeburn 10774: sub modify_quotas {
1.160.6.30 raeburn 10775: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 10776: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 10777: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 10778: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
10779: $validationfieldsref);
1.86 raeburn 10780: if ($action eq 'quotas') {
10781: $context = 'tools';
1.160.6.26 raeburn 10782: } else {
1.86 raeburn 10783: $context = $action;
10784: }
10785: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 10786: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 10787: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 10788: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
10789: %titles = &courserequest_titles();
10790: $toolregexp = join('|',@usertools);
10791: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 10792: $confname = $dom.'-domainconfig';
10793: my $servadm = $r->dir_config('lonAdmEMail');
10794: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 10795: ($validationitemsref,$validationnamesref,$validationfieldsref) =
10796: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 10797: } elsif ($context eq 'requestauthor') {
10798: @usertools = ('author');
10799: %titles = &authorrequest_titles();
1.86 raeburn 10800: } else {
1.160.6.4 raeburn 10801: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 10802: %titles = &tool_titles();
1.86 raeburn 10803: }
1.160.6.27 raeburn 10804: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 10805: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10806: foreach my $key (keys(%env)) {
1.101 raeburn 10807: if ($context eq 'requestcourses') {
10808: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
10809: my $item = $1;
10810: my $type = $2;
10811: if ($type =~ /^limit_(.+)/) {
10812: $limithash{$item}{$1} = $env{$key};
10813: } else {
10814: $confhash{$item}{$type} = $env{$key};
10815: }
10816: }
1.160.6.5 raeburn 10817: } elsif ($context eq 'requestauthor') {
10818: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
10819: $confhash{$1} = $env{$key};
10820: }
1.101 raeburn 10821: } else {
1.86 raeburn 10822: if ($key =~ /^form\.quota_(.+)$/) {
10823: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 10824: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
10825: $confhash{'authorquota'}{$1} = $env{$key};
10826: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 10827: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
10828: }
1.72 raeburn 10829: }
10830: }
1.160.6.5 raeburn 10831: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 10832: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 10833: @approvalnotify = sort(@approvalnotify);
10834: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 10835: my @crstypes = ('official','unofficial','community','textbook');
10836: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
10837: foreach my $type (@hasuniquecode) {
10838: if (grep(/^\Q$type\E$/,@crstypes)) {
10839: $confhash{'uniquecode'}{$type} = 1;
10840: }
10841: }
1.160.6.46 raeburn 10842: my (%newbook,%allpos);
1.160.6.30 raeburn 10843: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 10844: foreach my $type ('textbooks','templates') {
10845: @{$allpos{$type}} = ();
10846: my $invalid;
10847: if ($type eq 'textbooks') {
10848: $invalid = &mt('Invalid LON-CAPA course for textbook');
10849: } else {
10850: $invalid = &mt('Invalid LON-CAPA course for template');
10851: }
10852: if ($env{'form.'.$type.'_addbook'}) {
10853: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
10854: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
10855: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
10856: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
10857: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
10858: } else {
10859: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
10860: my $position = $env{'form.'.$type.'_addbook_pos'};
10861: $position =~ s/\D+//g;
10862: if ($position ne '') {
10863: $allpos{$type}[$position] = $newbook{$type};
10864: }
1.160.6.30 raeburn 10865: }
1.160.6.46 raeburn 10866: } else {
10867: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 10868: }
10869: }
1.160.6.46 raeburn 10870: }
1.160.6.30 raeburn 10871: }
1.102 raeburn 10872: if (ref($domconfig{$action}) eq 'HASH') {
10873: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
10874: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
10875: $changes{'notify'}{'approval'} = 1;
10876: }
10877: } else {
1.144 raeburn 10878: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10879: $changes{'notify'}{'approval'} = 1;
10880: }
10881: }
1.160.6.30 raeburn 10882: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
10883: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10884: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
10885: unless ($confhash{'uniquecode'}{$crstype}) {
10886: $changes{'uniquecode'} = 1;
10887: }
10888: }
10889: unless ($changes{'uniquecode'}) {
10890: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
10891: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
10892: $changes{'uniquecode'} = 1;
10893: }
10894: }
10895: }
10896: } else {
10897: $changes{'uniquecode'} = 1;
10898: }
10899: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
10900: $changes{'uniquecode'} = 1;
10901: }
10902: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 10903: foreach my $type ('textbooks','templates') {
10904: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10905: my %deletions;
10906: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
10907: if (@todelete) {
10908: map { $deletions{$_} = 1; } @todelete;
10909: }
10910: my %imgdeletions;
10911: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
10912: if (@todeleteimages) {
10913: map { $imgdeletions{$_} = 1; } @todeleteimages;
10914: }
10915: my $maxnum = $env{'form.'.$type.'_maxnum'};
10916: for (my $i=0; $i<=$maxnum; $i++) {
10917: my $itemid = $env{'form.'.$type.'_id_'.$i};
10918: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
10919: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
10920: if ($deletions{$key}) {
10921: if ($domconfig{$action}{$type}{$key}{'image'}) {
10922: #FIXME need to obsolete item in RES space
10923: }
10924: next;
10925: } else {
10926: my $newpos = $env{'form.'.$itemid};
10927: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 10928: foreach my $item ('subject','title','publisher','author') {
10929: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10930: ($type eq 'templates'));
1.160.6.46 raeburn 10931: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
10932: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
10933: $changes{$type}{$key} = 1;
10934: }
10935: }
10936: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 10937: }
1.160.6.46 raeburn 10938: if ($imgdeletions{$key}) {
10939: $changes{$type}{$key} = 1;
10940: #FIXME need to obsolete item in RES space
10941: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
10942: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 10943: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10944: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10945: } else {
10946: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
10947: $cdom,$cnum,$type,$configuserok,
10948: $switchserver,$author_ok);
10949: if ($imgurl) {
10950: $confhash{$type}{$key}{'image'} = $imgurl;
10951: $changes{$type}{$key} = 1;
10952: }
10953: if ($error) {
10954: &Apache::lonnet::logthis($error);
10955: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10956: }
1.160.6.46 raeburn 10957: }
10958: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
10959: $confhash{$type}{$key}{'image'} =
10960: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 10961: }
10962: }
10963: }
10964: }
10965: }
10966: }
1.102 raeburn 10967: } else {
1.144 raeburn 10968: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10969: $changes{'notify'}{'approval'} = 1;
10970: }
1.160.6.30 raeburn 10971: if (ref($confhash{'uniquecode'} eq 'HASH')) {
10972: $changes{'uniquecode'} = 1;
10973: }
10974: }
10975: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 10976: foreach my $type ('textbooks','templates') {
10977: if ($newbook{$type}) {
10978: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 10979: foreach my $item ('subject','title','publisher','author') {
10980: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10981: ($type eq 'template'));
1.160.6.46 raeburn 10982: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
10983: if ($env{'form.'.$type.'_addbook_'.$item}) {
10984: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
10985: }
10986: }
10987: if ($type eq 'textbooks') {
10988: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
10989: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 10990: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10991: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10992: } else {
10993: my ($imageurl,$error) =
10994: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
10995: $configuserok,$switchserver,$author_ok);
10996: if ($imageurl) {
10997: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
10998: }
10999: if ($error) {
11000: &Apache::lonnet::logthis($error);
11001: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11002: }
1.160.6.46 raeburn 11003: }
11004: }
1.160.6.30 raeburn 11005: }
11006: }
1.160.6.46 raeburn 11007: if (@{$allpos{$type}} > 0) {
11008: my $idx = 0;
11009: foreach my $item (@{$allpos{$type}}) {
11010: if ($item ne '') {
11011: $confhash{$type}{$item}{'order'} = $idx;
11012: if (ref($domconfig{$action}) eq 'HASH') {
11013: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11014: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
11015: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
11016: $changes{$type}{$item} = 1;
11017: }
1.160.6.30 raeburn 11018: }
11019: }
11020: }
1.160.6.46 raeburn 11021: $idx ++;
1.160.6.30 raeburn 11022: }
11023: }
11024: }
11025: }
1.160.6.39 raeburn 11026: if (ref($validationitemsref) eq 'ARRAY') {
11027: foreach my $item (@{$validationitemsref}) {
11028: if ($item eq 'fields') {
11029: my @changed;
11030: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
11031: if (@{$confhash{'validation'}{$item}} > 0) {
11032: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
11033: }
1.160.6.65 raeburn 11034: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11035: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11036: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
11037: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
11038: $domconfig{'requestcourses'}{'validation'}{$item});
11039: } else {
11040: @changed = @{$confhash{'validation'}{$item}};
11041: }
1.160.6.39 raeburn 11042: } else {
11043: @changed = @{$confhash{'validation'}{$item}};
11044: }
11045: } else {
11046: @changed = @{$confhash{'validation'}{$item}};
11047: }
11048: if (@changed) {
11049: if ($confhash{'validation'}{$item}) {
11050: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
11051: } else {
11052: $changes{'validation'}{$item} = &mt('None');
11053: }
11054: }
11055: } else {
11056: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
11057: if ($item eq 'markup') {
11058: if ($env{'form.requestcourses_validation_'.$item}) {
11059: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
11060: }
11061: }
1.160.6.65 raeburn 11062: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11063: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11064: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
11065: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11066: }
11067: } else {
11068: if ($confhash{'validation'}{$item} ne '') {
11069: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11070: }
1.160.6.39 raeburn 11071: }
11072: } else {
11073: if ($confhash{'validation'}{$item} ne '') {
11074: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11075: }
11076: }
11077: }
11078: }
11079: }
11080: if ($env{'form.validationdc'}) {
11081: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 11082: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 11083: if (exists($domcoords{$newval})) {
11084: $confhash{'validation'}{'dc'} = $newval;
11085: }
11086: }
11087: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 11088: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11089: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11090: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11091: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
11092: if ($confhash{'validation'}{'dc'} eq '') {
11093: $changes{'validation'}{'dc'} = &mt('None');
11094: } else {
11095: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11096: }
1.160.6.39 raeburn 11097: }
1.160.6.65 raeburn 11098: } elsif ($confhash{'validation'}{'dc'} ne '') {
11099: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 11100: }
11101: } elsif ($confhash{'validation'}{'dc'} ne '') {
11102: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11103: }
11104: } elsif ($confhash{'validation'}{'dc'} ne '') {
11105: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11106: }
1.160.6.65 raeburn 11107: } else {
11108: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11109: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11110: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11111: $changes{'validation'}{'dc'} = &mt('None');
11112: }
11113: }
1.160.6.39 raeburn 11114: }
11115: }
1.102 raeburn 11116: }
11117: } else {
1.86 raeburn 11118: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 11119: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 11120: }
1.72 raeburn 11121: foreach my $item (@usertools) {
11122: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 11123: my $unset;
1.101 raeburn 11124: if ($context eq 'requestcourses') {
1.104 raeburn 11125: $unset = '0';
11126: if ($type eq '_LC_adv') {
11127: $unset = '';
11128: }
1.101 raeburn 11129: if ($confhash{$item}{$type} eq 'autolimit') {
11130: $confhash{$item}{$type} .= '=';
11131: unless ($limithash{$item}{$type} =~ /\D/) {
11132: $confhash{$item}{$type} .= $limithash{$item}{$type};
11133: }
11134: }
1.160.6.5 raeburn 11135: } elsif ($context eq 'requestauthor') {
11136: $unset = '0';
11137: if ($type eq '_LC_adv') {
11138: $unset = '';
11139: }
1.72 raeburn 11140: } else {
1.101 raeburn 11141: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
11142: $confhash{$item}{$type} = 1;
11143: } else {
11144: $confhash{$item}{$type} = 0;
11145: }
1.72 raeburn 11146: }
1.86 raeburn 11147: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 11148: if ($action eq 'requestauthor') {
11149: if ($domconfig{$action}{$type} ne $confhash{$type}) {
11150: $changes{$type} = 1;
11151: }
11152: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 11153: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
11154: $changes{$item}{$type} = 1;
11155: }
11156: } else {
11157: if ($context eq 'requestcourses') {
1.104 raeburn 11158: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 11159: $changes{$item}{$type} = 1;
11160: }
11161: } else {
11162: if (!$confhash{$item}{$type}) {
11163: $changes{$item}{$type} = 1;
11164: }
11165: }
11166: }
11167: } else {
11168: if ($context eq 'requestcourses') {
1.104 raeburn 11169: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 11170: $changes{$item}{$type} = 1;
11171: }
1.160.6.5 raeburn 11172: } elsif ($context eq 'requestauthor') {
11173: if ($confhash{$type} ne $unset) {
11174: $changes{$type} = 1;
11175: }
1.72 raeburn 11176: } else {
11177: if (!$confhash{$item}{$type}) {
11178: $changes{$item}{$type} = 1;
11179: }
11180: }
11181: }
1.1 raeburn 11182: }
11183: }
1.160.6.5 raeburn 11184: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 11185: if (ref($domconfig{'quotas'}) eq 'HASH') {
11186: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11187: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
11188: if (exists($confhash{'defaultquota'}{$key})) {
11189: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
11190: $changes{'defaultquota'}{$key} = 1;
11191: }
11192: } else {
11193: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 11194: }
11195: }
1.86 raeburn 11196: } else {
11197: foreach my $key (keys(%{$domconfig{'quotas'}})) {
11198: if (exists($confhash{'defaultquota'}{$key})) {
11199: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
11200: $changes{'defaultquota'}{$key} = 1;
11201: }
11202: } else {
11203: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 11204: }
1.1 raeburn 11205: }
11206: }
1.160.6.20 raeburn 11207: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11208: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
11209: if (exists($confhash{'authorquota'}{$key})) {
11210: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
11211: $changes{'authorquota'}{$key} = 1;
11212: }
11213: } else {
11214: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
11215: }
11216: }
11217: }
1.1 raeburn 11218: }
1.86 raeburn 11219: if (ref($confhash{'defaultquota'}) eq 'HASH') {
11220: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
11221: if (ref($domconfig{'quotas'}) eq 'HASH') {
11222: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11223: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
11224: $changes{'defaultquota'}{$key} = 1;
11225: }
11226: } else {
11227: if (!exists($domconfig{'quotas'}{$key})) {
11228: $changes{'defaultquota'}{$key} = 1;
11229: }
1.72 raeburn 11230: }
11231: } else {
1.86 raeburn 11232: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 11233: }
1.1 raeburn 11234: }
11235: }
1.160.6.20 raeburn 11236: if (ref($confhash{'authorquota'}) eq 'HASH') {
11237: foreach my $key (keys(%{$confhash{'authorquota'}})) {
11238: if (ref($domconfig{'quotas'}) eq 'HASH') {
11239: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11240: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
11241: $changes{'authorquota'}{$key} = 1;
11242: }
11243: } else {
11244: $changes{'authorquota'}{$key} = 1;
11245: }
11246: } else {
11247: $changes{'authorquota'}{$key} = 1;
11248: }
11249: }
11250: }
1.1 raeburn 11251: }
1.72 raeburn 11252:
1.160.6.5 raeburn 11253: if ($context eq 'requestauthor') {
11254: $domdefaults{'requestauthor'} = \%confhash;
11255: } else {
11256: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 11257: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 11258: $domdefaults{$key} = $confhash{$key};
11259: }
1.160.6.5 raeburn 11260: }
1.72 raeburn 11261: }
1.160.6.5 raeburn 11262:
1.1 raeburn 11263: my %quotahash = (
1.86 raeburn 11264: $action => { %confhash }
1.1 raeburn 11265: );
11266: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
11267: $dom);
11268: if ($putresult eq 'ok') {
11269: if (keys(%changes) > 0) {
1.72 raeburn 11270: my $cachetime = 24*60*60;
11271: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11272: if (ref($lastactref) eq 'HASH') {
11273: $lastactref->{'domdefaults'} = 1;
11274: }
1.1 raeburn 11275: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 11276: unless (($context eq 'requestcourses') ||
11277: ($context eq 'requestauthor')) {
1.86 raeburn 11278: if (ref($changes{'defaultquota'}) eq 'HASH') {
11279: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
11280: foreach my $type (@{$types},'default') {
11281: if (defined($changes{'defaultquota'}{$type})) {
11282: my $typetitle = $usertypes->{$type};
11283: if ($type eq 'default') {
11284: $typetitle = $othertitle;
11285: }
1.160.6.28 raeburn 11286: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 11287: }
11288: }
1.86 raeburn 11289: $resulttext .= '</ul></li>';
1.72 raeburn 11290: }
1.160.6.20 raeburn 11291: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 11292: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 11293: foreach my $type (@{$types},'default') {
11294: if (defined($changes{'authorquota'}{$type})) {
11295: my $typetitle = $usertypes->{$type};
11296: if ($type eq 'default') {
11297: $typetitle = $othertitle;
11298: }
1.160.6.28 raeburn 11299: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 11300: }
11301: }
11302: $resulttext .= '</ul></li>';
11303: }
1.72 raeburn 11304: }
1.80 raeburn 11305: my %newenv;
1.72 raeburn 11306: foreach my $item (@usertools) {
1.160.6.5 raeburn 11307: my (%haschgs,%inconf);
11308: if ($context eq 'requestauthor') {
11309: %haschgs = %changes;
11310: %inconf = %confhash;
11311: } else {
11312: if (ref($changes{$item}) eq 'HASH') {
11313: %haschgs = %{$changes{$item}};
11314: }
11315: if (ref($confhash{$item}) eq 'HASH') {
11316: %inconf = %{$confhash{$item}};
11317: }
11318: }
11319: if (keys(%haschgs) > 0) {
1.80 raeburn 11320: my $newacc =
11321: &Apache::lonnet::usertools_access($env{'user.name'},
11322: $env{'user.domain'},
1.86 raeburn 11323: $item,'reload',$context);
1.160.6.5 raeburn 11324: if (($context eq 'requestcourses') ||
11325: ($context eq 'requestauthor')) {
1.108 raeburn 11326: if ($env{'environment.canrequest.'.$item} ne $newacc) {
11327: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 11328: }
11329: } else {
11330: if ($env{'environment.availabletools.'.$item} ne $newacc) {
11331: $newenv{'environment.availabletools.'.$item} = $newacc;
11332: }
1.80 raeburn 11333: }
1.160.6.5 raeburn 11334: unless ($context eq 'requestauthor') {
11335: $resulttext .= '<li>'.$titles{$item}.'<ul>';
11336: }
1.72 raeburn 11337: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 11338: if ($haschgs{$type}) {
1.72 raeburn 11339: my $typetitle = $usertypes->{$type};
11340: if ($type eq 'default') {
11341: $typetitle = $othertitle;
11342: } elsif ($type eq '_LC_adv') {
11343: $typetitle = 'LON-CAPA Advanced Users';
11344: }
1.160.6.5 raeburn 11345: if ($inconf{$type}) {
1.101 raeburn 11346: if ($context eq 'requestcourses') {
11347: my $cond;
1.160.6.5 raeburn 11348: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 11349: if ($1 eq '') {
11350: $cond = &mt('(Automatic processing of any request).');
11351: } else {
11352: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
11353: }
11354: } else {
1.160.6.5 raeburn 11355: $cond = $conditions{$inconf{$type}};
1.101 raeburn 11356: }
11357: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 11358: } elsif ($context eq 'requestauthor') {
11359: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
11360: $titles{$inconf{$type}},$typetitle);
11361:
1.101 raeburn 11362: } else {
11363: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
11364: }
1.72 raeburn 11365: } else {
1.104 raeburn 11366: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 11367: if ($inconf{$type} eq '0') {
1.104 raeburn 11368: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11369: } else {
11370: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
11371: }
11372: } else {
11373: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11374: }
1.72 raeburn 11375: }
11376: }
1.26 raeburn 11377: }
1.160.6.5 raeburn 11378: unless ($context eq 'requestauthor') {
11379: $resulttext .= '</ul></li>';
11380: }
1.26 raeburn 11381: }
1.1 raeburn 11382: }
1.160.6.5 raeburn 11383: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 11384: if (ref($changes{'notify'}) eq 'HASH') {
11385: if ($changes{'notify'}{'approval'}) {
11386: if (ref($confhash{'notify'}) eq 'HASH') {
11387: if ($confhash{'notify'}{'approval'}) {
11388: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
11389: } else {
1.160.6.5 raeburn 11390: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 11391: }
11392: }
11393: }
11394: }
11395: }
1.160.6.30 raeburn 11396: if ($action eq 'requestcourses') {
11397: my @offon = ('off','on');
11398: if ($changes{'uniquecode'}) {
11399: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11400: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
11401: $resulttext .= '<li>'.
11402: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
11403: '</li>';
11404: } else {
11405: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
11406: '</li>';
11407: }
11408: }
1.160.6.46 raeburn 11409: foreach my $type ('textbooks','templates') {
11410: if (ref($changes{$type}) eq 'HASH') {
11411: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
11412: foreach my $key (sort(keys(%{$changes{$type}}))) {
11413: my %coursehash = &Apache::lonnet::coursedescription($key);
11414: my $coursetitle = $coursehash{'description'};
11415: my $position = $confhash{$type}{$key}{'order'} + 1;
11416: $resulttext .= '<li>';
1.160.6.47 raeburn 11417: foreach my $item ('subject','title','publisher','author') {
11418: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11419: ($type eq 'templates'));
1.160.6.46 raeburn 11420: my $name = $item.':';
11421: $name =~ s/^(\w)/\U$1/;
11422: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
11423: }
11424: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
11425: if ($type eq 'textbooks') {
11426: if ($confhash{$type}{$key}{'image'}) {
11427: $resulttext .= ' '.&mt('Image: [_1]',
11428: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
11429: ' alt="Textbook cover" />').'<br />';
11430: }
11431: }
11432: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 11433: }
1.160.6.46 raeburn 11434: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 11435: }
11436: }
1.160.6.39 raeburn 11437: if (ref($changes{'validation'}) eq 'HASH') {
11438: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
11439: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
11440: foreach my $item (@{$validationitemsref}) {
11441: if (exists($changes{'validation'}{$item})) {
11442: if ($item eq 'markup') {
11443: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11444: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
11445: } else {
11446: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11447: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
11448: }
11449: }
11450: }
11451: if (exists($changes{'validation'}{'dc'})) {
11452: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
11453: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
11454: }
11455: }
11456: }
1.160.6.30 raeburn 11457: }
1.1 raeburn 11458: $resulttext .= '</ul>';
1.80 raeburn 11459: if (keys(%newenv)) {
11460: &Apache::lonnet::appenv(\%newenv);
11461: }
1.1 raeburn 11462: } else {
1.86 raeburn 11463: if ($context eq 'requestcourses') {
11464: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 11465: } elsif ($context eq 'requestauthor') {
11466: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 11467: } else {
1.90 weissno 11468: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 11469: }
1.1 raeburn 11470: }
11471: } else {
1.11 albertel 11472: $resulttext = '<span class="LC_error">'.
11473: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11474: }
1.160.6.30 raeburn 11475: if ($errors) {
11476: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
11477: '<ul>'.$errors.'</ul></p>';
11478: }
1.3 raeburn 11479: return $resulttext;
1.1 raeburn 11480: }
11481:
1.160.6.30 raeburn 11482: sub process_textbook_image {
1.160.6.46 raeburn 11483: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 11484: my $filename = $env{'form.'.$caller.'.filename'};
11485: my ($error,$url);
11486: my ($width,$height) = (50,50);
11487: if ($configuserok eq 'ok') {
11488: if ($switchserver) {
11489: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
11490: $switchserver);
11491: } elsif ($author_ok eq 'ok') {
11492: my ($result,$imageurl) =
11493: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88 raeburn 11494: "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 11495: if ($result eq 'ok') {
11496: $url = $imageurl;
11497: } else {
11498: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11499: }
11500: } else {
11501: $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);
11502: }
11503: } else {
11504: $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);
11505: }
11506: return ($url,$error);
11507: }
11508:
1.3 raeburn 11509: sub modify_autoenroll {
1.160.6.24 raeburn 11510: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 11511: my ($resulttext,%changes);
11512: my %currautoenroll;
11513: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
11514: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
11515: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
11516: }
11517: }
11518: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
11519: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 11520: sender => 'Sender for notification messages',
1.160.6.68 raeburn 11521: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.160.6.116 raeburn 11522: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 11523: my @offon = ('off','on');
1.17 raeburn 11524: my $sender_uname = $env{'form.sender_uname'};
11525: my $sender_domain = $env{'form.sender_domain'};
11526: if ($sender_domain eq '') {
11527: $sender_uname = '';
11528: } elsif ($sender_uname eq '') {
11529: $sender_domain = '';
11530: }
1.129 raeburn 11531: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.116 raeburn 11532: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
11533: $autofailsafe =~ s{^\s+|\s+$}{}g;
11534: if ($autofailsafe =~ /\D/) {
11535: undef($autofailsafe);
11536: }
1.160.6.68 raeburn 11537: my $failsafe = $env{'form.autoenroll_failsafe'};
1.160.6.116 raeburn 11538: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
11539: $failsafe = 'off';
11540: undef($autofailsafe);
1.160.6.68 raeburn 11541: }
1.1 raeburn 11542: my %autoenrollhash = (
1.129 raeburn 11543: autoenroll => { 'run' => $env{'form.autoenroll_run'},
11544: 'sender_uname' => $sender_uname,
11545: 'sender_domain' => $sender_domain,
11546: 'co-owners' => $coowners,
1.160.6.116 raeburn 11547: 'autofailsafe' => $autofailsafe,
11548: 'failsafe' => $failsafe,
1.1 raeburn 11549: }
11550: );
1.4 raeburn 11551: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
11552: $dom);
1.1 raeburn 11553: if ($putresult eq 'ok') {
11554: if (exists($currautoenroll{'run'})) {
11555: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
11556: $changes{'run'} = 1;
11557: }
11558: } elsif ($autorun) {
11559: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 11560: $changes{'run'} = 1;
1.1 raeburn 11561: }
11562: }
1.17 raeburn 11563: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 11564: $changes{'sender'} = 1;
11565: }
1.17 raeburn 11566: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 11567: $changes{'sender'} = 1;
11568: }
1.129 raeburn 11569: if ($currautoenroll{'co-owners'} ne '') {
11570: if ($currautoenroll{'co-owners'} ne $coowners) {
11571: $changes{'coowners'} = 1;
11572: }
11573: } elsif ($coowners) {
11574: $changes{'coowners'} = 1;
1.160.6.68 raeburn 11575: }
1.160.6.116 raeburn 11576: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.160.6.68 raeburn 11577: $changes{'autofailsafe'} = 1;
11578: }
1.160.6.116 raeburn 11579: if ($currautoenroll{'failsafe'} ne $failsafe) {
11580: $changes{'failsafe'} = 1;
11581: }
1.1 raeburn 11582: if (keys(%changes) > 0) {
11583: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 11584: if ($changes{'run'}) {
1.1 raeburn 11585: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
11586: }
11587: if ($changes{'sender'}) {
1.17 raeburn 11588: if ($sender_uname eq '' || $sender_domain eq '') {
11589: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
11590: } else {
11591: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
11592: }
1.1 raeburn 11593: }
1.129 raeburn 11594: if ($changes{'coowners'}) {
11595: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
11596: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 11597: if (ref($lastactref) eq 'HASH') {
11598: $lastactref->{'domainconfig'} = 1;
11599: }
1.129 raeburn 11600: }
1.160.6.68 raeburn 11601: if ($changes{'autofailsafe'}) {
1.160.6.116 raeburn 11602: if ($autofailsafe ne '') {
11603: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.160.6.68 raeburn 11604: } else {
1.160.6.116 raeburn 11605: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.160.6.68 raeburn 11606: }
1.160.6.116 raeburn 11607: }
11608: if ($changes{'failsafe'}) {
11609: if ($failsafe eq 'off') {
11610: unless ($changes{'autofailsafe'}) {
11611: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
11612: }
11613: } elsif ($failsafe eq 'zero') {
11614: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
11615: } else {
11616: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
11617: }
11618: }
11619: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.160.6.68 raeburn 11620: &Apache::lonnet::get_domain_defaults($dom,1);
11621: if (ref($lastactref) eq 'HASH') {
11622: $lastactref->{'domdefaults'} = 1;
11623: }
11624: }
1.1 raeburn 11625: $resulttext .= '</ul>';
11626: } else {
11627: $resulttext = &mt('No changes made to auto-enrollment settings');
11628: }
11629: } else {
1.11 albertel 11630: $resulttext = '<span class="LC_error">'.
11631: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11632: }
1.3 raeburn 11633: return $resulttext;
1.1 raeburn 11634: }
11635:
11636: sub modify_autoupdate {
1.3 raeburn 11637: my ($dom,%domconfig) = @_;
1.1 raeburn 11638: my ($resulttext,%currautoupdate,%fields,%changes);
11639: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
11640: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
11641: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
11642: }
11643: }
11644: my @offon = ('off','on');
11645: my %title = &Apache::lonlocal::texthash (
1.160.6.113 raeburn 11646: run => 'Auto-update:',
11647: classlists => 'Updates to user information in classlists?',
11648: unexpired => 'Skip updates for users without active or future roles?',
11649: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 11650: );
1.44 raeburn 11651: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 11652: my %fieldtitles = &Apache::lonlocal::texthash (
11653: id => 'Student/Employee ID',
1.20 raeburn 11654: permanentemail => 'E-mail address',
1.1 raeburn 11655: lastname => 'Last Name',
11656: firstname => 'First Name',
11657: middlename => 'Middle Name',
1.132 raeburn 11658: generation => 'Generation',
1.1 raeburn 11659: );
1.142 raeburn 11660: $othertitle = &mt('All users');
1.1 raeburn 11661: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 11662: $othertitle = &mt('Other users');
1.1 raeburn 11663: }
11664: foreach my $key (keys(%env)) {
11665: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 11666: my ($usertype,$item) = ($1,$2);
11667: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
11668: if ($usertype eq 'default') {
11669: push(@{$fields{$1}},$2);
11670: } elsif (ref($types) eq 'ARRAY') {
11671: if (grep(/^\Q$usertype\E$/,@{$types})) {
11672: push(@{$fields{$1}},$2);
11673: }
11674: }
11675: }
1.1 raeburn 11676: }
11677: }
1.131 raeburn 11678: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
11679: @lockablenames = sort(@lockablenames);
11680: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
11681: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11682: if (@changed) {
11683: $changes{'lockablenames'} = 1;
11684: }
11685: } else {
11686: if (@lockablenames) {
11687: $changes{'lockablenames'} = 1;
11688: }
11689: }
1.1 raeburn 11690: my %updatehash = (
11691: autoupdate => { run => $env{'form.autoupdate_run'},
11692: classlists => $env{'form.classlists'},
1.160.6.113 raeburn 11693: unexpired => $env{'form.unexpired'},
1.1 raeburn 11694: fields => {%fields},
1.131 raeburn 11695: lockablenames => \@lockablenames,
1.1 raeburn 11696: }
11697: );
1.160.6.113 raeburn 11698: my $lastactivedays;
11699: if ($env{'form.lastactive'}) {
11700: $lastactivedays = $env{'form.lastactivedays'};
11701: $lastactivedays =~ s/^\s+|\s+$//g;
11702: unless ($lastactivedays =~ /^\d+$/) {
11703: undef($lastactivedays);
11704: $env{'form.lastactive'} = 0;
11705: }
11706: }
11707: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 11708: foreach my $key (keys(%currautoupdate)) {
1.160.6.113 raeburn 11709: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 11710: if (exists($updatehash{autoupdate}{$key})) {
11711: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
11712: $changes{$key} = 1;
11713: }
11714: }
11715: } elsif ($key eq 'fields') {
11716: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 11717: foreach my $item (@{$types},'default') {
1.1 raeburn 11718: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
11719: my $change = 0;
11720: foreach my $type (@{$currautoupdate{$key}{$item}}) {
11721: if (!exists($fields{$item})) {
11722: $change = 1;
1.132 raeburn 11723: last;
1.1 raeburn 11724: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 11725: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 11726: $change = 1;
1.132 raeburn 11727: last;
1.1 raeburn 11728: }
11729: }
11730: }
11731: if ($change) {
11732: push(@{$changes{$key}},$item);
11733: }
1.26 raeburn 11734: }
1.1 raeburn 11735: }
11736: }
1.131 raeburn 11737: } elsif ($key eq 'lockablenames') {
11738: if (ref($currautoupdate{$key}) eq 'ARRAY') {
11739: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11740: if (@changed) {
11741: $changes{'lockablenames'} = 1;
11742: }
11743: } else {
11744: if (@lockablenames) {
11745: $changes{'lockablenames'} = 1;
11746: }
11747: }
11748: }
11749: }
11750: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
11751: if (@lockablenames) {
11752: $changes{'lockablenames'} = 1;
1.1 raeburn 11753: }
11754: }
1.160.6.113 raeburn 11755: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
11756: if ($updatehash{'autoupdate'}{'unexpired'}) {
11757: $changes{'unexpired'} = 1;
11758: }
11759: }
11760: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
11761: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
11762: $changes{'lastactive'} = 1;
11763: }
11764: }
1.26 raeburn 11765: foreach my $item (@{$types},'default') {
11766: if (defined($fields{$item})) {
11767: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 11768: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
11769: my $change = 0;
11770: if (ref($fields{$item}) eq 'ARRAY') {
11771: foreach my $type (@{$fields{$item}}) {
11772: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
11773: $change = 1;
11774: last;
11775: }
11776: }
11777: }
11778: if ($change) {
11779: push(@{$changes{'fields'}},$item);
11780: }
11781: } else {
1.26 raeburn 11782: push(@{$changes{'fields'}},$item);
11783: }
11784: } else {
11785: push(@{$changes{'fields'}},$item);
1.1 raeburn 11786: }
11787: }
11788: }
11789: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
11790: $dom);
11791: if ($putresult eq 'ok') {
11792: if (keys(%changes) > 0) {
11793: $resulttext = &mt('Changes made:').'<ul>';
11794: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 11795: if ($key eq 'lockablenames') {
11796: $resulttext .= '<li>';
11797: if (@lockablenames) {
11798: $usertypes->{'default'} = $othertitle;
11799: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
11800: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
11801: } else {
11802: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
11803: }
11804: $resulttext .= '</li>';
11805: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 11806: foreach my $item (@{$changes{$key}}) {
11807: my @newvalues;
11808: foreach my $type (@{$fields{$item}}) {
11809: push(@newvalues,$fieldtitles{$type});
11810: }
1.3 raeburn 11811: my $newvaluestr;
11812: if (@newvalues > 0) {
11813: $newvaluestr = join(', ',@newvalues);
11814: } else {
11815: $newvaluestr = &mt('none');
1.6 raeburn 11816: }
1.1 raeburn 11817: if ($item eq 'default') {
1.26 raeburn 11818: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 11819: } else {
1.26 raeburn 11820: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 11821: }
11822: }
11823: } else {
11824: my $newvalue;
11825: if ($key eq 'run') {
11826: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.160.6.113 raeburn 11827: } elsif ($key eq 'lastactive') {
11828: $newvalue = $offon[$env{'form.lastactive'}];
11829: unless ($lastactivedays eq '') {
11830: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
11831: }
1.1 raeburn 11832: } else {
11833: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 11834: }
1.1 raeburn 11835: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
11836: }
11837: }
11838: $resulttext .= '</ul>';
11839: } else {
1.3 raeburn 11840: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 11841: }
11842: } else {
1.11 albertel 11843: $resulttext = '<span class="LC_error">'.
11844: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11845: }
1.3 raeburn 11846: return $resulttext;
1.1 raeburn 11847: }
11848:
1.125 raeburn 11849: sub modify_autocreate {
11850: my ($dom,%domconfig) = @_;
11851: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
11852: if (ref($domconfig{'autocreate'}) eq 'HASH') {
11853: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
11854: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
11855: }
11856: }
11857: my %title= ( xml => 'Auto-creation of courses in XML course description files',
11858: req => 'Auto-creation of validated requests for official courses',
11859: xmldc => 'Identity of course creator of courses from XML files',
11860: );
11861: my @types = ('xml','req');
11862: foreach my $item (@types) {
11863: $newvals{$item} = $env{'form.autocreate_'.$item};
11864: $newvals{$item} =~ s/\D//g;
11865: $newvals{$item} = 0 if ($newvals{$item} eq '');
11866: }
11867: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 11868: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 11869: unless (exists($domcoords{$newvals{'xmldc'}})) {
11870: $newvals{'xmldc'} = '';
11871: }
11872: %autocreatehash = (
11873: autocreate => { xml => $newvals{'xml'},
11874: req => $newvals{'req'},
11875: }
11876: );
11877: if ($newvals{'xmldc'} ne '') {
11878: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
11879: }
11880: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
11881: $dom);
11882: if ($putresult eq 'ok') {
11883: my @items = @types;
11884: if ($newvals{'xml'}) {
11885: push(@items,'xmldc');
11886: }
11887: foreach my $item (@items) {
11888: if (exists($currautocreate{$item})) {
11889: if ($currautocreate{$item} ne $newvals{$item}) {
11890: $changes{$item} = 1;
11891: }
11892: } elsif ($newvals{$item}) {
11893: $changes{$item} = 1;
11894: }
11895: }
11896: if (keys(%changes) > 0) {
11897: my @offon = ('off','on');
11898: $resulttext = &mt('Changes made:').'<ul>';
11899: foreach my $item (@types) {
11900: if ($changes{$item}) {
11901: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 11902: $resulttext .= '<li>'.
11903: &mt("$title{$item} set to [_1]$newtxt [_2]",
11904: '<b>','</b>').
11905: '</li>';
1.125 raeburn 11906: }
11907: }
11908: if ($changes{'xmldc'}) {
11909: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
11910: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 11911: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 11912: }
11913: $resulttext .= '</ul>';
11914: } else {
11915: $resulttext = &mt('No changes made to auto-creation settings');
11916: }
11917: } else {
11918: $resulttext = '<span class="LC_error">'.
11919: &mt('An error occurred: [_1]',$putresult).'</span>';
11920: }
11921: return $resulttext;
11922: }
11923:
1.23 raeburn 11924: sub modify_directorysrch {
1.160.6.81 raeburn 11925: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 11926: my ($resulttext,%changes);
11927: my %currdirsrch;
11928: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
11929: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
11930: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
11931: }
11932: }
1.160.6.72 raeburn 11933: my %title = ( available => 'Institutional directory search available',
11934: localonly => 'Other domains can search institution',
11935: lcavailable => 'LON-CAPA directory search available',
11936: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 11937: searchby => 'Search types',
11938: searchtypes => 'Search latitude');
11939: my @offon = ('off','on');
1.24 raeburn 11940: my @otherdoms = ('Yes','No');
1.23 raeburn 11941:
1.25 raeburn 11942: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 11943: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
11944: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
11945:
1.44 raeburn 11946: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 11947: if (keys(%{$usertypes}) == 0) {
11948: @cansearch = ('default');
11949: } else {
11950: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
11951: foreach my $type (@{$currdirsrch{'cansearch'}}) {
11952: if (!grep(/^\Q$type\E$/,@cansearch)) {
11953: push(@{$changes{'cansearch'}},$type);
11954: }
1.23 raeburn 11955: }
1.26 raeburn 11956: foreach my $type (@cansearch) {
11957: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
11958: push(@{$changes{'cansearch'}},$type);
11959: }
1.23 raeburn 11960: }
1.26 raeburn 11961: } else {
11962: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 11963: }
11964: }
11965:
11966: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
11967: foreach my $by (@{$currdirsrch{'searchby'}}) {
11968: if (!grep(/^\Q$by\E$/,@searchby)) {
11969: push(@{$changes{'searchby'}},$by);
11970: }
11971: }
11972: foreach my $by (@searchby) {
11973: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
11974: push(@{$changes{'searchby'}},$by);
11975: }
11976: }
11977: } else {
11978: push(@{$changes{'searchby'}},@searchby);
11979: }
1.25 raeburn 11980:
11981: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
11982: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
11983: if (!grep(/^\Q$type\E$/,@searchtypes)) {
11984: push(@{$changes{'searchtypes'}},$type);
11985: }
11986: }
11987: foreach my $type (@searchtypes) {
11988: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
11989: push(@{$changes{'searchtypes'}},$type);
11990: }
11991: }
11992: } else {
11993: if (exists($currdirsrch{'searchtypes'})) {
11994: foreach my $type (@searchtypes) {
11995: if ($type ne $currdirsrch{'searchtypes'}) {
11996: push(@{$changes{'searchtypes'}},$type);
11997: }
11998: }
11999: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
12000: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
12001: }
12002: } else {
12003: push(@{$changes{'searchtypes'}},@searchtypes);
12004: }
12005: }
12006:
1.23 raeburn 12007: my %dirsrch_hash = (
12008: directorysrch => { available => $env{'form.dirsrch_available'},
12009: cansearch => \@cansearch,
1.160.6.72 raeburn 12010: localonly => $env{'form.dirsrch_instlocalonly'},
12011: lclocalonly => $env{'form.dirsrch_domlocalonly'},
12012: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 12013: searchby => \@searchby,
1.25 raeburn 12014: searchtypes => \@searchtypes,
1.23 raeburn 12015: }
12016: );
12017: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
12018: $dom);
12019: if ($putresult eq 'ok') {
12020: if (exists($currdirsrch{'available'})) {
12021: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
12022: $changes{'available'} = 1;
12023: }
12024: } else {
12025: if ($env{'form.dirsrch_available'} eq '1') {
12026: $changes{'available'} = 1;
12027: }
12028: }
1.160.6.72 raeburn 12029: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 12030: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
12031: $changes{'lcavailable'} = 1;
12032: }
1.24 raeburn 12033: } else {
1.160.6.72 raeburn 12034: if ($env{'form.dirsrch_lcavailable'} eq '1') {
12035: $changes{'lcavailable'} = 1;
12036: }
12037: }
12038: if (exists($currdirsrch{'localonly'})) {
12039: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 12040: $changes{'localonly'} = 1;
12041: }
1.160.6.72 raeburn 12042: } else {
12043: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
12044: $changes{'localonly'} = 1;
12045: }
12046: }
12047: if (exists($currdirsrch{'lclocalonly'})) {
12048: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
12049: $changes{'lclocalonly'} = 1;
12050: }
12051: } else {
12052: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
12053: $changes{'lclocalonly'} = 1;
12054: }
1.24 raeburn 12055: }
1.23 raeburn 12056: if (keys(%changes) > 0) {
12057: $resulttext = &mt('Changes made:').'<ul>';
12058: if ($changes{'available'}) {
12059: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
12060: }
1.160.6.72 raeburn 12061: if ($changes{'lcavailable'}) {
12062: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
12063: }
1.24 raeburn 12064: if ($changes{'localonly'}) {
1.160.6.72 raeburn 12065: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
12066: }
12067: if ($changes{'lclocalonly'}) {
12068: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 12069: }
1.23 raeburn 12070: if (ref($changes{'cansearch'}) eq 'ARRAY') {
12071: my $chgtext;
1.26 raeburn 12072: if (ref($usertypes) eq 'HASH') {
12073: if (keys(%{$usertypes}) > 0) {
12074: foreach my $type (@{$types}) {
12075: if (grep(/^\Q$type\E$/,@cansearch)) {
12076: $chgtext .= $usertypes->{$type}.'; ';
12077: }
12078: }
12079: if (grep(/^default$/,@cansearch)) {
12080: $chgtext .= $othertitle;
12081: } else {
12082: $chgtext =~ s/\; $//;
12083: }
1.160.6.13 raeburn 12084: $resulttext .=
12085: '<li>'.
12086: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
12087: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
12088: '</li>';
1.23 raeburn 12089: }
12090: }
12091: }
12092: if (ref($changes{'searchby'}) eq 'ARRAY') {
12093: my ($searchtitles,$titleorder) = &sorted_searchtitles();
12094: my $chgtext;
12095: foreach my $type (@{$titleorder}) {
12096: if (grep(/^\Q$type\E$/,@searchby)) {
12097: if (defined($searchtitles->{$type})) {
12098: $chgtext .= $searchtitles->{$type}.'; ';
12099: }
12100: }
12101: }
12102: $chgtext =~ s/\; $//;
12103: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
12104: }
1.25 raeburn 12105: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
12106: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
12107: my $chgtext;
12108: foreach my $type (@{$srchtypeorder}) {
12109: if (grep(/^\Q$type\E$/,@searchtypes)) {
12110: if (defined($srchtypes_desc->{$type})) {
12111: $chgtext .= $srchtypes_desc->{$type}.'; ';
12112: }
12113: }
12114: }
12115: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 12116: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 12117: }
12118: $resulttext .= '</ul>';
1.160.6.81 raeburn 12119: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
12120: if (ref($lastactref) eq 'HASH') {
12121: $lastactref->{'directorysrch'} = 1;
12122: }
1.23 raeburn 12123: } else {
1.160.6.72 raeburn 12124: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 12125: }
12126: } else {
12127: $resulttext = '<span class="LC_error">'.
1.27 raeburn 12128: &mt('An error occurred: [_1]',$putresult).'</span>';
12129: }
12130: return $resulttext;
12131: }
12132:
1.28 raeburn 12133: sub modify_contacts {
1.160.6.24 raeburn 12134: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 12135: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
12136: if (ref($domconfig{'contacts'}) eq 'HASH') {
12137: foreach my $key (keys(%{$domconfig{'contacts'}})) {
12138: $currsetting{$key} = $domconfig{'contacts'}{$key};
12139: }
12140: }
1.160.6.78 raeburn 12141: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 12142: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 12143: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 12144: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.107 raeburn 12145: my @toggles = ('reporterrors','reportupdates','reportstatus');
12146: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.160.6.78 raeburn 12147: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 12148: foreach my $type (@mailings) {
12149: @{$newsetting{$type}} =
12150: &Apache::loncommon::get_env_multiple('form.'.$type);
12151: foreach my $item (@contacts) {
12152: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
12153: $contacts_hash{contacts}{$type}{$item} = 1;
12154: } else {
12155: $contacts_hash{contacts}{$type}{$item} = 0;
12156: }
1.160.6.78 raeburn 12157: }
1.28 raeburn 12158: $others{$type} = $env{'form.'.$type.'_others'};
12159: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 12160: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12161: $bcc{$type} = $env{'form.'.$type.'_bcc'};
12162: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 12163: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
12164: $includestr{$type} = $env{'form.'.$type.'_includestr'};
12165: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
12166: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12167: }
1.134 raeburn 12168: }
1.28 raeburn 12169: }
12170: foreach my $item (@contacts) {
12171: $to{$item} = $env{'form.'.$item};
12172: $contacts_hash{'contacts'}{$item} = $to{$item};
12173: }
1.160.6.23 raeburn 12174: foreach my $item (@toggles) {
12175: if ($env{'form.'.$item} =~ /^(0|1)$/) {
12176: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
12177: }
12178: }
1.160.6.107 raeburn 12179: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
12180: foreach my $item (@lonstatus) {
12181: if ($item eq 'excluded') {
12182: my (%serverhomes,@excluded);
12183: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
12184: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
12185: if (@possexcluded) {
12186: foreach my $id (sort(@possexcluded)) {
12187: if ($serverhomes{$id}) {
12188: push(@excluded,$id);
12189: }
12190: }
12191: }
12192: if (@excluded) {
12193: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
12194: }
12195: } elsif ($item eq 'weights') {
12196: foreach my $type ('E','W','N','U') {
12197: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
12198: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
12199: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
12200: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
12201: $env{'form.error'.$item.'_'.$type};
12202: }
12203: }
12204: }
12205: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
12206: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
12207: if ($env{'form.error'.$item} =~ /^\d+$/) {
12208: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
12209: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
12210: }
12211: }
12212: }
12213: }
1.160.6.78 raeburn 12214: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
12215: foreach my $field (@{$fields}) {
12216: if (ref($possoptions->{$field}) eq 'ARRAY') {
12217: my $value = $env{'form.helpform_'.$field};
12218: $value =~ s/^\s+|\s+$//g;
12219: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101 raeburn 12220: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 12221: if ($field eq 'screenshot') {
12222: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
12223: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101 raeburn 12224: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 12225: }
12226: }
12227: }
12228: }
12229: }
12230: }
1.160.6.101 raeburn 12231: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12232: my (@statuses,%usertypeshash,@overrides);
12233: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
12234: @statuses = @{$types};
12235: if (ref($usertypes) eq 'HASH') {
12236: %usertypeshash = %{$usertypes};
12237: }
12238: }
12239: if (@statuses) {
12240: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
12241: foreach my $type (@possoverrides) {
12242: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
12243: push(@overrides,$type);
12244: }
12245: }
12246: if (@overrides) {
12247: foreach my $type (@overrides) {
12248: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
12249: foreach my $item (@contacts) {
12250: if (grep(/^\Q$item\E$/,@standard)) {
12251: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
12252: $newsetting{'override_'.$type}{$item} = 1;
12253: } else {
12254: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
12255: $newsetting{'override_'.$type}{$item} = 0;
12256: }
12257: }
12258: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
12259: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12260: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
12261: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12262: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
12263: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
12264: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
12265: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12266: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
12267: }
12268: }
12269: }
12270: }
1.28 raeburn 12271: if (keys(%currsetting) > 0) {
12272: foreach my $item (@contacts) {
12273: if ($to{$item} ne $currsetting{$item}) {
12274: $changes{$item} = 1;
12275: }
12276: }
12277: foreach my $type (@mailings) {
12278: foreach my $item (@contacts) {
12279: if (ref($currsetting{$type}) eq 'HASH') {
12280: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
12281: push(@{$changes{$type}},$item);
12282: }
12283: } else {
12284: push(@{$changes{$type}},@{$newsetting{$type}});
12285: }
12286: }
12287: if ($others{$type} ne $currsetting{$type}{'others'}) {
12288: push(@{$changes{$type}},'others');
12289: }
1.160.6.78 raeburn 12290: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12291: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
12292: push(@{$changes{$type}},'bcc');
12293: }
1.160.6.78 raeburn 12294: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
12295: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
12296: push(@{$changes{$type}},'include');
12297: }
12298: }
12299: }
12300: if (ref($fields) eq 'ARRAY') {
12301: if (ref($currsetting{'helpform'}) eq 'HASH') {
12302: foreach my $field (@{$fields}) {
12303: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
12304: push(@{$changes{'helpform'}},$field);
12305: }
12306: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12307: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
12308: push(@{$changes{'helpform'}},'maxsize');
12309: }
12310: }
12311: }
12312: } else {
12313: foreach my $field (@{$fields}) {
12314: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12315: push(@{$changes{'helpform'}},$field);
12316: }
12317: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12318: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12319: push(@{$changes{'helpform'}},'maxsize');
12320: }
12321: }
12322: }
1.134 raeburn 12323: }
1.28 raeburn 12324: }
1.160.6.101 raeburn 12325: if (@statuses) {
12326: if (ref($currsetting{'overrides'}) eq 'HASH') {
12327: foreach my $key (keys(%{$currsetting{'overrides'}})) {
12328: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
12329: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
12330: foreach my $item (@contacts,'bcc','others','include') {
12331: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
12332: push(@{$changes{'overrides'}},$key);
12333: last;
12334: }
12335: }
12336: } else {
12337: push(@{$changes{'overrides'}},$key);
12338: }
12339: }
12340: }
12341: foreach my $key (@overrides) {
12342: unless (exists($currsetting{'overrides'}{$key})) {
12343: push(@{$changes{'overrides'}},$key);
12344: }
12345: }
12346: } else {
12347: foreach my $key (@overrides) {
12348: push(@{$changes{'overrides'}},$key);
12349: }
12350: }
12351: }
1.160.6.107 raeburn 12352: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
12353: foreach my $key ('excluded','weights','threshold','sysmail') {
12354: if ($key eq 'excluded') {
12355: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
12356: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
12357: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
12358: (@{$currsetting{'lonstatus'}{$key}})) {
12359: my @diffs =
12360: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
12361: $currsetting{'lonstatus'}{$key});
12362: if (@diffs) {
12363: push(@{$changes{'lonstatus'}},$key);
12364: }
12365: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
12366: push(@{$changes{'lonstatus'}},$key);
12367: }
12368: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
12369: (@{$currsetting{'lonstatus'}{$key}})) {
12370: push(@{$changes{'lonstatus'}},$key);
12371: }
12372: } elsif ($key eq 'weights') {
12373: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
12374: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
12375: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
12376: foreach my $type ('E','W','N','U') {
12377: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
12378: $currsetting{'lonstatus'}{$key}{$type}) {
12379: push(@{$changes{'lonstatus'}},$key);
12380: last;
12381: }
12382: }
12383: } else {
12384: foreach my $type ('E','W','N','U') {
12385: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
12386: push(@{$changes{'lonstatus'}},$key);
12387: last;
12388: }
12389: }
12390: }
12391: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
12392: foreach my $type ('E','W','N','U') {
12393: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
12394: push(@{$changes{'lonstatus'}},$key);
12395: last;
12396: }
12397: }
12398: }
12399: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
12400: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12401: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
12402: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
12403: push(@{$changes{'lonstatus'}},$key);
12404: }
12405: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
12406: push(@{$changes{'lonstatus'}},$key);
12407: }
12408: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
12409: push(@{$changes{'lonstatus'}},$key);
12410: }
12411: }
12412: }
12413: } else {
12414: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12415: foreach my $key ('excluded','weights','threshold','sysmail') {
12416: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
12417: push(@{$changes{'lonstatus'}},$key);
12418: }
12419: }
12420: }
12421: }
1.28 raeburn 12422: } else {
12423: my %default;
12424: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
12425: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
12426: $default{'errormail'} = 'adminemail';
12427: $default{'packagesmail'} = 'adminemail';
12428: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 12429: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 12430: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 12431: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 12432: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 12433: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 12434: foreach my $item (@contacts) {
12435: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 12436: $changes{$item} = 1;
1.160.6.23 raeburn 12437: }
1.28 raeburn 12438: }
12439: foreach my $type (@mailings) {
12440: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
12441: push(@{$changes{$type}},@{$newsetting{$type}});
12442: }
12443: if ($others{$type} ne '') {
12444: push(@{$changes{$type}},'others');
1.134 raeburn 12445: }
1.160.6.78 raeburn 12446: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12447: if ($bcc{$type} ne '') {
12448: push(@{$changes{$type}},'bcc');
12449: }
1.160.6.78 raeburn 12450: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
12451: push(@{$changes{$type}},'include');
12452: }
12453: }
12454: }
12455: if (ref($fields) eq 'ARRAY') {
12456: foreach my $field (@{$fields}) {
12457: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12458: push(@{$changes{'helpform'}},$field);
12459: }
12460: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12461: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12462: push(@{$changes{'helpform'}},'maxsize');
12463: }
12464: }
1.134 raeburn 12465: }
1.28 raeburn 12466: }
1.160.6.107 raeburn 12467: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12468: foreach my $key ('excluded','weights','threshold','sysmail') {
12469: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
12470: push(@{$changes{'lonstatus'}},$key);
12471: }
12472: }
12473: }
1.28 raeburn 12474: }
1.160.6.23 raeburn 12475: foreach my $item (@toggles) {
12476: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
12477: $changes{$item} = 1;
12478: } elsif ((!$env{'form.'.$item}) &&
12479: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
12480: $changes{$item} = 1;
12481: }
12482: }
1.28 raeburn 12483: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
12484: $dom);
12485: if ($putresult eq 'ok') {
12486: if (keys(%changes) > 0) {
1.160.6.24 raeburn 12487: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 12488: if (ref($lastactref) eq 'HASH') {
12489: $lastactref->{'domainconfig'} = 1;
12490: }
1.28 raeburn 12491: my ($titles,$short_titles) = &contact_titles();
12492: $resulttext = &mt('Changes made:').'<ul>';
12493: foreach my $item (@contacts) {
12494: if ($changes{$item}) {
12495: $resulttext .= '<li>'.$titles->{$item}.
12496: &mt(' set to: ').
12497: '<span class="LC_cusr_emph">'.
12498: $to{$item}.'</span></li>';
12499: }
12500: }
12501: foreach my $type (@mailings) {
12502: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 12503: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
12504: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
12505: } else {
12506: $resulttext .= '<li>'.$titles->{$type}.': ';
12507: }
1.28 raeburn 12508: my @text;
12509: foreach my $item (@{$newsetting{$type}}) {
12510: push(@text,$short_titles->{$item});
12511: }
12512: if ($others{$type} ne '') {
12513: push(@text,$others{$type});
12514: }
1.160.6.78 raeburn 12515: if (@text) {
12516: $resulttext .= '<span class="LC_cusr_emph">'.
12517: join(', ',@text).'</span>';
12518: }
12519: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12520: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 12521: my $bcctext;
12522: if (@text) {
12523: $bcctext = ' '.&mt('with Bcc to');
12524: } else {
12525: $bcctext = '(Bcc)';
12526: }
12527: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
12528: } elsif (!@text) {
12529: $resulttext .= &mt('No one');
1.134 raeburn 12530: }
1.160.6.78 raeburn 12531: if ($includestr{$type} ne '') {
12532: if ($includeloc{$type} eq 'b') {
12533: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
12534: } elsif ($includeloc{$type} eq 's') {
12535: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
12536: }
12537: }
12538: } elsif (!@text) {
12539: $resulttext .= &mt('No recipients');
1.134 raeburn 12540: }
12541: $resulttext .= '</li>';
1.28 raeburn 12542: }
12543: }
1.160.6.101 raeburn 12544: if (ref($changes{'overrides'}) eq 'ARRAY') {
12545: my @deletions;
12546: foreach my $type (@{$changes{'overrides'}}) {
12547: if ($usertypeshash{$type}) {
12548: if (grep(/^\Q$type\E/,@overrides)) {
12549: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
12550: $usertypeshash{$type}).'<ul><li>';
12551: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
12552: my @text;
12553: foreach my $item (@contacts) {
12554: if ($newsetting{'override_'.$type}{$item}) {
12555: push(@text,$short_titles->{$item});
12556: }
12557: }
12558: if ($newsetting{'override_'.$type}{'others'} ne '') {
12559: push(@text,$newsetting{'override_'.$type}{'others'});
12560: }
12561:
12562: if (@text) {
12563: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
12564: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
12565: }
12566: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
12567: my $bcctext;
12568: if (@text) {
12569: $bcctext = ' '.&mt('with Bcc to');
12570: } else {
12571: $bcctext = '(Bcc)';
12572: }
12573: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
12574: } elsif (!@text) {
12575: $resulttext .= &mt('Helpdesk e-mail sent to no one');
12576: }
12577: $resulttext .= '</li>';
12578: if ($newsetting{'override_'.$type}{'include'} ne '') {
12579: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
12580: if ($loc eq 'b') {
12581: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
12582: } elsif ($loc eq 's') {
12583: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
12584: }
12585: }
12586: }
12587: $resulttext .= '</li></ul></li>';
12588: } else {
12589: push(@deletions,$usertypeshash{$type});
12590: }
12591: }
12592: }
12593: if (@deletions) {
12594: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
12595: join(', ',@deletions)).'</li>';
12596: }
12597: }
1.160.6.23 raeburn 12598: my @offon = ('off','on');
1.160.6.107 raeburn 12599: my $corelink = &core_link_msu();
1.160.6.23 raeburn 12600: if ($changes{'reporterrors'}) {
12601: $resulttext .= '<li>'.
12602: &mt('E-mail error reports to [_1] set to "'.
12603: $offon[$env{'form.reporterrors'}].'".',
1.160.6.107 raeburn 12604: $corelink).
1.160.6.23 raeburn 12605: '</li>';
12606: }
12607: if ($changes{'reportupdates'}) {
12608: $resulttext .= '<li>'.
12609: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
12610: $offon[$env{'form.reportupdates'}].'".',
1.160.6.107 raeburn 12611: $corelink).
1.160.6.23 raeburn 12612: '</li>';
12613: }
1.160.6.107 raeburn 12614: if ($changes{'reportstatus'}) {
12615: $resulttext .= '<li>'.
12616: &mt('E-mail status if errors above threshold to [_1] set to "'.
12617: $offon[$env{'form.reportstatus'}].'".',
12618: $corelink).
12619: '</li>';
12620: }
12621: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
12622: $resulttext .= '<li>'.
12623: &mt('Nightly status check e-mail settings').':<ul>';
12624: my (%defval,%use_def,%shown);
12625: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
12626: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
12627: $defval{'weights'} =
12628: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
12629: $defval{'excluded'} = &mt('None');
12630: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
12631: foreach my $item ('threshold','sysmail','weights','excluded') {
12632: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
12633: if (($item eq 'threshold') || ($item eq 'sysmail')) {
12634: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
12635: } elsif ($item eq 'weights') {
12636: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
12637: foreach my $type ('E','W','N','U') {
12638: $shown{$item} .= $lonstatus_names->{$type}.'=';
12639: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
12640: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
12641: } else {
12642: $shown{$item} .= $lonstatus_defs->{$type};
12643: }
12644: $shown{$item} .= ', ';
12645: }
12646: $shown{$item} =~ s/, $//;
12647: } else {
12648: $shown{$item} = $defval{$item};
12649: }
12650: } elsif ($item eq 'excluded') {
12651: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
12652: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
12653: } else {
12654: $shown{$item} = $defval{$item};
12655: }
12656: }
12657: } else {
12658: $shown{$item} = $defval{$item};
12659: }
12660: }
12661: } else {
12662: foreach my $item ('threshold','weights','excluded','sysmail') {
12663: $shown{$item} = $defval{$item};
12664: }
12665: }
12666: foreach my $item ('threshold','weights','excluded','sysmail') {
12667: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
12668: $shown{$item}).'</li>';
12669: }
12670: $resulttext .= '</ul></li>';
12671: }
1.160.6.78 raeburn 12672: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
12673: my (@optional,@required,@unused,$maxsizechg);
12674: foreach my $field (@{$changes{'helpform'}}) {
12675: if ($field eq 'maxsize') {
12676: $maxsizechg = 1;
12677: next;
12678: }
12679: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
12680: push(@optional,$field);
12681: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
12682: push(@unused,$field);
12683: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
12684: push(@required,$field);
12685: }
12686: }
12687: if (@optional) {
12688: $resulttext .= '<li>'.
12689: &mt('Help form fields changed to "Optional": [_1].',
12690: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
12691: '</li>';
12692: }
12693: if (@required) {
12694: $resulttext .= '<li>'.
12695: &mt('Help form fields changed to "Required": [_1].',
12696: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
12697: '</li>';
12698: }
12699: if (@unused) {
12700: $resulttext .= '<li>'.
12701: &mt('Help form fields changed to "Not shown": [_1].',
12702: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
12703: '</li>';
12704: }
12705: if ($maxsizechg) {
12706: $resulttext .= '<li>'.
12707: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
12708: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
12709: '</li>';
12710: }
12711: }
1.28 raeburn 12712: $resulttext .= '</ul>';
12713: } else {
1.160.6.78 raeburn 12714: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 12715: }
12716: } else {
12717: $resulttext = '<span class="LC_error">'.
12718: &mt('An error occurred: [_1].',$putresult).'</span>';
12719: }
12720: return $resulttext;
12721: }
12722:
1.160.6.98 raeburn 12723: sub modify_passwords {
12724: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
12725: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
12726: $updatedefaults,$updateconf);
12727: my $customfn = 'resetpw.html';
12728: if (ref($domconfig{'passwords'}) eq 'HASH') {
12729: %current = %{$domconfig{'passwords'}};
12730: }
12731: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12732: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12733: if (ref($types) eq 'ARRAY') {
12734: @oktypes = @{$types};
12735: }
12736: push(@oktypes,'default');
12737:
12738: my %titles = &Apache::lonlocal::texthash (
12739: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
12740: intauth_check => 'Check bcrypt cost if authenticated',
12741: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
12742: permanent => 'Permanent e-mail address',
12743: critical => 'Critical notification address',
12744: notify => 'Notification address',
12745: min => 'Minimum password length',
12746: max => 'Maximum password length',
12747: chars => 'Required characters',
12748: numsaved => 'Number of previous passwords to save',
12749: reset => 'Resetting Forgotten Password',
12750: intauth => 'Encryption of Stored Passwords (Internal Auth)',
12751: rules => 'Rules for LON-CAPA Passwords',
12752: crsownerchg => 'Course Owner Changing Student Passwords',
12753: username => 'Username',
12754: email => 'E-mail address',
12755: );
12756:
12757: #
12758: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
12759: #
12760: my (%curr_defaults,%save_defaults);
12761: if (ref($domconfig{'defaults'}) eq 'HASH') {
12762: foreach my $key (keys(%{$domconfig{'defaults'}})) {
12763: if ($key =~ /^intauth_(cost|check|switch)$/) {
12764: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
12765: } else {
12766: $save_defaults{$key} = $domconfig{'defaults'}{$key};
12767: }
12768: }
12769: }
12770: my %staticdefaults = (
12771: 'resetlink' => 2,
12772: 'resetcase' => \@oktypes,
12773: 'resetprelink' => 'both',
12774: 'resetemail' => ['critical','notify','permanent'],
12775: 'intauth_cost' => 10,
12776: 'intauth_check' => 0,
12777: 'intauth_switch' => 0,
12778: );
1.160.6.99 raeburn 12779: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 12780: foreach my $type (@oktypes) {
12781: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
12782: }
12783: my $linklife = $env{'form.passwords_link'};
12784: $linklife =~ s/^\s+|\s+$//g;
12785: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
12786: $newvalues{'resetlink'} = $linklife;
12787: if ($current{'resetlink'}) {
12788: if ($current{'resetlink'} ne $linklife) {
12789: $changes{'reset'} = 1;
12790: }
1.160.6.102 raeburn 12791: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12792: if ($staticdefaults{'resetlink'} ne $linklife) {
12793: $changes{'reset'} = 1;
12794: }
12795: }
12796: } elsif ($current{'resetlink'}) {
12797: $changes{'reset'} = 1;
12798: }
12799: my @casesens;
12800: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
12801: foreach my $case (sort(@posscase)) {
12802: if (grep(/^\Q$case\E$/,@oktypes)) {
12803: push(@casesens,$case);
12804: }
12805: }
12806: $newvalues{'resetcase'} = \@casesens;
12807: if (ref($current{'resetcase'}) eq 'ARRAY') {
12808: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
12809: if (@diffs > 0) {
12810: $changes{'reset'} = 1;
12811: }
1.160.6.102 raeburn 12812: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12813: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
12814: if (@diffs > 0) {
12815: $changes{'reset'} = 1;
12816: }
12817: }
12818: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
12819: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
12820: if (exists($current{'resetprelink'})) {
12821: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
12822: $changes{'reset'} = 1;
12823: }
1.160.6.102 raeburn 12824: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12825: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
12826: $changes{'reset'} = 1;
12827: }
12828: }
12829: } elsif ($current{'resetprelink'}) {
12830: $changes{'reset'} = 1;
12831: }
12832: foreach my $type (@oktypes) {
12833: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
12834: my @postlink;
12835: foreach my $item (sort(@possplink)) {
12836: if ($item =~ /^(email|username)$/) {
12837: push(@postlink,$item);
12838: }
12839: }
12840: $newvalues{'resetpostlink'}{$type} = \@postlink;
12841: unless ($changes{'reset'}) {
12842: if (ref($current{'resetpostlink'}) eq 'HASH') {
12843: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
12844: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
12845: if (@diffs > 0) {
12846: $changes{'reset'} = 1;
12847: }
12848: } else {
12849: $changes{'reset'} = 1;
12850: }
1.160.6.102 raeburn 12851: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12852: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
12853: if (@diffs > 0) {
12854: $changes{'reset'} = 1;
12855: }
12856: }
12857: }
12858: }
12859: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
12860: my @resetemail;
12861: foreach my $item (sort(@possemailsrc)) {
12862: if ($item =~ /^(permanent|critical|notify)$/) {
12863: push(@resetemail,$item);
12864: }
12865: }
12866: $newvalues{'resetemail'} = \@resetemail;
12867: unless ($changes{'reset'}) {
12868: if (ref($current{'resetemail'}) eq 'ARRAY') {
12869: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
12870: if (@diffs > 0) {
12871: $changes{'reset'} = 1;
12872: }
1.160.6.102 raeburn 12873: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12874: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
12875: if (@diffs > 0) {
12876: $changes{'reset'} = 1;
12877: }
12878: }
12879: }
12880: if ($env{'form.passwords_stdtext'} == 0) {
12881: $newvalues{'resetremove'} = 1;
12882: unless ($current{'resetremove'}) {
12883: $changes{'reset'} = 1;
12884: }
12885: } elsif ($current{'resetremove'}) {
12886: $changes{'reset'} = 1;
12887: }
12888: if ($env{'form.passwords_customfile.filename'} ne '') {
12889: my $servadm = $r->dir_config('lonAdmEMail');
12890: my $servadm = $r->dir_config('lonAdmEMail');
12891: my ($configuserok,$author_ok,$switchserver) =
12892: &config_check($dom,$confname,$servadm);
12893: my $error;
12894: if ($configuserok eq 'ok') {
12895: if ($switchserver) {
12896: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
12897: } else {
12898: if ($author_ok eq 'ok') {
12899: my ($result,$customurl) =
12900: &publishlogo($r,'upload','passwords_customfile',$dom,
12901: $confname,'customtext/resetpw','','',$customfn);
12902: if ($result eq 'ok') {
12903: $newvalues{'resetcustom'} = $customurl;
12904: $changes{'reset'} = 1;
12905: } else {
12906: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
12907: }
12908: } else {
12909: $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);
12910: }
12911: }
12912: } else {
12913: $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);
12914: }
12915: if ($error) {
12916: &Apache::lonnet::logthis($error);
12917: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12918: }
12919: } elsif ($current{'resetcustom'}) {
12920: if ($env{'form.passwords_custom_del'}) {
12921: $changes{'reset'} = 1;
12922: } else {
12923: $newvalues{'resetcustom'} = $current{'resetcustom'};
12924: }
12925: }
12926: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
12927: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
12928: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
12929: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
12930: $changes{'intauth'} = 1;
12931: }
12932: } else {
12933: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
12934: }
12935: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
12936: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
12937: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
12938: $changes{'intauth'} = 1;
12939: }
12940: } else {
12941: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
12942: }
12943: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
12944: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
12945: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
12946: $changes{'intauth'} = 1;
12947: }
12948: } else {
12949: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
12950: }
12951: foreach my $item ('cost','check','switch') {
12952: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
12953: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
12954: $updatedefaults = 1;
12955: }
12956: }
12957: foreach my $rule ('min','max','numsaved') {
12958: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.160.6.99 raeburn 12959: my $ruleok;
12960: if ($rule eq 'min') {
12961: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
12962: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
12963: $ruleok = 1;
12964: }
12965: }
12966: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
12967: ($env{'form.passwords_'.$rule} ne '0')) {
12968: $ruleok = 1;
12969: }
12970: if ($ruleok) {
1.160.6.98 raeburn 12971: $newvalues{$rule} = $env{'form.passwords_'.$rule};
12972: if (exists($current{$rule})) {
12973: if ($newvalues{$rule} ne $current{$rule}) {
12974: $changes{'rules'} = 1;
12975: }
12976: } elsif ($rule eq 'min') {
12977: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
12978: $changes{'rules'} = 1;
12979: }
1.160.6.104 raeburn 12980: } else {
12981: $changes{'rules'} = 1;
1.160.6.98 raeburn 12982: }
12983: } elsif (exists($current{$rule})) {
12984: $changes{'rules'} = 1;
12985: }
12986: }
12987: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
12988: my @chars;
12989: foreach my $item (sort(@posschars)) {
12990: if ($item =~ /^(uc|lc|num|spec)$/) {
12991: push(@chars,$item);
12992: }
12993: }
12994: $newvalues{'chars'} = \@chars;
12995: unless ($changes{'rules'}) {
12996: if (ref($current{'chars'}) eq 'ARRAY') {
12997: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
12998: if (@diffs > 0) {
12999: $changes{'rules'} = 1;
13000: }
13001: } else {
13002: if (@chars > 0) {
13003: $changes{'rules'} = 1;
13004: }
13005: }
13006: }
13007: my %crsownerchg = (
13008: by => [],
13009: for => [],
13010: );
13011: foreach my $item ('by','for') {
13012: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
13013: foreach my $type (sort(@posstypes)) {
13014: if (grep(/^\Q$type\E$/,@oktypes)) {
13015: push(@{$crsownerchg{$item}},$type);
13016: }
13017: }
13018: }
13019: $newvalues{'crsownerchg'} = \%crsownerchg;
13020: if (ref($current{'crsownerchg'}) eq 'HASH') {
13021: foreach my $item ('by','for') {
13022: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
13023: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
13024: if (@diffs > 0) {
13025: $changes{'crsownerchg'} = 1;
13026: last;
13027: }
13028: }
13029: }
1.160.6.102 raeburn 13030: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98 raeburn 13031: foreach my $item ('by','for') {
13032: if (@{$crsownerchg{$item}} > 0) {
13033: $changes{'crsownerchg'} = 1;
13034: last;
13035: }
13036: }
13037: }
13038:
13039: my %confighash = (
13040: defaults => \%save_defaults,
13041: passwords => \%newvalues,
13042: );
13043: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
13044:
13045: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
13046: if ($putresult eq 'ok') {
13047: if (keys(%changes) > 0) {
13048: $resulttext = &mt('Changes made: ').'<ul>';
13049: foreach my $key ('reset','intauth','rules','crsownerchg') {
13050: if ($changes{$key}) {
13051: unless ($key eq 'intauth') {
13052: $updateconf = 1;
13053: }
13054: $resulttext .= '<li>'.$titles{$key}.':<ul>';
13055: if ($key eq 'reset') {
13056: if ($confighash{'passwords'}{'captcha'} eq 'original') {
13057: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
13058: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
13059: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.160.6.104 raeburn 13060: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
13061: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
13062: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
13063: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
13064: }
1.160.6.98 raeburn 13065: } else {
13066: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
13067: }
13068: if ($confighash{'passwords'}{'resetlink'}) {
13069: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
13070: } else {
13071: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
13072: &mt('Will default to 2 hours').'</li>';
13073: }
13074: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
13075: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
13076: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
13077: } else {
13078: my $casesens;
13079: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
13080: if ($type eq 'default') {
13081: $casesens .= $othertitle.', ';
13082: } elsif ($usertypes->{$type} ne '') {
13083: $casesens .= $usertypes->{$type}.', ';
13084: }
13085: }
13086: $casesens =~ s/\Q, \E$//;
13087: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
13088: }
13089: } else {
13090: $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>';
13091: }
13092: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
13093: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
13094: } else {
13095: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
13096: }
13097: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
13098: my $output;
13099: if (ref($types) eq 'ARRAY') {
13100: foreach my $type (@{$types}) {
13101: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
13102: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
13103: $output .= $usertypes->{$type}.' -- '.&mt('none');
13104: } else {
13105: $output .= $usertypes->{$type}.' -- '.
13106: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
13107: }
13108: }
13109: }
13110: }
13111: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
13112: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
13113: $output .= $othertitle.' -- '.&mt('none');
13114: } else {
13115: $output .= $othertitle.' -- '.
13116: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
13117: }
13118: }
13119: if ($output) {
13120: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
13121: } else {
13122: $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>';
13123: }
13124: } else {
13125: $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>';
13126: }
13127: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
13128: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
13129: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
13130: } else {
13131: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
13132: }
13133: } else {
1.160.6.110 raeburn 13134: $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 13135: }
13136: if ($confighash{'passwords'}{'resetremove'}) {
13137: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
13138: } else {
13139: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
13140: }
13141: if ($confighash{'passwords'}{'resetcustom'}) {
13142: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.160.6.104 raeburn 13143: &mt('custom text'),600,500,undef,undef,
13144: undef,undef,'background-color:#ffffff');
13145: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.160.6.98 raeburn 13146: } else {
13147: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
13148: }
13149: } elsif ($key eq 'intauth') {
13150: foreach my $item ('cost','switch','check') {
13151: my $value = $save_defaults{$key.'_'.$item};
13152: if ($item eq 'switch') {
13153: my %optiondesc = &Apache::lonlocal::texthash (
13154: 0 => 'No',
13155: 1 => 'Yes',
13156: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
13157: );
13158: if ($value =~ /^(0|1|2)$/) {
13159: $value = $optiondesc{$value};
13160: } else {
13161: $value = &mt('none -- defaults to No');
13162: }
13163: } elsif ($item eq 'check') {
13164: my %optiondesc = &Apache::lonlocal::texthash (
13165: 0 => 'No',
13166: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
13167: 2 => 'Yes, disallow login if stored cost is less than domain default',
13168: );
13169: if ($value =~ /^(0|1|2)$/) {
13170: $value = $optiondesc{$value};
13171: } else {
13172: $value = &mt('none -- defaults to No');
13173: }
13174: }
13175: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
13176: }
13177: } elsif ($key eq 'rules') {
13178: foreach my $rule ('min','max','numsaved') {
13179: if ($confighash{'passwords'}{$rule} eq '') {
13180: if ($rule eq 'min') {
13181: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99 raeburn 13182: ' '.&mt('Default of [_1] will be used',
13183: $Apache::lonnet::passwdmin).'</li>';
1.160.6.98 raeburn 13184: } else {
13185: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
13186: }
13187: } else {
13188: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
13189: }
13190: }
1.160.6.104 raeburn 13191: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
13192: if (@{$confighash{'passwords'}{'chars'}} > 0) {
13193: my %rulenames = &Apache::lonlocal::texthash(
13194: uc => 'At least one upper case letter',
13195: lc => 'At least one lower case letter',
13196: num => 'At least one number',
13197: spec => 'At least one non-alphanumeric',
13198: );
13199: my $needed = '<ul><li>'.
13200: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
13201: '</li></ul>';
13202: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
13203: } else {
13204: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13205: }
13206: } else {
13207: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13208: }
1.160.6.98 raeburn 13209: } elsif ($key eq 'crsownerchg') {
13210: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
13211: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
13212: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
13213: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
13214: } else {
13215: my %crsownerstr;
13216: foreach my $item ('by','for') {
13217: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
13218: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
13219: if ($type eq 'default') {
13220: $crsownerstr{$item} .= $othertitle.', ';
13221: } elsif ($usertypes->{$type} ne '') {
13222: $crsownerstr{$item} .= $usertypes->{$type}.', ';
13223: }
13224: }
13225: $crsownerstr{$item} =~ s/\Q, \E$//;
13226: }
13227: }
13228: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
13229: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
13230: }
13231: } else {
13232: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
13233: }
13234: }
13235: $resulttext .= '</ul></li>';
13236: }
13237: }
13238: $resulttext .= '</ul>';
13239: } else {
13240: $resulttext = &mt('No changes made to password settings');
13241: }
13242: my $cachetime = 24*60*60;
13243: if ($updatedefaults) {
13244: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13245: if (ref($lastactref) eq 'HASH') {
13246: $lastactref->{'domdefaults'} = 1;
13247: }
13248: }
13249: if ($updateconf) {
13250: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
13251: if (ref($lastactref) eq 'HASH') {
13252: $lastactref->{'passwdconf'} = 1;
13253: }
13254: }
13255: } else {
13256: $resulttext = '<span class="LC_error">'.
13257: &mt('An error occurred: [_1]',$putresult).'</span>';
13258: }
13259: if ($errors) {
13260: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13261: $errors.'</ul></p>';
13262: }
13263: return $resulttext;
13264: }
13265:
1.28 raeburn 13266: sub modify_usercreation {
1.27 raeburn 13267: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 13268: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 13269: my $warningmsg;
1.27 raeburn 13270: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13271: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 13272: if ($key eq 'cancreate') {
13273: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13274: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 13275: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 13276: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 13277: } else {
13278: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 13279: }
1.50 raeburn 13280: }
1.43 raeburn 13281: }
1.160.6.34 raeburn 13282: } elsif ($key eq 'email_rule') {
13283: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13284: } else {
13285: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 13286: }
13287: }
1.34 raeburn 13288: }
1.160.6.34 raeburn 13289: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
13290: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
13291: my @contexts = ('author','course','requestcrs');
13292: foreach my $item(@contexts) {
13293: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 13294: }
1.34 raeburn 13295: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13296: foreach my $item (@contexts) {
1.160.6.34 raeburn 13297: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
13298: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 13299: }
1.27 raeburn 13300: }
1.34 raeburn 13301: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
13302: foreach my $item (@contexts) {
1.43 raeburn 13303: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 13304: if ($cancreate{$item} ne 'any') {
13305: push(@{$changes{'cancreate'}},$item);
13306: }
13307: } else {
13308: if ($cancreate{$item} ne 'none') {
13309: push(@{$changes{'cancreate'}},$item);
13310: }
1.27 raeburn 13311: }
13312: }
13313: } else {
1.43 raeburn 13314: foreach my $item (@contexts) {
1.34 raeburn 13315: push(@{$changes{'cancreate'}},$item);
13316: }
1.27 raeburn 13317: }
1.34 raeburn 13318:
1.27 raeburn 13319: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
13320: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
13321: if (!grep(/^\Q$type\E$/,@username_rule)) {
13322: push(@{$changes{'username_rule'}},$type);
13323: }
13324: }
13325: foreach my $type (@username_rule) {
13326: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
13327: push(@{$changes{'username_rule'}},$type);
13328: }
13329: }
13330: } else {
13331: push(@{$changes{'username_rule'}},@username_rule);
13332: }
13333:
1.32 raeburn 13334: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
13335: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
13336: if (!grep(/^\Q$type\E$/,@id_rule)) {
13337: push(@{$changes{'id_rule'}},$type);
13338: }
13339: }
13340: foreach my $type (@id_rule) {
13341: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
13342: push(@{$changes{'id_rule'}},$type);
13343: }
13344: }
13345: } else {
13346: push(@{$changes{'id_rule'}},@id_rule);
13347: }
13348:
1.43 raeburn 13349: my @authen_contexts = ('author','course','domain');
1.28 raeburn 13350: my @authtypes = ('int','krb4','krb5','loc');
13351: my %authhash;
1.43 raeburn 13352: foreach my $item (@authen_contexts) {
1.28 raeburn 13353: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
13354: foreach my $auth (@authtypes) {
13355: if (grep(/^\Q$auth\E$/,@authallowed)) {
13356: $authhash{$item}{$auth} = 1;
13357: } else {
13358: $authhash{$item}{$auth} = 0;
13359: }
13360: }
13361: }
13362: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 13363: foreach my $item (@authen_contexts) {
1.28 raeburn 13364: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
13365: foreach my $auth (@authtypes) {
13366: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
13367: push(@{$changes{'authtypes'}},$item);
13368: last;
13369: }
13370: }
13371: }
13372: }
13373: } else {
1.43 raeburn 13374: foreach my $item (@authen_contexts) {
1.28 raeburn 13375: push(@{$changes{'authtypes'}},$item);
13376: }
13377: }
13378:
1.160.6.34 raeburn 13379: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
13380: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
13381: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
13382: $save_usercreate{'id_rule'} = \@id_rule;
13383: $save_usercreate{'username_rule'} = \@username_rule,
13384: $save_usercreate{'authtypes'} = \%authhash;
13385:
1.27 raeburn 13386: my %usercreation_hash = (
1.160.6.34 raeburn 13387: usercreation => \%save_usercreate,
13388: );
1.27 raeburn 13389:
13390: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
13391: $dom);
1.50 raeburn 13392:
1.160.6.34 raeburn 13393: if ($putresult eq 'ok') {
13394: if (keys(%changes) > 0) {
13395: $resulttext = &mt('Changes made:').'<ul>';
13396: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13397: my %lt = &usercreation_types();
13398: foreach my $type (@{$changes{'cancreate'}}) {
13399: my $chgtext = $lt{$type}.', ';
13400: if ($cancreate{$type} eq 'none') {
13401: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
13402: } elsif ($cancreate{$type} eq 'any') {
13403: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
13404: } elsif ($cancreate{$type} eq 'official') {
13405: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
13406: } elsif ($cancreate{$type} eq 'unofficial') {
13407: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
13408: }
13409: $resulttext .= '<li>'.$chgtext.'</li>';
13410: }
13411: }
13412: if (ref($changes{'username_rule'}) eq 'ARRAY') {
13413: my ($rules,$ruleorder) =
13414: &Apache::lonnet::inst_userrules($dom,'username');
13415: my $chgtext = '<ul>';
13416: foreach my $type (@username_rule) {
13417: if (ref($rules->{$type}) eq 'HASH') {
13418: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
13419: }
13420: }
13421: $chgtext .= '</ul>';
13422: if (@username_rule > 0) {
13423: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13424: } else {
13425: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
13426: }
13427: }
13428: if (ref($changes{'id_rule'}) eq 'ARRAY') {
13429: my ($idrules,$idruleorder) =
13430: &Apache::lonnet::inst_userrules($dom,'id');
13431: my $chgtext = '<ul>';
13432: foreach my $type (@id_rule) {
13433: if (ref($idrules->{$type}) eq 'HASH') {
13434: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
13435: }
13436: }
13437: $chgtext .= '</ul>';
13438: if (@id_rule > 0) {
13439: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13440: } else {
13441: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
13442: }
13443: }
13444: my %authname = &authtype_names();
13445: my %context_title = &context_names();
13446: if (ref($changes{'authtypes'}) eq 'ARRAY') {
13447: my $chgtext = '<ul>';
13448: foreach my $type (@{$changes{'authtypes'}}) {
13449: my @allowed;
13450: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
13451: foreach my $auth (@authtypes) {
13452: if ($authhash{$type}{$auth}) {
13453: push(@allowed,$authname{$auth});
13454: }
13455: }
13456: if (@allowed > 0) {
13457: $chgtext .= join(', ',@allowed).'</li>';
13458: } else {
13459: $chgtext .= &mt('none').'</li>';
13460: }
13461: }
13462: $chgtext .= '</ul>';
13463: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
13464: $resulttext .= '</li>';
13465: }
13466: $resulttext .= '</ul>';
13467: } else {
13468: $resulttext = &mt('No changes made to user creation settings');
13469: }
13470: } else {
13471: $resulttext = '<span class="LC_error">'.
13472: &mt('An error occurred: [_1]',$putresult).'</span>';
13473: }
13474: if ($warningmsg ne '') {
13475: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13476: }
13477: return $resulttext;
13478: }
13479:
13480: sub modify_selfcreation {
1.160.6.93 raeburn 13481: my ($dom,$lastactref,%domconfig) = @_;
13482: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
13483: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
13484: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13485: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
13486: if (ref($typesref) eq 'ARRAY') {
13487: @types = @{$typesref};
13488: }
13489: if (ref($usertypesref) eq 'HASH') {
13490: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 13491: }
1.160.6.93 raeburn 13492: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 13493: #
13494: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
13495: #
13496: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13497: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
13498: if ($key eq 'cancreate') {
13499: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13500: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
13501: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 13502: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
13503: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
13504: ($item eq 'emailusername') || ($item eq 'shibenv') ||
13505: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
13506: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 13507: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13508: } else {
13509: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13510: }
13511: }
13512: }
13513: } elsif ($key eq 'email_rule') {
13514: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13515: } else {
13516: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13517: }
13518: }
13519: }
13520: #
13521: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
13522: #
13523: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13524: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
13525: if ($key eq 'selfcreate') {
13526: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
13527: } else {
13528: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
13529: }
13530: }
13531: }
1.160.6.93 raeburn 13532: #
13533: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
13534: #
13535: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13536: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
13537: if ($key eq 'inststatusguest') {
13538: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
13539: } else {
13540: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
13541: }
13542: }
13543: }
1.160.6.34 raeburn 13544:
13545: my @contexts = ('selfcreate');
13546: @{$cancreate{'selfcreate'}} = ();
13547: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 13548: if (@types) {
13549: @{$cancreate{'statustocreate'}} = ();
13550: }
1.160.6.40 raeburn 13551: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 13552: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 13553: %{$cancreate{'emailverified'}} = ();
13554: %{$cancreate{'emailoptions'}} = ();
13555: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 13556: my %selfcreatetypes = (
13557: sso => 'users authenticated by institutional single sign on',
13558: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 13559: email => 'users verified by e-mail',
1.50 raeburn 13560: );
1.160.6.34 raeburn 13561: #
13562: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
13563: # is permitted.
13564: #
1.160.6.40 raeburn 13565:
1.160.6.93 raeburn 13566: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 13567:
1.160.6.93 raeburn 13568: my (@statuses,%email_rule);
1.160.6.35 raeburn 13569: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 13570: if ($item eq 'email') {
1.160.6.40 raeburn 13571: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 13572: if (@types) {
13573: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
13574: foreach my $status (@poss_statuses) {
13575: if (grep(/^\Q$status\E$/,(@types,'default'))) {
13576: push(@statuses,$status);
13577: }
13578: }
13579: $save_inststatus{'inststatusguest'} = \@statuses;
13580: } else {
13581: push(@statuses,'default');
13582: }
13583: if (@statuses) {
13584: my %curr_rule;
13585: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
13586: foreach my $type (@statuses) {
13587: $curr_rule{$type} = $curr_usercreation{'email_rule'};
13588: }
13589: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
13590: foreach my $type (@statuses) {
13591: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
13592: }
13593: }
13594: push(@{$cancreate{'selfcreate'}},'email');
13595: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
13596: my %curremaildom;
13597: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
13598: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
13599: }
13600: foreach my $type (@statuses) {
13601: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
13602: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
13603: }
13604: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
13605: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
13606: }
13607: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
13608: #
13609: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
13610: #
13611: my $chosen = $1;
13612: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
13613: my $emaildom;
13614: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
13615: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
13616: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
13617: if (ref($curremaildom{$type}) eq 'HASH') {
13618: if (exists($curremaildom{$type}{$chosen})) {
13619: if ($curremaildom{$type}{$chosen} ne $emaildom) {
13620: push(@{$changes{'cancreate'}},'emaildomain');
13621: }
13622: } elsif ($emaildom ne '') {
13623: push(@{$changes{'cancreate'}},'emaildomain');
13624: }
13625: } elsif ($emaildom ne '') {
13626: push(@{$changes{'cancreate'}},'emaildomain');
13627: }
13628: }
13629: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13630: } elsif ($chosen eq 'custom') {
13631: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
13632: $email_rule{$type} = [];
13633: if (ref($emailrules) eq 'HASH') {
13634: foreach my $rule (@possemail_rules) {
13635: if (exists($emailrules->{$rule})) {
13636: push(@{$email_rule{$type}},$rule);
13637: }
13638: }
13639: }
13640: if (@{$email_rule{$type}}) {
13641: $cancreate{'emailoptions'}{$type} = 'custom';
13642: if (ref($curr_rule{$type}) eq 'ARRAY') {
13643: if (@{$curr_rule{$type}} > 0) {
13644: foreach my $rule (@{$curr_rule{$type}}) {
13645: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
13646: push(@{$changes{'email_rule'}},$type);
13647: }
13648: }
13649: }
13650: foreach my $type (@{$email_rule{$type}}) {
13651: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
13652: push(@{$changes{'email_rule'}},$type);
13653: }
13654: }
13655: } else {
13656: push(@{$changes{'email_rule'}},$type);
13657: }
13658: }
13659: } else {
13660: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13661: }
13662: }
13663: }
13664: if (@types) {
13665: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13666: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
13667: if (@changed) {
13668: push(@{$changes{'inststatus'}},'inststatusguest');
13669: }
13670: } else {
13671: push(@{$changes{'inststatus'}},'inststatusguest');
13672: }
13673: }
13674: } else {
13675: delete($env{'form.cancreate_email'});
13676: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13677: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13678: push(@{$changes{'inststatus'}},'inststatusguest');
13679: }
13680: }
13681: }
13682: } else {
13683: $save_inststatus{'inststatusguest'} = [];
13684: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13685: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13686: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 13687: }
13688: }
1.160.6.34 raeburn 13689: }
13690: } else {
13691: if ($env{'form.cancreate_'.$item}) {
13692: push(@{$cancreate{'selfcreate'}},$item);
13693: }
13694: }
13695: }
1.160.6.93 raeburn 13696: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 13697: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
13698: #
1.160.6.35 raeburn 13699: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
13700: # 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 13701: #
1.160.6.40 raeburn 13702:
1.160.6.48 raeburn 13703: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 13704: push(@contexts,'emailusername');
1.160.6.93 raeburn 13705: if (@statuses) {
13706: foreach my $type (@statuses) {
1.160.6.35 raeburn 13707: if (ref($infofields) eq 'ARRAY') {
13708: foreach my $field (@{$infofields}) {
13709: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
13710: $cancreate{'emailusername'}{$type}{$field} = $1;
13711: }
13712: }
1.160.6.34 raeburn 13713: }
13714: }
13715: }
13716: #
13717: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 13718: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 13719: #
13720:
13721: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
13722: @approvalnotify = sort(@approvalnotify);
13723: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
13724: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13725: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
13726: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
13727: push(@{$changes{'cancreate'}},'notify');
13728: }
13729: } else {
13730: if ($cancreate{'notify'}{'approval'}) {
13731: push(@{$changes{'cancreate'}},'notify');
13732: }
13733: }
13734: } elsif ($cancreate{'notify'}{'approval'}) {
13735: push(@{$changes{'cancreate'}},'notify');
13736: }
13737:
13738: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
13739: }
13740: #
1.160.6.40 raeburn 13741: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 13742: # institutional log-in.
13743: #
13744: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
13745: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
13746: ($domdefaults{'auth_def'} eq 'localauth'))) {
13747: $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.').' '.
13748: &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.');
13749: }
13750: }
13751: my @fields = ('lastname','firstname','middlename','generation',
13752: 'permanentemail','id');
1.160.6.44 raeburn 13753: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 13754: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13755: #
13756: # Where usernames may created for institutional log-in and/or institutional single sign on:
13757: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
13758: # may self-create accounts
13759: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
13760: # which the user may supply, if institutional data is unavailable.
13761: #
13762: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 13763: if (@types) {
13764: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
13765: push(@contexts,'statustocreate');
13766: foreach my $type (@types) {
1.160.6.34 raeburn 13767: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
13768: foreach my $field (@fields) {
13769: if (grep(/^\Q$field\E$/,@modifiable)) {
13770: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
13771: } else {
13772: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
13773: }
13774: }
13775: }
13776: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 13777: foreach my $type (@types) {
1.160.6.34 raeburn 13778: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
13779: foreach my $field (@fields) {
13780: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
13781: $curr_usermodify{'selfcreate'}{$type}{$field}) {
13782: push(@{$changes{'selfcreate'}},$type);
13783: last;
13784: }
13785: }
13786: }
13787: }
13788: } else {
1.160.6.93 raeburn 13789: foreach my $type (@types) {
1.160.6.34 raeburn 13790: push(@{$changes{'selfcreate'}},$type);
13791: }
13792: }
13793: }
1.160.6.44 raeburn 13794: foreach my $field (@shibfields) {
13795: if ($env{'form.shibenv_'.$field} ne '') {
13796: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
13797: }
13798: }
13799: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13800: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
13801: foreach my $field (@shibfields) {
13802: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
13803: push(@{$changes{'cancreate'}},'shibenv');
13804: }
13805: }
13806: } else {
13807: foreach my $field (@shibfields) {
13808: if ($env{'form.shibenv_'.$field}) {
13809: push(@{$changes{'cancreate'}},'shibenv');
13810: last;
13811: }
13812: }
13813: }
13814: }
1.160.6.34 raeburn 13815: }
13816: foreach my $item (@contexts) {
13817: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
13818: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
13819: if (ref($cancreate{$item}) eq 'ARRAY') {
13820: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
13821: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13822: push(@{$changes{'cancreate'}},$item);
13823: }
13824: }
13825: }
13826: }
13827: if (ref($cancreate{$item}) eq 'ARRAY') {
13828: foreach my $type (@{$cancreate{$item}}) {
13829: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
13830: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13831: push(@{$changes{'cancreate'}},$item);
13832: }
13833: }
13834: }
13835: }
13836: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
13837: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 13838: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
13839: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13840: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
13841: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 13842: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13843: push(@{$changes{'cancreate'}},$item);
13844: }
13845: }
13846: }
1.160.6.93 raeburn 13847: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13848: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 13849: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13850: push(@{$changes{'cancreate'}},$item);
13851: }
1.160.6.34 raeburn 13852: }
13853: }
13854: }
1.160.6.93 raeburn 13855: foreach my $type (keys(%{$cancreate{$item}})) {
13856: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13857: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13858: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13859: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 13860: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13861: push(@{$changes{'cancreate'}},$item);
13862: }
13863: }
13864: } else {
13865: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13866: push(@{$changes{'cancreate'}},$item);
13867: }
13868: }
13869: }
1.160.6.93 raeburn 13870: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13871: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 13872: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13873: push(@{$changes{'cancreate'}},$item);
13874: }
1.160.6.34 raeburn 13875: }
13876: }
13877: }
13878: }
13879: } elsif ($curr_usercreation{'cancreate'}{$item}) {
13880: if (ref($cancreate{$item}) eq 'ARRAY') {
13881: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
13882: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13883: push(@{$changes{'cancreate'}},$item);
13884: }
13885: }
1.160.6.93 raeburn 13886: }
13887: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13888: if (ref($cancreate{$item}) eq 'HASH') {
13889: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13890: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 13891: }
13892: }
13893: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 13894: if (ref($cancreate{$item}) eq 'HASH') {
13895: foreach my $type (keys(%{$cancreate{$item}})) {
13896: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13897: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13898: if ($cancreate{$item}{$type}{$field}) {
13899: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13900: push(@{$changes{'cancreate'}},$item);
13901: }
13902: last;
13903: }
13904: }
13905: }
13906: }
1.160.6.34 raeburn 13907: }
13908: }
13909: }
13910: #
13911: # Populate %save_usercreate hash with updates to self-creation configuration.
13912: #
13913: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
13914: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 13915: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 13916: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
13917: if (ref($cancreate{'notify'}) eq 'HASH') {
13918: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
13919: }
1.160.6.40 raeburn 13920: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
13921: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
13922: }
1.160.6.93 raeburn 13923: if (ref($cancreate{'emailverified'}) eq 'HASH') {
13924: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
13925: }
13926: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
13927: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
13928: }
13929: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
13930: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
13931: }
1.160.6.34 raeburn 13932: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13933: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
13934: }
1.160.6.44 raeburn 13935: if (ref($cancreate{'shibenv'}) eq 'HASH') {
13936: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
13937: }
1.160.6.34 raeburn 13938: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 13939: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 13940:
13941: my %userconfig_hash = (
13942: usercreation => \%save_usercreate,
13943: usermodification => \%save_usermodify,
1.160.6.93 raeburn 13944: inststatus => \%save_inststatus,
1.160.6.34 raeburn 13945: );
1.160.6.93 raeburn 13946:
1.160.6.34 raeburn 13947: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
13948: $dom);
13949: #
1.160.6.93 raeburn 13950: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 13951: #
1.27 raeburn 13952: if ($putresult eq 'ok') {
13953: if (keys(%changes) > 0) {
13954: $resulttext = &mt('Changes made:').'<ul>';
13955: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 13956: my %lt = &selfcreation_types();
1.34 raeburn 13957: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 13958: my $chgtext = '';
1.45 raeburn 13959: if ($type eq 'selfcreate') {
1.50 raeburn 13960: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 13961: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 13962: } else {
1.160.6.34 raeburn 13963: $chgtext .= &mt('Self-creation of a new account is permitted for:').
13964: '<ul>';
1.50 raeburn 13965: foreach my $case (@{$cancreate{$type}}) {
13966: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
13967: }
13968: $chgtext .= '</ul>';
1.100 raeburn 13969: if (ref($cancreate{$type}) eq 'ARRAY') {
13970: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
13971: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13972: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 13973: $chgtext .= '<span class="LC_warning">'.
13974: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
13975: '</span><br />';
1.100 raeburn 13976: }
13977: }
13978: }
1.160.6.93 raeburn 13979: if (grep(/^email$/,@{$cancreate{$type}})) {
13980: if (!@statuses) {
13981: $chgtext .= '<span class="LC_warning">'.
13982: &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.").
13983: '</span><br />';
13984:
13985: }
13986: }
1.100 raeburn 13987: }
1.43 raeburn 13988: }
1.160.6.44 raeburn 13989: } elsif ($type eq 'shibenv') {
13990: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 13991: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 13992: } else {
13993: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
13994: '<ul>';
13995: foreach my $field (@shibfields) {
13996: next if ($cancreate{$type}{$field} eq '');
13997: if ($field eq 'inststatus') {
13998: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
13999: } else {
14000: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
14001: }
14002: }
14003: $chgtext .= '</ul>';
1.160.6.93 raeburn 14004: }
1.93 raeburn 14005: } elsif ($type eq 'statustocreate') {
1.96 raeburn 14006: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
14007: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
14008: if (@{$cancreate{'selfcreate'}} > 0) {
14009: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 14010: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 14011: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 14012: $chgtext .= '<br />'.
14013: '<span class="LC_warning">'.
14014: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
14015: '</span>';
14016: }
1.160.6.93 raeburn 14017: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 14018: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 14019: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
14020: } else {
14021: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
14022: }
14023: $chgtext .= '<ul>';
14024: foreach my $case (@{$cancreate{$type}}) {
14025: if ($case eq 'default') {
14026: $chgtext .= '<li>'.$othertitle.'</li>';
14027: } else {
1.160.6.93 raeburn 14028: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 14029: }
14030: }
1.100 raeburn 14031: $chgtext .= '</ul>';
14032: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 14033: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 14034: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
14035: '</span>';
1.100 raeburn 14036: }
14037: }
14038: } else {
14039: if (@{$cancreate{$type}} == 0) {
14040: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
14041: } else {
14042: $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 14043: }
14044: }
1.160.6.93 raeburn 14045: $chgtext .= '<br />';
1.93 raeburn 14046: }
1.160.6.40 raeburn 14047: } elsif ($type eq 'selfcreateprocessing') {
14048: my %choices = &Apache::lonlocal::texthash (
14049: automatic => 'Automatic approval',
14050: approval => 'Queued for approval',
14051: );
1.160.6.93 raeburn 14052: if (@types) {
14053: if (@statuses) {
14054: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
14055: '<ul>';
14056: foreach my $status (@statuses) {
14057: if ($status eq 'default') {
14058: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
14059: } else {
14060: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
14061: }
14062: }
14063: $chgtext .= '</ul>';
14064: }
14065: } else {
14066: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
14067: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
14068: }
14069: } elsif ($type eq 'emailverified') {
14070: my %options = &Apache::lonlocal::texthash (
14071: all => 'Same as e-mail',
14072: first => 'Omit @domain',
14073: free => 'Free to choose',
14074: );
14075: if (@types) {
14076: if (@statuses) {
14077: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
14078: '<ul>';
14079: foreach my $status (@statuses) {
14080: if ($status eq 'default') {
14081: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
14082: } else {
14083: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
14084: }
14085: }
14086: $chgtext .= '</ul>';
14087: }
1.160.6.40 raeburn 14088: } else {
1.160.6.93 raeburn 14089: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
14090: $options{$cancreate{'emailverified'}{'default'}});
14091: }
14092: } elsif ($type eq 'emailoptions') {
14093: my %options = &Apache::lonlocal::texthash (
14094: any => 'Any e-mail',
14095: inst => 'Institutional only',
14096: noninst => 'Non-institutional only',
14097: custom => 'Custom restrictions',
14098: );
14099: if (@types) {
14100: if (@statuses) {
14101: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
14102: '<ul>';
14103: foreach my $status (@statuses) {
14104: if ($type eq 'default') {
14105: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
14106: } else {
14107: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
14108: }
14109: }
14110: $chgtext .= '</ul>';
14111: }
14112: } else {
14113: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
14114: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
14115: } else {
14116: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
14117: $options{$cancreate{'emailoptions'}{'default'}});
14118: }
14119: }
14120: } elsif ($type eq 'emaildomain') {
14121: my $output;
14122: if (@statuses) {
14123: foreach my $type (@statuses) {
14124: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
14125: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
14126: if ($type eq 'default') {
14127: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14128: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
14129: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
14130: } else {
14131: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
14132: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
14133: }
14134: } else {
14135: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14136: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
14137: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
14138: } else {
14139: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
14140: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
14141: }
14142: }
14143: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
14144: if ($type eq 'default') {
14145: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14146: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
14147: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
14148: } else {
14149: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
14150: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
14151: }
14152: } else {
14153: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14154: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
14155: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
14156: } else {
14157: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
14158: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
14159: }
14160: }
14161: }
14162: }
14163: }
14164: }
14165: if ($output ne '') {
14166: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
14167: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 14168: }
1.160.6.5 raeburn 14169: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 14170: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 14171: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
14172: } else {
14173: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 14174: if ($captchas{$savecaptcha{$type}}) {
14175: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 14176: } else {
14177: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
14178: }
14179: }
14180: } elsif ($type eq 'recaptchakeys') {
14181: my ($privkey,$pubkey);
1.160.6.34 raeburn 14182: if (ref($savecaptcha{$type}) eq 'HASH') {
14183: $pubkey = $savecaptcha{$type}{'public'};
14184: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 14185: }
14186: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
14187: if (!$pubkey) {
14188: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
14189: } else {
14190: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
14191: }
14192: if (!$privkey) {
14193: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
14194: } else {
14195: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
14196: }
14197: $chgtext .= '</ul>';
1.160.6.69 raeburn 14198: } elsif ($type eq 'recaptchaversion') {
14199: if ($savecaptcha{'captcha'} eq 'recaptcha') {
14200: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
14201: }
1.160.6.34 raeburn 14202: } elsif ($type eq 'emailusername') {
14203: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 14204: if (@statuses) {
14205: foreach my $type (@statuses) {
1.160.6.35 raeburn 14206: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
14207: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 14208: $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 14209: '<ul>';
14210: foreach my $field (@{$infofields}) {
14211: if ($cancreate{'emailusername'}{$type}{$field}) {
14212: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
14213: }
14214: }
1.160.6.50 raeburn 14215: $chgtext .= '</ul>';
14216: } else {
1.160.6.93 raeburn 14217: $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 14218: }
14219: } else {
1.160.6.93 raeburn 14220: $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 14221: }
14222: }
14223: }
14224: }
14225: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 14226: my $numapprove = 0;
1.160.6.34 raeburn 14227: if (ref($changes{'cancreate'}) eq 'ARRAY') {
14228: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
14229: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 14230: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
14231: $numapprove ++;
1.160.6.34 raeburn 14232: }
14233: }
1.43 raeburn 14234: }
1.160.6.93 raeburn 14235: unless ($numapprove) {
14236: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
14237: }
1.34 raeburn 14238: }
1.160.6.34 raeburn 14239: if ($chgtext) {
14240: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 14241: }
14242: }
14243: }
1.160.6.93 raeburn 14244: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 14245: my ($emailrules,$emailruleorder) =
14246: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 14247: foreach my $type (@{$changes{'email_rule'}}) {
14248: if (ref($email_rule{$type}) eq 'ARRAY') {
14249: my $chgtext = '<ul>';
14250: foreach my $rule (@{$email_rule{$type}}) {
14251: if (ref($emailrules->{$rule}) eq 'HASH') {
14252: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
14253: }
14254: }
14255: $chgtext .= '</ul>';
14256: my $typename;
14257: if (@types) {
14258: if ($type eq 'default') {
14259: $typename = $othertitle;
14260: } else {
14261: $typename = $usertypes{$type};
14262: }
14263: $chgtext .= &mt('(Affiliation: [_1])',$typename);
14264: }
14265: if (@{$email_rule{$type}} > 0) {
14266: $resulttext .= '<li>'.
14267: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
14268: $usertypes{$type}).
14269: $chgtext.
14270: '</li>';
14271: } else {
14272: $resulttext .= '<li>'.
14273: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
14274: '</li>'.
14275: &mt('(Affiliation: [_1])',$typename);
14276: }
1.43 raeburn 14277: }
14278: }
1.160.6.93 raeburn 14279: }
14280: if (ref($changes{'inststatus'}) eq 'ARRAY') {
14281: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
14282: if (@{$save_inststatus{'inststatusguest'}} > 0) {
14283: my $chgtext = '<ul>';
14284: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
14285: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
14286: }
14287: $chgtext .= '</ul>';
14288: $resulttext .= '<li>'.
14289: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
14290: $chgtext.
14291: '</li>';
14292: } else {
14293: $resulttext .= '<li>'.
14294: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
14295: '</li>';
14296: }
1.43 raeburn 14297: }
14298: }
1.160.6.34 raeburn 14299: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
14300: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
14301: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14302: foreach my $type (@{$changes{'selfcreate'}}) {
14303: my $typename = $type;
1.160.6.93 raeburn 14304: if (keys(%usertypes) > 0) {
14305: if ($usertypes{$type} ne '') {
14306: $typename = $usertypes{$type};
1.28 raeburn 14307: }
14308: }
1.160.6.34 raeburn 14309: my @modifiable;
14310: $resulttext .= '<li>'.
14311: &mt('Self-creation of account by users with status: [_1]',
14312: '<span class="LC_cusr_emph">'.$typename.'</span>').
14313: ' - '.&mt('modifiable fields (if institutional data blank): ');
14314: foreach my $field (@fields) {
14315: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
14316: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
14317: }
14318: }
14319: if (@modifiable > 0) {
14320: $resulttext .= join(', ',@modifiable);
1.43 raeburn 14321: } else {
1.160.6.34 raeburn 14322: $resulttext .= &mt('none');
1.43 raeburn 14323: }
1.160.6.34 raeburn 14324: $resulttext .= '</li>';
1.28 raeburn 14325: }
1.160.6.34 raeburn 14326: $resulttext .= '</ul></li>';
1.28 raeburn 14327: }
1.27 raeburn 14328: $resulttext .= '</ul>';
1.160.6.93 raeburn 14329: my $cachetime = 24*60*60;
14330: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
14331: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14332: if (ref($lastactref) eq 'HASH') {
14333: $lastactref->{'domdefaults'} = 1;
14334: }
1.27 raeburn 14335: } else {
1.160.6.34 raeburn 14336: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 14337: }
14338: } else {
14339: $resulttext = '<span class="LC_error">'.
1.23 raeburn 14340: &mt('An error occurred: [_1]',$putresult).'</span>';
14341: }
1.43 raeburn 14342: if ($warningmsg ne '') {
14343: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
14344: }
1.23 raeburn 14345: return $resulttext;
14346: }
14347:
1.160.6.5 raeburn 14348: sub process_captcha {
1.160.6.104 raeburn 14349: my ($container,$changes,$newsettings,$currsettings) = @_;
14350: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.160.6.5 raeburn 14351: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
14352: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
14353: $newsettings->{'captcha'} = 'original';
14354: }
1.160.6.104 raeburn 14355: my %current;
14356: if (ref($currsettings) eq 'HASH') {
14357: %current = %{$currsettings};
14358: }
14359: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.160.6.5 raeburn 14360: if ($container eq 'cancreate') {
14361: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14362: push(@{$changes->{'cancreate'}},'captcha');
14363: } elsif (!defined($changes->{'cancreate'})) {
14364: $changes->{'cancreate'} = ['captcha'];
14365: }
1.160.6.102 raeburn 14366: } elsif ($container eq 'passwords') {
14367: $changes->{'reset'} = 1;
1.160.6.5 raeburn 14368: } else {
14369: $changes->{'captcha'} = 1;
14370: }
14371: }
1.160.6.69 raeburn 14372: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 14373: if ($newsettings->{'captcha'} eq 'recaptcha') {
14374: $newpub = $env{'form.'.$container.'_recaptchapub'};
14375: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 14376: $newpub =~ s/[^\w\-]//g;
14377: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 14378: $newsettings->{'recaptchakeys'} = {
14379: public => $newpub,
14380: private => $newpriv,
14381: };
1.160.6.69 raeburn 14382: $newversion = $env{'form.'.$container.'_recaptchaversion'};
14383: $newversion =~ s/\D//g;
14384: if ($newversion ne '2') {
14385: $newversion = 1;
14386: }
14387: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 14388: }
1.160.6.104 raeburn 14389: if (ref($current{'recaptchakeys'}) eq 'HASH') {
14390: $currpub = $current{'recaptchakeys'}{'public'};
14391: $currpriv = $current{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 14392: unless ($newsettings->{'captcha'} eq 'recaptcha') {
14393: $newsettings->{'recaptchakeys'} = {
14394: public => '',
14395: private => '',
14396: }
14397: }
1.160.6.5 raeburn 14398: }
1.160.6.104 raeburn 14399: if ($current{'captcha'} eq 'recaptcha') {
14400: $currversion = $current{'recaptchaversion'};
1.160.6.69 raeburn 14401: if ($currversion ne '2') {
14402: $currversion = 1;
14403: }
14404: }
14405: if ($currversion ne $newversion) {
14406: if ($container eq 'cancreate') {
14407: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14408: push(@{$changes->{'cancreate'}},'recaptchaversion');
14409: } elsif (!defined($changes->{'cancreate'})) {
14410: $changes->{'cancreate'} = ['recaptchaversion'];
14411: }
1.160.6.102 raeburn 14412: } elsif ($container eq 'passwords') {
14413: $changes->{'reset'} = 1;
1.160.6.69 raeburn 14414: } else {
14415: $changes->{'recaptchaversion'} = 1;
14416: }
14417: }
1.160.6.5 raeburn 14418: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
14419: if ($container eq 'cancreate') {
14420: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14421: push(@{$changes->{'cancreate'}},'recaptchakeys');
14422: } elsif (!defined($changes->{'cancreate'})) {
14423: $changes->{'cancreate'} = ['recaptchakeys'];
14424: }
1.160.6.102 raeburn 14425: } elsif ($container eq 'passwords') {
14426: $changes->{'reset'} = 1;
1.160.6.5 raeburn 14427: } else {
14428: $changes->{'recaptchakeys'} = 1;
14429: }
14430: }
14431: return;
14432: }
14433:
1.33 raeburn 14434: sub modify_usermodification {
14435: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 14436: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 14437: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14438: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 14439: if ($key eq 'selfcreate') {
14440: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
14441: } else {
14442: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
14443: }
1.33 raeburn 14444: }
14445: }
1.160.6.34 raeburn 14446: my @contexts = ('author','course');
1.33 raeburn 14447: my %context_title = (
14448: author => 'In author context',
14449: course => 'In course context',
14450: );
14451: my @fields = ('lastname','firstname','middlename','generation',
14452: 'permanentemail','id');
14453: my %roles = (
14454: author => ['ca','aa'],
14455: course => ['st','ep','ta','in','cr'],
14456: );
14457: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14458: foreach my $context (@contexts) {
14459: foreach my $role (@{$roles{$context}}) {
14460: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
14461: foreach my $item (@fields) {
14462: if (grep(/^\Q$item\E$/,@modifiable)) {
14463: $modifyhash{$context}{$role}{$item} = 1;
14464: } else {
14465: $modifyhash{$context}{$role}{$item} = 0;
14466: }
14467: }
14468: }
14469: if (ref($curr_usermodification{$context}) eq 'HASH') {
14470: foreach my $role (@{$roles{$context}}) {
14471: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
14472: foreach my $field (@fields) {
14473: if ($modifyhash{$context}{$role}{$field} ne
14474: $curr_usermodification{$context}{$role}{$field}) {
14475: push(@{$changes{$context}},$role);
14476: last;
14477: }
14478: }
14479: }
14480: }
14481: } else {
14482: foreach my $context (@contexts) {
14483: foreach my $role (@{$roles{$context}}) {
14484: push(@{$changes{$context}},$role);
14485: }
14486: }
14487: }
14488: }
14489: my %usermodification_hash = (
14490: usermodification => \%modifyhash,
14491: );
14492: my $putresult = &Apache::lonnet::put_dom('configuration',
14493: \%usermodification_hash,$dom);
14494: if ($putresult eq 'ok') {
14495: if (keys(%changes) > 0) {
14496: $resulttext = &mt('Changes made: ').'<ul>';
14497: foreach my $context (@contexts) {
14498: if (ref($changes{$context}) eq 'ARRAY') {
14499: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
14500: if (ref($changes{$context}) eq 'ARRAY') {
14501: foreach my $role (@{$changes{$context}}) {
14502: my $rolename;
1.160.6.34 raeburn 14503: if ($role eq 'cr') {
14504: $rolename = &mt('Custom');
1.33 raeburn 14505: } else {
1.160.6.34 raeburn 14506: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 14507: }
14508: my @modifiable;
1.160.6.34 raeburn 14509: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 14510: foreach my $field (@fields) {
14511: if ($modifyhash{$context}{$role}{$field}) {
14512: push(@modifiable,$fieldtitles{$field});
14513: }
14514: }
14515: if (@modifiable > 0) {
14516: $resulttext .= join(', ',@modifiable);
14517: } else {
14518: $resulttext .= &mt('none');
14519: }
14520: $resulttext .= '</li>';
14521: }
14522: $resulttext .= '</ul></li>';
14523: }
14524: }
14525: }
14526: $resulttext .= '</ul>';
14527: } else {
14528: $resulttext = &mt('No changes made to user modification settings');
14529: }
14530: } else {
14531: $resulttext = '<span class="LC_error">'.
14532: &mt('An error occurred: [_1]',$putresult).'</span>';
14533: }
14534: return $resulttext;
14535: }
14536:
1.43 raeburn 14537: sub modify_defaults {
1.160.6.27 raeburn 14538: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 14539: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 14540: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 14541: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98 raeburn 14542: 'portal_def');
1.43 raeburn 14543: my @authtypes = ('internal','krb4','krb5','localauth');
14544: foreach my $item (@items) {
14545: $newvalues{$item} = $env{'form.'.$item};
14546: if ($item eq 'auth_def') {
14547: if ($newvalues{$item} ne '') {
14548: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
14549: push(@errors,$item);
14550: }
14551: }
14552: } elsif ($item eq 'lang_def') {
14553: if ($newvalues{$item} ne '') {
14554: if ($newvalues{$item} =~ /^(\w+)/) {
14555: my $langcode = $1;
1.103 raeburn 14556: if ($langcode ne 'x_chef') {
14557: if (code2language($langcode) eq '') {
14558: push(@errors,$item);
14559: }
1.43 raeburn 14560: }
14561: } else {
14562: push(@errors,$item);
14563: }
14564: }
1.54 raeburn 14565: } elsif ($item eq 'timezone_def') {
14566: if ($newvalues{$item} ne '') {
1.62 raeburn 14567: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 14568: push(@errors,$item);
14569: }
14570: }
1.68 raeburn 14571: } elsif ($item eq 'datelocale_def') {
14572: if ($newvalues{$item} ne '') {
14573: my @datelocale_ids = DateTime::Locale->ids();
14574: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
14575: push(@errors,$item);
14576: }
14577: }
1.141 raeburn 14578: } elsif ($item eq 'portal_def') {
14579: if ($newvalues{$item} ne '') {
14580: 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])\/?$/) {
14581: push(@errors,$item);
14582: }
14583: }
1.43 raeburn 14584: }
14585: if (grep(/^\Q$item\E$/,@errors)) {
14586: $newvalues{$item} = $domdefaults{$item};
14587: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
14588: $changes{$item} = 1;
14589: }
1.72 raeburn 14590: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 14591: }
1.160.6.98 raeburn 14592: my %staticdefaults = (
14593: 'intauth_cost' => 10,
14594: 'intauth_check' => 0,
14595: 'intauth_switch' => 0,
14596: );
14597: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
14598: if (exists($domdefaults{$item})) {
14599: $newvalues{$item} = $domdefaults{$item};
14600: } else {
14601: $newvalues{$item} = $staticdefaults{$item};
14602: }
14603: }
1.160.6.122! raeburn 14604: my ($unamemaprules,$ruleorder);
! 14605: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
! 14606: if (@possunamemaprules) {
! 14607: ($unamemaprules,$ruleorder) =
! 14608: &Apache::lonnet::inst_userrules($dom,'unamemap');
! 14609: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
! 14610: if (@{$ruleorder} > 0) {
! 14611: my %possrules;
! 14612: map { $possrules{$_} = 1; } @possunamemaprules;
! 14613: foreach my $rule (@{$ruleorder}) {
! 14614: if ($possrules{$rule}) {
! 14615: push(@{$newvalues{'unamemap_rule'}},$rule);
! 14616: }
! 14617: }
! 14618: }
! 14619: }
! 14620: }
! 14621: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
! 14622: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
! 14623: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
! 14624: $newvalues{'unamemap_rule'});
! 14625: if (@rulediffs) {
! 14626: $changes{'unamemap_rule'} = 1;
! 14627: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
! 14628: }
! 14629: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
! 14630: $changes{'unamemap_rule'} = 1;
! 14631: delete($domdefaults{'unamemap_rule'});
! 14632: }
! 14633: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
! 14634: if (@{$newvalues{'unamemap_rule'}} > 0) {
! 14635: $changes{'unamemap_rule'} = 1;
! 14636: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
! 14637: }
! 14638: }
1.43 raeburn 14639: my %defaults_hash = (
1.72 raeburn 14640: defaults => \%newvalues,
14641: );
1.43 raeburn 14642: my $title = &defaults_titles();
1.160.6.40 raeburn 14643:
14644: my $currinststatus;
14645: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14646: $currinststatus = $domconfig{'inststatus'};
14647: } else {
14648: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14649: $currinststatus = {
14650: inststatustypes => $usertypes,
14651: inststatusorder => $types,
14652: inststatusguest => [],
14653: };
14654: }
14655: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
14656: my @allpos;
14657: my %alltypes;
1.160.6.93 raeburn 14658: my @inststatusguest;
14659: if (ref($currinststatus) eq 'HASH') {
14660: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
14661: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
14662: unless (grep(/^\Q$type\E$/,@todelete)) {
14663: push(@inststatusguest,$type);
14664: }
14665: }
14666: }
14667: }
14668: my ($currtitles,$currorder);
1.160.6.40 raeburn 14669: if (ref($currinststatus) eq 'HASH') {
14670: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
14671: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
14672: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
14673: if ($currinststatus->{inststatustypes}->{$type} ne '') {
14674: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
14675: }
14676: }
14677: unless (grep(/^\Q$type\E$/,@todelete)) {
14678: my $position = $env{'form.inststatus_pos_'.$type};
14679: $position =~ s/\D+//g;
14680: $allpos[$position] = $type;
14681: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
14682: $alltypes{$type} =~ s/`//g;
14683: }
14684: }
14685: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
14686: $currtitles =~ s/,$//;
14687: }
14688: }
14689: if ($env{'form.addinststatus'}) {
14690: my $newtype = $env{'form.addinststatus'};
14691: $newtype =~ s/\W//g;
14692: unless (exists($alltypes{$newtype})) {
14693: $alltypes{$newtype} = $env{'form.addinststatus_title'};
14694: $alltypes{$newtype} =~ s/`//g;
14695: my $position = $env{'form.addinststatus_pos'};
14696: $position =~ s/\D+//g;
14697: if ($position ne '') {
14698: $allpos[$position] = $newtype;
14699: }
14700: }
14701: }
1.160.6.93 raeburn 14702: my @orderedstatus;
1.160.6.40 raeburn 14703: foreach my $type (@allpos) {
14704: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
14705: push(@orderedstatus,$type);
14706: }
14707: }
14708: foreach my $type (keys(%alltypes)) {
14709: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
14710: delete($alltypes{$type});
14711: }
14712: }
14713: $defaults_hash{'inststatus'} = {
14714: inststatustypes => \%alltypes,
14715: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 14716: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 14717: };
14718: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
14719: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
14720: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
14721: }
14722: }
14723: if ($currorder ne join(',',@orderedstatus)) {
14724: $changes{'inststatus'}{'inststatusorder'} = 1;
14725: }
14726: my $newtitles;
14727: foreach my $item (@orderedstatus) {
14728: $newtitles .= $alltypes{$item}.',';
14729: }
14730: $newtitles =~ s/,$//;
14731: if ($currtitles ne $newtitles) {
14732: $changes{'inststatus'}{'inststatustypes'} = 1;
14733: }
1.43 raeburn 14734: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
14735: $dom);
14736: if ($putresult eq 'ok') {
14737: if (keys(%changes) > 0) {
14738: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 14739: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 14740: 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";
14741: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 14742: if ($item eq 'inststatus') {
14743: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 14744: if (@orderedstatus) {
1.160.6.40 raeburn 14745: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
14746: foreach my $type (@orderedstatus) {
14747: $resulttext .= $alltypes{$type}.', ';
14748: }
14749: $resulttext =~ s/, $//;
14750: $resulttext .= '</li>';
1.160.6.93 raeburn 14751: } else {
14752: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 14753: }
14754: }
1.160.6.122! raeburn 14755: } elsif ($item eq 'unamemap_rule') {
! 14756: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
! 14757: my @rulenames;
! 14758: if (ref($unamemaprules) eq 'HASH') {
! 14759: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
! 14760: if (ref($unamemaprules->{$rule}) eq 'HASH') {
! 14761: push(@rulenames,$unamemaprules->{$rule}->{'name'});
! 14762: }
! 14763: }
! 14764: }
! 14765: if (@rulenames) {
! 14766: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
! 14767: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
! 14768: '</li>';
! 14769: } else {
! 14770: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
! 14771: }
! 14772: } else {
! 14773: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
! 14774: }
1.160.6.40 raeburn 14775: } else {
14776: my $value = $env{'form.'.$item};
14777: if ($value eq '') {
14778: $value = &mt('none');
14779: } elsif ($item eq 'auth_def') {
14780: my %authnames = &authtype_names();
14781: my %shortauth = (
14782: internal => 'int',
14783: krb4 => 'krb4',
14784: krb5 => 'krb5',
14785: localauth => 'loc',
14786: );
14787: $value = $authnames{$shortauth{$value}};
14788: }
14789: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
14790: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 14791: }
14792: }
14793: $resulttext .= '</ul>';
14794: $mailmsgtext .= "\n";
14795: my $cachetime = 24*60*60;
1.72 raeburn 14796: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 14797: if (ref($lastactref) eq 'HASH') {
14798: $lastactref->{'domdefaults'} = 1;
14799: }
1.68 raeburn 14800: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 14801: my $notify = 1;
14802: if (ref($domconfig{'contacts'}) eq 'HASH') {
14803: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
14804: $notify = 0;
14805: }
14806: }
14807: if ($notify) {
14808: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
14809: "LON-CAPA Domain Settings Change - $dom",
14810: $mailmsgtext);
14811: }
1.54 raeburn 14812: }
1.43 raeburn 14813: } else {
1.54 raeburn 14814: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 14815: }
14816: } else {
14817: $resulttext = '<span class="LC_error">'.
14818: &mt('An error occurred: [_1]',$putresult).'</span>';
14819: }
14820: if (@errors > 0) {
14821: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
14822: foreach my $item (@errors) {
14823: $resulttext .= ' "'.$title->{$item}.'",';
14824: }
14825: $resulttext =~ s/,$//;
14826: }
14827: return $resulttext;
14828: }
14829:
1.46 raeburn 14830: sub modify_scantron {
1.160.6.24 raeburn 14831: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 14832: my ($resulttext,%confhash,%changes,$errors);
14833: my $custom = 'custom.tab';
14834: my $default = 'default.tab';
14835: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 14836: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 14837: &config_check($dom,$confname,$servadm);
14838: if ($env{'form.scantronformat.filename'} ne '') {
14839: my $error;
14840: if ($configuserok eq 'ok') {
14841: if ($switchserver) {
1.130 raeburn 14842: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 14843: } else {
14844: if ($author_ok eq 'ok') {
14845: my ($result,$scantronurl) =
14846: &publishlogo($r,'upload','scantronformat',$dom,
14847: $confname,'scantron','','',$custom);
14848: if ($result eq 'ok') {
14849: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 14850: $changes{'scantronformat'} = 1;
1.46 raeburn 14851: } else {
14852: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
14853: }
14854: } else {
14855: $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);
14856: }
14857: }
14858: } else {
14859: $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);
14860: }
14861: if ($error) {
14862: &Apache::lonnet::logthis($error);
14863: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14864: }
14865: }
1.48 raeburn 14866: if (ref($domconfig{'scantron'}) eq 'HASH') {
14867: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
14868: if ($env{'form.scantronformat_del'}) {
14869: $confhash{'scantron'}{'scantronformat'} = '';
14870: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 14871: } else {
14872: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
14873: }
14874: }
14875: }
14876: my @options = ('hdr','pad','rem');
14877: my @fields = &scantroncsv_fields();
14878: my %titles = &scantronconfig_titles();
14879: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
14880: my ($newdat,$currdat,%newcol,%currcol);
14881: if (grep(/^dat$/,@formats)) {
14882: $confhash{'scantron'}{config}{dat} = 1;
14883: $newdat = 1;
14884: } else {
14885: $newdat = 0;
14886: }
14887: if (grep(/^csv$/,@formats)) {
14888: my %bynum;
14889: foreach my $field (@fields) {
14890: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
14891: my $posscol = $1;
14892: if (($posscol < 20) && (!$bynum{$posscol})) {
14893: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
14894: $bynum{$posscol} = $field;
14895: $newcol{$field} = $posscol;
14896: }
14897: }
14898: }
14899: if (keys(%newcol)) {
14900: foreach my $option (@options) {
14901: if ($env{'form.scantroncsv_'.$option}) {
14902: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
14903: }
14904: }
14905: }
14906: }
14907: $currdat = 1;
14908: if (ref($domconfig{'scantron'}) eq 'HASH') {
14909: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
14910: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
14911: $currdat = 0;
14912: }
14913: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
14914: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
14915: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
14916: }
14917: }
14918: }
14919: }
14920: if ($currdat != $newdat) {
14921: $changes{'config'} = 1;
14922: } else {
14923: foreach my $field (@fields) {
14924: if ($currcol{$field} ne '') {
14925: if ($currcol{$field} ne $newcol{$field}) {
14926: $changes{'config'} = 1;
14927: last;
14928: }
14929: } elsif ($newcol{$field} ne '') {
14930: $changes{'config'} = 1;
14931: last;
1.46 raeburn 14932: }
14933: }
14934: }
14935: if (keys(%confhash) > 0) {
14936: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
14937: $dom);
14938: if ($putresult eq 'ok') {
14939: if (keys(%changes) > 0) {
1.48 raeburn 14940: if (ref($confhash{'scantron'}) eq 'HASH') {
14941: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 14942: if ($changes{'scantronformat'}) {
14943: if ($confhash{'scantron'}{'scantronformat'} eq '') {
14944: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
14945: } else {
14946: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
14947: }
14948: }
14949: if ($changes{'config'}) {
14950: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
14951: if ($confhash{'scantron'}{'config'}{'dat'}) {
14952: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
14953: }
14954: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
14955: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
14956: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
14957: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
14958: foreach my $field (@fields) {
14959: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
14960: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
14961: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
14962: }
14963: }
14964: $resulttext .= '</ul></li>';
14965: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
14966: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
14967: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
14968: foreach my $option (@options) {
14969: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
14970: $resulttext .= '<li>'.$titles{$option}.'</li>';
14971: }
14972: }
14973: $resulttext .= '</ul></li>';
14974: }
14975: }
14976: }
14977: }
14978: }
14979: } else {
14980: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
14981: }
1.46 raeburn 14982: }
1.48 raeburn 14983: $resulttext .= '</ul>';
14984: } else {
1.130 raeburn 14985: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 14986: }
14987: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 14988: if (ref($lastactref) eq 'HASH') {
14989: $lastactref->{'domainconfig'} = 1;
14990: }
1.46 raeburn 14991: } else {
1.160.6.97 raeburn 14992: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 14993: }
14994: } else {
14995: $resulttext = '<span class="LC_error">'.
14996: &mt('An error occurred: [_1]',$putresult).'</span>';
14997: }
14998: } else {
1.160.6.97 raeburn 14999: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 15000: }
15001: if ($errors) {
15002: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15003: $errors.'</ul>';
15004: }
15005: return $resulttext;
15006: }
15007:
1.48 raeburn 15008: sub modify_coursecategories {
1.160.6.43 raeburn 15009: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 15010: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
15011: $cathash);
1.48 raeburn 15012: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 15013: my @catitems = ('unauth','auth');
15014: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 15015: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 15016: $cathash = $domconfig{'coursecategories'}{'cats'};
15017: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
15018: $changes{'togglecats'} = 1;
15019: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
15020: }
15021: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
15022: $changes{'categorize'} = 1;
15023: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
15024: }
1.120 raeburn 15025: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
15026: $changes{'togglecatscomm'} = 1;
15027: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
15028: }
15029: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
15030: $changes{'categorizecomm'} = 1;
15031: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
15032: }
1.160.6.42 raeburn 15033: foreach my $item (@catitems) {
15034: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
15035: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
15036: $changes{$item} = 1;
15037: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
15038: }
15039: }
15040: }
1.57 raeburn 15041: } else {
15042: $changes{'togglecats'} = 1;
15043: $changes{'categorize'} = 1;
1.124 raeburn 15044: $changes{'togglecatscomm'} = 1;
15045: $changes{'categorizecomm'} = 1;
1.87 raeburn 15046: $domconfig{'coursecategories'} = {
15047: togglecats => $env{'form.togglecats'},
15048: categorize => $env{'form.categorize'},
1.124 raeburn 15049: togglecatscomm => $env{'form.togglecatscomm'},
15050: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 15051: };
1.160.6.42 raeburn 15052: foreach my $item (@catitems) {
15053: if ($env{'form.coursecat_'.$item} ne 'std') {
15054: $changes{$item} = 1;
15055: }
15056: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
15057: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
15058: }
15059: }
1.57 raeburn 15060: }
15061: if (ref($cathash) eq 'HASH') {
15062: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 15063: push (@deletecategory,'instcode::0');
15064: }
1.120 raeburn 15065: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
15066: push(@deletecategory,'communities::0');
15067: }
1.48 raeburn 15068: }
1.57 raeburn 15069: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
15070: if (ref($cathash) eq 'HASH') {
1.48 raeburn 15071: if (@deletecategory > 0) {
15072: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 15073: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 15074: foreach my $item (@deletecategory) {
1.57 raeburn 15075: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
15076: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 15077: $deletions{$item} = 1;
1.57 raeburn 15078: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 15079: }
15080: }
15081: }
1.57 raeburn 15082: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 15083: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 15084: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 15085: $reorderings{$item} = 1;
1.57 raeburn 15086: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 15087: }
15088: if ($env{'form.addcategory_name_'.$item} ne '') {
15089: my $newcat = $env{'form.addcategory_name_'.$item};
15090: my $newdepth = $depth+1;
15091: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 15092: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 15093: $adds{$newitem} = 1;
15094: }
15095: if ($env{'form.subcat_'.$item} ne '') {
15096: my $newcat = $env{'form.subcat_'.$item};
15097: my $newdepth = $depth+1;
15098: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 15099: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 15100: $adds{$newitem} = 1;
15101: }
15102: }
15103: }
15104: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 15105: if (ref($cathash) eq 'HASH') {
1.48 raeburn 15106: my $newitem = 'instcode::0';
1.57 raeburn 15107: if ($cathash->{$newitem} eq '') {
15108: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 15109: $adds{$newitem} = 1;
15110: }
15111: } else {
15112: my $newitem = 'instcode::0';
1.57 raeburn 15113: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 15114: $adds{$newitem} = 1;
15115: }
15116: }
1.120 raeburn 15117: if ($env{'form.communities'} eq '1') {
15118: if (ref($cathash) eq 'HASH') {
15119: my $newitem = 'communities::0';
15120: if ($cathash->{$newitem} eq '') {
15121: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
15122: $adds{$newitem} = 1;
15123: }
15124: } else {
15125: my $newitem = 'communities::0';
15126: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
15127: $adds{$newitem} = 1;
15128: }
15129: }
1.48 raeburn 15130: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 15131: if (($env{'form.addcategory_name'} ne 'instcode') &&
15132: ($env{'form.addcategory_name'} ne 'communities')) {
15133: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
15134: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
15135: $adds{$newitem} = 1;
15136: }
1.48 raeburn 15137: }
1.57 raeburn 15138: my $putresult;
1.48 raeburn 15139: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
15140: if (keys(%deletions) > 0) {
15141: foreach my $key (keys(%deletions)) {
15142: if ($predelallitems{$key} ne '') {
15143: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
15144: }
15145: }
15146: }
15147: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 15148: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 15149: if (ref($chkcats[0]) eq 'ARRAY') {
15150: my $depth = 0;
15151: my $chg = 0;
15152: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
15153: my $name = $chkcats[0][$i];
15154: my $item;
15155: if ($name eq '') {
15156: $chg ++;
15157: } else {
15158: $item = &escape($name).'::0';
15159: if ($chg) {
1.57 raeburn 15160: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 15161: }
15162: $depth ++;
1.57 raeburn 15163: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 15164: $depth --;
15165: }
15166: }
15167: }
1.57 raeburn 15168: }
15169: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
15170: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 15171: if ($putresult eq 'ok') {
1.57 raeburn 15172: my %title = (
1.120 raeburn 15173: togglecats => 'Show/Hide a course in catalog',
15174: categorize => 'Assign a category to a course',
15175: togglecatscomm => 'Show/Hide a community in catalog',
15176: categorizecomm => 'Assign a category to a community',
1.57 raeburn 15177: );
15178: my %level = (
1.120 raeburn 15179: dom => 'set in Domain ("Modify Course/Community")',
15180: crs => 'set in Course ("Course Configuration")',
15181: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 15182: none => 'No catalog',
15183: std => 'Standard catalog',
15184: domonly => 'Domain-only catalog',
15185: codesrch => 'Code search form',
1.57 raeburn 15186: );
1.48 raeburn 15187: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 15188: if ($changes{'togglecats'}) {
15189: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
15190: }
15191: if ($changes{'categorize'}) {
15192: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 15193: }
1.120 raeburn 15194: if ($changes{'togglecatscomm'}) {
15195: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
15196: }
15197: if ($changes{'categorizecomm'}) {
15198: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
15199: }
1.160.6.42 raeburn 15200: if ($changes{'unauth'}) {
15201: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
15202: }
15203: if ($changes{'auth'}) {
15204: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
15205: }
1.57 raeburn 15206: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
15207: my $cathash;
15208: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
15209: $cathash = $domconfig{'coursecategories'}{'cats'};
15210: } else {
15211: $cathash = {};
15212: }
15213: my (@cats,@trails,%allitems);
15214: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
15215: if (keys(%deletions) > 0) {
15216: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
15217: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
15218: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
15219: }
15220: $resulttext .= '</ul></li>';
15221: }
15222: if (keys(%reorderings) > 0) {
15223: my %sort_by_trail;
15224: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
15225: foreach my $key (keys(%reorderings)) {
15226: if ($allitems{$key} ne '') {
15227: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
15228: }
1.48 raeburn 15229: }
1.57 raeburn 15230: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
15231: $resulttext .= '<li>'.$trails[$trail].'</li>';
15232: }
15233: $resulttext .= '</ul></li>';
1.48 raeburn 15234: }
1.57 raeburn 15235: if (keys(%adds) > 0) {
15236: my %sort_by_trail;
15237: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
15238: foreach my $key (keys(%adds)) {
15239: if ($allitems{$key} ne '') {
15240: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
15241: }
15242: }
15243: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
15244: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 15245: }
1.57 raeburn 15246: $resulttext .= '</ul></li>';
1.48 raeburn 15247: }
1.160.6.92 raeburn 15248: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
15249: if (ref($lastactref) eq 'HASH') {
15250: $lastactref->{'cats'} = 1;
15251: }
1.48 raeburn 15252: }
15253: $resulttext .= '</ul>';
1.160.6.43 raeburn 15254: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 15255: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15256: if ($changes{'auth'}) {
15257: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
15258: }
15259: if ($changes{'unauth'}) {
15260: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
15261: }
15262: my $cachetime = 24*60*60;
15263: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 15264: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 15265: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 15266: }
15267: }
1.48 raeburn 15268: } else {
15269: $resulttext = '<span class="LC_error">'.
1.57 raeburn 15270: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 15271: }
15272: } else {
1.120 raeburn 15273: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 15274: }
15275: return $resulttext;
15276: }
15277:
1.69 raeburn 15278: sub modify_serverstatuses {
15279: my ($dom,%domconfig) = @_;
15280: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
15281: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
15282: %currserverstatus = %{$domconfig{'serverstatuses'}};
15283: }
15284: my @pages = &serverstatus_pages();
15285: foreach my $type (@pages) {
15286: $newserverstatus{$type}{'namedusers'} = '';
15287: $newserverstatus{$type}{'machines'} = '';
15288: if (defined($env{'form.'.$type.'_namedusers'})) {
15289: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
15290: my @okusers;
15291: foreach my $user (@users) {
15292: my ($uname,$udom) = split(/:/,$user);
15293: if (($udom =~ /^$match_domain$/) &&
15294: (&Apache::lonnet::domain($udom)) &&
15295: ($uname =~ /^$match_username$/)) {
15296: if (!grep(/^\Q$user\E/,@okusers)) {
15297: push(@okusers,$user);
15298: }
15299: }
15300: }
15301: if (@okusers > 0) {
15302: @okusers = sort(@okusers);
15303: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
15304: }
15305: }
15306: if (defined($env{'form.'.$type.'_machines'})) {
15307: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
15308: my @okmachines;
15309: foreach my $ip (@machines) {
15310: my @parts = split(/\./,$ip);
15311: next if (@parts < 4);
15312: my $badip = 0;
15313: for (my $i=0; $i<4; $i++) {
15314: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
15315: $badip = 1;
15316: last;
15317: }
15318: }
15319: if (!$badip) {
15320: push(@okmachines,$ip);
15321: }
15322: }
15323: @okmachines = sort(@okmachines);
15324: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
15325: }
15326: }
15327: my %serverstatushash = (
15328: serverstatuses => \%newserverstatus,
15329: );
15330: foreach my $type (@pages) {
1.83 raeburn 15331: foreach my $setting ('namedusers','machines') {
1.84 raeburn 15332: my (@current,@new);
1.83 raeburn 15333: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 15334: if ($currserverstatus{$type}{$setting} ne '') {
15335: @current = split(/,/,$currserverstatus{$type}{$setting});
15336: }
15337: }
15338: if ($newserverstatus{$type}{$setting} ne '') {
15339: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 15340: }
15341: if (@current > 0) {
15342: if (@new > 0) {
15343: foreach my $item (@current) {
15344: if (!grep(/^\Q$item\E$/,@new)) {
15345: $changes{$type}{$setting} = 1;
1.82 raeburn 15346: last;
15347: }
15348: }
1.84 raeburn 15349: foreach my $item (@new) {
15350: if (!grep(/^\Q$item\E$/,@current)) {
15351: $changes{$type}{$setting} = 1;
15352: last;
1.82 raeburn 15353: }
15354: }
15355: } else {
1.83 raeburn 15356: $changes{$type}{$setting} = 1;
1.69 raeburn 15357: }
1.83 raeburn 15358: } elsif (@new > 0) {
15359: $changes{$type}{$setting} = 1;
1.69 raeburn 15360: }
15361: }
15362: }
15363: if (keys(%changes) > 0) {
1.81 raeburn 15364: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 15365: my $putresult = &Apache::lonnet::put_dom('configuration',
15366: \%serverstatushash,$dom);
15367: if ($putresult eq 'ok') {
15368: $resulttext .= &mt('Changes made:').'<ul>';
15369: foreach my $type (@pages) {
1.84 raeburn 15370: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 15371: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 15372: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 15373: if ($newserverstatus{$type}{'namedusers'} eq '') {
15374: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
15375: } else {
15376: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
15377: }
1.84 raeburn 15378: }
15379: if ($changes{$type}{'machines'}) {
1.69 raeburn 15380: if ($newserverstatus{$type}{'machines'} eq '') {
15381: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
15382: } else {
15383: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
15384: }
15385:
15386: }
15387: $resulttext .= '</ul></li>';
15388: }
15389: }
15390: $resulttext .= '</ul>';
15391: } else {
15392: $resulttext = '<span class="LC_error">'.
15393: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
15394:
15395: }
15396: } else {
15397: $resulttext = &mt('No changes made to access to server status pages');
15398: }
15399: return $resulttext;
15400: }
15401:
1.118 jms 15402: sub modify_helpsettings {
1.160.6.77 raeburn 15403: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 15404: my ($resulttext,$errors,%changes,%helphash);
15405: my %defaultchecked = ('submitbugs' => 'on');
15406: my @offon = ('off','on');
1.118 jms 15407: my @toggles = ('submitbugs');
1.160.6.77 raeburn 15408: my %current = ('submitbugs' => '',
15409: 'adhoc' => {},
15410: );
1.118 jms 15411: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 15412: %current = %{$domconfig{'helpsettings'}};
15413: }
1.160.6.77 raeburn 15414: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 15415: foreach my $item (@toggles) {
15416: if ($defaultchecked{$item} eq 'on') {
15417: if ($current{$item} eq '') {
15418: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 15419: $changes{$item} = 1;
15420: }
1.160.6.73 raeburn 15421: } elsif ($current{$item} ne $env{'form.'.$item}) {
15422: $changes{$item} = 1;
15423: }
15424: } elsif ($defaultchecked{$item} eq 'off') {
15425: if ($current{$item} eq '') {
15426: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 15427: $changes{$item} = 1;
15428: }
1.160.6.73 raeburn 15429: } elsif ($current{$item} ne $env{'form.'.$item}) {
15430: $changes{$item} = 1;
15431: }
15432: }
15433: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
15434: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
15435: }
15436: }
1.160.6.77 raeburn 15437: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 15438: my $confname = $dom.'-domainconfig';
15439: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 15440: my (@allpos,%newsettings,%changedprivs,$newrole);
15441: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 15442: my @accesstypes = ('all','dh','da','none','status','inc','exc');
15443: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 15444: my %lt = &Apache::lonlocal::texthash(
15445: s => 'system',
15446: d => 'domain',
15447: order => 'Display order',
15448: access => 'Role usage',
1.160.6.79 raeburn 15449: all => 'All with domain helpdesk or helpdesk assistant role',
15450: dh => 'All with domain helpdesk role',
15451: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 15452: none => 'None',
15453: status => 'Determined based on institutional status',
15454: inc => 'Include all, but exclude specific personnel',
15455: exc => 'Exclude all, but include specific personnel',
15456: );
15457: for (my $num=0; $num<=$maxnum; $num++) {
15458: my ($prefix,$identifier,$rolename,%curr);
15459: if ($num == $maxnum) {
15460: next unless ($env{'form.newcusthelp'} == $maxnum);
15461: $identifier = 'custhelp'.$num;
15462: $prefix = 'helproles_'.$num;
15463: $rolename = $env{'form.custhelpname'.$num};
15464: $rolename=~s/[^A-Za-z0-9]//gs;
15465: next if ($rolename eq '');
15466: next if (exists($existing{'rolesdef_'.$rolename}));
15467: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15468: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15469: $newprivs{'c'},$confname,$dom);
15470: if ($result ne 'ok') {
15471: $errors .= '<li><span class="LC_error">'.
15472: &mt('An error occurred storing the new custom role: [_1]',
15473: $result).'</span></li>';
15474: next;
15475: } else {
15476: $changedprivs{$rolename} = \%newprivs;
15477: $newrole = $rolename;
15478: }
15479: } else {
15480: $prefix = 'helproles_'.$num;
15481: $rolename = $env{'form.'.$prefix};
15482: next if ($rolename eq '');
15483: next unless (exists($existing{'rolesdef_'.$rolename}));
15484: $identifier = 'custhelp'.$num;
15485: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15486: my %currprivs;
15487: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
15488: split(/\_/,$existing{'rolesdef_'.$rolename});
15489: foreach my $level ('c','d','s') {
15490: if ($newprivs{$level} ne $currprivs{$level}) {
15491: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15492: $newprivs{'c'},$confname,$dom);
15493: if ($result ne 'ok') {
15494: $errors .= '<li><span class="LC_error">'.
15495: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
15496: $rolename,$result).'</span></li>';
15497: } else {
15498: $changedprivs{$rolename} = \%newprivs;
15499: }
15500: last;
15501: }
15502: }
15503: if (ref($current{'adhoc'}) eq 'HASH') {
15504: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15505: %curr = %{$current{'adhoc'}{$rolename}};
15506: }
15507: }
15508: }
15509: my $newpos = $env{'form.'.$prefix.'_pos'};
15510: $newpos =~ s/\D+//g;
15511: $allpos[$newpos] = $rolename;
15512: my $newdesc = $env{'form.'.$prefix.'_desc'};
15513: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
15514: if ($curr{'desc'}) {
15515: if ($curr{'desc'} ne $newdesc) {
15516: $changes{'customrole'}{$rolename}{'desc'} = 1;
15517: $newsettings{$rolename}{'desc'} = $newdesc;
15518: }
15519: } elsif ($newdesc ne '') {
15520: $changes{'customrole'}{$rolename}{'desc'} = 1;
15521: $newsettings{$rolename}{'desc'} = $newdesc;
15522: }
15523: my $access = $env{'form.'.$prefix.'_access'};
15524: if (grep(/^\Q$access\E$/,@accesstypes)) {
15525: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
15526: if ($access eq 'status') {
15527: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
15528: if (scalar(@statuses) == 0) {
15529: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
15530: } else {
15531: my (@shownstatus,$numtypes);
15532: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15533: if (ref($types) eq 'ARRAY') {
15534: $numtypes = scalar(@{$types});
15535: foreach my $type (sort(@statuses)) {
15536: if ($type eq 'default') {
15537: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15538: } elsif (grep(/^\Q$type\E$/,@{$types})) {
15539: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15540: push(@shownstatus,$usertypes->{$type});
15541: }
1.160.6.73 raeburn 15542: }
15543: }
1.160.6.77 raeburn 15544: if (grep(/^default$/,@statuses)) {
15545: push(@shownstatus,$othertitle);
15546: }
15547: if (scalar(@shownstatus) == 1+$numtypes) {
15548: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
15549: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
15550: } else {
15551: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
15552: if (ref($curr{'status'}) eq 'ARRAY') {
15553: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15554: if (@diffs) {
15555: $changes{'customrole'}{$rolename}{$access} = 1;
15556: }
15557: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15558: $changes{'customrole'}{$rolename}{$access} = 1;
15559: }
15560: }
15561: }
15562: } elsif (($access eq 'inc') || ($access eq 'exc')) {
15563: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
15564: my @newspecstaff;
15565: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15566: foreach my $person (sort(@personnel)) {
15567: if ($domhelpdesk{$person}) {
15568: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
15569: }
15570: }
15571: if (ref($curr{$access}) eq 'ARRAY') {
15572: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15573: if (@diffs) {
15574: $changes{'customrole'}{$rolename}{$access} = 1;
15575: }
15576: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15577: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 15578: }
1.160.6.77 raeburn 15579: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15580: my ($uname,$udom) = split(/:/,$person);
15581: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
15582: }
15583: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 15584: }
1.160.6.77 raeburn 15585: } else {
15586: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
15587: }
15588: unless ($curr{'access'} eq $access) {
15589: $changes{'customrole'}{$rolename}{'access'} = 1;
15590: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 15591: }
15592: }
1.160.6.77 raeburn 15593: if (@allpos > 0) {
15594: my $idx = 0;
15595: foreach my $rolename (@allpos) {
15596: if ($rolename ne '') {
15597: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
15598: if (ref($current{'adhoc'}) eq 'HASH') {
15599: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15600: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
15601: $changes{'customrole'}{$rolename}{'order'} = 1;
15602: $newsettings{$rolename}{'order'} = $idx+1;
15603: }
15604: }
1.160.6.73 raeburn 15605: }
1.160.6.77 raeburn 15606: $idx ++;
1.122 jms 15607: }
15608: }
1.118 jms 15609: }
1.123 jms 15610: my $putresult;
15611: if (keys(%changes) > 0) {
1.160.6.5 raeburn 15612: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
15613: if ($putresult eq 'ok') {
1.160.6.77 raeburn 15614: if (ref($helphash{'helpsettings'}) eq 'HASH') {
15615: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
15616: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
15617: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
15618: }
15619: }
15620: my $cachetime = 24*60*60;
15621: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15622: if (ref($lastactref) eq 'HASH') {
15623: $lastactref->{'domdefaults'} = 1;
15624: }
15625: } else {
15626: $errors .= '<li><span class="LC_error">'.
15627: &mt('An error occurred storing the settings: [_1]',
15628: $putresult).'</span></li>';
15629: }
15630: }
15631: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
15632: $resulttext = &mt('Changes made:').'<ul>';
15633: my (%shownprivs,@levelorder);
15634: @levelorder = ('c','d','s');
15635: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 15636: foreach my $item (sort(keys(%changes))) {
15637: if ($item eq 'submitbugs') {
15638: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
15639: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
15640: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 15641: } elsif ($item eq 'customrole') {
15642: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 15643: my @keyorder = ('order','desc','access','status','exc','inc');
15644: my %keytext = &Apache::lonlocal::texthash(
15645: order => 'Order',
15646: desc => 'Role description',
15647: access => 'Role usage',
1.160.6.83 raeburn 15648: status => 'Allowed institutional types',
1.160.6.77 raeburn 15649: exc => 'Allowed personnel',
15650: inc => 'Disallowed personnel',
15651: );
1.160.6.73 raeburn 15652: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 15653: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
15654: if ($role eq $newrole) {
15655: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
15656: $role).'<ul>';
15657: } else {
15658: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15659: $role).'<ul>';
15660: }
15661: foreach my $key (@keyorder) {
15662: if ($changes{'customrole'}{$role}{$key}) {
15663: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
15664: $keytext{$key},$newsettings{$role}{$key}).
15665: '</li>';
15666: }
15667: }
15668: if (ref($changedprivs{$role}) eq 'HASH') {
15669: $shownprivs{$role} = 1;
15670: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
15671: foreach my $level (@levelorder) {
15672: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15673: next if ($item eq '');
15674: my ($priv) = split(/\&/,$item,2);
15675: if (&Apache::lonnet::plaintext($priv)) {
15676: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15677: unless ($level eq 'c') {
15678: $resulttext .= ' ('.$lt{$level}.')';
15679: }
15680: $resulttext .= '</li>';
15681: }
15682: }
15683: }
15684: $resulttext .= '</ul>';
15685: }
15686: $resulttext .= '</ul></li>';
15687: }
1.160.6.73 raeburn 15688: }
15689: }
1.160.6.5 raeburn 15690: }
15691: }
15692: }
1.160.6.77 raeburn 15693: if (keys(%changedprivs)) {
15694: foreach my $role (sort(keys(%changedprivs))) {
15695: unless ($shownprivs{$role}) {
15696: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15697: $role).'<ul>'.
15698: '<li>'.&mt('Privileges set to :').'<ul>';
15699: foreach my $level (@levelorder) {
15700: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15701: next if ($item eq '');
15702: my ($priv) = split(/\&/,$item,2);
15703: if (&Apache::lonnet::plaintext($priv)) {
15704: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15705: unless ($level eq 'c') {
15706: $resulttext .= ' ('.$lt{$level}.')';
15707: }
15708: $resulttext .= '</li>';
15709: }
15710: }
15711: }
15712: $resulttext .= '</ul></li></ul></li>';
15713: }
15714: }
15715: }
15716: $resulttext .= '</ul>';
15717: } else {
15718: $resulttext = &mt('No changes made to help settings');
1.118 jms 15719: }
15720: if ($errors) {
1.160.6.5 raeburn 15721: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 15722: $errors.'</ul>';
1.118 jms 15723: }
15724: return $resulttext;
15725: }
15726:
1.121 raeburn 15727: sub modify_coursedefaults {
1.160.6.27 raeburn 15728: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 15729: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 15730: my %defaultchecked = (
15731: 'uselcmath' => 'on',
1.160.6.115 raeburn 15732: 'usejsme' => 'on',
15733: 'inline_chem' => 'on',
1.160.6.57 raeburn 15734: );
1.160.6.115 raeburn 15735: my @toggles = ('uselcmath','usejsme','inline_chem');
1.160.6.21 raeburn 15736: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 15737: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
15738: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 15739: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 15740: my %staticdefaults = (
15741: anonsurvey_threshold => 10,
15742: uploadquota => 500,
1.160.6.57 raeburn 15743: postsubmit => 60,
1.160.6.70 raeburn 15744: mysqltables => 172800,
1.160.6.21 raeburn 15745: );
1.160.6.90 raeburn 15746: my %texoptions = (
15747: MathJax => 'MathJax',
15748: mimetex => &mt('Convert to Images'),
15749: tth => &mt('TeX to HTML'),
15750: );
1.121 raeburn 15751: $defaultshash{'coursedefaults'} = {};
15752:
15753: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
15754: if ($domconfig{'coursedefaults'} eq '') {
15755: $domconfig{'coursedefaults'} = {};
15756: }
15757: }
15758:
15759: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
15760: foreach my $item (@toggles) {
15761: if ($defaultchecked{$item} eq 'on') {
15762: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15763: ($env{'form.'.$item} eq '0')) {
15764: $changes{$item} = 1;
1.160.6.16 raeburn 15765: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 15766: $changes{$item} = 1;
15767: }
15768: } elsif ($defaultchecked{$item} eq 'off') {
15769: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15770: ($env{'form.'.$item} eq '1')) {
15771: $changes{$item} = 1;
15772: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
15773: $changes{$item} = 1;
15774: }
15775: }
15776: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
15777: }
1.160.6.21 raeburn 15778: foreach my $item (@numbers) {
15779: my ($currdef,$newdef);
1.160.6.26 raeburn 15780: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 15781: if ($item eq 'anonsurvey_threshold') {
15782: $currdef = $domconfig{'coursedefaults'}{$item};
15783: $newdef =~ s/\D//g;
15784: if ($newdef eq '' || $newdef < 1) {
15785: $newdef = 1;
15786: }
15787: $defaultshash{'coursedefaults'}{$item} = $newdef;
15788: } else {
1.160.6.70 raeburn 15789: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
15790: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
15791: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 15792: }
15793: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 15794: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 15795: }
15796: if ($currdef ne $newdef) {
15797: if ($item eq 'anonsurvey_threshold') {
15798: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
15799: $changes{$item} = 1;
15800: }
1.160.6.70 raeburn 15801: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
15802: my $setting = $1;
15803: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
15804: $changes{$setting} = 1;
1.160.6.21 raeburn 15805: }
15806: }
1.139 raeburn 15807: }
15808: }
1.160.6.90 raeburn 15809: my $texengine;
15810: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
15811: $texengine = $env{'form.texengine'};
15812: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
15813: if ($currdef eq '') {
15814: unless ($texengine eq $Apache::lonnet::deftex) {
15815: $changes{'texengine'} = 1;
15816: }
15817: } elsif ($currdef ne $texengine) {
15818: $changes{'texengine'} = 1;
15819: }
15820: }
15821: if ($texengine ne '') {
15822: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
15823: }
1.160.6.64 raeburn 15824: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
15825: my @currclonecode;
15826: if (ref($currclone) eq 'HASH') {
15827: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
15828: @currclonecode = @{$currclone->{'instcode'}};
15829: }
15830: }
15831: my $newclone;
15832: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
15833: $newclone = $env{'form.canclone'};
15834: }
15835: if ($newclone eq 'instcode') {
15836: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
15837: my (%codedefaults,@code_order,@clonecode);
15838: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
15839: \@code_order);
15840: foreach my $item (@code_order) {
15841: if (grep(/^\Q$item\E$/,@newcodes)) {
15842: push(@clonecode,$item);
15843: }
15844: }
15845: if (@clonecode) {
15846: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
15847: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
15848: if (@diffs) {
15849: $changes{'canclone'} = 1;
15850: }
15851: } else {
15852: $newclone eq '';
15853: }
15854: } elsif ($newclone ne '') {
15855: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
15856: }
15857: if ($newclone ne $currclone) {
15858: $changes{'canclone'} = 1;
15859: }
1.160.6.57 raeburn 15860: my %credits;
15861: foreach my $type (@types) {
15862: unless ($type eq 'community') {
15863: $credits{$type} = $env{'form.'.$type.'_credits'};
15864: $credits{$type} =~ s/[^\d.]+//g;
15865: }
15866: }
15867: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
15868: ($env{'form.coursecredits'} eq '1')) {
15869: $changes{'coursecredits'} = 1;
15870: foreach my $type (keys(%credits)) {
15871: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15872: }
15873: } else {
15874: if ($env{'form.coursecredits'} eq '1') {
15875: foreach my $type (@types) {
15876: unless ($type eq 'community') {
15877: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
15878: $changes{'coursecredits'} = 1;
15879: }
15880: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15881: }
15882: }
15883: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15884: foreach my $type (@types) {
15885: unless ($type eq 'community') {
15886: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
15887: $changes{'coursecredits'} = 1;
15888: last;
15889: }
15890: }
15891: }
15892: }
15893: }
15894: if ($env{'form.postsubmit'} eq '1') {
15895: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
15896: my %currtimeout;
15897: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15898: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
15899: $changes{'postsubmit'} = 1;
15900: }
15901: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15902: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
15903: }
15904: } else {
15905: $changes{'postsubmit'} = 1;
15906: }
15907: foreach my $type (@types) {
15908: my $timeout = $env{'form.'.$type.'_timeout'};
15909: $timeout =~ s/\D//g;
15910: if ($timeout == $staticdefaults{'postsubmit'}) {
15911: $timeout = '';
15912: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
15913: $timeout = '0';
15914: }
15915: unless ($timeout eq '') {
15916: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
15917: }
15918: if (exists($currtimeout{$type})) {
15919: if ($timeout ne $currtimeout{$type}) {
15920: $changes{'postsubmit'} = 1;
15921: }
15922: } elsif ($timeout ne '') {
15923: $changes{'postsubmit'} = 1;
15924: }
15925: }
15926: } else {
15927: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
15928: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15929: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
15930: $changes{'postsubmit'} = 1;
15931: }
15932: } else {
15933: $changes{'postsubmit'} = 1;
15934: }
1.160.6.16 raeburn 15935: }
1.121 raeburn 15936: }
15937: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15938: $dom);
15939: if ($putresult eq 'ok') {
15940: if (keys(%changes) > 0) {
1.160.6.27 raeburn 15941: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 15942: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 15943: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.115 raeburn 15944: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
15945: ($changes{'inline_chem'})) {
15946: foreach my $item ('uselcmath','usejsme','inline_chem','texengine') {
1.160.6.57 raeburn 15947: if ($changes{$item}) {
15948: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
15949: }
1.160.6.16 raeburn 15950: }
15951: if ($changes{'coursecredits'}) {
15952: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 15953: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
15954: $domdefaults{$type.'credits'} =
15955: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
15956: }
15957: }
15958: }
15959: if ($changes{'postsubmit'}) {
15960: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15961: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
15962: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15963: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
15964: $domdefaults{$type.'postsubtimeout'} =
15965: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15966: }
15967: }
1.160.6.16 raeburn 15968: }
15969: }
1.160.6.21 raeburn 15970: if ($changes{'uploadquota'}) {
15971: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15972: foreach my $type (@types) {
15973: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
15974: }
15975: }
15976: }
1.160.6.64 raeburn 15977: if ($changes{'canclone'}) {
15978: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15979: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15980: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
15981: if (@clonecodes) {
15982: $domdefaults{'canclone'} = join('+',@clonecodes);
15983: }
15984: }
15985: } else {
15986: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
15987: }
15988: }
1.121 raeburn 15989: my $cachetime = 24*60*60;
15990: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 15991: if (ref($lastactref) eq 'HASH') {
15992: $lastactref->{'domdefaults'} = 1;
15993: }
1.121 raeburn 15994: }
15995: $resulttext = &mt('Changes made:').'<ul>';
15996: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 15997: if ($item eq 'uselcmath') {
1.121 raeburn 15998: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 15999: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 16000: } else {
1.160.6.57 raeburn 16001: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
16002: }
16003: } elsif ($item eq 'usejsme') {
16004: if ($env{'form.'.$item} eq '1') {
16005: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
16006: } else {
16007: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 16008: }
1.160.6.115 raeburn 16009: } elsif ($item eq 'inline_chem') {
16010: if ($env{'form.'.$item} eq '1') {
16011: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
16012: } else {
16013: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
16014: }
1.160.6.90 raeburn 16015: } elsif ($item eq 'texengine') {
16016: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
16017: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
16018: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
16019: }
1.139 raeburn 16020: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 16021: $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 16022: } elsif ($item eq 'uploadquota') {
16023: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
16024: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
16025: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
16026: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 16027: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
16028:
1.160.6.21 raeburn 16029: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
16030: '</ul>'.
16031: '</li>';
16032: } else {
16033: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
16034: }
1.160.6.70 raeburn 16035: } elsif ($item eq 'mysqltables') {
16036: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
16037: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
16038: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
16039: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
16040: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
16041: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
16042: '</ul>'.
16043: '</li>';
16044: } else {
16045: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
16046: }
1.160.6.57 raeburn 16047: } elsif ($item eq 'postsubmit') {
16048: if ($domdefaults{'postsubmit'} eq 'off') {
16049: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
16050: } else {
16051: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
16052: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
16053: $resulttext .= &mt('durations:').'<ul>';
16054: foreach my $type (@types) {
16055: $resulttext .= '<li>';
16056: my $timeout;
16057: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
16058: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
16059: }
16060: my $display;
16061: if ($timeout eq '0') {
16062: $display = &mt('unlimited');
16063: } elsif ($timeout eq '') {
16064: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
16065: } else {
16066: $display = &mt('[quant,_1,second]',$timeout);
16067: }
16068: if ($type eq 'community') {
16069: $resulttext .= &mt('Communities');
16070: } elsif ($type eq 'official') {
16071: $resulttext .= &mt('Official courses');
16072: } elsif ($type eq 'unofficial') {
16073: $resulttext .= &mt('Unofficial courses');
16074: } elsif ($type eq 'textbook') {
16075: $resulttext .= &mt('Textbook courses');
16076: }
16077: $resulttext .= ' -- '.$display.'</li>';
16078: }
16079: $resulttext .= '</ul>';
16080: }
16081: $resulttext .= '</li>';
16082: }
1.160.6.16 raeburn 16083: } elsif ($item eq 'coursecredits') {
16084: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
16085: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 16086: ($domdefaults{'unofficialcredits'} eq '') &&
16087: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 16088: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
16089: } else {
16090: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
16091: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
16092: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 16093: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 16094: '</ul>'.
16095: '</li>';
16096: }
16097: } else {
16098: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
16099: }
1.160.6.64 raeburn 16100: } elsif ($item eq 'canclone') {
16101: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
16102: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
16103: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
16104: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
16105: }
16106: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
16107: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
16108: } else {
16109: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
16110: }
1.140 raeburn 16111: }
1.121 raeburn 16112: }
16113: $resulttext .= '</ul>';
16114: } else {
16115: $resulttext = &mt('No changes made to course defaults');
16116: }
16117: } else {
16118: $resulttext = '<span class="LC_error">'.
16119: &mt('An error occurred: [_1]',$putresult).'</span>';
16120: }
16121: return $resulttext;
16122: }
16123:
1.160.6.37 raeburn 16124: sub modify_selfenrollment {
16125: my ($dom,$lastactref,%domconfig) = @_;
16126: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
16127: my @types = ('official','unofficial','community','textbook');
16128: my %titles = &tool_titles();
16129: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
16130: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
16131: $ordered{'default'} = ['types','registered','approval','limit'];
16132:
16133: my (%roles,%shown,%toplevel);
16134: $roles{'0'} = &Apache::lonnet::plaintext('dc');
16135:
16136: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
16137: if ($domconfig{'selfenrollment'} eq '') {
16138: $domconfig{'selfenrollment'} = {};
16139: }
16140: }
16141: %toplevel = (
16142: admin => 'Configuration Rights',
16143: default => 'Default settings',
16144: validation => 'Validation of self-enrollment requests',
16145: );
16146: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
16147:
16148: if (ref($ordered{'admin'}) eq 'ARRAY') {
16149: foreach my $item (@{$ordered{'admin'}}) {
16150: foreach my $type (@types) {
16151: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
16152: $selfenrollhash{'admin'}{$type}{$item} = 1;
16153: } else {
16154: $selfenrollhash{'admin'}{$type}{$item} = 0;
16155: }
16156: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
16157: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
16158: if ($selfenrollhash{'admin'}{$type}{$item} ne
16159: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
16160: push(@{$changes{'admin'}{$type}},$item);
16161: }
16162: } else {
16163: if (!$selfenrollhash{'admin'}{$type}{$item}) {
16164: push(@{$changes{'admin'}{$type}},$item);
16165: }
16166: }
16167: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
16168: push(@{$changes{'admin'}{$type}},$item);
16169: }
16170: }
16171: }
16172: }
16173:
16174: foreach my $item (@{$ordered{'default'}}) {
16175: foreach my $type (@types) {
16176: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
16177: if ($item eq 'types') {
16178: unless (($value eq 'all') || ($value eq 'dom')) {
16179: $value = '';
16180: }
16181: } elsif ($item eq 'registered') {
16182: unless ($value eq '1') {
16183: $value = 0;
16184: }
16185: } elsif ($item eq 'approval') {
16186: unless ($value =~ /^[012]$/) {
16187: $value = 0;
16188: }
16189: } else {
16190: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
16191: $value = 'none';
16192: }
16193: }
16194: $selfenrollhash{'default'}{$type}{$item} = $value;
16195: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
16196: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
16197: if ($selfenrollhash{'default'}{$type}{$item} ne
16198: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
16199: push(@{$changes{'default'}{$type}},$item);
16200: }
16201: } else {
16202: push(@{$changes{'default'}{$type}},$item);
16203: }
16204: } else {
16205: push(@{$changes{'default'}{$type}},$item);
16206: }
16207: if ($item eq 'limit') {
16208: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
16209: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
16210: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
16211: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
16212: }
16213: } else {
16214: $selfenrollhash{'default'}{$type}{'cap'} = '';
16215: }
16216: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
16217: if ($selfenrollhash{'default'}{$type}{'cap'} ne
16218: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
16219: push(@{$changes{'default'}{$type}},'cap');
16220: }
16221: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
16222: push(@{$changes{'default'}{$type}},'cap');
16223: }
16224: }
16225: }
16226: }
16227:
16228: foreach my $item (@{$itemsref}) {
16229: if ($item eq 'fields') {
16230: my @changed;
16231: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
16232: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
16233: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
16234: }
16235: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
16236: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
16237: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
16238: $domconfig{'selfenrollment'}{'validation'}{$item});
16239: } else {
16240: @changed = @{$selfenrollhash{'validation'}{$item}};
16241: }
16242: } else {
16243: @changed = @{$selfenrollhash{'validation'}{$item}};
16244: }
16245: if (@changed) {
16246: if ($selfenrollhash{'validation'}{$item}) {
16247: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
16248: } else {
16249: $changes{'validation'}{$item} = &mt('None');
16250: }
16251: }
16252: } else {
16253: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
16254: if ($item eq 'markup') {
16255: if ($env{'form.selfenroll_validation_'.$item}) {
16256: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
16257: }
16258: }
16259: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
16260: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
16261: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
16262: }
16263: }
16264: }
16265: }
16266:
16267: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
16268: $dom);
16269: if ($putresult eq 'ok') {
16270: if (keys(%changes) > 0) {
16271: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16272: $resulttext = &mt('Changes made:').'<ul>';
16273: foreach my $key ('admin','default','validation') {
16274: if (ref($changes{$key}) eq 'HASH') {
16275: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
16276: if ($key eq 'validation') {
16277: foreach my $item (@{$itemsref}) {
16278: if (exists($changes{$key}{$item})) {
16279: if ($item eq 'markup') {
16280: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
16281: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
16282: } else {
16283: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
16284: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
16285: }
16286: }
16287: }
16288: } else {
16289: foreach my $type (@types) {
16290: if ($type eq 'community') {
16291: $roles{'1'} = &mt('Community personnel');
16292: } else {
16293: $roles{'1'} = &mt('Course personnel');
16294: }
16295: if (ref($changes{$key}{$type}) eq 'ARRAY') {
16296: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
16297: if ($key eq 'admin') {
16298: my @mgrdc = ();
16299: if (ref($ordered{$key}) eq 'ARRAY') {
16300: foreach my $item (@{$ordered{'admin'}}) {
16301: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
16302: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
16303: push(@mgrdc,$item);
16304: }
16305: }
16306: }
16307: if (@mgrdc) {
16308: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
16309: } else {
16310: delete($domdefaults{$type.'selfenrolladmdc'});
16311: }
16312: }
16313: } else {
16314: if (ref($ordered{$key}) eq 'ARRAY') {
16315: foreach my $item (@{$ordered{$key}}) {
16316: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
16317: $domdefaults{$type.'selfenroll'.$item} =
16318: $selfenrollhash{$key}{$type}{$item};
16319: }
16320: }
16321: }
16322: }
16323: }
16324: $resulttext .= '<li>'.$titles{$type}.'<ul>';
16325: foreach my $item (@{$ordered{$key}}) {
16326: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
16327: $resulttext .= '<li>';
16328: if ($key eq 'admin') {
16329: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
16330: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
16331: } else {
16332: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
16333: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
16334: }
16335: $resulttext .= '</li>';
16336: }
16337: }
16338: $resulttext .= '</ul></li>';
16339: }
16340: }
16341: $resulttext .= '</ul></li>';
16342: }
16343: }
1.160.6.93 raeburn 16344: }
16345: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
16346: my $cachetime = 24*60*60;
16347: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16348: if (ref($lastactref) eq 'HASH') {
16349: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 16350: }
16351: }
16352: $resulttext .= '</ul>';
16353: } else {
16354: $resulttext = &mt('No changes made to self-enrollment settings');
16355: }
16356: } else {
16357: $resulttext = '<span class="LC_error">'.
16358: &mt('An error occurred: [_1]',$putresult).'</span>';
16359: }
16360: return $resulttext;
16361: }
16362:
1.160.6.113 raeburn 16363: sub modify_wafproxy {
16364: my ($dom,$action,$lastactref,%domconfig) = @_;
16365: my %servers = &Apache::lonnet::internet_dom_servers($dom);
16366: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
16367: %wafproxy,%changes,%expirecache,%expiresaml);
16368: foreach my $server (sort(keys(%servers))) {
16369: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
16370: if ($serverhome eq $server) {
16371: my $serverdom = &Apache::lonnet::host_domain($server);
16372: if ($serverdom eq $dom) {
16373: $canset{$server} = 1;
16374: }
16375: }
16376: }
16377: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
16378: %{$values{$dom}} = ();
16379: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
16380: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
16381: }
16382: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
16383: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
16384: }
16385: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
16386: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
16387: }
16388: }
16389: my $output;
16390: if (keys(%canset)) {
16391: %{$wafproxy{'alias'}} = ();
16392: %{$wafproxy{'saml'}} = ();
16393: foreach my $key (sort(keys(%canset))) {
16394: if ($env{'form.wafproxy_'.$dom}) {
16395: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
16396: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
16397: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
16398: $changes{'alias'} = 1;
16399: }
16400: if ($env{'form.wafproxy_alias_saml_'.$key}) {
16401: $wafproxy{'saml'}{$key} = 1;
16402: }
16403: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
16404: $changes{'saml'} = 1;
16405: }
16406: } else {
16407: $wafproxy{'alias'}{$key} = '';
16408: $wafproxy{'saml'}{$key} = '';
16409: if ($curralias{$key}) {
16410: $changes{'alias'} = 1;
16411: }
16412: if ($currsaml{$key}) {
16413: $changes{'saml'} = 1;
16414: }
16415: }
16416: if ($wafproxy{'alias'}{$key} eq '') {
16417: if ($curralias{$key}) {
16418: $expirecache{$key} = 1;
16419: }
16420: delete($wafproxy{'alias'}{$key});
16421: }
16422: if ($wafproxy{'saml'}{$key} eq '') {
16423: if ($currsaml{$key}) {
16424: $expiresaml{$key} = 1;
16425: }
16426: delete($wafproxy{'saml'}{$key});
16427: }
16428: }
16429: unless (keys(%{$wafproxy{'alias'}})) {
16430: delete($wafproxy{'alias'});
16431: }
16432: unless (keys(%{$wafproxy{'saml'}})) {
16433: delete($wafproxy{'saml'});
16434: }
16435: # Localization for values in %warn occurs in &mt() calls separately.
16436: my %warn = (
16437: trusted => 'trusted IP range(s)',
16438: vpnint => 'internal IP range(s) for VPN sessions(s)',
16439: vpnext => 'IP range(s) for backend WAF connections',
16440: );
16441: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
16442: my $possible = $env{'form.wafproxy_'.$item};
16443: $possible =~ s/^\s+|\s+$//g;
16444: if ($possible ne '') {
16445: if ($item eq 'remoteip') {
16446: if ($possible =~ /^[mhn]$/) {
16447: $wafproxy{$item} = $possible;
16448: }
16449: } elsif ($item eq 'ipheader') {
16450: if ($wafproxy{'remoteip'} eq 'h') {
16451: $wafproxy{$item} = $possible;
16452: }
16453: } elsif ($item eq 'sslopt') {
16454: if ($possible =~ /^0|1$/) {
16455: $wafproxy{$item} = $possible;
16456: }
16457: } else {
16458: my (@ok,$count);
16459: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
16460: unless ($env{'form.wafproxy_vpnaccess'}) {
16461: $possible = '';
16462: }
16463: } elsif ($item eq 'trusted') {
16464: unless ($wafproxy{'remoteip'} eq 'h') {
16465: $possible = '';
16466: }
16467: }
16468: unless ($possible eq '') {
16469: $possible =~ s/[\r\n]+/\s/g;
16470: $possible =~ s/\s*-\s*/-/g;
16471: $possible =~ s/\s+/,/g;
16472: $possible =~ s/,+/,/g;
16473: }
16474: $count = 0;
16475: if ($possible ne '') {
16476: foreach my $poss (split(/\,/,$possible)) {
16477: $count ++;
16478: $poss = &validate_ip_pattern($poss);
16479: if ($poss ne '') {
16480: push(@ok,$poss);
16481: }
16482: }
16483: my $diff = $count - scalar(@ok);
16484: if ($diff) {
16485: push(@warnings,'<li>'.
16486: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
16487: $diff,$warn{$item}).
16488: '</li>');
16489: }
16490: if (@ok) {
16491: my @cidr_list;
16492: foreach my $item (@ok) {
16493: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
16494: }
16495: $wafproxy{$item} = join(',',@cidr_list);
16496: }
16497: }
16498: }
16499: if ($wafproxy{$item} ne $currvalue{$item}) {
16500: $changes{$item} = 1;
16501: }
16502: } elsif ($currvalue{$item}) {
16503: $changes{$item} = 1;
16504: }
16505: }
16506: } else {
16507: if (keys(%curralias)) {
16508: $changes{'alias'} = 1;
16509: }
16510: if (keys(%currsaml)) {
16511: $changes{'saml'} = 1;
16512: }
16513: if (keys(%currvalue)) {
16514: foreach my $key (keys(%currvalue)) {
16515: $changes{$key} = 1;
16516: }
16517: }
16518: }
16519: if (keys(%changes)) {
16520: my %defaultshash = (
16521: wafproxy => \%wafproxy,
16522: );
16523: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16524: $dom);
16525: if ($putresult eq 'ok') {
16526: my $cachetime = 24*60*60;
16527: my (%domdefaults,$updatedomdefs);
16528: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
16529: if ($changes{$item}) {
16530: unless ($updatedomdefs) {
16531: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
16532: $updatedomdefs = 1;
16533: }
16534: if ($wafproxy{$item}) {
16535: $domdefaults{'waf_'.$item} = $wafproxy{$item};
16536: } elsif (exists($domdefaults{'waf_'.$item})) {
16537: delete($domdefaults{'waf_'.$item});
16538: }
16539: }
16540: }
16541: if ($updatedomdefs) {
16542: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16543: if (ref($lastactref) eq 'HASH') {
16544: $lastactref->{'domdefaults'} = 1;
16545: }
16546: }
16547: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
16548: my %updates = %expirecache;
16549: foreach my $key (keys(%expirecache)) {
16550: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
16551: }
16552: if (ref($wafproxy{'alias'}) eq 'HASH') {
16553: my $cachetime = 24*60*60;
16554: foreach my $key (keys(%{$wafproxy{'alias'}})) {
16555: $updates{$key} = 1;
16556: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
16557: $cachetime);
16558: }
16559: }
16560: if (ref($lastactref) eq 'HASH') {
16561: $lastactref->{'proxyalias'} = \%updates;
16562: }
16563: }
16564: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
16565: my %samlupdates = %expiresaml;
16566: foreach my $key (keys(%expiresaml)) {
16567: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
16568: }
16569: if (ref($wafproxy{'saml'}) eq 'HASH') {
16570: my $cachetime = 24*60*60;
16571: foreach my $key (keys(%{$wafproxy{'saml'}})) {
16572: $samlupdates{$key} = 1;
16573: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
16574: $cachetime);
16575: }
16576: }
16577: if (ref($lastactref) eq 'HASH') {
16578: $lastactref->{'proxysaml'} = \%samlupdates;
16579: }
16580: }
16581: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.160.6.118 raeburn 16582: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.160.6.113 raeburn 16583: if ($changes{$item}) {
16584: if ($item eq 'alias') {
16585: my $numaliased = 0;
16586: if (ref($wafproxy{'alias'}) eq 'HASH') {
16587: my $shown;
16588: if (keys(%{$wafproxy{'alias'}})) {
16589: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
16590: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
16591: &Apache::lonnet::hostname($server),
16592: $wafproxy{'alias'}{$server}).'</li>';
16593: $numaliased ++;
16594: }
16595: if ($numaliased) {
16596: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
16597: '<ul>'.$shown.'</ul>').'</li>';
16598: }
16599: }
16600: }
16601: unless ($numaliased) {
16602: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
16603: }
16604: } elsif ($item eq 'saml') {
16605: my $shown;
16606: if (ref($wafproxy{'saml'}) eq 'HASH') {
16607: if (keys(%{$wafproxy{'saml'}})) {
16608: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
16609: }
16610: }
16611: if ($shown) {
16612: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
16613: $shown).'</li>';
16614: } else {
16615: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
16616: }
16617: } else {
16618: if ($item eq 'remoteip') {
16619: my %ip_methods = &remoteip_methods();
16620: if ($wafproxy{$item} =~ /^[mh]$/) {
16621: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
16622: $ip_methods{$wafproxy{$item}}).'</li>';
16623: } else {
16624: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
16625: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
16626: '</li>';
16627: } else {
16628: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
16629: }
16630: }
16631: } elsif ($item eq 'ipheader') {
16632: if ($wafproxy{$item}) {
16633: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
16634: $wafproxy{$item}).'</li>';
16635: } else {
16636: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
16637: }
16638: } elsif ($item eq 'trusted') {
16639: if ($wafproxy{$item}) {
16640: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
16641: $wafproxy{$item}).'</li>';
16642: } else {
16643: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
16644: }
16645: } elsif ($item eq 'vpnint') {
16646: if ($wafproxy{$item}) {
16647: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
16648: $wafproxy{$item}).'</li>';
16649: } else {
16650: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
16651: }
16652: } elsif ($item eq 'vpnext') {
16653: if ($wafproxy{$item}) {
16654: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
16655: $wafproxy{$item}).'</li>';
16656: } else {
16657: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
16658: }
16659: } elsif ($item eq 'sslopt') {
16660: if ($wafproxy{$item}) {
16661: $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>';
16662: } else {
16663: $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>';
16664: }
16665: }
16666: }
16667: }
16668: }
16669: } else {
16670: $output = '<span class="LC_error">'.
16671: &mt('An error occurred: [_1]',$putresult).'</span>';
16672: }
16673: } elsif (keys(%canset)) {
16674: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
16675: }
16676: if (@warnings) {
16677: $output .= '<br />'.&mt('Warnings:').'<ul>'.
16678: join("\n",@warnings).'</ul>';
16679: }
16680: return $output;
16681: }
16682:
16683: sub validate_ip_pattern {
16684: my ($pattern) = @_;
16685: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
16686: my ($start,$end) = ($1,$2);
16687: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
16688: if (($start !~ m{/}) && ($end !~ m{/})) {
16689: return $start.'-'.$end;
16690: }
16691: }
16692: } elsif ($pattern ne '') {
16693: $pattern = &Net::CIDR::cidrvalidate($pattern);
16694: if ($pattern ne '') {
16695: return $pattern;
16696: }
16697: }
16698: return;
16699: }
16700:
1.137 raeburn 16701: sub modify_usersessions {
1.160.6.27 raeburn 16702: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 16703: my @hostingtypes = ('version','excludedomain','includedomain');
16704: my @offloadtypes = ('primary','default');
16705: my %types = (
16706: remote => \@hostingtypes,
16707: hosted => \@hostingtypes,
16708: spares => \@offloadtypes,
16709: );
16710: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 16711: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 16712: my (%by_ip,%by_location,@intdoms);
16713: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
16714: my @locations = sort(keys(%by_location));
1.137 raeburn 16715: my (%defaultshash,%changes);
16716: foreach my $prefix (@prefixes) {
16717: $defaultshash{'usersessions'}{$prefix} = {};
16718: }
1.160.6.27 raeburn 16719: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 16720: my $resulttext;
1.138 raeburn 16721: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 16722: foreach my $prefix (@prefixes) {
1.145 raeburn 16723: next if ($prefix eq 'spares');
16724: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 16725: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16726: if ($type eq 'version') {
16727: my $value = $env{'form.'.$prefix.'_'.$type};
16728: my $okvalue;
16729: if ($value ne '') {
16730: if (grep(/^\Q$value\E$/,@lcversions)) {
16731: $okvalue = $value;
16732: }
16733: }
16734: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16735: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16736: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
16737: if ($inuse == 0) {
16738: $changes{$prefix}{$type} = 1;
16739: } else {
16740: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
16741: $changes{$prefix}{$type} = 1;
16742: }
16743: if ($okvalue ne '') {
16744: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16745: }
16746: }
16747: } else {
16748: if (($inuse == 1) && ($okvalue ne '')) {
16749: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16750: $changes{$prefix}{$type} = 1;
16751: }
16752: }
16753: } else {
16754: if (($inuse == 1) && ($okvalue ne '')) {
16755: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16756: $changes{$prefix}{$type} = 1;
16757: }
16758: }
16759: } else {
16760: if (($inuse == 1) && ($okvalue ne '')) {
16761: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16762: $changes{$prefix}{$type} = 1;
16763: }
16764: }
16765: } else {
16766: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16767: my @okvals;
16768: foreach my $val (@vals) {
1.138 raeburn 16769: if ($val =~ /:/) {
16770: my @items = split(/:/,$val);
16771: foreach my $item (@items) {
16772: if (ref($by_location{$item}) eq 'ARRAY') {
16773: push(@okvals,$item);
16774: }
16775: }
16776: } else {
16777: if (ref($by_location{$val}) eq 'ARRAY') {
16778: push(@okvals,$val);
16779: }
1.137 raeburn 16780: }
16781: }
16782: @okvals = sort(@okvals);
16783: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16784: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16785: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16786: if ($inuse == 0) {
16787: $changes{$prefix}{$type} = 1;
16788: } else {
16789: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16790: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
16791: if (@changed > 0) {
16792: $changes{$prefix}{$type} = 1;
16793: }
16794: }
16795: } else {
16796: if ($inuse == 1) {
16797: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16798: $changes{$prefix}{$type} = 1;
16799: }
16800: }
16801: } else {
16802: if ($inuse == 1) {
16803: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16804: $changes{$prefix}{$type} = 1;
16805: }
16806: }
16807: } else {
16808: if ($inuse == 1) {
16809: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16810: $changes{$prefix}{$type} = 1;
16811: }
16812: }
16813: }
16814: }
16815: }
1.145 raeburn 16816:
16817: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 16818: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 16819: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
16820: my $savespares;
16821:
16822: foreach my $lonhost (sort(keys(%servers))) {
16823: my $serverhomeID =
16824: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 16825: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 16826: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
16827: my %spareschg;
16828: foreach my $type (@{$types{'spares'}}) {
16829: my @okspares;
16830: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
16831: foreach my $server (@checked) {
1.152 raeburn 16832: if (&Apache::lonnet::hostname($server) ne '') {
16833: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
16834: unless (grep(/^\Q$server\E$/,@okspares)) {
16835: push(@okspares,$server);
16836: }
1.145 raeburn 16837: }
16838: }
16839: }
16840: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
16841: my $newspare;
1.152 raeburn 16842: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
16843: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 16844: $newspare = $new;
16845: }
16846: }
1.152 raeburn 16847: my @spares;
16848: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
16849: @spares = sort(@okspares,$newspare);
16850: } else {
16851: @spares = sort(@okspares);
16852: }
16853: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 16854: if (ref($spareid{$lonhost}) eq 'HASH') {
16855: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 16856: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 16857: if (@diffs > 0) {
16858: $spareschg{$type} = 1;
16859: }
16860: }
16861: }
16862: }
16863: if (keys(%spareschg) > 0) {
16864: $changes{'spares'}{$lonhost} = \%spareschg;
16865: }
16866: }
1.160.6.61 raeburn 16867: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.160.6.105 raeburn 16868: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.160.6.61 raeburn 16869: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
16870: my @okoffload;
16871: if (@offloadnow) {
16872: foreach my $server (@offloadnow) {
16873: if (&Apache::lonnet::hostname($server) ne '') {
16874: unless (grep(/^\Q$server\E$/,@okoffload)) {
16875: push(@okoffload,$server);
16876: }
16877: }
16878: }
16879: if (@okoffload) {
16880: foreach my $lonhost (@okoffload) {
16881: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
16882: }
16883: }
16884: }
1.160.6.105 raeburn 16885: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
16886: my @okoffloadoth;
16887: if (@offloadoth) {
16888: foreach my $server (@offloadoth) {
16889: if (&Apache::lonnet::hostname($server) ne '') {
16890: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
16891: push(@okoffloadoth,$server);
16892: }
16893: }
16894: }
16895: if (@okoffloadoth) {
16896: foreach my $lonhost (@okoffloadoth) {
16897: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
16898: }
16899: }
16900: }
1.145 raeburn 16901: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16902: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
16903: if (ref($changes{'spares'}) eq 'HASH') {
16904: if (keys(%{$changes{'spares'}}) > 0) {
16905: $savespares = 1;
16906: }
16907: }
16908: } else {
16909: $savespares = 1;
16910: }
1.160.6.105 raeburn 16911: foreach my $offload ('offloadnow','offloadoth') {
16912: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
16913: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
16914: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
16915: $changes{$offload} = 1;
1.160.6.61 raeburn 16916: last;
16917: }
16918: }
1.160.6.105 raeburn 16919: unless ($changes{$offload}) {
16920: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
16921: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
16922: $changes{$offload} = 1;
16923: last;
16924: }
16925: }
16926: }
16927: } else {
16928: if (($offload eq 'offloadnow') && (@okoffload)) {
16929: $changes{'offloadnow'} = 1;
16930: }
16931: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
16932: $changes{'offloadoth'} = 1;
16933: }
1.160.6.61 raeburn 16934: }
1.160.6.105 raeburn 16935: }
16936: } else {
16937: if (@okoffload) {
1.160.6.61 raeburn 16938: $changes{'offloadnow'} = 1;
16939: }
1.160.6.105 raeburn 16940: if (@okoffloadoth) {
16941: $changes{'offloadoth'} = 1;
16942: }
1.145 raeburn 16943: }
1.147 raeburn 16944: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
16945: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 16946: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16947: $dom);
16948: if ($putresult eq 'ok') {
16949: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16950: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
16951: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
16952: }
16953: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
16954: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
16955: }
1.160.6.61 raeburn 16956: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16957: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
16958: }
1.160.6.105 raeburn 16959: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
16960: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
16961: }
1.137 raeburn 16962: }
16963: my $cachetime = 24*60*60;
16964: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 16965: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 16966: if (ref($lastactref) eq 'HASH') {
16967: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 16968: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 16969: }
1.147 raeburn 16970: if (keys(%changes) > 0) {
16971: my %lt = &usersession_titles();
16972: $resulttext = &mt('Changes made:').'<ul>';
16973: foreach my $prefix (@prefixes) {
16974: if (ref($changes{$prefix}) eq 'HASH') {
16975: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16976: if ($prefix eq 'spares') {
16977: if (ref($changes{$prefix}) eq 'HASH') {
16978: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
16979: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 16980: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 16981: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
16982: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 16983: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
16984: foreach my $type (@{$types{$prefix}}) {
16985: if ($changes{$prefix}{$lonhost}{$type}) {
16986: my $offloadto = &mt('None');
16987: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
16988: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
16989: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
16990: }
1.145 raeburn 16991: }
1.147 raeburn 16992: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 16993: }
1.137 raeburn 16994: }
16995: }
1.147 raeburn 16996: $resulttext .= '</li>';
1.137 raeburn 16997: }
16998: }
1.147 raeburn 16999: } else {
17000: foreach my $type (@{$types{$prefix}}) {
17001: if (defined($changes{$prefix}{$type})) {
17002: my $newvalue;
17003: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
17004: if (ref($defaultshash{'usersessions'}{$prefix})) {
17005: if ($type eq 'version') {
17006: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
17007: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
17008: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
17009: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
17010: }
1.145 raeburn 17011: }
17012: }
17013: }
1.147 raeburn 17014: if ($newvalue eq '') {
17015: if ($type eq 'version') {
17016: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
17017: } else {
17018: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
17019: }
1.145 raeburn 17020: } else {
1.147 raeburn 17021: if ($type eq 'version') {
17022: $newvalue .= ' '.&mt('(or later)');
17023: }
17024: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 17025: }
1.137 raeburn 17026: }
17027: }
17028: }
1.147 raeburn 17029: $resulttext .= '</ul>';
1.137 raeburn 17030: }
17031: }
1.160.6.61 raeburn 17032: if ($changes{'offloadnow'}) {
17033: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
17034: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.160.6.105 raeburn 17035: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.160.6.61 raeburn 17036: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
17037: $resulttext .= '<li>'.$lonhost.'</li>';
17038: }
17039: $resulttext .= '</ul>';
17040: } else {
1.160.6.105 raeburn 17041: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
17042: }
17043: } else {
17044: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
17045: }
17046: }
17047: if ($changes{'offloadoth'}) {
17048: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
17049: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
17050: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
17051: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
17052: $resulttext .= '<li>'.$lonhost.'</li>';
17053: }
17054: $resulttext .= '</ul>';
17055: } else {
17056: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.160.6.61 raeburn 17057: }
17058: } else {
1.160.6.105 raeburn 17059: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.160.6.61 raeburn 17060: }
17061: }
1.147 raeburn 17062: $resulttext .= '</ul>';
17063: } else {
17064: $resulttext = $nochgmsg;
1.137 raeburn 17065: }
17066: } else {
17067: $resulttext = '<span class="LC_error">'.
17068: &mt('An error occurred: [_1]',$putresult).'</span>';
17069: }
17070: } else {
1.147 raeburn 17071: $resulttext = $nochgmsg;
1.137 raeburn 17072: }
17073: return $resulttext;
17074: }
17075:
1.150 raeburn 17076: sub modify_loadbalancing {
17077: my ($dom,%domconfig) = @_;
17078: my $primary_id = &Apache::lonnet::domain($dom,'primary');
17079: my $intdom = &Apache::lonnet::internet_dom($primary_id);
17080: my ($othertitle,$usertypes,$types) =
17081: &Apache::loncommon::sorted_inst_types($dom);
17082: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 17083: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 17084: my @sparestypes = ('primary','default');
17085: my %typetitles = &sparestype_titles();
17086: my $resulttext;
1.160.6.94 raeburn 17087: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 17088: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
17089: %existing = %{$domconfig{'loadbalancing'}};
17090: }
17091: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 17092: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 17093: my ($saveloadbalancing,%defaultshash,%changes);
17094: my ($alltypes,$othertypes,$titles) =
17095: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
17096: my %ruletitles = &offloadtype_text();
17097: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
17098: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
17099: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
17100: if ($balancer eq '') {
17101: next;
17102: }
17103: if (!exists($servers{$balancer})) {
17104: if (exists($currbalancer{$balancer})) {
17105: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 17106: }
1.160.6.7 raeburn 17107: next;
17108: }
17109: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
17110: push(@{$changes{'delete'}},$balancer);
17111: next;
17112: }
17113: if (!exists($currbalancer{$balancer})) {
17114: push(@{$changes{'add'}},$balancer);
17115: }
17116: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
17117: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
17118: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
17119: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
17120: $saveloadbalancing = 1;
17121: }
17122: foreach my $sparetype (@sparestypes) {
17123: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
17124: my @offloadto;
17125: foreach my $target (@targets) {
17126: if (($servers{$target}) && ($target ne $balancer)) {
17127: if ($sparetype eq 'default') {
17128: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
17129: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 17130: }
17131: }
1.160.6.7 raeburn 17132: unless(grep(/^\Q$target\E$/,@offloadto)) {
17133: push(@offloadto,$target);
17134: }
1.150 raeburn 17135: }
17136: }
1.160.6.76 raeburn 17137: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
17138: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
17139: push(@offloadto,$balancer);
17140: }
17141: }
17142: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 17143: }
1.160.6.94 raeburn 17144: if ($env{'form.loadbalancing_cookie_'.$i}) {
17145: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
17146: if (exists($currbalancer{$balancer})) {
17147: unless ($currcookies{$balancer}) {
17148: $changes{'curr'}{$balancer}{'cookie'} = 1;
17149: }
17150: }
17151: } elsif (exists($currbalancer{$balancer})) {
17152: if ($currcookies{$balancer}) {
17153: $changes{'curr'}{$balancer}{'cookie'} = 1;
17154: }
17155: }
1.160.6.7 raeburn 17156: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 17157: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 17158: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
17159: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 17160: if (@targetdiffs > 0) {
1.160.6.7 raeburn 17161: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 17162: }
1.160.6.7 raeburn 17163: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17164: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
17165: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 17166: }
17167: }
17168: }
17169: } else {
1.160.6.7 raeburn 17170: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
17171: foreach my $sparetype (@sparestypes) {
17172: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17173: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
17174: $changes{'curr'}{$balancer}{'targets'} = 1;
17175: }
1.150 raeburn 17176: }
17177: }
1.160.6.7 raeburn 17178: }
1.150 raeburn 17179: }
17180: my $ishomedom;
1.160.6.7 raeburn 17181: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
17182: $ishomedom = 1;
1.150 raeburn 17183: }
17184: if (ref($alltypes) eq 'ARRAY') {
17185: foreach my $type (@{$alltypes}) {
17186: my $rule;
1.160.6.7 raeburn 17187: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 17188: (!$ishomedom)) {
1.160.6.7 raeburn 17189: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
17190: }
17191: if ($rule eq 'specific') {
1.160.6.55 raeburn 17192: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
17193: if (exists($servers{$specifiedhost})) {
17194: $rule = $specifiedhost;
17195: }
1.150 raeburn 17196: }
1.160.6.7 raeburn 17197: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
17198: if (ref($currrules{$balancer}) eq 'HASH') {
17199: if ($rule ne $currrules{$balancer}{$type}) {
17200: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 17201: }
17202: } elsif ($rule ne '') {
1.160.6.7 raeburn 17203: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 17204: }
17205: }
17206: }
1.160.6.7 raeburn 17207: }
17208: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
17209: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
17210: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
17211: $defaultshash{'loadbalancing'} = {};
17212: }
17213: my $putresult = &Apache::lonnet::put_dom('configuration',
17214: \%defaultshash,$dom);
17215: if ($putresult eq 'ok') {
17216: if (keys(%changes) > 0) {
1.160.6.54 raeburn 17217: my %toupdate;
1.160.6.7 raeburn 17218: if (ref($changes{'delete'}) eq 'ARRAY') {
17219: foreach my $balancer (sort(@{$changes{'delete'}})) {
17220: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 17221: $toupdate{$balancer} = 1;
1.150 raeburn 17222: }
1.160.6.7 raeburn 17223: }
17224: if (ref($changes{'add'}) eq 'ARRAY') {
17225: foreach my $balancer (sort(@{$changes{'add'}})) {
17226: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 17227: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 17228: }
17229: }
17230: if (ref($changes{'curr'}) eq 'HASH') {
17231: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 17232: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 17233: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
17234: if ($changes{'curr'}{$balancer}{'targets'}) {
17235: my %offloadstr;
17236: foreach my $sparetype (@sparestypes) {
17237: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17238: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
17239: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
17240: }
17241: }
1.150 raeburn 17242: }
1.160.6.7 raeburn 17243: if (keys(%offloadstr) == 0) {
17244: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 17245: } else {
1.160.6.7 raeburn 17246: my $showoffload;
17247: foreach my $sparetype (@sparestypes) {
17248: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
17249: if (defined($offloadstr{$sparetype})) {
17250: $showoffload .= $offloadstr{$sparetype};
17251: } else {
17252: $showoffload .= &mt('None');
17253: }
17254: $showoffload .= (' 'x3);
17255: }
17256: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 17257: }
17258: }
17259: }
1.160.6.7 raeburn 17260: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
17261: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
17262: foreach my $type (@{$alltypes}) {
17263: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
17264: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
17265: my $balancetext;
17266: if ($rule eq '') {
17267: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 17268: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 17269: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
17270: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 17271: foreach my $sparetype (@sparestypes) {
17272: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17273: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
17274: }
17275: }
1.160.6.55 raeburn 17276: foreach my $item (@{$alltypes}) {
17277: next if ($item =~ /^_LC_ipchange/);
17278: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
17279: if ($hasrule eq 'homeserver') {
17280: map { $toupdate{$_} = 1; } (keys(%libraryservers));
17281: } else {
17282: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
17283: if ($servers{$hasrule}) {
17284: $toupdate{$hasrule} = 1;
17285: }
17286: }
17287: }
17288: }
17289: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
17290: $balancetext = $ruletitles{$rule};
17291: } else {
17292: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
17293: $balancetext = $ruletitles{'particular'}.' '.$receiver;
17294: if ($receiver) {
17295: $toupdate{$receiver};
17296: }
17297: }
17298: } else {
17299: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 17300: }
1.160.6.7 raeburn 17301: } else {
17302: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
17303: }
1.160.6.26 raeburn 17304: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 17305: }
17306: }
17307: }
17308: }
1.160.6.94 raeburn 17309: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.160.6.117 raeburn 17310: if ($currcookies{$balancer}) {
17311: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
17312: $balancer).'</li>';
17313: } else {
17314: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
17315: $balancer).'</li>';
17316: }
1.160.6.94 raeburn 17317: }
1.160.6.106 raeburn 17318: }
17319: }
17320: if (keys(%toupdate)) {
17321: my %thismachine;
17322: my $updatedhere;
17323: my $cachetime = 60*60*24;
17324: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
17325: foreach my $lonhost (keys(%toupdate)) {
17326: if ($thismachine{$lonhost}) {
17327: unless ($updatedhere) {
17328: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
17329: $defaultshash{'loadbalancing'},
17330: $cachetime);
17331: $updatedhere = 1;
1.160.6.54 raeburn 17332: }
1.160.6.106 raeburn 17333: } else {
17334: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
17335: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.160.6.54 raeburn 17336: }
1.150 raeburn 17337: }
1.160.6.7 raeburn 17338: }
17339: if ($resulttext ne '') {
17340: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 17341: } else {
17342: $resulttext = $nochgmsg;
17343: }
17344: } else {
1.160.6.7 raeburn 17345: $resulttext = $nochgmsg;
1.150 raeburn 17346: }
17347: } else {
1.160.6.7 raeburn 17348: $resulttext = '<span class="LC_error">'.
17349: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 17350: }
17351: } else {
1.160.6.7 raeburn 17352: $resulttext = $nochgmsg;
1.150 raeburn 17353: }
17354: return $resulttext;
17355: }
17356:
1.48 raeburn 17357: sub recurse_check {
17358: my ($chkcats,$categories,$depth,$name) = @_;
17359: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
17360: my $chg = 0;
17361: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
17362: my $category = $chkcats->[$depth]{$name}[$j];
17363: my $item;
17364: if ($category eq '') {
17365: $chg ++;
17366: } else {
17367: my $deeper = $depth + 1;
17368: $item = &escape($category).':'.&escape($name).':'.$depth;
17369: if ($chg) {
17370: $categories->{$item} -= $chg;
17371: }
17372: &recurse_check($chkcats,$categories,$deeper,$category);
17373: $deeper --;
17374: }
17375: }
17376: }
17377: return;
17378: }
17379:
17380: sub recurse_cat_deletes {
17381: my ($item,$coursecategories,$deletions) = @_;
17382: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
17383: my $subdepth = $depth + 1;
17384: if (ref($coursecategories) eq 'HASH') {
17385: foreach my $subitem (keys(%{$coursecategories})) {
17386: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
17387: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
17388: delete($coursecategories->{$subitem});
17389: $deletions->{$subitem} = 1;
17390: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 17391: }
1.48 raeburn 17392: }
17393: }
17394: return;
17395: }
17396:
1.125 raeburn 17397: sub active_dc_picker {
1.160.6.16 raeburn 17398: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 17399: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 17400: my @domcoord = keys(%domcoords);
17401: if (keys(%currhash)) {
17402: foreach my $dc (keys(%currhash)) {
17403: unless (exists($domcoords{$dc})) {
17404: push(@domcoord,$dc);
17405: }
17406: }
17407: }
17408: @domcoord = sort(@domcoord);
17409: my $numdcs = scalar(@domcoord);
17410: my $rows = 0;
17411: my $table;
1.125 raeburn 17412: if ($numdcs > 1) {
1.160.6.16 raeburn 17413: $table = '<table>';
17414: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 17415: my $rem = $i%($numinrow);
17416: if ($rem == 0) {
17417: if ($i > 0) {
1.160.6.16 raeburn 17418: $table .= '</tr>';
1.125 raeburn 17419: }
1.160.6.16 raeburn 17420: $table .= '<tr>';
17421: $rows ++;
1.125 raeburn 17422: }
1.160.6.16 raeburn 17423: my $check = '';
17424: if ($inputtype eq 'radio') {
17425: if (keys(%currhash) == 0) {
17426: if (!$i) {
17427: $check = ' checked="checked"';
17428: }
17429: } elsif (exists($currhash{$domcoord[$i]})) {
17430: $check = ' checked="checked"';
17431: }
17432: } else {
17433: if (exists($currhash{$domcoord[$i]})) {
17434: $check = ' checked="checked"';
1.125 raeburn 17435: }
17436: }
1.160.6.16 raeburn 17437: if ($i == @domcoord - 1) {
1.125 raeburn 17438: my $colsleft = $numinrow - $rem;
17439: if ($colsleft > 1) {
1.160.6.16 raeburn 17440: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 17441: } else {
1.160.6.16 raeburn 17442: $table .= '<td class="LC_left_item">';
1.125 raeburn 17443: }
17444: } else {
1.160.6.16 raeburn 17445: $table .= '<td class="LC_left_item">';
17446: }
17447: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
17448: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
17449: $table .= '<span class="LC_nobreak"><label>'.
17450: '<input type="'.$inputtype.'" name="'.$name.'"'.
17451: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
17452: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 17453: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 17454: }
1.160.6.33 raeburn 17455: $table .= '</label></span></td>';
1.125 raeburn 17456: }
1.160.6.16 raeburn 17457: $table .= '</tr></table>';
17458: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 17459: my ($dcname,$dcdom) = split(':',$domcoord[0]);
17460: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 17461: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 17462: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 17463: if ($user ne $dcname.':'.$dcdom) {
17464: $table .= ' ('.$dcname.':'.$dcdom.')';
17465: }
1.160.6.16 raeburn 17466: } else {
17467: my $check;
17468: if (exists($currhash{$domcoord[0]})) {
17469: $check = ' checked="checked"';
17470: }
1.160.6.50 raeburn 17471: $table = '<span class="LC_nobreak"><label>'.
17472: '<input type="checkbox" name="'.$name.'" '.
17473: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 17474: if ($user ne $dcname.':'.$dcdom) {
17475: $table .= ' ('.$dcname.':'.$dcdom.')';
17476: }
17477: $table .= '</label></span>';
1.160.6.16 raeburn 17478: $rows ++;
17479: }
1.125 raeburn 17480: }
1.160.6.16 raeburn 17481: return ($numdcs,$table,$rows);
1.125 raeburn 17482: }
17483:
1.137 raeburn 17484: sub usersession_titles {
17485: return &Apache::lonlocal::texthash(
17486: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
17487: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 17488: spares => 'Servers offloaded to, when busy',
1.137 raeburn 17489: version => 'LON-CAPA version requirement',
1.138 raeburn 17490: excludedomain => 'Allow all, but exclude specific domains',
17491: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 17492: primary => 'Primary (checked first)',
1.154 raeburn 17493: default => 'Default',
1.137 raeburn 17494: );
17495: }
17496:
1.152 raeburn 17497: sub id_for_thisdom {
17498: my (%servers) = @_;
17499: my %altids;
17500: foreach my $server (keys(%servers)) {
17501: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
17502: if ($serverhome ne $server) {
17503: $altids{$serverhome} = $server;
17504: }
17505: }
17506: return %altids;
17507: }
17508:
1.150 raeburn 17509: sub count_servers {
17510: my ($currbalancer,%servers) = @_;
17511: my (@spares,$numspares);
17512: foreach my $lonhost (sort(keys(%servers))) {
17513: next if ($currbalancer eq $lonhost);
17514: push(@spares,$lonhost);
17515: }
17516: if ($currbalancer) {
17517: $numspares = scalar(@spares);
17518: } else {
17519: $numspares = scalar(@spares) - 1;
17520: }
17521: return ($numspares,@spares);
17522: }
17523:
17524: sub lonbalance_targets_js {
1.160.6.7 raeburn 17525: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 17526: my $select = &mt('Select');
17527: my ($alltargets,$allishome,$allinsttypes,@alltypes);
17528: if (ref($servers) eq 'HASH') {
17529: $alltargets = join("','",sort(keys(%{$servers})));
17530: my @homedoms;
17531: foreach my $server (sort(keys(%{$servers}))) {
17532: if (&Apache::lonnet::host_domain($server) eq $dom) {
17533: push(@homedoms,'1');
17534: } else {
17535: push(@homedoms,'0');
17536: }
17537: }
17538: $allishome = join("','",@homedoms);
17539: }
17540: if (ref($types) eq 'ARRAY') {
17541: if (@{$types} > 0) {
17542: @alltypes = @{$types};
17543: }
17544: }
17545: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
17546: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 17547: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 17548: if (ref($settings) eq 'HASH') {
17549: %existing = %{$settings};
17550: }
17551: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 17552: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 17553: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 17554: return <<"END";
17555:
17556: <script type="text/javascript">
17557: // <![CDATA[
17558:
1.160.6.7 raeburn 17559: currBalancers = new Array('$balancers');
17560:
17561: function toggleTargets(balnum) {
17562: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17563: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
17564: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
17565: var prevbalancer = prevhostitem.value;
17566: var baltotal = document.getElementById('loadbalancing_total').value;
17567: prevhostitem.value = balancer;
17568: if (prevbalancer != '') {
17569: var prevIdx = currBalancers.indexOf(prevbalancer);
17570: if (prevIdx != -1) {
17571: currBalancers.splice(prevIdx,1);
17572: }
17573: }
1.150 raeburn 17574: if (balancer == '') {
1.160.6.7 raeburn 17575: hideSpares(balnum);
1.150 raeburn 17576: } else {
1.160.6.7 raeburn 17577: var currIdx = currBalancers.indexOf(balancer);
17578: if (currIdx == -1) {
17579: currBalancers.push(balancer);
17580: }
1.150 raeburn 17581: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 17582: var ishomedom = homedoms[lonhostitem.selectedIndex];
17583: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 17584: }
1.160.6.7 raeburn 17585: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 17586: return;
17587: }
17588:
1.160.6.7 raeburn 17589: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 17590: var alltargets = new Array('$alltargets');
17591: var insttypes = new Array('$allinsttypes');
1.151 raeburn 17592: var offloadtypes = new Array('primary','default');
17593:
1.160.6.7 raeburn 17594: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
17595: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 17596:
1.151 raeburn 17597: for (var i=0; i<offloadtypes.length; i++) {
17598: var count = 0;
17599: for (var j=0; j<alltargets.length; j++) {
17600: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 17601: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
17602: item.value = alltargets[j];
17603: item.style.textAlign='left';
17604: item.style.textFace='normal';
17605: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
17606: if (currBalancers.indexOf(alltargets[j]) == -1) {
17607: item.disabled = '';
17608: } else {
17609: item.disabled = 'disabled';
17610: item.checked = false;
17611: }
1.151 raeburn 17612: count ++;
17613: }
1.150 raeburn 17614: }
17615: }
1.151 raeburn 17616: for (var k=0; k<insttypes.length; k++) {
17617: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 17618: if (ishomedom == 1) {
1.160.6.7 raeburn 17619: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17620: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17621: } else {
1.160.6.7 raeburn 17622: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17623: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 17624: }
17625: } else {
1.160.6.7 raeburn 17626: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17627: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17628: }
1.151 raeburn 17629: if ((insttypes[k] != '_LC_external') &&
17630: ((insttypes[k] != '_LC_internetdom') ||
17631: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 17632: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
17633: item.options.length = 0;
17634: item.options[0] = new Option("","",true,true);
17635: var idx = 0;
1.151 raeburn 17636: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 17637: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
17638: idx ++;
17639: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 17640: }
17641: }
17642: }
17643: }
17644: return;
17645: }
17646:
1.160.6.7 raeburn 17647: function hideSpares(balnum) {
1.150 raeburn 17648: var alltargets = new Array('$alltargets');
17649: var insttypes = new Array('$allinsttypes');
17650: var offloadtypes = new Array('primary','default');
17651:
1.160.6.7 raeburn 17652: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
17653: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 17654:
17655: var total = alltargets.length - 1;
17656: for (var i=0; i<offloadtypes; i++) {
17657: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 17658: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
17659: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
17660: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 17661: }
1.150 raeburn 17662: }
17663: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 17664: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17665: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 17666: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 17667: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
17668: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 17669: }
17670: }
17671: return;
17672: }
17673:
1.160.6.7 raeburn 17674: function checkOffloads(item,balnum,type) {
1.150 raeburn 17675: var alltargets = new Array('$alltargets');
17676: var offloadtypes = new Array('primary','default');
17677: if (item.checked) {
17678: var total = alltargets.length - 1;
17679: var other;
17680: if (type == offloadtypes[0]) {
1.151 raeburn 17681: other = offloadtypes[1];
1.150 raeburn 17682: } else {
1.151 raeburn 17683: other = offloadtypes[0];
1.150 raeburn 17684: }
17685: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 17686: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 17687: if (server == item.value) {
1.160.6.7 raeburn 17688: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
17689: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 17690: }
17691: }
17692: }
17693: }
17694: return;
17695: }
17696:
1.160.6.7 raeburn 17697: function singleServerToggle(balnum,type) {
17698: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 17699: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 17700: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
17701: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17702:
17703: } else {
1.160.6.7 raeburn 17704: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
17705: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 17706: }
17707: return;
17708: }
17709:
1.160.6.7 raeburn 17710: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 17711: if (type == '_LC_external') {
1.160.6.26 raeburn 17712: return;
1.150 raeburn 17713: }
1.160.6.7 raeburn 17714: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 17715: for (var i=0; i<typesRules.length; i++) {
17716: if (formname.elements[typesRules[i]].checked) {
17717: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 17718: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
17719: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17720: } else {
1.160.6.7 raeburn 17721: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
17722: }
17723: }
17724: }
17725: return;
17726: }
17727:
17728: function balancerDeleteChange(balnum) {
17729: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17730: var baltotal = document.getElementById('loadbalancing_total').value;
17731: var addtarget;
17732: var removetarget;
17733: var action = 'delete';
17734: if (document.getElementById('loadbalancing_delete_'+balnum)) {
17735: var lonhost = hostitem.value;
17736: var currIdx = currBalancers.indexOf(lonhost);
17737: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
17738: if (currIdx != -1) {
17739: currBalancers.splice(currIdx,1);
17740: }
17741: addtarget = lonhost;
17742: } else {
17743: if (currIdx == -1) {
17744: currBalancers.push(lonhost);
17745: }
17746: removetarget = lonhost;
17747: action = 'undelete';
17748: }
17749: balancerChange(balnum,baltotal,action,addtarget,removetarget);
17750: }
17751: return;
17752: }
17753:
17754: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
17755: if (baltotal > 1) {
17756: var offloadtypes = new Array('primary','default');
17757: var alltargets = new Array('$alltargets');
17758: var insttypes = new Array('$allinsttypes');
17759: for (var i=0; i<baltotal; i++) {
17760: if (i != balnum) {
17761: for (var j=0; j<offloadtypes.length; j++) {
17762: var total = alltargets.length - 1;
17763: for (var k=0; k<total; k++) {
17764: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
17765: var server = serveritem.value;
17766: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17767: if (server == addtarget) {
17768: serveritem.disabled = '';
17769: }
17770: }
17771: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17772: if (server == removetarget) {
17773: serveritem.disabled = 'disabled';
17774: serveritem.checked = false;
17775: }
17776: }
17777: }
17778: }
17779: for (var j=0; j<insttypes.length; j++) {
17780: if (insttypes[j] != '_LC_external') {
17781: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
17782: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
17783: var currSel = singleserver.selectedIndex;
17784: var currVal = singleserver.options[currSel].value;
17785: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17786: var numoptions = singleserver.options.length;
17787: var needsnew = 1;
17788: for (var k=0; k<numoptions; k++) {
17789: if (singleserver.options[k] == addtarget) {
17790: needsnew = 0;
17791: break;
17792: }
17793: }
17794: if (needsnew == 1) {
17795: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
17796: }
17797: }
17798: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17799: singleserver.options.length = 0;
17800: if ((currVal) && (currVal != removetarget)) {
17801: singleserver.options[0] = new Option("","",false,false);
17802: } else {
17803: singleserver.options[0] = new Option("","",true,true);
17804: }
17805: var idx = 0;
17806: for (var m=0; m<alltargets.length; m++) {
17807: if (currBalancers.indexOf(alltargets[m]) == -1) {
17808: idx ++;
17809: if (currVal == alltargets[m]) {
17810: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
17811: } else {
17812: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
17813: }
17814: }
17815: }
17816: }
17817: }
17818: }
17819: }
1.150 raeburn 17820: }
17821: }
17822: }
17823: return;
17824: }
17825:
1.152 raeburn 17826: // ]]>
17827: </script>
17828:
17829: END
17830: }
17831:
17832: sub new_spares_js {
17833: my @sparestypes = ('primary','default');
17834: my $types = join("','",@sparestypes);
17835: my $select = &mt('Select');
17836: return <<"END";
17837:
17838: <script type="text/javascript">
17839: // <![CDATA[
17840:
17841: function updateNewSpares(formname,lonhost) {
17842: var types = new Array('$types');
17843: var include = new Array();
17844: var exclude = new Array();
17845: for (var i=0; i<types.length; i++) {
17846: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
17847: for (var j=0; j<spareboxes.length; j++) {
17848: if (formname.elements[spareboxes[j]].checked) {
17849: exclude.push(formname.elements[spareboxes[j]].value);
17850: } else {
17851: include.push(formname.elements[spareboxes[j]].value);
17852: }
17853: }
17854: }
17855: for (var i=0; i<types.length; i++) {
17856: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
17857: var selIdx = newSpare.selectedIndex;
17858: var currnew = newSpare.options[selIdx].value;
17859: var okSpares = new Array();
17860: for (var j=0; j<newSpare.options.length; j++) {
17861: var possible = newSpare.options[j].value;
17862: if (possible != '') {
17863: if (exclude.indexOf(possible) == -1) {
17864: okSpares.push(possible);
17865: } else {
17866: if (currnew == possible) {
17867: selIdx = 0;
17868: }
17869: }
17870: }
17871: }
17872: for (var k=0; k<include.length; k++) {
17873: if (okSpares.indexOf(include[k]) == -1) {
17874: okSpares.push(include[k]);
17875: }
17876: }
17877: okSpares.sort();
17878: newSpare.options.length = 0;
17879: if (selIdx == 0) {
17880: newSpare.options[0] = new Option("$select","",true,true);
17881: } else {
17882: newSpare.options[0] = new Option("$select","",false,false);
17883: }
17884: for (var m=0; m<okSpares.length; m++) {
17885: var idx = m+1;
17886: var selThis = 0;
17887: if (selIdx != 0) {
17888: if (okSpares[m] == currnew) {
17889: selThis = 1;
17890: }
17891: }
17892: if (selThis == 1) {
17893: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
17894: } else {
17895: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
17896: }
17897: }
17898: }
17899: return;
17900: }
17901:
17902: function checkNewSpares(lonhost,type) {
17903: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
17904: var chosen = newSpare.options[newSpare.selectedIndex].value;
17905: if (chosen != '') {
17906: var othertype;
17907: var othernewSpare;
17908: if (type == 'primary') {
17909: othernewSpare = document.getElementById('newspare_default_'+lonhost);
17910: }
17911: if (type == 'default') {
17912: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
17913: }
17914: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
17915: othernewSpare.selectedIndex = 0;
17916: }
17917: }
17918: return;
17919: }
17920:
17921: // ]]>
17922: </script>
17923:
17924: END
17925:
17926: }
17927:
17928: sub common_domprefs_js {
17929: return <<"END";
17930:
17931: <script type="text/javascript">
17932: // <![CDATA[
17933:
1.150 raeburn 17934: function getIndicesByName(formname,item) {
1.152 raeburn 17935: var group = new Array();
1.150 raeburn 17936: for (var i=0;i<formname.elements.length;i++) {
17937: if (formname.elements[i].name == item) {
1.152 raeburn 17938: group.push(formname.elements[i].id);
1.150 raeburn 17939: }
17940: }
1.152 raeburn 17941: return group;
1.150 raeburn 17942: }
17943:
17944: // ]]>
17945: </script>
17946:
17947: END
1.152 raeburn 17948:
1.150 raeburn 17949: }
17950:
1.160.6.5 raeburn 17951: sub recaptcha_js {
17952: my %lt = &captcha_phrases();
17953: return <<"END";
17954:
17955: <script type="text/javascript">
17956: // <![CDATA[
17957:
17958: function updateCaptcha(caller,context) {
17959: var privitem;
17960: var pubitem;
17961: var privtext;
17962: var pubtext;
1.160.6.69 raeburn 17963: var versionitem;
17964: var versiontext;
1.160.6.5 raeburn 17965: if (document.getElementById(context+'_recaptchapub')) {
17966: pubitem = document.getElementById(context+'_recaptchapub');
17967: } else {
17968: return;
17969: }
17970: if (document.getElementById(context+'_recaptchapriv')) {
17971: privitem = document.getElementById(context+'_recaptchapriv');
17972: } else {
17973: return;
17974: }
17975: if (document.getElementById(context+'_recaptchapubtxt')) {
17976: pubtext = document.getElementById(context+'_recaptchapubtxt');
17977: } else {
17978: return;
17979: }
17980: if (document.getElementById(context+'_recaptchaprivtxt')) {
17981: privtext = document.getElementById(context+'_recaptchaprivtxt');
17982: } else {
17983: return;
17984: }
1.160.6.69 raeburn 17985: if (document.getElementById(context+'_recaptchaversion')) {
17986: versionitem = document.getElementById(context+'_recaptchaversion');
17987: } else {
17988: return;
17989: }
17990: if (document.getElementById(context+'_recaptchavertxt')) {
17991: versiontext = document.getElementById(context+'_recaptchavertxt');
17992: } else {
17993: return;
17994: }
1.160.6.5 raeburn 17995: if (caller.checked) {
17996: if (caller.value == 'recaptcha') {
17997: pubitem.type = 'text';
17998: privitem.type = 'text';
17999: pubitem.size = '40';
18000: privitem.size = '40';
18001: pubtext.innerHTML = "$lt{'pub'}";
18002: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 18003: versionitem.type = 'text';
18004: versionitem.size = '3';
18005: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 18006: } else {
18007: pubitem.type = 'hidden';
18008: privitem.type = 'hidden';
1.160.6.69 raeburn 18009: versionitem.type = 'hidden';
1.160.6.5 raeburn 18010: pubtext.innerHTML = '';
18011: privtext.innerHTML = '';
1.160.6.69 raeburn 18012: versiontext.innerHTML = '';
1.160.6.5 raeburn 18013: }
18014: }
18015: return;
18016: }
18017:
18018: // ]]>
18019: </script>
18020:
18021: END
18022:
18023: }
18024:
1.160.6.40 raeburn 18025: sub toggle_display_js {
1.160.6.16 raeburn 18026: return <<"END";
18027:
18028: <script type="text/javascript">
18029: // <![CDATA[
18030:
1.160.6.40 raeburn 18031: function toggleDisplay(domForm,caller) {
18032: if (document.getElementById(caller)) {
18033: var divitem = document.getElementById(caller);
18034: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 18035: var checkval = 1;
18036: var dispval = 'block';
1.160.6.93 raeburn 18037: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 18038: if (caller == 'emailoptions') {
18039: optionsElement = domForm.cancreate_email;
18040: }
1.160.6.57 raeburn 18041: if (caller == 'studentsubmission') {
18042: optionsElement = domForm.postsubmit;
18043: }
1.160.6.64 raeburn 18044: if (caller == 'cloneinstcode') {
18045: optionsElement = domForm.canclone;
18046: checkval = 'instcode';
18047: }
1.160.6.93 raeburn 18048: if (selfcreateRegExp.test(caller)) {
18049: optionsElement = domForm.elements[caller];
18050: checkval = 'other';
18051: dispval = 'inline'
18052: }
1.160.6.40 raeburn 18053: if (optionsElement.length) {
1.160.6.16 raeburn 18054: var currval;
1.160.6.40 raeburn 18055: for (var i=0; i<optionsElement.length; i++) {
18056: if (optionsElement[i].checked) {
18057: currval = optionsElement[i].value;
1.160.6.16 raeburn 18058: }
18059: }
1.160.6.64 raeburn 18060: if (currval == checkval) {
18061: divitem.style.display = dispval;
1.160.6.16 raeburn 18062: } else {
1.160.6.40 raeburn 18063: divitem.style.display = 'none';
1.160.6.16 raeburn 18064: }
18065: }
18066: }
18067: return;
18068: }
18069:
18070: // ]]>
18071: </script>
18072:
18073: END
18074:
18075: }
18076:
1.160.6.5 raeburn 18077: sub captcha_phrases {
18078: return &Apache::lonlocal::texthash (
18079: priv => 'Private key',
18080: pub => 'Public key',
18081: original => 'original (CAPTCHA)',
18082: recaptcha => 'successor (ReCAPTCHA)',
18083: notused => 'unused',
1.160.6.69 raeburn 18084: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 18085: );
18086: }
18087:
1.160.6.24 raeburn 18088: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 18089: my ($dom,$cachekeys) = @_;
18090: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 18091: my %servers = &Apache::lonnet::internet_dom_servers($dom);
18092: my %thismachine;
18093: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.98 raeburn 18094: my @posscached = ('domainconfig','domdefaults','usersessions',
1.160.6.113 raeburn 18095: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
18096: 'ipaccess');
18097: my %cache_by_lonhost;
18098: if (exists($cachekeys->{'samllanding'})) {
18099: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
18100: my %landing = %{$cachekeys->{'samllanding'}};
18101: my %domservers = &Apache::lonnet::get_servers($dom);
18102: if (keys(%domservers)) {
18103: foreach my $server (keys(%domservers)) {
18104: my @cached;
18105: next if ($thismachine{$server});
18106: if ($landing{$server}) {
18107: push(@cached,&escape('samllanding').':'.&escape($server));
18108: }
18109: if (@cached) {
18110: $cache_by_lonhost{$server} = \@cached;
18111: }
18112: }
18113: }
18114: }
18115: }
1.160.6.61 raeburn 18116: if (keys(%servers)) {
1.160.6.24 raeburn 18117: foreach my $server (keys(%servers)) {
18118: next if ($thismachine{$server});
1.160.6.27 raeburn 18119: my @cached;
18120: foreach my $name (@posscached) {
18121: if ($cachekeys->{$name}) {
1.160.6.113 raeburn 18122: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
18123: if (ref($cachekeys->{$name}) eq 'HASH') {
18124: foreach my $key (keys(%{$cachekeys->{$name}})) {
18125: push(@cached,&escape($name).':'.&escape($key));
18126: }
18127: }
18128: } else {
18129: push(@cached,&escape($name).':'.&escape($dom));
18130: }
1.160.6.27 raeburn 18131: }
18132: }
1.160.6.113 raeburn 18133: if ((exists($cache_by_lonhost{$server})) &&
18134: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
18135: push(@cached,@{$cache_by_lonhost{$server}});
18136: }
1.160.6.27 raeburn 18137: if (@cached) {
18138: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
18139: }
1.160.6.24 raeburn 18140: }
18141: }
18142: return;
18143: }
18144:
1.3 raeburn 18145: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>