Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.113
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.113! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.112 2021/03/07 01:13:14 raeburn Exp $
1.160.6.40 raeburn 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.160.6.78 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
30: ##############################################################
31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.160.6.13 raeburn 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.160.6.27 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.160.6.5 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.160.6.20 raeburn 98: used by course owners to request creation of a course, and to display/store
1.160.6.34 raeburn 99: default quota sizes for Authoring Spaces.
1.160.6.20 raeburn 100:
1.101 raeburn 101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.160.6.30 raeburn 107: (official, unofficial, community, and textbook). In each case the radio buttons
108: allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.160.6.37 raeburn 168: use Apache::lonuserutils();
1.160.6.39 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.9 raeburn 173: use File::Copy;
1.43 raeburn 174: use Locale::Language;
1.62 raeburn 175: use DateTime::TimeZone;
1.68 raeburn 176: use DateTime::Locale;
1.160.6.113! raeburn 177: use Net::CIDR;
1.1 raeburn 178:
1.155 raeburn 179: my $registered_cleanup;
180: my $modified_urls;
181:
1.1 raeburn 182: sub handler {
183: my $r=shift;
184: if ($r->header_only) {
185: &Apache::loncommon::content_type($r,'text/html');
186: $r->send_http_header;
187: return OK;
188: }
189:
1.91 raeburn 190: my $context = 'domain';
1.1 raeburn 191: my $dom = $env{'request.role.domain'};
1.5 albertel 192: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 193: if (&Apache::lonnet::allowed('mau',$dom)) {
194: &Apache::loncommon::content_type($r,'text/html');
195: $r->send_http_header;
196: } else {
197: $env{'user.error.msg'}=
198: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
199: return HTTP_NOT_ACCEPTABLE;
200: }
1.155 raeburn 201:
202: $registered_cleanup=0;
203: @{$modified_urls}=();
204:
1.1 raeburn 205: &Apache::lonhtmlcommon::clear_breadcrumbs();
206: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 207: ['phase','actions']);
1.30 raeburn 208: my $phase = 'pickactions';
1.3 raeburn 209: if ( exists($env{'form.phase'}) ) {
210: $phase = $env{'form.phase'};
211: }
1.150 raeburn 212: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 213: my %domconfig =
1.6 raeburn 214: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 215: 'quotas','autoenroll','autoupdate','autocreate',
216: 'directorysrch','usercreation','usermodification',
217: 'contacts','defaults','scantron','coursecategories',
1.160.6.73 raeburn 218: 'serverstatuses','requestcourses','helpsettings',
219: 'coursedefaults','usersessions','loadbalancing',
1.160.6.113! raeburn 220: 'requestauthor','selfenrollment','inststatus',
! 221: 'passwords','wafproxy','ipaccess'],$dom);
! 222: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
! 223: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
! 224: 'contacts','usercreation','selfcreation','usermodification',
! 225: 'scantron','requestcourses','requestauthor','coursecategories',
1.160.6.73 raeburn 226: 'serverstatuses','helpsettings','coursedefaults',
227: 'selfenrollment','usersessions');
1.160.6.7 raeburn 228: my %existing;
229: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
230: %existing = %{$domconfig{'loadbalancing'}};
231: }
232: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 233: push(@prefs_order,'loadbalancing');
234: }
1.30 raeburn 235: my %prefs = (
236: 'rolecolors' =>
237: { text => 'Default color schemes',
1.67 raeburn 238: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 239: header => [{col1 => 'Student Settings',
240: col2 => '',},
241: {col1 => 'Coordinator Settings',
242: col2 => '',},
243: {col1 => 'Author Settings',
244: col2 => '',},
245: {col1 => 'Administrator Settings',
246: col2 => '',}],
1.160.6.37 raeburn 247: print => \&print_rolecolors,
248: modify => \&modify_rolecolors,
1.30 raeburn 249: },
1.110 raeburn 250: 'login' =>
1.30 raeburn 251: { text => 'Log-in page options',
1.67 raeburn 252: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 253: header => [{col1 => 'Log-in Page Items',
254: col2 => '',},
255: {col1 => 'Log-in Help',
1.160.6.56 raeburn 256: col2 => 'Value'},
257: {col1 => 'Custom HTML in document head',
1.160.6.113! raeburn 258: col2 => 'Value'},
! 259: {col1 => 'SSO',
! 260: col2 => 'Dual login: SSO and non-SSO options'},
! 261: ],
1.160.6.37 raeburn 262: print => \&print_login,
263: modify => \&modify_login,
1.30 raeburn 264: },
1.43 raeburn 265: 'defaults' =>
1.160.6.40 raeburn 266: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 267: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 268: header => [{col1 => 'Setting',
1.160.6.40 raeburn 269: col2 => 'Value'},
270: {col1 => 'Institutional user types',
1.160.6.93 raeburn 271: col2 => 'Name displayed'}],
1.160.6.37 raeburn 272: print => \&print_defaults,
273: modify => \&modify_defaults,
1.43 raeburn 274: },
1.160.6.113! raeburn 275: 'wafproxy' =>
! 276: { text => 'Web Application Firewall/Reverse Proxy',
! 277: help => 'Domain_Configuration_WAF_Proxy',
! 278: header => [{col1 => 'Domain(s)',
! 279: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
! 280: },
! 281: {col1 => 'Domain(s)',
! 282: col2 => 'WAF Configuration',}],
! 283: print => \&print_wafproxy,
! 284: modify => \&modify_wafproxy,
! 285: },
1.160.6.98 raeburn 286: 'passwords' =>
287: { text => 'Passwords (Internal authentication)',
288: help => 'Domain_Configuration_Passwords',
289: header => [{col1 => 'Resetting Forgotten Password',
290: col2 => 'Settings'},
291: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
292: col2 => 'Settings'},
293: {col1 => 'Rules for LON-CAPA Passwords',
294: col2 => 'Settings'},
295: {col1 => 'Course Owner Changing Student Passwords',
296: col2 => 'Settings'}],
297: print => \&print_passwords,
298: modify => \&modify_passwords,
299: },
1.30 raeburn 300: 'quotas' =>
1.160.6.20 raeburn 301: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 302: help => 'Domain_Configuration_Quotas',
1.77 raeburn 303: header => [{col1 => 'User affiliation',
1.72 raeburn 304: col2 => 'Available tools',
1.160.6.28 raeburn 305: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 306: print => \&print_quotas,
307: modify => \&modify_quotas,
1.30 raeburn 308: },
309: 'autoenroll' =>
310: { text => 'Auto-enrollment settings',
1.67 raeburn 311: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 312: header => [{col1 => 'Configuration setting',
313: col2 => 'Value(s)'}],
1.160.6.37 raeburn 314: print => \&print_autoenroll,
315: modify => \&modify_autoenroll,
1.30 raeburn 316: },
317: 'autoupdate' =>
318: { text => 'Auto-update settings',
1.67 raeburn 319: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 320: header => [{col1 => 'Setting',
321: col2 => 'Value',},
1.131 raeburn 322: {col1 => 'Setting',
323: col2 => 'Affiliation'},
1.43 raeburn 324: {col1 => 'User population',
1.160.6.35 raeburn 325: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 326: print => \&print_autoupdate,
327: modify => \&modify_autoupdate,
1.30 raeburn 328: },
1.125 raeburn 329: 'autocreate' =>
330: { text => 'Auto-course creation settings',
331: help => 'Domain_Configuration_Auto_Creation',
332: header => [{col1 => 'Configuration Setting',
333: col2 => 'Value',}],
1.160.6.37 raeburn 334: print => \&print_autocreate,
335: modify => \&modify_autocreate,
1.125 raeburn 336: },
1.30 raeburn 337: 'directorysrch' =>
1.160.6.72 raeburn 338: { text => 'Directory searches',
1.67 raeburn 339: help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72 raeburn 340: header => [{col1 => 'Institutional Directory Setting',
341: col2 => 'Value',},
342: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 343: col2 => 'Value',}],
1.160.6.37 raeburn 344: print => \&print_directorysrch,
345: modify => \&modify_directorysrch,
1.30 raeburn 346: },
347: 'contacts' =>
1.160.6.78 raeburn 348: { text => 'E-mail addresses and helpform',
1.67 raeburn 349: help => 'Domain_Configuration_Contact_Info',
1.160.6.78 raeburn 350: header => [{col1 => 'Default e-mail addresses',
351: col2 => 'Value',},
352: {col1 => 'Recipient(s) for notifications',
353: col2 => 'Value',},
1.160.6.107 raeburn 354: {col1 => 'Nightly status check e-mail',
355: col2 => 'Settings',},
1.160.6.78 raeburn 356: {col1 => 'Ask helpdesk form settings',
357: col2 => 'Value',},],
1.160.6.37 raeburn 358: print => \&print_contacts,
359: modify => \&modify_contacts,
1.30 raeburn 360: },
361: 'usercreation' =>
362: { text => 'User creation',
1.67 raeburn 363: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 364: header => [{col1 => 'Format rule type',
365: col2 => 'Format rules in force'},
1.34 raeburn 366: {col1 => 'User account creation',
367: col2 => 'Usernames which may be created',},
1.30 raeburn 368: {col1 => 'Context',
1.43 raeburn 369: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 370: print => \&print_usercreation,
371: modify => \&modify_usercreation,
1.30 raeburn 372: },
1.160.6.34 raeburn 373: 'selfcreation' =>
374: { text => 'Users self-creating accounts',
375: help => 'Domain_Configuration_Self_Creation',
376: header => [{col1 => 'Self-creation with institutional username',
377: col2 => 'Enabled?'},
378: {col1 => 'Institutional user type (login/SSO self-creation)',
379: col2 => 'Information user can enter'},
1.160.6.93 raeburn 380: {col1 => 'Self-creation with e-mail verification',
1.160.6.34 raeburn 381: col2 => 'Settings'}],
1.160.6.37 raeburn 382: print => \&print_selfcreation,
383: modify => \&modify_selfcreation,
1.160.6.34 raeburn 384: },
1.69 raeburn 385: 'usermodification' =>
1.33 raeburn 386: { text => 'User modification',
1.67 raeburn 387: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 388: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 389: col2 => 'User information updatable in author context'},
1.33 raeburn 390: {col1 => 'Target user has role',
1.160.6.35 raeburn 391: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 392: print => \&print_usermodification,
393: modify => \&modify_usermodification,
1.33 raeburn 394: },
1.69 raeburn 395: 'scantron' =>
1.160.6.97 raeburn 396: { text => 'Bubblesheet format',
1.67 raeburn 397: help => 'Domain_Configuration_Scantron_Format',
1.160.6.97 raeburn 398: header => [ {col1 => 'Bubblesheet format file',
399: col2 => ''},
400: {col1 => 'Bubblesheet data upload formats',
401: col2 => 'Settings'}],
1.160.6.37 raeburn 402: print => \&print_scantron,
403: modify => \&modify_scantron,
1.46 raeburn 404: },
1.86 raeburn 405: 'requestcourses' =>
406: {text => 'Request creation of courses',
407: help => 'Domain_Configuration_Request_Courses',
408: header => [{col1 => 'User affiliation',
1.102 raeburn 409: col2 => 'Availability/Processing of requests',},
410: {col1 => 'Setting',
1.160.6.30 raeburn 411: col2 => 'Value'},
412: {col1 => 'Available textbooks',
1.160.6.39 raeburn 413: col2 => ''},
1.160.6.46 raeburn 414: {col1 => 'Available templates',
415: col2 => ''},
1.160.6.39 raeburn 416: {col1 => 'Validation (not official courses)',
417: col2 => 'Value'},],
1.160.6.37 raeburn 418: print => \&print_quotas,
419: modify => \&modify_quotas,
1.86 raeburn 420: },
1.160.6.5 raeburn 421: 'requestauthor' =>
1.160.6.34 raeburn 422: {text => 'Request Authoring Space',
1.160.6.5 raeburn 423: help => 'Domain_Configuration_Request_Author',
424: header => [{col1 => 'User affiliation',
425: col2 => 'Availability/Processing of requests',},
426: {col1 => 'Setting',
427: col2 => 'Value'}],
1.160.6.37 raeburn 428: print => \&print_quotas,
429: modify => \&modify_quotas,
1.160.6.5 raeburn 430: },
1.69 raeburn 431: 'coursecategories' =>
1.120 raeburn 432: { text => 'Cataloging of courses/communities',
1.67 raeburn 433: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 434: header => [{col1 => 'Catalog type/availability',
435: col2 => '',},
436: {col1 => 'Category settings for standard catalog',
1.57 raeburn 437: col2 => '',},
438: {col1 => 'Categories',
439: col2 => '',
440: }],
1.160.6.37 raeburn 441: print => \&print_coursecategories,
442: modify => \&modify_coursecategories,
1.69 raeburn 443: },
444: 'serverstatuses' =>
1.77 raeburn 445: {text => 'Access to server status pages',
1.69 raeburn 446: help => 'Domain_Configuration_Server_Status',
447: header => [{col1 => 'Status Page',
448: col2 => 'Other named users',
449: col3 => 'Specific IPs',
450: }],
1.160.6.37 raeburn 451: print => \&print_serverstatuses,
452: modify => \&modify_serverstatuses,
1.69 raeburn 453: },
1.160.6.73 raeburn 454: 'helpsettings' =>
455: {text => 'Support settings',
456: help => 'Domain_Configuration_Help_Settings',
457: header => [{col1 => 'Help Page Settings (logged-in users)',
458: col2 => 'Value'},
459: {col1 => 'Helpdesk Roles',
460: col2 => 'Settings'},],
461: print => \&print_helpsettings,
462: modify => \&modify_helpsettings,
463: },
1.160.6.39 raeburn 464: 'coursedefaults' =>
1.160.6.16 raeburn 465: {text => 'Course/Community defaults',
466: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 467: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
468: col2 => 'Value',},
469: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 470: col2 => 'Value',},],
1.160.6.37 raeburn 471: print => \&print_coursedefaults,
472: modify => \&modify_coursedefaults,
473: },
1.160.6.39 raeburn 474: 'selfenrollment' =>
1.160.6.37 raeburn 475: {text => 'Self-enrollment in Course/Community',
476: help => 'Domain_Configuration_Selfenrollment',
477: header => [{col1 => 'Configuration Rights',
478: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
479: {col1 => 'Defaults',
480: col2 => 'Value'},
481: {col1 => 'Self-enrollment validation (optional)',
482: col2 => 'Value'},],
483: print => \&print_selfenrollment,
484: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 485: },
1.141 raeburn 486: 'usersessions' =>
1.145 raeburn 487: {text => 'User session hosting/offloading',
1.137 raeburn 488: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 489: header => [{col1 => 'Domain server',
490: col2 => 'Servers to offload sessions to when busy'},
491: {col1 => 'Hosting of users from other domains',
1.137 raeburn 492: col2 => 'Rules'},
493: {col1 => "Hosting domain's own users elsewhere",
494: col2 => 'Rules'}],
1.160.6.37 raeburn 495: print => \&print_usersessions,
496: modify => \&modify_usersessions,
1.137 raeburn 497: },
1.160.6.78 raeburn 498: 'loadbalancing' =>
1.160.6.7 raeburn 499: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 500: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 501: header => [{col1 => 'Balancers',
1.150 raeburn 502: col2 => 'Default destinations',
1.160.6.13 raeburn 503: col3 => 'User affiliation',
1.150 raeburn 504: col4 => 'Overrides'},
505: ],
1.160.6.37 raeburn 506: print => \&print_loadbalancing,
507: modify => \&modify_loadbalancing,
1.150 raeburn 508: },
1.160.6.113! raeburn 509: 'ipaccess' =>
! 510: {text => 'IP-based access control',
! 511: help => 'Domain_Configuration_IP_Access',
! 512: header => [{col1 => 'Setting',
! 513: col2 => 'Value'},],
! 514: print => \&print_ipaccess,
! 515: modify => \&modify_ipaccess,
! 516: },
1.3 raeburn 517: );
1.110 raeburn 518: if (keys(%servers) > 1) {
519: $prefs{'login'} = { text => 'Log-in page options',
520: help => 'Domain_Configuration_Login_Page',
521: header => [{col1 => 'Log-in Service',
522: col2 => 'Server Setting',},
523: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 524: col2 => ''},
525: {col1 => 'Log-in Help',
1.160.6.56 raeburn 526: col2 => 'Value'},
527: {col1 => 'Custom HTML in document head',
1.160.6.113! raeburn 528: col2 => 'Value'},
! 529: {col1 => 'SSO',
! 530: col2 => 'Dual login: SSO and non-SSO options'},
! 531: ],
1.160.6.37 raeburn 532: print => \&print_login,
533: modify => \&modify_login,
1.110 raeburn 534: };
535: }
1.160.6.13 raeburn 536:
1.6 raeburn 537: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 538: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 539: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 540: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 541: text=>"Settings to display/modify"});
1.9 raeburn 542: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 543:
1.3 raeburn 544: if ($phase eq 'process') {
1.160.6.27 raeburn 545: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
546: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 547: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 548: $r->rflush();
1.160.6.27 raeburn 549: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 550: }
1.30 raeburn 551: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 552: my $js = &recaptcha_js().
1.160.6.40 raeburn 553: &toggle_display_js();
1.160.6.7 raeburn 554: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 555: my ($othertitle,$usertypes,$types) =
556: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 557: $js .= &lonbalance_targets_js($dom,$types,\%servers,
558: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 559: &new_spares_js().
560: &common_domprefs_js().
561: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 562: }
1.160.6.30 raeburn 563: if (grep(/^requestcourses$/,@actions)) {
564: my $javascript_validations;
565: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
566: $js .= <<END;
567: <script type="text/javascript">
568: $javascript_validations
569: </script>
570: $coursebrowserjs
571: END
1.160.6.113! raeburn 572: } elsif (grep(/^ipaccess$/,@actions)) {
! 573: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.160.6.30 raeburn 574: }
1.160.6.93 raeburn 575: if (grep(/^selfcreation$/,@actions)) {
576: $js .= &selfcreate_javascript();
577: }
1.160.6.78 raeburn 578: if (grep(/^contacts$/,@actions)) {
579: $js .= &contacts_javascript();
580: }
1.160.6.97 raeburn 581: if (grep(/^scantron$/,@actions)) {
582: $js .= &scantron_javascript();
583: }
1.150 raeburn 584: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 585: } else {
1.160.6.11 raeburn 586: # check if domconfig user exists for the domain.
587: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 588: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 589: &config_check($dom,$confname,$servadm);
590: unless ($configuserok eq 'ok') {
591: &Apache::lonconfigsettings::print_header($r,$phase,$context);
592: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
593: $confname).
594: '<br />'
595: );
596: if ($switchserver) {
597: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
598: '<br />'.
599: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
600: '<br />'.
601: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
602: '<br />'.
603: &mt('To do that now, use the following link: [_1]',$switchserver)
604: );
605: } else {
606: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
607: '<br />'.
608: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
609: );
610: }
611: $r->print(&Apache::loncommon::end_page());
612: return OK;
613: }
1.21 raeburn 614: if (keys(%domconfig) == 0) {
615: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 616: my @ids=&Apache::lonnet::current_machine_ids();
617: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 618: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 619: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 620: my $custom_img_count = 0;
621: foreach my $img (@loginimages) {
622: if ($designhash{$dom.'.login.'.$img} ne '') {
623: $custom_img_count ++;
624: }
625: }
626: foreach my $role (@roles) {
627: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
628: $custom_img_count ++;
629: }
630: }
631: if ($custom_img_count > 0) {
1.94 raeburn 632: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 633: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 634: $r->print(
635: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
636: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
637: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
638: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
639: if ($switch_server) {
1.30 raeburn 640: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 641: }
1.91 raeburn 642: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 643: return OK;
644: }
645: }
646: }
1.91 raeburn 647: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 648: }
649: return OK;
650: }
651:
652: sub process_changes {
1.160.6.24 raeburn 653: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 654: my %domconfig;
655: if (ref($values) eq 'HASH') {
656: %domconfig = %{$values};
657: }
1.3 raeburn 658: my $output;
659: if ($action eq 'login') {
1.160.6.24 raeburn 660: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 661: } elsif ($action eq 'rolecolors') {
1.9 raeburn 662: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 663: $lastactref,%domconfig);
1.3 raeburn 664: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 665: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 666: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 667: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 668: } elsif ($action eq 'autoupdate') {
669: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 670: } elsif ($action eq 'autocreate') {
671: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 672: } elsif ($action eq 'directorysrch') {
1.160.6.81 raeburn 673: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 674: } elsif ($action eq 'usercreation') {
1.28 raeburn 675: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 676: } elsif ($action eq 'selfcreation') {
1.160.6.93 raeburn 677: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 678: } elsif ($action eq 'usermodification') {
679: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 680: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 681: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 682: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 683: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 684: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 685: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 686: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 687: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 688: } elsif ($action eq 'serverstatuses') {
689: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 690: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 691: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 692: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 693: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 694: } elsif ($action eq 'helpsettings') {
1.160.6.77 raeburn 695: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16 raeburn 696: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 697: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 698: } elsif ($action eq 'selfenrollment') {
699: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 700: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 701: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 702: } elsif ($action eq 'loadbalancing') {
703: $output = &modify_loadbalancing($dom,%domconfig);
1.160.6.98 raeburn 704: } elsif ($action eq 'passwords') {
705: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.113! raeburn 706: } elsif ($action eq 'wafproxy') {
! 707: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
! 708: } elsif ($action eq 'ipaccess') {
! 709: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.3 raeburn 710: }
711: return $output;
712: }
713:
714: sub print_config_box {
1.9 raeburn 715: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 716: my $rowtotal = 0;
1.49 raeburn 717: my $output;
718: if ($action eq 'coursecategories') {
719: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 720: } elsif ($action eq 'defaults') {
721: $output = &defaults_javascript($settings);
1.160.6.98 raeburn 722: } elsif ($action eq 'passwords') {
723: $output = &passwords_javascript();
1.160.6.73 raeburn 724: } elsif ($action eq 'helpsettings') {
725: my (%privs,%levelscurrent);
726: my %full=();
727: my %levels=(
728: course => {},
729: domain => {},
730: system => {},
731: );
732: my $context = 'domain';
733: my $crstype = 'Course';
734: my $formname = 'display';
735: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
736: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
737: $output =
738: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
739: \@templateroles);
1.160.6.113! raeburn 740: } elsif ($action eq 'wafproxy') {
! 741: $output .= &wafproxy_javascript($dom);
! 742: } elsif ($action eq 'autoupdate') {
! 743: $output .= &autoupdate_javascript();
! 744: } elsif ($action eq 'login') {
! 745: $output .= &saml_javascript();
! 746: } elsif ($action eq 'ipaccess') {
! 747: $output .= &ipaccess_javascript($settings);
1.91 raeburn 748: }
1.160.6.40 raeburn 749: $output .=
1.30 raeburn 750: '<table class="LC_nested_outer">
1.3 raeburn 751: <tr>
1.160.6.113! raeburn 752: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 753: &mt($item->{text}).' '.
754: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
755: '</tr>';
1.30 raeburn 756: $rowtotal ++;
1.110 raeburn 757: my $numheaders = 1;
758: if (ref($item->{'header'}) eq 'ARRAY') {
759: $numheaders = scalar(@{$item->{'header'}});
760: }
761: if ($numheaders > 1) {
1.64 raeburn 762: my $colspan = '';
1.145 raeburn 763: my $rightcolspan = '';
1.160.6.104 raeburn 764: my $leftnobr = '';
1.160.6.42 raeburn 765: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 766: ($action eq 'directorysrch') ||
1.160.6.113! raeburn 767: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 768: $colspan = ' colspan="2"';
769: }
1.145 raeburn 770: if ($action eq 'usersessions') {
771: $rightcolspan = ' colspan="3"';
772: }
1.160.6.104 raeburn 773: if ($action eq 'passwords') {
774: $leftnobr = ' LC_nobreak';
775: }
1.30 raeburn 776: $output .= '
1.3 raeburn 777: <tr>
778: <td>
779: <table class="LC_nested">
780: <tr class="LC_info_row">
1.160.6.104 raeburn 781: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 782: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 783: </tr>';
1.69 raeburn 784: $rowtotal ++;
1.160.6.37 raeburn 785: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 786: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 787: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.113! raeburn 788: ($action eq 'helpsettings') || ($action eq 'contacts') || ($action eq 'wafproxy')) {
1.160.6.37 raeburn 789: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.160.6.98 raeburn 790: } elsif ($action eq 'passwords') {
791: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 792: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 793: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.160.6.97 raeburn 794: } elsif ($action eq 'scantron') {
795: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 796: } elsif ($action eq 'login') {
1.160.6.113! raeburn 797: if ($numheaders == 5) {
1.160.6.5 raeburn 798: $colspan = ' colspan="2"';
799: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
800: } else {
801: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
802: }
1.160.6.37 raeburn 803: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 804: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 805: } elsif ($action eq 'rolecolors') {
1.30 raeburn 806: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 807: }
1.30 raeburn 808: $output .= '
1.6 raeburn 809: </table>
810: </td>
811: </tr>
812: <tr>
813: <td>
814: <table class="LC_nested">
815: <tr class="LC_info_row">
1.160.6.37 raeburn 816: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 817: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 818: </tr>';
819: $rowtotal ++;
1.160.6.37 raeburn 820: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
821: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 822: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.98 raeburn 823: ($action eq 'contacts') || ($action eq 'passwords')) {
1.160.6.42 raeburn 824: if ($action eq 'coursecategories') {
825: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
826: $colspan = ' colspan="2"';
1.160.6.98 raeburn 827: } elsif ($action eq 'passwords') {
828: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.160.6.42 raeburn 829: } else {
830: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
831: }
832: $output .= '
1.63 raeburn 833: </table>
834: </td>
835: </tr>
836: <tr>
837: <td>
838: <table class="LC_nested">
839: <tr class="LC_info_row">
1.160.6.113! raeburn 840: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 841: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 842: </tr>'."\n";
843: if ($action eq 'coursecategories') {
844: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.160.6.108 raeburn 845: } elsif (($action eq 'contacts') || ($action eq 'passwords')) {
1.160.6.107 raeburn 846: if ($action eq 'passwords') {
847: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
848: } else {
849: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
850: }
851: $output .= '
1.160.6.98 raeburn 852: </tr>
853: </table>
854: </td>
855: </tr>
856: <tr>
857: <td>
858: <table class="LC_nested">
859: <tr class="LC_info_row">
1.160.6.113! raeburn 860: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.160.6.107 raeburn 861: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1.160.6.108 raeburn 862: if ($action eq 'passwords') {
863: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
864: } else {
865: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
866: }
867: $output .= '
1.160.6.98 raeburn 868: </table>
869: </td>
870: </tr>
871: <tr>';
1.160.6.42 raeburn 872: } else {
873: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
874: }
1.63 raeburn 875: $rowtotal ++;
1.160.6.57 raeburn 876: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 877: ($action eq 'defaults') || ($action eq 'directorysrch') ||
1.160.6.113! raeburn 878: ($action eq 'helpsettings') || ($action eq 'wafproxy')) {
1.160.6.37 raeburn 879: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.160.6.97 raeburn 880: } elsif ($action eq 'scantron') {
881: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 882: } elsif ($action eq 'login') {
1.160.6.113! raeburn 883: if ($numheaders == 5) {
1.160.6.5 raeburn 884: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
885: </table>
886: </td>
887: </tr>
888: <tr>
889: <td>
890: <table class="LC_nested">
891: <tr class="LC_info_row">
892: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 893: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 894: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
895: $rowtotal ++;
896: } else {
897: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
898: }
1.160.6.56 raeburn 899: $output .= '
900: </table>
901: </td>
902: </tr>
903: <tr>
904: <td>
905: <table class="LC_nested">
906: <tr class="LC_info_row">';
1.160.6.113! raeburn 907: if ($numheaders == 5) {
1.160.6.56 raeburn 908: $output .= '
909: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
910: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
911: </tr>';
912: } else {
913: $output .= '
914: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
915: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
916: </tr>';
917: }
918: $rowtotal ++;
1.160.6.113! raeburn 919: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
! 920: </table>
! 921: </td>
! 922: </tr>
! 923: <tr>
! 924: <td>
! 925: <table class="LC_nested">
! 926: <tr class="LC_info_row">';
! 927: if ($numheaders == 5) {
! 928: $output .= '
! 929: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
! 930: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
! 931: </tr>';
! 932: } else {
! 933: $output .= '
! 934: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
! 935: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
! 936: </tr>';
! 937: }
! 938: $rowtotal ++;
! 939: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 940: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 941: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
942: $rowtotal ++;
943: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 944: </table>
945: </td>
946: </tr>
947: <tr>
948: <td>
949: <table class="LC_nested">
950: <tr class="LC_info_row">
951: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
952: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 953: &textbookcourses_javascript($settings).
954: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
955: </table>
956: </td>
957: </tr>
958: <tr>
959: <td>
960: <table class="LC_nested">
961: <tr class="LC_info_row">
962: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
963: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
964: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 965: </table>
966: </td>
967: </tr>
968: <tr>
969: <td>
970: <table class="LC_nested">
971: <tr class="LC_info_row">
1.160.6.46 raeburn 972: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
973: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 974: </tr>'.
975: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 976: } elsif ($action eq 'requestauthor') {
977: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 978: $rowtotal ++;
1.122 jms 979: } elsif ($action eq 'rolecolors') {
1.30 raeburn 980: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 981: </table>
982: </td>
983: </tr>
984: <tr>
985: <td>
986: <table class="LC_nested">
987: <tr class="LC_info_row">
1.69 raeburn 988: <td class="LC_left_item"'.$colspan.' valign="top">'.
989: &mt($item->{'header'}->[2]->{'col1'}).'</td>
990: <td class="LC_right_item" valign="top">'.
991: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 992: </tr>'.
1.30 raeburn 993: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 994: </table>
995: </td>
996: </tr>
997: <tr>
998: <td>
999: <table class="LC_nested">
1000: <tr class="LC_info_row">
1.59 bisitz 1001: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1002: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1003: </tr>'.
1.30 raeburn 1004: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1005: $rowtotal += 2;
1.6 raeburn 1006: }
1.3 raeburn 1007: } else {
1.30 raeburn 1008: $output .= '
1.3 raeburn 1009: <tr>
1010: <td>
1011: <table class="LC_nested">
1.30 raeburn 1012: <tr class="LC_info_row">';
1.160.6.72 raeburn 1013: if ($action eq 'login') {
1.30 raeburn 1014: $output .= '
1.59 bisitz 1015: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1016: } elsif ($action eq 'serverstatuses') {
1017: $output .= '
1018: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
1019: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1020:
1.6 raeburn 1021: } else {
1.30 raeburn 1022: $output .= '
1.69 raeburn 1023: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1024: }
1.72 raeburn 1025: if (defined($item->{'header'}->[0]->{'col3'})) {
1026: $output .= '<td class="LC_left_item" valign="top">'.
1027: &mt($item->{'header'}->[0]->{'col2'});
1028: if ($action eq 'serverstatuses') {
1029: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1030: }
1.69 raeburn 1031: } else {
1032: $output .= '<td class="LC_right_item" valign="top">'.
1033: &mt($item->{'header'}->[0]->{'col2'});
1034: }
1035: $output .= '</td>';
1036: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1037: if (defined($item->{'header'}->[0]->{'col4'})) {
1038: $output .= '<td class="LC_left_item" valign="top">'.
1039: &mt($item->{'header'}->[0]->{'col3'});
1040: } else {
1041: $output .= '<td class="LC_right_item" valign="top">'.
1042: &mt($item->{'header'}->[0]->{'col3'});
1043: }
1.69 raeburn 1044: if ($action eq 'serverstatuses') {
1045: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1046: }
1047: $output .= '</td>';
1.6 raeburn 1048: }
1.150 raeburn 1049: if ($item->{'header'}->[0]->{'col4'}) {
1050: $output .= '<td class="LC_right_item" valign="top">'.
1051: &mt($item->{'header'}->[0]->{'col4'});
1052: }
1.69 raeburn 1053: $output .= '</tr>';
1.48 raeburn 1054: $rowtotal ++;
1.160.6.5 raeburn 1055: if ($action eq 'quotas') {
1.86 raeburn 1056: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 1057: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.113! raeburn 1058: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
! 1059: ($action eq 'ipaccess')) {
1.160.6.37 raeburn 1060: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1061: }
1.3 raeburn 1062: }
1.30 raeburn 1063: $output .= '
1.3 raeburn 1064: </table>
1065: </td>
1066: </tr>
1.30 raeburn 1067: </table><br />';
1068: return ($output,$rowtotal);
1.1 raeburn 1069: }
1070:
1.3 raeburn 1071: sub print_login {
1.160.6.5 raeburn 1072: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.160.6.113! raeburn 1073: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1074: my %choices = &login_choices();
1.160.6.113! raeburn 1075: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
! 1076: %lt = &login_file_options();
! 1077: $switchserver = &check_switchserver($dom,$confname);
! 1078: }
1.110 raeburn 1079:
1.160.6.5 raeburn 1080: if ($caller eq 'service') {
1.149 raeburn 1081: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1082: my $choice = $choices{'disallowlogin'};
1083: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1084: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 1085: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1086: '<th>'.$choices{'server'}.'</th>'.
1087: '<th>'.$choices{'serverpath'}.'</th>'.
1088: '<th>'.$choices{'custompath'}.'</th>'.
1089: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1090: my %disallowed;
1091: if (ref($settings) eq 'HASH') {
1092: if (ref($settings->{'loginvia'}) eq 'HASH') {
1093: %disallowed = %{$settings->{'loginvia'}};
1094: }
1095: }
1096: foreach my $lonhost (sort(keys(%servers))) {
1097: my $direct = 'selected="selected"';
1.128 raeburn 1098: if (ref($disallowed{$lonhost}) eq 'HASH') {
1099: if ($disallowed{$lonhost}{'server'} ne '') {
1100: $direct = '';
1101: }
1.110 raeburn 1102: }
1.115 raeburn 1103: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1104: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1105: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1106: '</option>';
1.160.6.13 raeburn 1107: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1108: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1109: my $selected = '';
1.128 raeburn 1110: if (ref($disallowed{$lonhost}) eq 'HASH') {
1111: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1112: $selected = 'selected="selected"';
1113: }
1.110 raeburn 1114: }
1115: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1116: $servers{$hostid}.'</option>';
1117: }
1.128 raeburn 1118: $datatable .= '</select></td>'.
1119: '<td><select name="'.$lonhost.'_serverpath">';
1120: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1121: my $pathname = $path;
1122: if ($path eq 'custom') {
1123: $pathname = &mt('Custom Path').' ->';
1124: }
1125: my $selected = '';
1126: if (ref($disallowed{$lonhost}) eq 'HASH') {
1127: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1128: $selected = 'selected="selected"';
1129: }
1130: } elsif ($path eq '') {
1131: $selected = 'selected="selected"';
1132: }
1133: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1134: }
1135: $datatable .= '</select></td>';
1136: my ($custom,$exempt);
1137: if (ref($disallowed{$lonhost}) eq 'HASH') {
1138: $custom = $disallowed{$lonhost}{'custompath'};
1139: $exempt = $disallowed{$lonhost}{'exempt'};
1140: }
1141: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1142: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1143: '</tr>';
1.110 raeburn 1144: }
1145: $datatable .= '</table></td></tr>';
1146: return $datatable;
1.160.6.5 raeburn 1147: } elsif ($caller eq 'page') {
1148: my %defaultchecked = (
1149: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1150: 'helpdesk' => 'on',
1.160.6.5 raeburn 1151: 'adminmail' => 'off',
1152: 'newuser' => 'off',
1153: );
1.160.6.14 raeburn 1154: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1155: my (%checkedon,%checkedoff);
1.42 raeburn 1156: foreach my $item (@toggles) {
1.160.6.5 raeburn 1157: if ($defaultchecked{$item} eq 'on') {
1158: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1159: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1160: } elsif ($defaultchecked{$item} eq 'off') {
1161: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1162: $checkedon{$item} = ' ';
1163: }
1.1 raeburn 1164: }
1.160.6.5 raeburn 1165: my @images = ('img','logo','domlogo','login');
1166: my @logintext = ('textcol','bgcol');
1167: my @bgs = ('pgbg','mainbg','sidebg');
1168: my @links = ('link','alink','vlink');
1169: my %designhash = &Apache::loncommon::get_domainconf($dom);
1170: my %defaultdesign = %Apache::loncommon::defaultdesign;
1171: my (%is_custom,%designs);
1172: my %defaults = (
1173: font => $defaultdesign{'login.font'},
1174: );
1.6 raeburn 1175: foreach my $item (@images) {
1.160.6.5 raeburn 1176: $defaults{$item} = $defaultdesign{'login.'.$item};
1177: $defaults{'showlogo'}{$item} = 1;
1178: }
1179: foreach my $item (@bgs) {
1180: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1181: }
1.41 raeburn 1182: foreach my $item (@logintext) {
1.160.6.5 raeburn 1183: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1184: }
1.160.6.5 raeburn 1185: foreach my $item (@links) {
1186: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1187: }
1.160.6.5 raeburn 1188: if (ref($settings) eq 'HASH') {
1189: foreach my $item (@toggles) {
1190: if ($settings->{$item} eq '1') {
1191: $checkedon{$item} = ' checked="checked" ';
1192: $checkedoff{$item} = ' ';
1193: } elsif ($settings->{$item} eq '0') {
1194: $checkedoff{$item} = ' checked="checked" ';
1195: $checkedon{$item} = ' ';
1196: }
1.6 raeburn 1197: }
1.160.6.5 raeburn 1198: foreach my $item (@images) {
1199: if (defined($settings->{$item})) {
1200: $designs{$item} = $settings->{$item};
1201: $is_custom{$item} = 1;
1202: }
1203: if (defined($settings->{'showlogo'}{$item})) {
1204: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1205: }
1206: }
1207: foreach my $item (@logintext) {
1208: if ($settings->{$item} ne '') {
1209: $designs{'logintext'}{$item} = $settings->{$item};
1210: $is_custom{$item} = 1;
1211: }
1212: }
1213: if ($settings->{'font'} ne '') {
1214: $designs{'font'} = $settings->{'font'};
1215: $is_custom{'font'} = 1;
1216: }
1217: foreach my $item (@bgs) {
1218: if ($settings->{$item} ne '') {
1219: $designs{'bgs'}{$item} = $settings->{$item};
1220: $is_custom{$item} = 1;
1221: }
1222: }
1223: foreach my $item (@links) {
1224: if ($settings->{$item} ne '') {
1225: $designs{'links'}{$item} = $settings->{$item};
1226: $is_custom{$item} = 1;
1227: }
1228: }
1229: } else {
1230: if ($designhash{$dom.'.login.font'} ne '') {
1231: $designs{'font'} = $designhash{$dom.'.login.font'};
1232: $is_custom{'font'} = 1;
1233: }
1234: foreach my $item (@images) {
1235: if ($designhash{$dom.'.login.'.$item} ne '') {
1236: $designs{$item} = $designhash{$dom.'.login.'.$item};
1237: $is_custom{$item} = 1;
1238: }
1239: }
1240: foreach my $item (@bgs) {
1241: if ($designhash{$dom.'.login.'.$item} ne '') {
1242: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1243: $is_custom{$item} = 1;
1244: }
1245: }
1246: foreach my $item (@links) {
1247: if ($designhash{$dom.'.login.'.$item} ne '') {
1248: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1249: $is_custom{$item} = 1;
1250: }
1.6 raeburn 1251: }
1252: }
1.160.6.5 raeburn 1253: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1254: logo => 'Institution Logo',
1255: domlogo => 'Domain Logo',
1256: login => 'Login box');
1257: my $itemcount = 1;
1258: foreach my $item (@toggles) {
1259: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1260: $datatable .=
1261: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1262: '</td><td>'.
1263: '<span class="LC_nobreak"><label><input type="radio" name="'.
1264: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1265: '</label> <label><input type="radio" name="'.$item.'"'.
1266: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1267: '</tr>';
1268: $itemcount ++;
1.6 raeburn 1269: }
1.160.6.5 raeburn 1270: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1271: $datatable .= '</tr></table></td></tr>';
1272: } elsif ($caller eq 'help') {
1.160.6.113! raeburn 1273: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.160.6.5 raeburn 1274: my $itemcount = 1;
1275: $defaulturl = '/adm/loginproblems.html';
1276: $defaulttype = 'default';
1277: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1278: my @currlangs;
1279: if (ref($settings) eq 'HASH') {
1280: if (ref($settings->{'helpurl'}) eq 'HASH') {
1281: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1282: next if ($settings->{'helpurl'}{$key} eq '');
1283: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1284: $type{$key} = 'custom';
1285: unless ($key eq 'nolang') {
1286: push(@currlangs,$key);
1287: }
1288: }
1289: } elsif ($settings->{'helpurl'} ne '') {
1290: $type{'nolang'} = 'custom';
1291: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1292: }
1293: }
1.160.6.5 raeburn 1294: foreach my $lang ('nolang',sort(@currlangs)) {
1295: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1296: $datatable .= '<tr'.$css_class.'>';
1297: if ($url{$lang} eq '') {
1298: $url{$lang} = $defaulturl;
1299: }
1300: if ($type{$lang} eq '') {
1301: $type{$lang} = $defaulttype;
1302: }
1303: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1304: if ($lang eq 'nolang') {
1305: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1306: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1307: } else {
1308: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1309: $langchoices{$lang},
1310: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1311: }
1312: $datatable .= '</span></td>'."\n".
1313: '<td class="LC_left_item">';
1314: if ($type{$lang} eq 'custom') {
1315: $datatable .= '<span class="LC_nobreak"><label>'.
1316: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1317: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1318: } else {
1319: $datatable .= $lt{'upl'};
1320: }
1321: $datatable .='<br />';
1322: if ($switchserver) {
1323: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1324: } else {
1325: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1326: }
1.160.6.5 raeburn 1327: $datatable .= '</td></tr>';
1328: $itemcount ++;
1.6 raeburn 1329: }
1.160.6.5 raeburn 1330: my @addlangs;
1331: foreach my $lang (sort(keys(%langchoices))) {
1332: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1333: push(@addlangs,$lang);
1334: }
1335: if (@addlangs > 0) {
1336: my %toadd;
1337: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1338: $toadd{''} = &mt('Select');
1339: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1340: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1341: &mt('Add log-in help page for a specific language:').' '.
1342: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1343: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1344: if ($switchserver) {
1345: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1346: } else {
1347: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1348: }
1.160.6.5 raeburn 1349: $datatable .= '</td></tr>';
1350: $itemcount ++;
1.6 raeburn 1351: }
1.160.6.5 raeburn 1352: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1353: } elsif ($caller eq 'headtag') {
1354: my %domservers = &Apache::lonnet::get_servers($dom);
1355: my $choice = $choices{'headtag'};
1356: $css_class = ' class="LC_odd_row"';
1357: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1358: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1359: '<th>'.$choices{'current'}.'</th>'.
1360: '<th>'.$choices{'action'}.'</th>'.
1361: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1362: my (%currurls,%currexempt);
1363: if (ref($settings) eq 'HASH') {
1364: if (ref($settings->{'headtag'}) eq 'HASH') {
1365: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1366: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1367: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1368: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1369: }
1370: }
1371: }
1372: }
1373: foreach my $lonhost (sort(keys(%domservers))) {
1374: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1375: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1376: if ($currurls{$lonhost}) {
1377: $datatable .= '<td class="LC_right_item"><a href="'.
1378: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1379: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1380: '">'.$lt{'curr'}.'</a></td>'.
1381: '<td><span class="LC_nobreak"><label>'.
1382: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1383: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1384: } else {
1385: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1386: }
1387: $datatable .='<br />';
1388: if ($switchserver) {
1389: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1390: } else {
1391: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1392: }
1.160.6.87 raeburn 1393: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56 raeburn 1394: }
1395: $datatable .= '</table></td></tr>';
1.160.6.113! raeburn 1396: } elsif ($caller eq 'saml') {
! 1397: my %domservers = &Apache::lonnet::get_servers($dom);
! 1398: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
! 1399: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
! 1400: '<th>'.$choices{'samllanding'}.'</th>'.
! 1401: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
! 1402: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso,%styleon,%styleoff);
! 1403: foreach my $lonhost (keys(%domservers)) {
! 1404: $samlurl{$lonhost} = '/adm/sso';
! 1405: $styleon{$lonhost} = 'display:none';
! 1406: $styleoff{$lonhost} = '';
! 1407: }
! 1408: if (ref($settings->{'saml'}) eq 'HASH') {
! 1409: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
! 1410: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
! 1411: $saml{$lonhost} = 1;
! 1412: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
! 1413: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
! 1414: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
! 1415: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
! 1416: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
! 1417: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
! 1418: $styleon{$lonhost} = '';
! 1419: $styleoff{$lonhost} = 'display:none';
! 1420: } else {
! 1421: $styleon{$lonhost} = 'display:none';
! 1422: $styleoff{$lonhost} = '';
! 1423: }
! 1424: }
! 1425: }
! 1426: my $itemcount = 1;
! 1427: foreach my $lonhost (sort(keys(%domservers))) {
! 1428: my $samlon = ' ';
! 1429: my $samloff = ' checked="checked" ';
! 1430: if ($saml{$lonhost}) {
! 1431: $samlon = $samloff;
! 1432: $samloff = ' ';
! 1433: }
! 1434: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 1435: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
! 1436: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
! 1437: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
! 1438: &mt('No').'</label>'.(' 'x2).
! 1439: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
! 1440: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
! 1441: &mt('Yes').'</label></span></td>'.
! 1442: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
! 1443: '<table><tr><th colspan="5" align="center">'.&mt('SSO').'</th><th align="center">'.
! 1444: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
! 1445: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
! 1446: '<th>'.&mt('Alt Text').'</th><th>'.&mt('URL').'</th>'.
! 1447: '<th>'.&mt('Tool Tip').'</th><th>'.&mt('Text').'</th></tr>'.
! 1448: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="8" value="'.
! 1449: $samltext{$lonhost}.'" /></td><td>';
! 1450: if ($samlimg{$lonhost}) {
! 1451: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
! 1452: '<span class="LC_nobreak"><label>'.
! 1453: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
! 1454: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
! 1455: } else {
! 1456: $datatable .= $lt{'upl'};
! 1457: }
! 1458: $datatable .='<br />';
! 1459: if ($switchserver) {
! 1460: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
! 1461: } else {
! 1462: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
! 1463: }
! 1464: $datatable .= '</td>'.
! 1465: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="20" '.
! 1466: 'value="'.$samlalt{$lonhost}.'" /></td>'.
! 1467: '<td><input type="text" name="saml_url_'.$lonhost.'" size="8" '.
! 1468: 'value="'.$samlurl{$lonhost}.'" /></td>'.
! 1469: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="15">'.
! 1470: $samltitle{$lonhost}.'</textarea></td>'.
! 1471: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="8" '.
! 1472: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
! 1473: '</table></td>'.
! 1474: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
! 1475: $itemcount ++;
! 1476: }
! 1477: $datatable .= '</table></td></tr>';
1.1 raeburn 1478: }
1.6 raeburn 1479: return $datatable;
1480: }
1481:
1482: sub login_choices {
1483: my %choices =
1484: &Apache::lonlocal::texthash (
1.116 bisitz 1485: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1486: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1487: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1488: disallowlogin => "Login page requests redirected",
1489: hostid => "Server",
1.128 raeburn 1490: server => "Redirect to:",
1491: serverpath => "Path",
1492: custompath => "Custom",
1493: exempt => "Exempt IP(s)",
1.110 raeburn 1494: directlogin => "No redirect",
1495: newuser => "Link to create a user account",
1496: img => "Header",
1497: logo => "Main Logo",
1498: domlogo => "Domain Logo",
1499: login => "Log-in Header",
1500: textcol => "Text color",
1501: bgcol => "Box color",
1502: bgs => "Background colors",
1503: links => "Link colors",
1504: font => "Font color",
1505: pgbg => "Header",
1506: mainbg => "Page",
1507: sidebg => "Login box",
1508: link => "Link",
1509: alink => "Active link",
1510: vlink => "Visited link",
1.160.6.56 raeburn 1511: headtag => "Custom markup",
1512: action => "Action",
1513: current => "Current",
1.160.6.113! raeburn 1514: samllanding => "Dual login?",
! 1515: samloptions => "Options",
1.6 raeburn 1516: );
1517: return %choices;
1518: }
1519:
1.160.6.113! raeburn 1520: sub login_file_options {
! 1521: return &Apache::lonlocal::texthash(
! 1522: del => 'Delete?',
! 1523: rep => 'Replace:',
! 1524: upl => 'Upload:',
! 1525: curr => 'View contents',
! 1526: default => 'Default',
! 1527: custom => 'Custom',
! 1528: none => 'None',
! 1529: );
! 1530: }
! 1531:
! 1532: sub print_ipaccess {
! 1533: my ($dom,$settings,$rowtotal) = @_;
! 1534: my $css_class;
! 1535: my $itemcount = 0;
! 1536: my $datatable;
! 1537: my %ordered;
! 1538: if (ref($settings) eq 'HASH') {
! 1539: foreach my $item (keys(%{$settings})) {
! 1540: if (ref($settings->{$item}) eq 'HASH') {
! 1541: my $num = $settings->{$item}{'order'};
! 1542: if ($num eq '') {
! 1543: $num = scalar(keys(%{$settings}));
! 1544: }
! 1545: $ordered{$num} = $item;
! 1546: }
! 1547: }
! 1548: }
! 1549: my $maxnum = scalar(keys(%ordered));
! 1550: if (keys(%ordered)) {
! 1551: my @items = sort { $a <=> $b } keys(%ordered);
! 1552: for (my $i=0; $i<@items; $i++) {
! 1553: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 1554: my $item = $ordered{$items[$i]};
! 1555: my ($name,$ipranges,%commblocks,%courses);
! 1556: if (ref($settings->{$item}) eq 'HASH') {
! 1557: $name = $settings->{$item}->{'name'};
! 1558: $ipranges = $settings->{$item}->{'ip'};
! 1559: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
! 1560: %commblocks = %{$settings->{$item}->{'commblocks'}};
! 1561: }
! 1562: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
! 1563: %courses = %{$settings->{$item}->{'courses'}};
! 1564: }
! 1565: }
! 1566: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
! 1567: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
! 1568: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
! 1569: for (my $k=0; $k<=$maxnum; $k++) {
! 1570: my $vpos = $k+1;
! 1571: my $selstr;
! 1572: if ($k == $i) {
! 1573: $selstr = ' selected="selected" ';
! 1574: }
! 1575: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
! 1576: }
! 1577: $datatable .= '</select>'.(' 'x2).
! 1578: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
! 1579: &mt('Delete?').'</label></span></td>'.
! 1580: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
! 1581: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
! 1582: '</td></tr>';
! 1583: $itemcount ++;
! 1584: }
! 1585: }
! 1586: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 1587: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
! 1588: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
! 1589: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
! 1590: '<select name="ipaccess_pos_add"'.$chgstr.'>';
! 1591: for (my $k=0; $k<$maxnum+1; $k++) {
! 1592: my $vpos = $k+1;
! 1593: my $selstr;
! 1594: if ($k == $maxnum) {
! 1595: $selstr = ' selected="selected" ';
! 1596: }
! 1597: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
! 1598: }
! 1599: $datatable .= '</select> '."\n".
! 1600: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
! 1601: '<td colspan="2">'.
! 1602: &ipaccess_options('add',$itemcount,$dom).
! 1603: '</td>'."\n".
! 1604: '</tr>'."\n";
! 1605: $$rowtotal ++;
! 1606: return $datatable;
! 1607: }
! 1608:
! 1609: sub ipaccess_options {
! 1610: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
! 1611: my (%currblocks,%currcourses,$output);
! 1612: if (ref($blocksref) eq 'HASH') {
! 1613: %currblocks = %{$blocksref};
! 1614: }
! 1615: if (ref($coursesref) eq 'HASH') {
! 1616: %currcourses = %{$coursesref};
! 1617: }
! 1618: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
! 1619: '<span class="LC_nobreak">'.&mt('Name').': '.
! 1620: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
! 1621: '</span></fieldset>'.
! 1622: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
! 1623: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
! 1624: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
! 1625: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
! 1626: $ipranges.'</textarea></fieldset>'.
! 1627: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
! 1628: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
! 1629: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
! 1630: '<table>';
! 1631: foreach my $cid (sort(keys(%currcourses))) {
! 1632: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
! 1633: $output .= '<tr><td><span class="LC_nobreak">'.
! 1634: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
! 1635: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
! 1636: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
! 1637: }
! 1638: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
! 1639: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
! 1640: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
! 1641: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
! 1642: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
! 1643: '</span></td></tr></table>'."\n".
! 1644: '</fieldset>';
! 1645: return $output;
! 1646: }
! 1647:
! 1648: sub blocker_checkboxes {
! 1649: my ($num,$blocks) = @_;
! 1650: my ($typeorder,$types) = &commblocktype_text();
! 1651: my $numinrow = 6;
! 1652: my $output = '<table>';
! 1653: for (my $i=0; $i<@{$typeorder}; $i++) {
! 1654: my $block = $typeorder->[$i];
! 1655: my $blockstatus;
! 1656: if (ref($blocks) eq 'HASH') {
! 1657: if ($blocks->{$block} eq 'on') {
! 1658: $blockstatus = 'checked="checked"';
! 1659: }
! 1660: }
! 1661: my $rem = $i%($numinrow);
! 1662: if ($rem == 0) {
! 1663: if ($i > 0) {
! 1664: $output .= '</tr>';
! 1665: }
! 1666: $output .= '<tr>';
! 1667: }
! 1668: if ($i == scalar(@{$typeorder})-1) {
! 1669: my $colsleft = $numinrow-$rem;
! 1670: if ($colsleft > 1) {
! 1671: $output .= '<td colspan="'.$colsleft.'">';
! 1672: } else {
! 1673: $output .= '<td>';
! 1674: }
! 1675: } else {
! 1676: $output .= '<td>';
! 1677: }
! 1678: my $item = 'ipaccess_block_'.$num;
! 1679: if ($blockstatus) {
! 1680: $blockstatus = ' '.$blockstatus;
! 1681: }
! 1682: $output .= '<span class="LC_nobreak"><label>'."\n".
! 1683: '<input type="checkbox" name="'.$item.'"'.
! 1684: $blockstatus.' value="'.$block.'"'.' />'.
! 1685: $types->{$block}.'</label></span>'."\n".
! 1686: '<br /></td>';
! 1687: }
! 1688: $output .= '</tr></table>';
! 1689: return $output;
! 1690: }
! 1691:
! 1692: sub commblocktype_text {
! 1693: my %types = &Apache::lonlocal::texthash(
! 1694: 'com' => 'Messaging',
! 1695: 'chat' => 'Chat Room',
! 1696: 'boards' => 'Discussion',
! 1697: 'port' => 'Portfolio',
! 1698: 'groups' => 'Groups',
! 1699: 'blogs' => 'Blogs',
! 1700: 'about' => 'User Information',
! 1701: 'printout' => 'Printouts',
! 1702: 'passwd' => 'Change Password',
! 1703: 'grades' => 'Gradebook',
! 1704: );
! 1705: my $typeorder = ['com','chat','boards','port','groups','blogs','about','printout','grades','passwd'];
! 1706: return ($typeorder,\%types);
! 1707: }
! 1708:
1.6 raeburn 1709: sub print_rolecolors {
1.30 raeburn 1710: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1711: my %choices = &color_font_choices();
1712: my @bgs = ('pgbg','tabbg','sidebg');
1713: my @links = ('link','alink','vlink');
1714: my @images = ('img');
1715: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1716: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1717: my %defaultdesign = %Apache::loncommon::defaultdesign;
1718: my (%is_custom,%designs);
1.160.6.22 raeburn 1719: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1720: if (ref($settings) eq 'HASH') {
1721: if (ref($settings->{$role}) eq 'HASH') {
1722: if ($settings->{$role}->{'img'} ne '') {
1723: $designs{'img'} = $settings->{$role}->{'img'};
1724: $is_custom{'img'} = 1;
1725: }
1726: if ($settings->{$role}->{'font'} ne '') {
1727: $designs{'font'} = $settings->{$role}->{'font'};
1728: $is_custom{'font'} = 1;
1729: }
1.97 tempelho 1730: if ($settings->{$role}->{'fontmenu'} ne '') {
1731: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1732: $is_custom{'fontmenu'} = 1;
1733: }
1.6 raeburn 1734: foreach my $item (@bgs) {
1735: if ($settings->{$role}->{$item} ne '') {
1736: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1737: $is_custom{$item} = 1;
1738: }
1739: }
1740: foreach my $item (@links) {
1741: if ($settings->{$role}->{$item} ne '') {
1742: $designs{'links'}{$item} = $settings->{$role}->{$item};
1743: $is_custom{$item} = 1;
1744: }
1745: }
1746: }
1747: } else {
1748: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1749: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1750: $is_custom{'img'} = 1;
1751: }
1.97 tempelho 1752: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1753: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1754: $is_custom{'fontmenu'} = 1;
1755: }
1.6 raeburn 1756: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1757: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1758: $is_custom{'font'} = 1;
1759: }
1760: foreach my $item (@bgs) {
1761: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1762: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1763: $is_custom{$item} = 1;
1764:
1765: }
1766: }
1767: foreach my $item (@links) {
1768: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1769: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1770: $is_custom{$item} = 1;
1771: }
1772: }
1773: }
1774: my $itemcount = 1;
1.30 raeburn 1775: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1776: $datatable .= '</tr></table></td></tr>';
1777: return $datatable;
1778: }
1779:
1.160.6.22 raeburn 1780: sub role_defaults {
1781: my ($role,$bgs,$links,$images,$logintext) = @_;
1782: my %defaults;
1783: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1784: return %defaults;
1785: }
1786: my %defaultdesign = %Apache::loncommon::defaultdesign;
1787: if ($role eq 'login') {
1788: %defaults = (
1789: font => $defaultdesign{$role.'.font'},
1790: );
1791: if (ref($logintext) eq 'ARRAY') {
1792: foreach my $item (@{$logintext}) {
1793: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1794: }
1795: }
1796: foreach my $item (@{$images}) {
1797: $defaults{'showlogo'}{$item} = 1;
1798: }
1799: } else {
1800: %defaults = (
1801: img => $defaultdesign{$role.'.img'},
1802: font => $defaultdesign{$role.'.font'},
1803: fontmenu => $defaultdesign{$role.'.fontmenu'},
1804: );
1805: }
1806: foreach my $item (@{$bgs}) {
1807: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1808: }
1809: foreach my $item (@{$links}) {
1810: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1811: }
1812: foreach my $item (@{$images}) {
1813: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1814: }
1815: return %defaults;
1816: }
1817:
1.6 raeburn 1818: sub display_color_options {
1.9 raeburn 1819: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1820: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1821: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1822: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1823: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1824: '<td>'.$choices->{'font'}.'</td>';
1825: if (!$is_custom->{'font'}) {
1.160.6.87 raeburn 1826: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1827: } else {
1828: $datatable .= '<td> </td>';
1829: }
1.160.6.9 raeburn 1830: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1831:
1.8 raeburn 1832: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1833: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1834: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1835: ' </span></td></tr>';
1.107 raeburn 1836: unless ($role eq 'login') {
1837: $datatable .= '<tr'.$css_class.'>'.
1838: '<td>'.$choices->{'fontmenu'}.'</td>';
1839: if (!$is_custom->{'fontmenu'}) {
1.160.6.87 raeburn 1840: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1841: } else {
1842: $datatable .= '<td> </td>';
1843: }
1.160.6.22 raeburn 1844: $current_color = $designs->{'fontmenu'} ?
1845: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1846: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1847: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1848: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1849: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1850: ' </span></td></tr>';
1.97 tempelho 1851: }
1.9 raeburn 1852: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1853: foreach my $img (@{$images}) {
1.18 albertel 1854: $itemcount ++;
1.6 raeburn 1855: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1856: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1857: '<td>'.$choices->{$img};
1.41 raeburn 1858: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1859: if ($role eq 'login') {
1860: if ($img eq 'login') {
1861: $login_hdr_pick =
1.135 bisitz 1862: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1863: $logincolors =
1864: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1865: $designs,$defaults);
1.70 raeburn 1866: } elsif ($img ne 'domlogo') {
1867: $datatable.= &logo_display_options($img,$defaults,$designs);
1868: }
1869: }
1870: $datatable .= '</td>';
1.6 raeburn 1871: if ($designs->{$img} ne '') {
1872: $imgfile = $designs->{$img};
1.18 albertel 1873: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1874: } else {
1875: $imgfile = $defaults->{$img};
1876: }
1877: if ($imgfile) {
1.9 raeburn 1878: my ($showfile,$fullsize);
1879: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1880: my $urldir = $1;
1881: my $filename = $2;
1882: my @info = &Apache::lonnet::stat_file($designs->{$img});
1883: if (@info) {
1884: my $thumbfile = 'tn-'.$filename;
1885: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1886: if (@thumb) {
1887: $showfile = $urldir.'/'.$thumbfile;
1888: } else {
1889: $showfile = $imgfile;
1890: }
1891: } else {
1892: $showfile = '';
1893: }
1894: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1895: $showfile = $imgfile;
1.6 raeburn 1896: my $imgdir = $1;
1897: my $filename = $2;
1.159 raeburn 1898: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1899: $showfile = "/$imgdir/tn-".$filename;
1900: } else {
1.159 raeburn 1901: my $input = $londocroot.$imgfile;
1902: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1903: if (!-e $output) {
1.9 raeburn 1904: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1905: my ($fullwidth,$fullheight) = &check_dimensions($input);
1906: if ($fullwidth ne '' && $fullheight ne '') {
1907: if ($fullwidth > $width && $fullheight > $height) {
1908: my $size = $width.'x'.$height;
1.160.6.88 raeburn 1909: my @args = ('convert','-sample',$size,$input,$output);
1910: system({$args[0]} @args);
1.159 raeburn 1911: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1912: }
1913: }
1.6 raeburn 1914: }
1915: }
1.16 raeburn 1916: }
1.6 raeburn 1917: if ($showfile) {
1.40 raeburn 1918: if ($showfile =~ m{^/(adm|res)/}) {
1919: if ($showfile =~ m{^/res/}) {
1920: my $local_showfile =
1921: &Apache::lonnet::filelocation('',$showfile);
1922: &Apache::lonnet::repcopy($local_showfile);
1923: }
1924: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1925: }
1926: if ($imgfile) {
1927: if ($imgfile =~ m{^/(adm|res)/}) {
1928: if ($imgfile =~ m{^/res/}) {
1929: my $local_imgfile =
1930: &Apache::lonnet::filelocation('',$imgfile);
1931: &Apache::lonnet::repcopy($local_imgfile);
1932: }
1933: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1934: } else {
1935: $fullsize = $imgfile;
1936: }
1937: }
1.41 raeburn 1938: $datatable .= '<td>';
1939: if ($img eq 'login') {
1.135 bisitz 1940: $datatable .= $login_hdr_pick;
1941: }
1.41 raeburn 1942: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1943: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1944: } else {
1.160.6.22 raeburn 1945: $datatable .= '<td> </td><td class="LC_left_item">'.
1946: &mt('Upload:').'<br />';
1.6 raeburn 1947: }
1948: } else {
1.160.6.22 raeburn 1949: $datatable .= '<td> </td><td class="LC_left_item">'.
1950: &mt('Upload:').'<br />';
1.6 raeburn 1951: }
1.9 raeburn 1952: if ($switchserver) {
1953: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1954: } else {
1.135 bisitz 1955: if ($img ne 'login') { # suppress file selection for Log-in header
1956: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1957: }
1.9 raeburn 1958: }
1959: $datatable .= '</td></tr>';
1.6 raeburn 1960: }
1961: $itemcount ++;
1962: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1963: $datatable .= '<tr'.$css_class.'>'.
1964: '<td>'.$choices->{'bgs'}.'</td>';
1965: my $bgs_def;
1966: foreach my $item (@{$bgs}) {
1967: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1968: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1969: }
1970: }
1971: if ($bgs_def) {
1.8 raeburn 1972: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1973: } else {
1974: $datatable .= '<td> </td>';
1975: }
1976: $datatable .= '<td class="LC_right_item">'.
1977: '<table border="0"><tr>';
1.160.6.13 raeburn 1978:
1.6 raeburn 1979: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1980: $datatable .= '<td align="center">'.$choices->{$item};
1981: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1982: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1983: $datatable .= ' ';
1.6 raeburn 1984: }
1.160.6.9 raeburn 1985: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1986: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1987: }
1988: $datatable .= '</tr></table></td></tr>';
1989: $itemcount ++;
1990: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1991: $datatable .= '<tr'.$css_class.'>'.
1992: '<td>'.$choices->{'links'}.'</td>';
1993: my $links_def;
1994: foreach my $item (@{$links}) {
1995: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1996: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1997: }
1998: }
1999: if ($links_def) {
1.8 raeburn 2000: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2001: } else {
2002: $datatable .= '<td> </td>';
2003: }
2004: $datatable .= '<td class="LC_right_item">'.
2005: '<table border="0"><tr>';
2006: foreach my $item (@{$links}) {
1.160.6.39 raeburn 2007: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 2008: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 2009: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 2010: $datatable.=' ';
1.6 raeburn 2011: }
1.160.6.9 raeburn 2012: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2013: '" /></td>';
2014: }
1.30 raeburn 2015: $$rowtotal += $itemcount;
1.3 raeburn 2016: return $datatable;
2017: }
2018:
1.70 raeburn 2019: sub logo_display_options {
2020: my ($img,$defaults,$designs) = @_;
2021: my $checkedon;
2022: if (ref($defaults) eq 'HASH') {
2023: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2024: if ($defaults->{'showlogo'}{$img}) {
2025: $checkedon = 'checked="checked" ';
2026: }
2027: }
2028: }
2029: if (ref($designs) eq 'HASH') {
2030: if (ref($designs->{'showlogo'}) eq 'HASH') {
2031: if (defined($designs->{'showlogo'}{$img})) {
2032: if ($designs->{'showlogo'}{$img} == 0) {
2033: $checkedon = '';
2034: } elsif ($designs->{'showlogo'}{$img} == 1) {
2035: $checkedon = 'checked="checked" ';
2036: }
2037: }
2038: }
2039: }
2040: return '<br /><label> <input type="checkbox" name="'.
2041: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2042: &mt('show').'</label>'."\n";
2043: }
2044:
1.41 raeburn 2045: sub login_header_options {
1.135 bisitz 2046: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2047: my $output = '';
1.41 raeburn 2048: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2049: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2050: if (!$is_custom->{'textcol'}) {
2051: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2052: ' ';
2053: }
2054: if (!$is_custom->{'bgcol'}) {
2055: $output .= $choices->{'bgcol'}.': '.
2056: '<span id="css_'.$role.'_font" style="background-color: '.
2057: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2058: }
2059: $output .= '<br />';
2060: }
2061: $output .='<br />';
2062: return $output;
2063: }
2064:
2065: sub login_text_colors {
1.160.6.22 raeburn 2066: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2067: my $color_menu = '<table border="0"><tr>';
2068: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 2069: $color_menu .= '<td align="center">'.$choices->{$item};
2070: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2071: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2072: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2073: }
2074: $color_menu .= '</tr></table><br />';
2075: return $color_menu;
2076: }
2077:
2078: sub image_changes {
2079: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2080: my $output;
1.135 bisitz 2081: if ($img eq 'login') {
1.160.6.87 raeburn 2082: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2083: } elsif (!$is_custom) {
1.70 raeburn 2084: if ($img ne 'domlogo') {
1.160.6.87 raeburn 2085: $output = &mt('Default image:').'<br />';
1.41 raeburn 2086: } else {
1.160.6.87 raeburn 2087: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2088: }
2089: }
1.160.6.87 raeburn 2090: if ($img ne 'login') {
1.135 bisitz 2091: if ($img_import) {
2092: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2093: }
2094: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2095: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2096: if ($is_custom) {
2097: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2098: '<input type="checkbox" name="'.
2099: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2100: '</label> '.&mt('Replace:').'</span><br />';
2101: } else {
1.160.6.22 raeburn 2102: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2103: }
1.41 raeburn 2104: }
2105: return $output;
2106: }
2107:
1.3 raeburn 2108: sub print_quotas {
1.86 raeburn 2109: my ($dom,$settings,$rowtotal,$action) = @_;
2110: my $context;
2111: if ($action eq 'quotas') {
2112: $context = 'tools';
2113: } else {
2114: $context = $action;
2115: }
1.160.6.20 raeburn 2116: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2117: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2118: my $typecount = 0;
1.101 raeburn 2119: my ($css_class,%titles);
1.86 raeburn 2120: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 2121: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 2122: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2123: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2124: %titles = &courserequest_titles();
1.160.6.5 raeburn 2125: } elsif ($context eq 'requestauthor') {
2126: @usertools = ('author');
2127: @options = ('norequest','approval','automatic');
2128: %titles = &authorrequest_titles();
1.86 raeburn 2129: } else {
1.160.6.4 raeburn 2130: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 2131: %titles = &tool_titles();
1.86 raeburn 2132: }
1.26 raeburn 2133: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2134: foreach my $type (@{$types}) {
1.160.6.20 raeburn 2135: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 2136: unless (($context eq 'requestcourses') ||
2137: ($context eq 'requestauthor')) {
1.86 raeburn 2138: if (ref($settings) eq 'HASH') {
2139: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 2140: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2141: } else {
2142: $currdefquota = $settings->{$type};
2143: }
1.160.6.20 raeburn 2144: if (ref($settings->{authorquota}) eq 'HASH') {
2145: $currauthorquota = $settings->{authorquota}->{$type};
2146: }
1.78 raeburn 2147: }
1.72 raeburn 2148: }
1.3 raeburn 2149: if (defined($usertypes->{$type})) {
2150: $typecount ++;
2151: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2152: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2153: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2154: '<td class="LC_left_item">';
1.101 raeburn 2155: if ($context eq 'requestcourses') {
2156: $datatable .= '<table><tr>';
2157: }
2158: my %cell;
1.72 raeburn 2159: foreach my $item (@usertools) {
1.101 raeburn 2160: if ($context eq 'requestcourses') {
2161: my ($curroption,$currlimit);
2162: if (ref($settings) eq 'HASH') {
2163: if (ref($settings->{$item}) eq 'HASH') {
2164: $curroption = $settings->{$item}->{$type};
2165: if ($curroption =~ /^autolimit=(\d*)$/) {
2166: $currlimit = $1;
2167: }
2168: }
2169: }
2170: if (!$curroption) {
2171: $curroption = 'norequest';
2172: }
2173: $datatable .= '<th>'.$titles{$item}.'</th>';
2174: foreach my $option (@options) {
2175: my $val = $option;
2176: if ($option eq 'norequest') {
2177: $val = 0;
2178: }
2179: if ($option eq 'validate') {
2180: my $canvalidate = 0;
2181: if (ref($validations{$item}) eq 'HASH') {
2182: if ($validations{$item}{$type}) {
2183: $canvalidate = 1;
2184: }
2185: }
2186: next if (!$canvalidate);
2187: }
2188: my $checked = '';
2189: if ($option eq $curroption) {
2190: $checked = ' checked="checked"';
2191: } elsif ($option eq 'autolimit') {
2192: if ($curroption =~ /^autolimit/) {
2193: $checked = ' checked="checked"';
2194: }
2195: }
2196: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2197: '<input type="radio" name="crsreq_'.$item.
2198: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2199: $titles{$option}.'</label>';
1.101 raeburn 2200: if ($option eq 'autolimit') {
1.127 raeburn 2201: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2202: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2203: 'value="'.$currlimit.'" />';
1.101 raeburn 2204: }
1.127 raeburn 2205: $cell{$item} .= '</span> ';
1.103 raeburn 2206: if ($option eq 'autolimit') {
1.127 raeburn 2207: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2208: }
1.101 raeburn 2209: }
1.160.6.5 raeburn 2210: } elsif ($context eq 'requestauthor') {
2211: my $curroption;
2212: if (ref($settings) eq 'HASH') {
2213: $curroption = $settings->{$type};
2214: }
2215: if (!$curroption) {
2216: $curroption = 'norequest';
2217: }
2218: foreach my $option (@options) {
2219: my $val = $option;
2220: if ($option eq 'norequest') {
2221: $val = 0;
2222: }
2223: my $checked = '';
2224: if ($option eq $curroption) {
2225: $checked = ' checked="checked"';
2226: }
2227: $datatable .= '<span class="LC_nobreak"><label>'.
2228: '<input type="radio" name="authorreq_'.$type.
2229: '" value="'.$val.'"'.$checked.' />'.
2230: $titles{$option}.'</label></span> ';
2231: }
1.101 raeburn 2232: } else {
2233: my $checked = 'checked="checked" ';
2234: if (ref($settings) eq 'HASH') {
2235: if (ref($settings->{$item}) eq 'HASH') {
2236: if ($settings->{$item}->{$type} == 0) {
2237: $checked = '';
2238: } elsif ($settings->{$item}->{$type} == 1) {
2239: $checked = 'checked="checked" ';
2240: }
1.78 raeburn 2241: }
1.72 raeburn 2242: }
1.101 raeburn 2243: $datatable .= '<span class="LC_nobreak"><label>'.
2244: '<input type="checkbox" name="'.$context.'_'.$item.
2245: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2246: '</label></span> ';
1.72 raeburn 2247: }
1.101 raeburn 2248: }
2249: if ($context eq 'requestcourses') {
2250: $datatable .= '</tr><tr>';
2251: foreach my $item (@usertools) {
1.106 raeburn 2252: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2253: }
2254: $datatable .= '</tr></table>';
1.72 raeburn 2255: }
1.86 raeburn 2256: $datatable .= '</td>';
1.160.6.5 raeburn 2257: unless (($context eq 'requestcourses') ||
2258: ($context eq 'requestauthor')) {
1.86 raeburn 2259: $datatable .=
1.160.6.20 raeburn 2260: '<td class="LC_right_item">'.
2261: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2262: '<input type="text" name="quota_'.$type.
1.72 raeburn 2263: '" value="'.$currdefquota.
1.160.6.20 raeburn 2264: '" size="5" /></span>'.(' ' x 2).
2265: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2266: '<input type="text" name="authorquota_'.$type.
2267: '" value="'.$currauthorquota.
2268: '" size="5" /></span></td>';
1.86 raeburn 2269: }
2270: $datatable .= '</tr>';
1.3 raeburn 2271: }
2272: }
2273: }
1.160.6.5 raeburn 2274: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2275: $defaultquota = '20';
1.160.6.20 raeburn 2276: $authorquota = '500';
1.86 raeburn 2277: if (ref($settings) eq 'HASH') {
2278: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2279: $defaultquota = $settings->{'defaultquota'}->{'default'};
2280: } elsif (defined($settings->{'default'})) {
2281: $defaultquota = $settings->{'default'};
2282: }
1.160.6.20 raeburn 2283: if (ref($settings->{'authorquota'}) eq 'HASH') {
2284: $authorquota = $settings->{'authorquota'}->{'default'};
2285: }
1.3 raeburn 2286: }
2287: }
2288: $typecount ++;
2289: $css_class = $typecount%2?' class="LC_odd_row"':'';
2290: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2291: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2292: '<td class="LC_left_item">';
1.101 raeburn 2293: if ($context eq 'requestcourses') {
2294: $datatable .= '<table><tr>';
2295: }
2296: my %defcell;
1.72 raeburn 2297: foreach my $item (@usertools) {
1.101 raeburn 2298: if ($context eq 'requestcourses') {
2299: my ($curroption,$currlimit);
2300: if (ref($settings) eq 'HASH') {
2301: if (ref($settings->{$item}) eq 'HASH') {
2302: $curroption = $settings->{$item}->{'default'};
2303: if ($curroption =~ /^autolimit=(\d*)$/) {
2304: $currlimit = $1;
2305: }
2306: }
2307: }
2308: if (!$curroption) {
2309: $curroption = 'norequest';
2310: }
2311: $datatable .= '<th>'.$titles{$item}.'</th>';
2312: foreach my $option (@options) {
2313: my $val = $option;
2314: if ($option eq 'norequest') {
2315: $val = 0;
2316: }
2317: if ($option eq 'validate') {
2318: my $canvalidate = 0;
2319: if (ref($validations{$item}) eq 'HASH') {
2320: if ($validations{$item}{'default'}) {
2321: $canvalidate = 1;
2322: }
2323: }
2324: next if (!$canvalidate);
2325: }
2326: my $checked = '';
2327: if ($option eq $curroption) {
2328: $checked = ' checked="checked"';
2329: } elsif ($option eq 'autolimit') {
2330: if ($curroption =~ /^autolimit/) {
2331: $checked = ' checked="checked"';
2332: }
2333: }
2334: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2335: '<input type="radio" name="crsreq_'.$item.
2336: '_default" value="'.$val.'"'.$checked.' />'.
2337: $titles{$option}.'</label>';
2338: if ($option eq 'autolimit') {
1.127 raeburn 2339: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2340: $item.'_limit_default" size="1" '.
2341: 'value="'.$currlimit.'" />';
2342: }
1.127 raeburn 2343: $defcell{$item} .= '</span> ';
1.104 raeburn 2344: if ($option eq 'autolimit') {
1.127 raeburn 2345: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2346: }
1.101 raeburn 2347: }
1.160.6.5 raeburn 2348: } elsif ($context eq 'requestauthor') {
2349: my $curroption;
2350: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 2351: $curroption = $settings->{'default'};
1.160.6.5 raeburn 2352: }
2353: if (!$curroption) {
2354: $curroption = 'norequest';
2355: }
2356: foreach my $option (@options) {
2357: my $val = $option;
2358: if ($option eq 'norequest') {
2359: $val = 0;
2360: }
2361: my $checked = '';
2362: if ($option eq $curroption) {
2363: $checked = ' checked="checked"';
2364: }
2365: $datatable .= '<span class="LC_nobreak"><label>'.
2366: '<input type="radio" name="authorreq_default"'.
2367: ' value="'.$val.'"'.$checked.' />'.
2368: $titles{$option}.'</label></span> ';
2369: }
1.101 raeburn 2370: } else {
2371: my $checked = 'checked="checked" ';
2372: if (ref($settings) eq 'HASH') {
2373: if (ref($settings->{$item}) eq 'HASH') {
2374: if ($settings->{$item}->{'default'} == 0) {
2375: $checked = '';
2376: } elsif ($settings->{$item}->{'default'} == 1) {
2377: $checked = 'checked="checked" ';
2378: }
1.78 raeburn 2379: }
1.72 raeburn 2380: }
1.101 raeburn 2381: $datatable .= '<span class="LC_nobreak"><label>'.
2382: '<input type="checkbox" name="'.$context.'_'.$item.
2383: '" value="default" '.$checked.'/>'.$titles{$item}.
2384: '</label></span> ';
2385: }
2386: }
2387: if ($context eq 'requestcourses') {
2388: $datatable .= '</tr><tr>';
2389: foreach my $item (@usertools) {
1.106 raeburn 2390: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2391: }
1.101 raeburn 2392: $datatable .= '</tr></table>';
1.72 raeburn 2393: }
1.86 raeburn 2394: $datatable .= '</td>';
1.160.6.5 raeburn 2395: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2396: $datatable .= '<td class="LC_right_item">'.
2397: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2398: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2399: $defaultquota.'" size="5" /></span>'.(' ' x2).
2400: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2401: '<input type="text" name="authorquota" value="'.
2402: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2403: }
2404: $datatable .= '</tr>';
1.72 raeburn 2405: $typecount ++;
2406: $css_class = $typecount%2?' class="LC_odd_row"':'';
2407: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2408: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2409: if ($context eq 'requestcourses') {
1.109 raeburn 2410: $datatable .= &mt('(overrides affiliation, if set)').
2411: '</td>'.
2412: '<td class="LC_left_item">'.
2413: '<table><tr>';
1.101 raeburn 2414: } else {
1.109 raeburn 2415: $datatable .= &mt('(overrides affiliation, if checked)').
2416: '</td>'.
2417: '<td class="LC_left_item" colspan="2">'.
2418: '<br />';
1.101 raeburn 2419: }
2420: my %advcell;
1.72 raeburn 2421: foreach my $item (@usertools) {
1.101 raeburn 2422: if ($context eq 'requestcourses') {
2423: my ($curroption,$currlimit);
2424: if (ref($settings) eq 'HASH') {
2425: if (ref($settings->{$item}) eq 'HASH') {
2426: $curroption = $settings->{$item}->{'_LC_adv'};
2427: if ($curroption =~ /^autolimit=(\d*)$/) {
2428: $currlimit = $1;
2429: }
2430: }
2431: }
2432: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2433: my $checked = '';
2434: if ($curroption eq '') {
2435: $checked = ' checked="checked"';
2436: }
2437: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2438: '<input type="radio" name="crsreq_'.$item.
2439: '__LC_adv" value=""'.$checked.' />'.
2440: &mt('No override set').'</label></span> ';
1.101 raeburn 2441: foreach my $option (@options) {
2442: my $val = $option;
2443: if ($option eq 'norequest') {
2444: $val = 0;
2445: }
2446: if ($option eq 'validate') {
2447: my $canvalidate = 0;
2448: if (ref($validations{$item}) eq 'HASH') {
2449: if ($validations{$item}{'_LC_adv'}) {
2450: $canvalidate = 1;
2451: }
2452: }
2453: next if (!$canvalidate);
2454: }
2455: my $checked = '';
1.104 raeburn 2456: if ($val eq $curroption) {
1.101 raeburn 2457: $checked = ' checked="checked"';
2458: } elsif ($option eq 'autolimit') {
2459: if ($curroption =~ /^autolimit/) {
2460: $checked = ' checked="checked"';
2461: }
2462: }
2463: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2464: '<input type="radio" name="crsreq_'.$item.
2465: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2466: $titles{$option}.'</label>';
2467: if ($option eq 'autolimit') {
1.127 raeburn 2468: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2469: $item.'_limit__LC_adv" size="1" '.
2470: 'value="'.$currlimit.'" />';
2471: }
1.127 raeburn 2472: $advcell{$item} .= '</span> ';
1.104 raeburn 2473: if ($option eq 'autolimit') {
1.127 raeburn 2474: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2475: }
1.101 raeburn 2476: }
1.160.6.5 raeburn 2477: } elsif ($context eq 'requestauthor') {
2478: my $curroption;
2479: if (ref($settings) eq 'HASH') {
2480: $curroption = $settings->{'_LC_adv'};
2481: }
2482: my $checked = '';
2483: if ($curroption eq '') {
2484: $checked = ' checked="checked"';
2485: }
2486: $datatable .= '<span class="LC_nobreak"><label>'.
2487: '<input type="radio" name="authorreq__LC_adv"'.
2488: ' value=""'.$checked.' />'.
2489: &mt('No override set').'</label></span> ';
2490: foreach my $option (@options) {
2491: my $val = $option;
2492: if ($option eq 'norequest') {
2493: $val = 0;
2494: }
2495: my $checked = '';
2496: if ($val eq $curroption) {
2497: $checked = ' checked="checked"';
2498: }
2499: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2500: '<input type="radio" name="authorreq__LC_adv"'.
2501: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2502: $titles{$option}.'</label></span> ';
2503: }
1.101 raeburn 2504: } else {
2505: my $checked = 'checked="checked" ';
2506: if (ref($settings) eq 'HASH') {
2507: if (ref($settings->{$item}) eq 'HASH') {
2508: if ($settings->{$item}->{'_LC_adv'} == 0) {
2509: $checked = '';
2510: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2511: $checked = 'checked="checked" ';
2512: }
1.79 raeburn 2513: }
1.72 raeburn 2514: }
1.101 raeburn 2515: $datatable .= '<span class="LC_nobreak"><label>'.
2516: '<input type="checkbox" name="'.$context.'_'.$item.
2517: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2518: '</label></span> ';
2519: }
2520: }
2521: if ($context eq 'requestcourses') {
2522: $datatable .= '</tr><tr>';
2523: foreach my $item (@usertools) {
1.106 raeburn 2524: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2525: }
1.101 raeburn 2526: $datatable .= '</tr></table>';
1.72 raeburn 2527: }
1.98 raeburn 2528: $datatable .= '</td></tr>';
1.30 raeburn 2529: $$rowtotal += $typecount;
1.3 raeburn 2530: return $datatable;
2531: }
2532:
1.160.6.5 raeburn 2533: sub print_requestmail {
1.160.6.93 raeburn 2534: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25 raeburn 2535: my ($now,$datatable,%currapp);
1.102 raeburn 2536: $now = time;
2537: if (ref($settings) eq 'HASH') {
2538: if (ref($settings->{'notify'}) eq 'HASH') {
2539: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2540: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2541: }
2542: }
2543: }
1.160.6.16 raeburn 2544: my $numinrow = 2;
1.160.6.34 raeburn 2545: my $css_class;
1.160.6.93 raeburn 2546: if ($$rowtotal%2) {
2547: $css_class = 'LC_odd_row';
2548: }
2549: if ($customcss) {
2550: $css_class .= " $customcss";
2551: }
2552: $css_class =~ s/^\s+//;
2553: if ($css_class) {
2554: $css_class = ' class="'.$css_class.'"';
2555: }
2556: if ($rowstyle) {
2557: $css_class .= ' style="'.$rowstyle.'"';
2558: }
1.160.6.5 raeburn 2559: my $text;
2560: if ($action eq 'requestcourses') {
2561: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2562: } elsif ($action eq 'requestauthor') {
2563: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2564: } else {
1.160.6.34 raeburn 2565: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2566: }
1.160.6.34 raeburn 2567: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2568: ' <td>'.$text.'</td>'.
1.102 raeburn 2569: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2570: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2571: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2572: if ($numdc > 0) {
2573: $datatable .= $table;
1.102 raeburn 2574: } else {
2575: $datatable .= &mt('There are no active Domain Coordinators');
2576: }
2577: $datatable .='</td></tr>';
2578: return $datatable;
2579: }
2580:
1.160.6.30 raeburn 2581: sub print_studentcode {
2582: my ($settings,$rowtotal) = @_;
2583: my $rownum = 0;
2584: my ($output,%current);
2585: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2586: if (ref($settings) eq 'HASH') {
2587: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2588: foreach my $type (@crstypes) {
2589: $current{$type} = $settings->{'uniquecode'}{$type};
2590: }
1.160.6.30 raeburn 2591: }
2592: }
2593: $output .= '<tr>'.
2594: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2595: '<td class="LC_left_item">';
2596: foreach my $type (@crstypes) {
2597: my $check = ' ';
2598: if ($current{$type}) {
2599: $check = ' checked="checked" ';
2600: }
2601: $output .= '<span class="LC_nobreak"><label>'.
2602: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2603: &mt($type).'</label></span>'.(' 'x2).' ';
2604: }
2605: $output .= '</td></tr>';
2606: $$rowtotal ++;
2607: return $output;
2608: }
2609:
2610: sub print_textbookcourses {
1.160.6.46 raeburn 2611: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2612: my $rownum = 0;
2613: my $css_class;
2614: my $itemcount = 1;
2615: my $maxnum = 0;
2616: my $bookshash;
2617: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2618: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2619: }
2620: my %ordered;
2621: if (ref($bookshash) eq 'HASH') {
2622: foreach my $item (keys(%{$bookshash})) {
2623: if (ref($bookshash->{$item}) eq 'HASH') {
2624: my $num = $bookshash->{$item}{'order'};
2625: $ordered{$num} = $item;
2626: }
2627: }
2628: }
2629: my $confname = $dom.'-domainconfig';
2630: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2631: my $maxnum = scalar(keys(%ordered));
2632: my $datatable;
1.160.6.30 raeburn 2633: if (keys(%ordered)) {
2634: my @items = sort { $a <=> $b } keys(%ordered);
2635: for (my $i=0; $i<@items; $i++) {
2636: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2637: my $key = $ordered{$items[$i]};
2638: my %coursehash=&Apache::lonnet::coursedescription($key);
2639: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2640: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2641: if (ref($bookshash->{$key}) eq 'HASH') {
2642: $subject = $bookshash->{$key}->{'subject'};
2643: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2644: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2645: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2646: $author = $bookshash->{$key}->{'author'};
2647: $image = $bookshash->{$key}->{'image'};
2648: if ($image ne '') {
2649: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2650: my $imagethumb = "$path/tn-".$imagefile;
2651: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2652: }
1.160.6.30 raeburn 2653: }
2654: }
1.160.6.46 raeburn 2655: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2656: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2657: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2658: for (my $k=0; $k<=$maxnum; $k++) {
2659: my $vpos = $k+1;
2660: my $selstr;
2661: if ($k == $i) {
2662: $selstr = ' selected="selected" ';
2663: }
2664: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2665: }
2666: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2667: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2668: &mt('Delete?').'</label></span></td>'.
2669: '<td colspan="2">'.
1.160.6.46 raeburn 2670: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2671: (' 'x2).
1.160.6.46 raeburn 2672: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2673: if ($type eq 'textbooks') {
2674: $datatable .= (' 'x2).
1.160.6.47 raeburn 2675: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2676: (' 'x2).
1.160.6.46 raeburn 2677: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2678: (' 'x2).
2679: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2680: if ($image) {
2681: $datatable .= '<span class="LC_nobreak">'.
2682: $imgsrc.
2683: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2684: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2685: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2686: }
2687: if ($switchserver) {
2688: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2689: } else {
2690: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2691: }
1.160.6.30 raeburn 2692: }
1.160.6.46 raeburn 2693: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2694: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2695: $coursetitle.'</span></td></tr>'."\n";
2696: $itemcount ++;
2697: }
2698: }
2699: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2700: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2701: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2702: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2703: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2704: for (my $k=0; $k<$maxnum+1; $k++) {
2705: my $vpos = $k+1;
2706: my $selstr;
2707: if ($k == $maxnum) {
2708: $selstr = ' selected="selected" ';
2709: }
2710: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2711: }
2712: $datatable .= '</select> '."\n".
1.160.6.87 raeburn 2713: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2714: '<td colspan="2">'.
1.160.6.46 raeburn 2715: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2716: (' 'x2).
1.160.6.46 raeburn 2717: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2718: (' 'x2);
2719: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2720: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2721: (' 'x2).
2722: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2723: (' 'x2).
2724: '<span class="LC_nobreak">'.&mt('Image:').' ';
2725: if ($switchserver) {
2726: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2727: } else {
2728: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2729: }
1.160.6.87 raeburn 2730: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2731: }
1.160.6.87 raeburn 2732: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2733: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2734: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2735: &Apache::loncommon::selectcourse_link
1.160.6.87 raeburn 2736: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2737: '</span></td>'."\n".
2738: '</tr>'."\n";
2739: $itemcount ++;
2740: return $datatable;
2741: }
2742:
2743: sub textbookcourses_javascript {
1.160.6.46 raeburn 2744: my ($settings) = @_;
2745: return unless(ref($settings) eq 'HASH');
2746: my (%ordered,%total,%jstext);
2747: foreach my $type ('textbooks','templates') {
2748: $total{$type} = 0;
2749: if (ref($settings->{$type}) eq 'HASH') {
2750: foreach my $item (keys(%{$settings->{$type}})) {
2751: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2752: my $num = $settings->{$type}->{$item}{'order'};
2753: $ordered{$type}{$num} = $item;
2754: }
2755: }
2756: $total{$type} = scalar(keys(%{$settings->{$type}}));
2757: }
2758: my @jsarray = ();
2759: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2760: push(@jsarray,$ordered{$type}{$item});
2761: }
2762: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2763: }
2764: return <<"ENDSCRIPT";
2765: <script type="text/javascript">
2766: // <![CDATA[
1.160.6.46 raeburn 2767: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2768: var changedVal;
1.160.6.46 raeburn 2769: $jstext{'textbooks'};
2770: $jstext{'templates'};
2771: var newpos;
2772: var maxh;
2773: if (caller == 'textbooks') {
2774: newpos = 'textbooks_addbook_pos';
2775: maxh = 1 + $total{'textbooks'};
2776: } else {
2777: newpos = 'templates_addbook_pos';
2778: maxh = 1 + $total{'templates'};
2779: }
1.160.6.30 raeburn 2780: var current = new Array;
2781: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2782: if (item == newpos) {
2783: changedVal = newitemVal;
2784: } else {
2785: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2786: current[newitemVal] = newpos;
2787: }
1.160.6.46 raeburn 2788: if (caller == 'textbooks') {
2789: for (var i=0; i<textbooks.length; i++) {
2790: var elementName = 'textbooks_'+textbooks[i];
2791: if (elementName != item) {
2792: if (form.elements[elementName]) {
2793: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2794: current[currVal] = elementName;
2795: }
2796: }
2797: }
2798: }
2799: if (caller == 'templates') {
2800: for (var i=0; i<templates.length; i++) {
2801: var elementName = 'templates_'+templates[i];
2802: if (elementName != item) {
2803: if (form.elements[elementName]) {
2804: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2805: current[currVal] = elementName;
2806: }
1.160.6.30 raeburn 2807: }
2808: }
2809: }
2810: var oldVal;
2811: for (var j=0; j<maxh; j++) {
2812: if (current[j] == undefined) {
2813: oldVal = j;
2814: }
2815: }
2816: if (oldVal < changedVal) {
2817: for (var k=oldVal+1; k<=changedVal ; k++) {
2818: var elementName = current[k];
2819: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2820: }
2821: } else {
2822: for (var k=changedVal; k<oldVal; k++) {
2823: var elementName = current[k];
2824: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2825: }
2826: }
2827: return;
2828: }
2829:
2830: // ]]>
2831: </script>
2832:
2833: ENDSCRIPT
2834: }
2835:
1.160.6.113! raeburn 2836: sub wafproxy_javascript {
! 2837: my ($dom) = @_;
! 2838: return <<"ENDSCRIPT";
! 2839: <script type="text/javascript">
! 2840: // <![CDATA[
! 2841: function updateWAF() {
! 2842: if (document.getElementById('wafproxy_remoteip')) {
! 2843: var wafremote = 0;
! 2844: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
! 2845: wafremote = 1;
! 2846: }
! 2847: var fields = new Array('header','trust');
! 2848: for (var i=0; i<fields.length; i++) {
! 2849: if (document.getElementById('wafproxy_'+fields[i])) {
! 2850: if (wafremote == 1) {
! 2851: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
! 2852: }
! 2853: else {
! 2854: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
! 2855: }
! 2856: }
! 2857: }
! 2858: if (document.getElementById('wafproxyranges_$dom')) {
! 2859: if (wafremote == 1) {
! 2860: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
! 2861: } else {
! 2862: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
! 2863: if (document.display.wafproxy_vpnaccess[i].checked) {
! 2864: if (document.display.wafproxy_vpnaccess[i].value == 0) {
! 2865: document.getElementById('wafproxyranges_$dom').style.display = 'none';
! 2866: }
! 2867: }
! 2868: }
! 2869: }
! 2870: }
! 2871: }
! 2872: return;
! 2873: }
! 2874:
! 2875: function checkWAF() {
! 2876: if (document.getElementById('wafproxy_remoteip')) {
! 2877: var wafvpn = 0;
! 2878: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
! 2879: if (document.display.wafproxy_vpnaccess[i].checked) {
! 2880: if (document.display.wafproxy_vpnaccess[i].value == 1) {
! 2881: wafvpn = 1;
! 2882: }
! 2883: break;
! 2884: }
! 2885: }
! 2886: var vpn = new Array('vpnint','vpnext');
! 2887: for (var i=0; i<vpn.length; i++) {
! 2888: if (document.getElementById('wafproxy_show_'+vpn[i])) {
! 2889: if (wafvpn == 1) {
! 2890: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
! 2891: }
! 2892: else {
! 2893: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
! 2894: }
! 2895: }
! 2896: }
! 2897: if (document.getElementById('wafproxyranges_$dom')) {
! 2898: if (wafvpn == 1) {
! 2899: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
! 2900: }
! 2901: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
! 2902: document.getElementById('wafproxyranges_$dom').style.display = 'none';
! 2903: }
! 2904: }
! 2905: }
! 2906: return;
! 2907: }
! 2908:
! 2909: function toggleWAF() {
! 2910: if (document.getElementById('wafproxy_table')) {
! 2911: var wafproxy = 0;
! 2912: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
! 2913: if (document.display.wafproxy_${dom}[i].checked) {
! 2914: if (document.display.wafproxy_${dom}[i].value == 1) {
! 2915: wafproxy = 1;
! 2916: break;
! 2917: }
! 2918: }
! 2919: }
! 2920: if (wafproxy == 1) {
! 2921: document.getElementById('wafproxy_table').style.display='inline';
! 2922: }
! 2923: else {
! 2924: document.getElementById('wafproxy_table').style.display='none';
! 2925: }
! 2926: if (document.getElementById('wafproxyrow_${dom}')) {
! 2927: if (wafproxy == 1) {
! 2928: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
! 2929: }
! 2930: else {
! 2931: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
! 2932: }
! 2933: }
! 2934: if (document.getElementById('nowafproxyrow_$dom')) {
! 2935: if (wafproxy == 1) {
! 2936: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
! 2937: }
! 2938: else {
! 2939: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
! 2940: }
! 2941: }
! 2942: }
! 2943: return;
! 2944: }
! 2945: // ]]>
! 2946: </script>
! 2947:
! 2948: ENDSCRIPT
! 2949: }
! 2950:
! 2951: sub autoupdate_javascript {
! 2952: return <<"ENDSCRIPT";
! 2953: <script type="text/javascript">
! 2954: // <![CDATA[
! 2955: function toggleLastActiveDays(form) {
! 2956: var radioname = 'lastactive';
! 2957: var divid = 'lastactive_div';
! 2958: var num = form.elements[radioname].length;
! 2959: if (num) {
! 2960: var setvis = '';
! 2961: for (var i=0; i<num; i++) {
! 2962: if (form.elements[radioname][i].checked) {
! 2963: if (form.elements[radioname][i].value == '1') {
! 2964: if (document.getElementById(divid)) {
! 2965: document.getElementById(divid).style.display = 'inline-block';
! 2966: }
! 2967: setvis = 1;
! 2968: }
! 2969: break;
! 2970: }
! 2971: }
! 2972: if (!setvis) {
! 2973: if (document.getElementById(divid)) {
! 2974: document.getElementById(divid).style.display = 'none';
! 2975: }
! 2976: }
! 2977: }
! 2978: return;
! 2979: }
! 2980: // ]]>
! 2981: </script>
! 2982:
! 2983: ENDSCRIPT
! 2984: }
! 2985:
! 2986: sub saml_javascript {
! 2987: return <<"ENDSCRIPT";
! 2988: <script type="text/javascript">
! 2989: // <![CDATA[
! 2990: function toggleSamlOptions(form,hostid) {
! 2991: var radioname = 'saml_'+hostid;
! 2992: var tablecellon = 'samloptionson_'+hostid;
! 2993: var tablecelloff = 'samloptionsoff_'+hostid;
! 2994: var num = form.elements[radioname].length;
! 2995: if (num) {
! 2996: var setvis = '';
! 2997: for (var i=0; i<num; i++) {
! 2998: if (form.elements[radioname][i].checked) {
! 2999: if (form.elements[radioname][i].value == '1') {
! 3000: if (document.getElementById(tablecellon)) {
! 3001: document.getElementById(tablecellon).style.display='';
! 3002: }
! 3003: if (document.getElementById(tablecelloff)) {
! 3004: document.getElementById(tablecelloff).style.display='none';
! 3005: }
! 3006: setvis = 1;
! 3007: }
! 3008: break;
! 3009: }
! 3010: }
! 3011: if (!setvis) {
! 3012: if (document.getElementById(tablecellon)) {
! 3013: document.getElementById(tablecellon).style.display='none';
! 3014: }
! 3015: if (document.getElementById(tablecelloff)) {
! 3016: document.getElementById(tablecelloff).style.display='';
! 3017: }
! 3018: }
! 3019: }
! 3020: return;
! 3021: }
! 3022: // ]]>
! 3023: </script>
! 3024:
! 3025: ENDSCRIPT
! 3026: }
! 3027:
! 3028: sub ipaccess_javascript {
! 3029: my ($settings) = @_;
! 3030: my (%ordered,$total,%jstext);
! 3031: $total = 0;
! 3032: if (ref($settings) eq 'HASH') {
! 3033: foreach my $item (keys(%{$settings})) {
! 3034: if (ref($settings->{$item}) eq 'HASH') {
! 3035: my $num = $settings->{$item}{'order'};
! 3036: $ordered{$num} = $item;
! 3037: }
! 3038: }
! 3039: $total = scalar(keys(%{$settings}));
! 3040: }
! 3041: my @jsarray = ();
! 3042: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
! 3043: push(@jsarray,$ordered{$item});
! 3044: }
! 3045: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
! 3046: return <<"ENDSCRIPT";
! 3047: <script type="text/javascript">
! 3048: // <![CDATA[
! 3049: function reorderIPaccess(form,item) {
! 3050: var changedVal;
! 3051: $jstext
! 3052: var newpos = 'ipaccess_pos_add';
! 3053: var maxh = 1 + $total;
! 3054: var current = new Array;
! 3055: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
! 3056: if (item == newpos) {
! 3057: changedVal = newitemVal;
! 3058: } else {
! 3059: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
! 3060: current[newitemVal] = newpos;
! 3061: }
! 3062: for (var i=0; i<ipaccess.length; i++) {
! 3063: var elementName = 'ipaccess_pos_'+ipaccess[i];
! 3064: if (elementName != item) {
! 3065: if (form.elements[elementName]) {
! 3066: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
! 3067: current[currVal] = elementName;
! 3068: }
! 3069: }
! 3070: }
! 3071: var oldVal;
! 3072: for (var j=0; j<maxh; j++) {
! 3073: if (current[j] == undefined) {
! 3074: oldVal = j;
! 3075: }
! 3076: }
! 3077: if (oldVal < changedVal) {
! 3078: for (var k=oldVal+1; k<=changedVal ; k++) {
! 3079: var elementName = current[k];
! 3080: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
! 3081: }
! 3082: } else {
! 3083: for (var k=changedVal; k<oldVal; k++) {
! 3084: var elementName = current[k];
! 3085: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
! 3086: }
! 3087: }
! 3088: return;
! 3089: }
! 3090: // ]]>
! 3091: </script>
! 3092:
! 3093: ENDSCRIPT
! 3094: }
! 3095:
1.3 raeburn 3096: sub print_autoenroll {
1.30 raeburn 3097: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3098: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68 raeburn 3099: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 3100: if (ref($settings) eq 'HASH') {
3101: if (exists($settings->{'run'})) {
3102: if ($settings->{'run'} eq '0') {
3103: $runoff = ' checked="checked" ';
3104: $runon = ' ';
3105: } else {
3106: $runon = ' checked="checked" ';
3107: $runoff = ' ';
3108: }
3109: } else {
3110: if ($autorun) {
3111: $runon = ' checked="checked" ';
3112: $runoff = ' ';
3113: } else {
3114: $runoff = ' checked="checked" ';
3115: $runon = ' ';
3116: }
3117: }
1.129 raeburn 3118: if (exists($settings->{'co-owners'})) {
3119: if ($settings->{'co-owners'} eq '0') {
3120: $coownersoff = ' checked="checked" ';
3121: $coownerson = ' ';
3122: } else {
3123: $coownerson = ' checked="checked" ';
3124: $coownersoff = ' ';
3125: }
3126: } else {
3127: $coownersoff = ' checked="checked" ';
3128: $coownerson = ' ';
3129: }
1.3 raeburn 3130: if (exists($settings->{'sender_domain'})) {
3131: $defdom = $settings->{'sender_domain'};
3132: }
1.160.6.68 raeburn 3133: if (exists($settings->{'autofailsafe'})) {
3134: $failsafe = $settings->{'autofailsafe'};
3135: }
1.14 raeburn 3136: } else {
3137: if ($autorun) {
3138: $runon = ' checked="checked" ';
3139: $runoff = ' ';
3140: } else {
3141: $runoff = ' checked="checked" ';
3142: $runon = ' ';
3143: }
1.3 raeburn 3144: }
3145: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3146: my $notif_sender;
3147: if (ref($settings) eq 'HASH') {
3148: $notif_sender = $settings->{'sender_uname'};
3149: }
1.3 raeburn 3150: my $datatable='<tr class="LC_odd_row">'.
3151: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3152: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3153: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3154: $runon.' value="1" />'.&mt('Yes').'</label> '.
3155: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3156: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3157: '</tr><tr>'.
3158: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3159: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3160: &mt('username').': '.
3161: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3162: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3163: ': '.$domform.'</span></td></tr>'.
3164: '<tr class="LC_odd_row">'.
3165: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3166: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3167: '<input type="radio" name="autoassign_coowners"'.
3168: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3169: '<label><input type="radio" name="autoassign_coowners"'.
3170: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 3171: '</tr><tr>'.
3172: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3173: '<td class="LC_right_item"><span class="LC_nobreak">'.
3174: '<input type="text" name="autoenroll_failsafe"'.
1.160.6.87 raeburn 3175: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.160.6.68 raeburn 3176: $$rowtotal += 4;
1.3 raeburn 3177: return $datatable;
3178: }
3179:
3180: sub print_autoupdate {
1.30 raeburn 3181: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.113! raeburn 3182: my ($enable,$datatable);
1.3 raeburn 3183: if ($position eq 'top') {
1.160.6.113! raeburn 3184: my %choices = &Apache::lonlocal::texthash (
! 3185: run => 'Auto-update active?',
! 3186: classlists => 'Update information in classlists?',
! 3187: unexpired => 'Skip updates for users without active or future roles?',
! 3188: lastactive => 'Skip updates for inactive users?',
! 3189: );
! 3190: my $itemcount = 0;
1.3 raeburn 3191: my $updateon = ' ';
3192: my $updateoff = ' checked="checked" ';
3193: if (ref($settings) eq 'HASH') {
3194: if ($settings->{'run'} eq '1') {
3195: $updateon = $updateoff;
3196: $updateoff = ' ';
3197: }
3198: }
1.160.6.113! raeburn 3199: $enable = '<tr class="LC_odd_row">'.
! 3200: '<td>'.&mt($choices{'run'}).'</td>'.
! 3201: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3202: '<input type="radio" name="autoupdate_run"'.
1.160.6.113! raeburn 3203: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 3204: '<label><input type="radio" name="autoupdate_run"'.
1.160.6.113! raeburn 3205: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 3206: '</tr>';
1.160.6.113! raeburn 3207: my @toggles = ('classlists','unexpired');
! 3208: my %defaultchecked = ('classlists' => 'off',
! 3209: 'unexpired' => 'off'
! 3210: );
! 3211: $$rowtotal ++;
! 3212: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
! 3213: \%choices,$itemcount,'','','left','no');
! 3214: $datatable = $enable.$datatable;
! 3215: $$rowtotal += $itemcount;
! 3216: my $lastactiveon = ' ';
! 3217: my $lastactiveoff = ' checked="checked" ';
! 3218: my $lastactivestyle = 'none';
! 3219: my $lastactivedays;
! 3220: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
! 3221: if (ref($settings) eq 'HASH') {
! 3222: if ($settings->{'lastactive'} =~ /^\d+$/) {
! 3223: $lastactiveon = $lastactiveoff;
! 3224: $lastactiveoff = ' ';
! 3225: $lastactivestyle = 'inline-block';
! 3226: $lastactivedays = $settings->{'lastactive'};
! 3227: }
! 3228: }
! 3229: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 3230: $datatable .= '<tr'.$css_class.'>'.
! 3231: '<td>'.$choices{'lastactive'}.'</td>'.
! 3232: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
! 3233: '<input type="radio" name="lastactive"'.
! 3234: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
! 3235: ' <label>'.
! 3236: '<input type="radio" name="lastactive"'.
! 3237: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
! 3238: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
! 3239: ': '.&mt('inactive = no activity in last [_1] days',
! 3240: '<input type="text" size="5" name="lastactivedays" value="'.
! 3241: $lastactivedays.'" />').
! 3242: '</span></td>'.
! 3243: '</tr>';
! 3244: $$rowtotal ++;
1.131 raeburn 3245: } elsif ($position eq 'middle') {
3246: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3247: my $numinrow = 3;
3248: my $locknamesettings;
3249: $datatable .= &insttypes_row($settings,$types,$usertypes,
3250: $dom,$numinrow,$othertitle,
1.160.6.93 raeburn 3251: 'lockablenames',$rowtotal);
1.131 raeburn 3252: $$rowtotal ++;
1.3 raeburn 3253: } else {
1.44 raeburn 3254: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3255: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3256: 'permanentemail','id');
1.33 raeburn 3257: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3258: my $numrows = 0;
1.26 raeburn 3259: if (ref($types) eq 'ARRAY') {
3260: if (@{$types} > 0) {
3261: $datatable =
3262: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3263: \@fields,$types,\$numrows);
1.30 raeburn 3264: $$rowtotal += @{$types};
1.26 raeburn 3265: }
1.3 raeburn 3266: }
3267: $datatable .=
3268: &usertype_update_row($settings,{'default' => $othertitle},
3269: \%fieldtitles,\@fields,['default'],
3270: \$numrows);
1.30 raeburn 3271: $$rowtotal ++;
1.3 raeburn 3272: }
3273: return $datatable;
3274: }
3275:
1.125 raeburn 3276: sub print_autocreate {
3277: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3278: my (%createon,%createoff,%currhash);
1.125 raeburn 3279: my @types = ('xml','req');
3280: if (ref($settings) eq 'HASH') {
3281: foreach my $item (@types) {
3282: $createoff{$item} = ' checked="checked" ';
3283: $createon{$item} = ' ';
3284: if (exists($settings->{$item})) {
3285: if ($settings->{$item}) {
3286: $createon{$item} = ' checked="checked" ';
3287: $createoff{$item} = ' ';
3288: }
3289: }
3290: }
1.160.6.16 raeburn 3291: if ($settings->{'xmldc'} ne '') {
3292: $currhash{$settings->{'xmldc'}} = 1;
3293: }
1.125 raeburn 3294: } else {
3295: foreach my $item (@types) {
3296: $createoff{$item} = ' checked="checked" ';
3297: $createon{$item} = ' ';
3298: }
3299: }
3300: $$rowtotal += 2;
1.160.6.16 raeburn 3301: my $numinrow = 2;
1.125 raeburn 3302: my $datatable='<tr class="LC_odd_row">'.
3303: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3304: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3305: '<input type="radio" name="autocreate_xml"'.
3306: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3307: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3308: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3309: '</td></tr><tr>'.
3310: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3311: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3312: '<input type="radio" name="autocreate_req"'.
3313: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3314: '<label><input type="radio" name="autocreate_req"'.
3315: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 3316: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3317: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 3318: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3319: if ($numdc > 1) {
1.160.6.50 raeburn 3320: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3321: '</td><td class="LC_left_item">';
1.125 raeburn 3322: } else {
1.160.6.50 raeburn 3323: $datatable .= &mt('Course creation processed as:').
3324: '</td><td class="LC_right_item">';
1.125 raeburn 3325: }
1.160.6.50 raeburn 3326: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 3327: $$rowtotal += $rows;
1.125 raeburn 3328: return $datatable;
3329: }
3330:
1.23 raeburn 3331: sub print_directorysrch {
1.160.6.72 raeburn 3332: my ($position,$dom,$settings,$rowtotal) = @_;
3333: my $datatable;
3334: if ($position eq 'top') {
3335: my $instsrchon = ' ';
3336: my $instsrchoff = ' checked="checked" ';
3337: my ($exacton,$containson,$beginson);
3338: my $instlocalon = ' ';
3339: my $instlocaloff = ' checked="checked" ';
3340: if (ref($settings) eq 'HASH') {
3341: if ($settings->{'available'} eq '1') {
3342: $instsrchon = $instsrchoff;
3343: $instsrchoff = ' ';
3344: }
3345: if ($settings->{'localonly'} eq '1') {
3346: $instlocalon = $instlocaloff;
3347: $instlocaloff = ' ';
3348: }
3349: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3350: foreach my $type (@{$settings->{'searchtypes'}}) {
3351: if ($type eq 'exact') {
3352: $exacton = ' checked="checked" ';
3353: } elsif ($type eq 'contains') {
3354: $containson = ' checked="checked" ';
3355: } elsif ($type eq 'begins') {
3356: $beginson = ' checked="checked" ';
3357: }
3358: }
3359: } else {
3360: if ($settings->{'searchtypes'} eq 'exact') {
3361: $exacton = ' checked="checked" ';
3362: } elsif ($settings->{'searchtypes'} eq 'contains') {
3363: $containson = ' checked="checked" ';
3364: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3365: $exacton = ' checked="checked" ';
3366: $containson = ' checked="checked" ';
3367: }
3368: }
1.23 raeburn 3369: }
1.160.6.72 raeburn 3370: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3371: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 3372:
1.160.6.72 raeburn 3373: my $numinrow = 4;
3374: my $cansrchrow = 0;
3375: $datatable='<tr class="LC_odd_row">'.
3376: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3377: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3378: '<input type="radio" name="dirsrch_available"'.
3379: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3380: '<label><input type="radio" name="dirsrch_available"'.
3381: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3382: '</tr><tr>'.
3383: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3384: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3385: '<input type="radio" name="dirsrch_instlocalonly"'.
3386: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3387: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3388: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3389: '</tr>';
3390: $$rowtotal += 2;
3391: if (ref($usertypes) eq 'HASH') {
3392: if (keys(%{$usertypes}) > 0) {
3393: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93 raeburn 3394: $numinrow,$othertitle,'cansearch',
3395: $rowtotal);
1.160.6.72 raeburn 3396: $cansrchrow = 1;
3397: }
1.26 raeburn 3398: }
1.160.6.72 raeburn 3399: if ($cansrchrow) {
3400: $$rowtotal ++;
3401: $datatable .= '<tr>';
3402: } else {
3403: $datatable .= '<tr class="LC_odd_row">';
3404: }
3405: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3406: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3407: foreach my $title (@{$titleorder}) {
3408: if (defined($searchtitles->{$title})) {
3409: my $check = ' ';
3410: if (ref($settings) eq 'HASH') {
3411: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3412: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3413: $check = ' checked="checked" ';
3414: }
1.39 raeburn 3415: }
1.25 raeburn 3416: }
1.160.6.72 raeburn 3417: $datatable .= '<td class="LC_left_item">'.
3418: '<span class="LC_nobreak"><label>'.
3419: '<input type="checkbox" name="searchby" '.
3420: 'value="'.$title.'"'.$check.'/>'.
3421: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3422: }
3423: }
1.160.6.72 raeburn 3424: $datatable .= '</tr></table></td></tr>';
3425: $$rowtotal ++;
3426: if ($cansrchrow) {
3427: $datatable .= '<tr class="LC_odd_row">';
3428: } else {
3429: $datatable .= '<tr>';
3430: }
3431: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3432: '<td class="LC_left_item" colspan="2">'.
3433: '<span class="LC_nobreak"><label>'.
3434: '<input type="checkbox" name="searchtypes" '.
3435: $exacton.' value="exact" />'.&mt('Exact match').
3436: '</label> '.
3437: '<label><input type="checkbox" name="searchtypes" '.
3438: $beginson.' value="begins" />'.&mt('Begins with').
3439: '</label> '.
3440: '<label><input type="checkbox" name="searchtypes" '.
3441: $containson.' value="contains" />'.&mt('Contains').
3442: '</label></span></td></tr>';
3443: $$rowtotal ++;
1.26 raeburn 3444: } else {
1.160.6.72 raeburn 3445: my $domsrchon = ' checked="checked" ';
3446: my $domsrchoff = ' ';
3447: my $domlocalon = ' ';
3448: my $domlocaloff = ' checked="checked" ';
3449: if (ref($settings) eq 'HASH') {
3450: if ($settings->{'lclocalonly'} eq '1') {
3451: $domlocalon = $domlocaloff;
3452: $domlocaloff = ' ';
3453: }
3454: if ($settings->{'lcavailable'} eq '0') {
3455: $domsrchoff = $domsrchon;
3456: $domsrchon = ' ';
3457: }
3458: }
3459: $datatable='<tr class="LC_odd_row">'.
3460: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3461: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3462: '<input type="radio" name="dirsrch_domavailable"'.
3463: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3464: '<label><input type="radio" name="dirsrch_domavailable"'.
3465: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3466: '</tr><tr>'.
3467: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3468: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3469: '<input type="radio" name="dirsrch_domlocalonly"'.
3470: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3471: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3472: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3473: '</tr>';
3474: $$rowtotal += 2;
1.26 raeburn 3475: }
1.25 raeburn 3476: return $datatable;
3477: }
3478:
1.28 raeburn 3479: sub print_contacts {
1.160.6.78 raeburn 3480: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3481: my $datatable;
3482: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 3483: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.160.6.107 raeburn 3484: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.160.6.78 raeburn 3485: if ($position eq 'top') {
3486: if (ref($settings) eq 'HASH') {
3487: foreach my $item (@contacts) {
3488: if (exists($settings->{$item})) {
3489: $to{$item} = $settings->{$item};
3490: }
1.28 raeburn 3491: }
3492: }
1.160.6.78 raeburn 3493: } elsif ($position eq 'middle') {
3494: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91 raeburn 3495: 'updatesmail','idconflictsmail','hostipmail');
1.28 raeburn 3496: foreach my $type (@mailings) {
1.160.6.78 raeburn 3497: $otheremails{$type} = '';
3498: }
1.160.6.107 raeburn 3499: } elsif ($position eq 'lower') {
3500: if (ref($settings) eq 'HASH') {
3501: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3502: %lonstatus = %{$settings->{'lonstatus'}};
3503: }
3504: }
1.160.6.78 raeburn 3505: } else {
3506: @mailings = ('helpdeskmail','otherdomsmail');
3507: foreach my $type (@mailings) {
3508: $otheremails{$type} = '';
3509: }
3510: $bccemails{'helpdeskmail'} = '';
3511: $bccemails{'otherdomsmail'} = '';
3512: $includestr{'helpdeskmail'} = '';
3513: $includestr{'otherdomsmail'} = '';
3514: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3515: }
3516: if (ref($settings) eq 'HASH') {
1.160.6.107 raeburn 3517: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 3518: foreach my $type (@mailings) {
3519: if (exists($settings->{$type})) {
3520: if (ref($settings->{$type}) eq 'HASH') {
3521: foreach my $item (@contacts) {
3522: if ($settings->{$type}{$item}) {
3523: $checked{$type}{$item} = ' checked="checked" ';
3524: }
1.28 raeburn 3525: }
1.160.6.78 raeburn 3526: $otheremails{$type} = $settings->{$type}{'others'};
3527: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3528: $bccemails{$type} = $settings->{$type}{'bcc'};
3529: if ($settings->{$type}{'include'} ne '') {
3530: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3531: $includestr{$type} = &unescape($includestr{$type});
3532: }
3533: }
3534: }
3535: } elsif ($type eq 'lonstatusmail') {
3536: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3537: }
3538: }
3539: }
3540: if ($position eq 'bottom') {
3541: foreach my $type (@mailings) {
3542: $bccemails{$type} = $settings->{$type}{'bcc'};
3543: if ($settings->{$type}{'include'} ne '') {
3544: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3545: $includestr{$type} = &unescape($includestr{$type});
3546: }
3547: }
3548: if (ref($settings->{'helpform'}) eq 'HASH') {
3549: if (ref($fields) eq 'ARRAY') {
3550: foreach my $field (@{$fields}) {
3551: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3552: }
1.160.6.78 raeburn 3553: }
3554: if (exists($settings->{'helpform'}{'maxsize'})) {
3555: $maxsize = $settings->{'helpform'}{'maxsize'};
3556: } else {
3557: $maxsize = '1.0';
3558: }
3559: } else {
3560: if (ref($fields) eq 'ARRAY') {
3561: foreach my $field (@{$fields}) {
3562: $currfield{$field} = 'yes';
1.134 raeburn 3563: }
1.28 raeburn 3564: }
1.160.6.78 raeburn 3565: $maxsize = '1.0';
1.28 raeburn 3566: }
3567: }
3568: } else {
1.160.6.78 raeburn 3569: if ($position eq 'top') {
3570: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3571: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3572: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3573: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
3574: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3575: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3576: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3577: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91 raeburn 3578: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78 raeburn 3579: } elsif ($position eq 'bottom') {
3580: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3581: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3582: if (ref($fields) eq 'ARRAY') {
3583: foreach my $field (@{$fields}) {
3584: $currfield{$field} = 'yes';
3585: }
3586: }
3587: $maxsize = '1.0';
3588: }
1.28 raeburn 3589: }
3590: my ($titles,$short_titles) = &contact_titles();
3591: my $rownum = 0;
3592: my $css_class;
1.160.6.78 raeburn 3593: if ($position eq 'top') {
3594: foreach my $item (@contacts) {
3595: $css_class = $rownum%2?' class="LC_odd_row"':'';
3596: $datatable .= '<tr'.$css_class.'>'.
3597: '<td><span class="LC_nobreak">'.$titles->{$item}.
3598: '</span></td><td class="LC_right_item">'.
3599: '<input type="text" name="'.$item.'" value="'.
3600: $to{$item}.'" /></td></tr>';
3601: $rownum ++;
3602: }
1.160.6.101 raeburn 3603: } elsif ($position eq 'bottom') {
3604: $css_class = $rownum%2?' class="LC_odd_row"':'';
3605: $datatable .= '<tr'.$css_class.'>'.
3606: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3607: &mt('(e-mail, subject, and description always shown)').
3608: '</td><td class="LC_left_item">';
3609: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3610: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3611: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3612: foreach my $field (@{$fields}) {
3613: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3614: if (($field eq 'screenshot') || ($field eq 'cc')) {
3615: $datatable .= ' '.&mt('(logged-in users)');
3616: }
3617: $datatable .='</td><td>';
3618: my $clickaction;
3619: if ($field eq 'screenshot') {
3620: $clickaction = ' onclick="screenshotSize(this);"';
3621: }
3622: if (ref($possoptions->{$field}) eq 'ARRAY') {
3623: foreach my $option (@{$possoptions->{$field}}) {
3624: my $checked;
3625: if ($currfield{$field} eq $option) {
3626: $checked = ' checked="checked"';
3627: }
3628: $datatable .= '<span class="LC_nobreak"><label>'.
3629: '<input type="radio" name="helpform_'.$field.'" '.
3630: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3631: '</label></span>'.(' 'x2);
3632: }
3633: }
3634: if ($field eq 'screenshot') {
3635: my $display;
3636: if ($currfield{$field} eq 'no') {
3637: $display = ' style="display:none"';
3638: }
3639: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
3640: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3641: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3642: }
3643: $datatable .= '</td></tr>';
3644: }
3645: $datatable .= '</table>';
3646: }
3647: $datatable .= '</td></tr>'."\n";
3648: $rownum ++;
3649: }
1.160.6.107 raeburn 3650: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 3651: foreach my $type (@mailings) {
3652: $css_class = $rownum%2?' class="LC_odd_row"':'';
3653: $datatable .= '<tr'.$css_class.'>'.
3654: '<td><span class="LC_nobreak">'.
3655: $titles->{$type}.': </span></td>'.
3656: '<td class="LC_left_item">';
3657: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3658: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3659: }
3660: $datatable .= '<span class="LC_nobreak">';
3661: foreach my $item (@contacts) {
3662: $datatable .= '<label>'.
3663: '<input type="checkbox" name="'.$type.'"'.
3664: $checked{$type}{$item}.
3665: ' value="'.$item.'" />'.$short_titles->{$item}.
3666: '</label> ';
3667: }
3668: $datatable .= '</span><br />'.&mt('Others').': '.
3669: '<input type="text" name="'.$type.'_others" '.
3670: 'value="'.$otheremails{$type}.'" />';
3671: my %locchecked;
3672: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3673: foreach my $loc ('s','b') {
3674: if ($includeloc{$type} eq $loc) {
3675: $locchecked{$loc} = ' checked="checked"';
3676: last;
3677: }
3678: }
3679: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3680: '<input type="text" name="'.$type.'_bcc" '.
3681: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3682: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3683: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 3684: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 3685: '<span class="LC_nobreak">'.&mt('Location:').' '.
3686: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3687: (' 'x2).
3688: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3689: '</span></fieldset>';
3690: }
3691: $datatable .= '</td></tr>'."\n";
3692: $rownum ++;
3693: }
1.28 raeburn 3694: }
1.160.6.78 raeburn 3695: if ($position eq 'middle') {
3696: my %choices;
1.160.6.107 raeburn 3697: my $corelink = &core_link_msu();
3698: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.160.6.78 raeburn 3699: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.160.6.107 raeburn 3700: $corelink);
3701: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
3702: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.160.6.78 raeburn 3703: my %defaultchecked = ('reporterrors' => 'on',
1.160.6.107 raeburn 3704: 'reportupdates' => 'on',
3705: 'reportstatus' => 'on');
1.160.6.78 raeburn 3706: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3707: \%choices,$rownum);
3708: $datatable .= $reports;
1.160.6.107 raeburn 3709: } elsif ($position eq 'lower') {
1.160.6.109 raeburn 3710: my (%current,%excluded,%weights);
1.160.6.107 raeburn 3711: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
3712: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.160.6.109 raeburn 3713: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.160.6.107 raeburn 3714: } else {
1.160.6.109 raeburn 3715: $current{'errorthreshold'} = $defaults->{'threshold'};
1.160.6.107 raeburn 3716: }
3717: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.160.6.109 raeburn 3718: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.160.6.107 raeburn 3719: } else {
1.160.6.109 raeburn 3720: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.160.6.107 raeburn 3721: }
3722: if (ref($lonstatus{'weights'}) eq 'HASH') {
3723: foreach my $type ('E','W','N','U') {
3724: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
3725: $weights{$type} = $lonstatus{'weights'}{$type};
3726: } else {
3727: $weights{$type} = $defaults->{$type};
3728: }
3729: }
3730: } else {
3731: foreach my $type ('E','W','N','U') {
3732: $weights{$type} = $defaults->{$type};
3733: }
3734: }
3735: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
3736: if (@{$lonstatus{'excluded'}} > 0) {
3737: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
3738: }
3739: }
1.160.6.109 raeburn 3740: foreach my $item ('errorthreshold','errorsysmail') {
3741: $css_class = $rownum%2?' class="LC_odd_row"':'';
3742: $datatable .= '<tr'.$css_class.'>'.
3743: '<td class="LC_left_item"><span class="LC_nobreak">'.
3744: $titles->{$item}.
3745: '</span></td><td class="LC_left_item">'.
3746: '<input type="text" name="'.$item.'" value="'.
3747: $current{$item}.'" size="5" /></td></tr>';
3748: $rownum ++;
3749: }
1.160.6.107 raeburn 3750: $css_class = $rownum%2?' class="LC_odd_row"':'';
3751: $datatable .= '<tr'.$css_class.'>'.
3752: '<td class="LC_left_item">'.
3753: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
3754: '</span></td><td class="LC_left_item"><table><tr>';
3755: foreach my $type ('E','W','N','U') {
3756: $datatable .= '<td>'.$names->{$type}.'<br />'.
3757: '<input type="text" name="errorweights_'.$type.'" value="'.
3758: $weights{$type}.'" size="5" /></td>';
3759: }
3760: $datatable .= '</tr></table></tr>';
3761: $rownum ++;
3762: $css_class = $rownum%2?' class="LC_odd_row"':'';
3763: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
3764: $titles->{'errorexcluded'}.'</td>'.
3765: '<td class="LC_left_item"><table>';
3766: my $numinrow = 4;
3767: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
3768: for (my $i=0; $i<@ids; $i++) {
3769: my $rem = $i%($numinrow);
3770: if ($rem == 0) {
3771: if ($i > 0) {
3772: $datatable .= '</tr>';
3773: }
3774: $datatable .= '<tr>';
3775: }
3776: my $check;
3777: if ($excluded{$ids[$i]}) {
3778: $check = ' checked="checked" ';
3779: }
3780: $datatable .= '<td class="LC_left_item">'.
3781: '<span class="LC_nobreak"><label>'.
3782: '<input type="checkbox" name="errorexcluded" '.
3783: 'value="'.$ids[$i].'"'.$check.' />'.
3784: $ids[$i].'</label></span></td>';
3785: }
3786: my $colsleft = $numinrow - @ids%($numinrow);
3787: if ($colsleft > 1 ) {
3788: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3789: ' </td>';
3790: } elsif ($colsleft == 1) {
3791: $datatable .= '<td class="LC_left_item"> </td>';
3792: }
3793: $datatable .= '</tr></table></td></tr>';
3794: $rownum ++;
1.160.6.78 raeburn 3795: } elsif ($position eq 'bottom') {
1.160.6.101 raeburn 3796: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3797: my (@posstypes,%usertypeshash);
3798: if (ref($types) eq 'ARRAY') {
3799: @posstypes = @{$types};
3800: }
3801: if (@posstypes) {
3802: if (ref($usertypes) eq 'HASH') {
3803: %usertypeshash = %{$usertypes};
3804: }
3805: my @overridden;
3806: my $numinrow = 4;
3807: if (ref($settings) eq 'HASH') {
3808: if (ref($settings->{'overrides'}) eq 'HASH') {
3809: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3810: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3811: push(@overridden,$key);
3812: foreach my $item (@contacts) {
3813: if ($settings->{'overrides'}{$key}{$item}) {
3814: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3815: }
3816: }
3817: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3818: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3819: $includeloc{'override_'.$key} = '';
3820: $includestr{'override_'.$key} = '';
3821: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3822: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3823: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3824: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3825: }
1.160.6.78 raeburn 3826: }
3827: }
3828: }
1.160.6.101 raeburn 3829: }
3830: my $customclass = 'LC_helpdesk_override';
3831: my $optionsprefix = 'LC_options_helpdesk_';
3832:
3833: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3834:
3835: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3836: $numinrow,$othertitle,'overrides',
3837: \$rownum,$onclicktypes,$customclass);
3838: $rownum ++;
3839: $usertypeshash{'default'} = $othertitle;
3840: foreach my $status (@posstypes) {
3841: my $css_class;
3842: if ($rownum%2) {
3843: $css_class = 'LC_odd_row ';
3844: }
3845: $css_class .= $customclass;
3846: my $rowid = $optionsprefix.$status;
3847: my $hidden = 1;
3848: my $currstyle = 'display:none';
3849: if (grep(/^\Q$status\E$/,@overridden)) {
3850: $currstyle = 'display:table-row';
3851: $hidden = 0;
3852: }
3853: my $key = 'override_'.$status;
3854: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3855: $includeloc{$key},$includestr{$key},$status,$rowid,
3856: $usertypeshash{$status},$css_class,$currstyle,
3857: \@contacts,$short_titles);
3858: unless ($hidden) {
3859: $rownum ++;
1.160.6.78 raeburn 3860: }
3861: }
1.134 raeburn 3862: }
1.28 raeburn 3863: }
1.30 raeburn 3864: $$rowtotal += $rownum;
1.28 raeburn 3865: return $datatable;
3866: }
3867:
1.160.6.107 raeburn 3868: sub core_link_msu {
3869: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3870: &mt('LON-CAPA core group - MSU'),600,500);
3871: }
3872:
1.160.6.101 raeburn 3873: sub overridden_helpdesk {
3874: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3875: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3876: my $class = 'LC_left_item';
3877: if ($css_class) {
3878: $css_class = ' class="'.$css_class.'"';
3879: }
3880: if ($rowid) {
3881: $rowid = ' id="'.$rowid.'"';
3882: }
3883: if ($rowstyle) {
3884: $rowstyle = ' style="'.$rowstyle.'"';
3885: }
3886: my ($output,$description);
3887: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3888: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3889: "<td>$description</td>\n".
3890: '<td class="'.$class.'" colspan="2">'.
3891: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3892: '<span class="LC_nobreak">';
3893: if (ref($contacts) eq 'ARRAY') {
3894: foreach my $item (@{$contacts}) {
3895: my $check;
3896: if (ref($checked) eq 'HASH') {
3897: $check = $checked->{$item};
3898: }
3899: my $title;
3900: if (ref($short_titles) eq 'HASH') {
3901: $title = $short_titles->{$item};
3902: }
3903: $output .= '<label>'.
3904: '<input type="checkbox" name="override_'.$type.'"'.$check.
3905: ' value="'.$item.'" />'.$title.'</label> ';
3906: }
3907: }
3908: $output .= '</span><br />'.&mt('Others').': '.
3909: '<input type="text" name="override_'.$type.'_others" '.
3910: 'value="'.$otheremails.'" />';
3911: my %locchecked;
3912: foreach my $loc ('s','b') {
3913: if ($includeloc eq $loc) {
3914: $locchecked{$loc} = ' checked="checked"';
3915: last;
3916: }
3917: }
3918: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3919: '<input type="text" name="override_'.$type.'_bcc" '.
3920: 'value="'.$bccemails.'" /></fieldset>'.
3921: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3922: &mt('Text automatically added to e-mail:').' '.
3923: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
3924: '<span class="LC_nobreak">'.&mt('Location:').' '.
3925: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3926: (' 'x2).
3927: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3928: '</span></fieldset>'.
3929: '</td></tr>'."\n";
3930: return $output;
3931: }
3932:
1.160.6.78 raeburn 3933: sub contacts_javascript {
3934: return <<"ENDSCRIPT";
3935:
3936: <script type="text/javascript">
3937: // <![CDATA[
3938:
3939: function screenshotSize(field) {
3940: if (document.getElementById('help_screenshotsize')) {
3941: if (field.value == 'no') {
3942: document.getElementById('help_screenshotsize').style.display="none";
3943: } else {
3944: document.getElementById('help_screenshotsize').style.display="";
3945: }
3946: }
3947: return;
3948: }
3949:
1.160.6.101 raeburn 3950: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3951: if (form.elements[checkbox].length != undefined) {
3952: var count = 0;
3953: if (docount) {
3954: for (var i=0; i<form.elements[checkbox].length; i++) {
3955: if (form.elements[checkbox][i].checked) {
3956: count ++;
3957: }
3958: }
3959: }
3960: for (var i=0; i<form.elements[checkbox].length; i++) {
3961: var type = form.elements[checkbox][i].value;
3962: if (document.getElementById(prefix+type)) {
3963: if (form.elements[checkbox][i].checked) {
3964: document.getElementById(prefix+type).style.display = 'table-row';
3965: if (count % 2 == 1) {
3966: document.getElementById(prefix+type).className = target+' LC_odd_row';
3967: } else {
3968: document.getElementById(prefix+type).className = target;
3969: }
3970: count ++;
3971: } else {
3972: document.getElementById(prefix+type).style.display = 'none';
3973: }
3974: }
3975: }
3976: }
3977: return;
3978: }
3979:
1.160.6.78 raeburn 3980: // ]]>
3981: </script>
3982:
3983: ENDSCRIPT
3984: }
3985:
1.118 jms 3986: sub print_helpsettings {
1.160.6.73 raeburn 3987: my ($position,$dom,$settings,$rowtotal) = @_;
3988: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 3989: my $formname = 'display';
1.160.6.5 raeburn 3990: my ($datatable,$itemcount);
1.160.6.73 raeburn 3991: if ($position eq 'top') {
3992: $itemcount = 1;
3993: my (%choices,%defaultchecked,@toggles);
3994: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3995: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3996: &mt('LON-CAPA bug tracker'),600,500));
3997: %defaultchecked = ('submitbugs' => 'on');
3998: @toggles = ('submitbugs');
3999: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4000: \%choices,$itemcount);
4001: $$rowtotal ++;
4002: } else {
4003: my $css_class;
4004: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 4005: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 4006: if (ref($settings) eq 'HASH') {
4007: if (ref($settings->{'adhoc'}) eq 'HASH') {
4008: %current = %{$settings->{'adhoc'}};
4009: }
1.160.6.77 raeburn 4010: }
4011: my $count = 0;
4012: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 4013: if ($key=~/^rolesdef\_(\w+)$/) {
4014: my $rolename = $1;
1.160.6.77 raeburn 4015: my (%privs,$order);
1.160.6.73 raeburn 4016: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4017: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 4018: if (ref($current{$rolename}) eq 'HASH') {
4019: $order = $current{$rolename}{'order'};
4020: }
4021: if ($order eq '') {
4022: $order = $count;
4023: }
4024: $ordered{$order} = $rolename;
4025: $count++;
1.160.6.73 raeburn 4026: }
4027: }
1.160.6.77 raeburn 4028: my $maxnum = scalar(keys(%ordered));
4029: my @roles_by_num = ();
4030: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4031: push(@roles_by_num,$item);
4032: }
4033: my $context = 'domprefs';
4034: my $crstype = 'Course';
4035: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 4036: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 4037: my ($numstatustypes,@jsarray);
4038: if (ref($types) eq 'ARRAY') {
4039: if (@{$types} > 0) {
4040: $numstatustypes = scalar(@{$types});
4041: push(@accesstypes,'status');
4042: @jsarray = ('bystatus');
4043: }
4044: }
1.160.6.86 raeburn 4045: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 4046: if (keys(%domhelpdesk)) {
4047: push(@accesstypes,('inc','exc'));
4048: push(@jsarray,('notinc','notexc'));
4049: }
4050: my $hiddenstr = join("','",@jsarray);
4051: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 4052: my $context = 'domprefs';
4053: my $crstype = 'Course';
1.160.6.77 raeburn 4054: my $prefix = 'helproles_';
4055: my $add_class = 'LC_hidden';
4056: foreach my $num (@roles_by_num) {
4057: my $role = $ordered{$num};
4058: my ($desc,$access,@statuses);
4059: if (ref($current{$role}) eq 'HASH') {
4060: $desc = $current{$role}{'desc'};
4061: $access = $current{$role}{'access'};
4062: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4063: @statuses = @{$current{$role}{'insttypes'}};
4064: }
4065: }
4066: if ($desc eq '') {
4067: $desc = $role;
4068: }
4069: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 4070: my %full=();
4071: my %levels= (
4072: course => {},
4073: domain => {},
4074: system => {},
4075: );
4076: my %levelscurrent=(
4077: course => {},
4078: domain => {},
4079: system => {},
4080: );
4081: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4082: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4083: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 4084: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
4085: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
4086: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4087: for (my $k=0; $k<=$maxnum; $k++) {
4088: my $vpos = $k+1;
4089: my $selstr;
4090: if ($k == $num) {
4091: $selstr = ' selected="selected" ';
4092: }
4093: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4094: }
4095: $datatable .= '</select>'.(' 'x2).
4096: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4097: '</td>'.
4098: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4099: &mt('Name shown to users:').
4100: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4101: '</fieldset>'.
4102: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4103: $othertitle,$usertypes,$types,\%domhelpdesk).
4104: '<fieldset>'.
4105: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 4106: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 4107: \%levelscurrent,$identifier,
4108: 'LC_hidden',$prefix.$num.'_privs').
4109: '</fieldset></td>';
1.160.6.73 raeburn 4110: $itemcount ++;
4111: }
4112: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4113: my $newcust = 'custhelp'.$count;
4114: my (%privs,%levelscurrent);
4115: my %full=();
4116: my %levels= (
4117: course => {},
4118: domain => {},
4119: system => {},
4120: );
4121: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4122: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 4123: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
4124: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
4125: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4126: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4127: for (my $k=0; $k<$maxnum+1; $k++) {
4128: my $vpos = $k+1;
4129: my $selstr;
4130: if ($k == $maxnum) {
4131: $selstr = ' selected="selected" ';
4132: }
4133: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4134: }
4135: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 4136: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4137: '</label></span></td>'.
1.160.6.77 raeburn 4138: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4139: '<span class="LC_nobreak">'.
4140: &mt('Internal name:').
4141: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4142: '</span>'.(' 'x4).
4143: '<span class="LC_nobreak">'.
4144: &mt('Name shown to users:').
4145: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4146: '</span></fieldset>'.
4147: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4148: $usertypes,$types,\%domhelpdesk).
4149: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 4150: &Apache::lonuserutils::custom_role_header($context,$crstype,
4151: \@templateroles,$newcust).
4152: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4153: \%levelscurrent,$newcust).
1.160.6.87 raeburn 4154: '</fieldset>'.
4155: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4156: '</td></tr>';
1.160.6.73 raeburn 4157: $count ++;
4158: $$rowtotal += $count;
4159: }
1.160.6.5 raeburn 4160: return $datatable;
1.121 raeburn 4161: }
4162:
1.160.6.77 raeburn 4163: sub adhocbutton {
4164: my ($prefix,$num,$field,$visibility) = @_;
4165: my %lt = &Apache::lonlocal::texthash(
4166: show => 'Show details',
4167: hide => 'Hide details',
4168: );
4169: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4170: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4171: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4172: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4173: }
4174:
4175: sub helpsettings_javascript {
4176: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4177: return unless(ref($roles_by_num) eq 'ARRAY');
4178: my %html_js_lt = &Apache::lonlocal::texthash(
4179: show => 'Show details',
4180: hide => 'Hide details',
4181: );
4182: &html_escape(\%html_js_lt);
4183: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4184: return <<"ENDSCRIPT";
4185: <script type="text/javascript">
4186: // <![CDATA[
4187:
4188: function reorderHelpRoles(form,item) {
4189: var changedVal;
4190: $jstext
4191: var newpos = 'helproles_${total}_pos';
4192: var maxh = 1 + $total;
4193: var current = new Array();
4194: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4195: if (item == newpos) {
4196: changedVal = newitemVal;
4197: } else {
4198: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4199: current[newitemVal] = newpos;
4200: }
4201: for (var i=0; i<helproles.length; i++) {
4202: var elementName = 'helproles_'+helproles[i]+'_pos';
4203: if (elementName != item) {
4204: if (form.elements[elementName]) {
4205: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4206: current[currVal] = elementName;
4207: }
4208: }
4209: }
4210: var oldVal;
4211: for (var j=0; j<maxh; j++) {
4212: if (current[j] == undefined) {
4213: oldVal = j;
4214: }
4215: }
4216: if (oldVal < changedVal) {
4217: for (var k=oldVal+1; k<=changedVal ; k++) {
4218: var elementName = current[k];
4219: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4220: }
4221: } else {
4222: for (var k=changedVal; k<oldVal; k++) {
4223: var elementName = current[k];
4224: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4225: }
4226: }
4227: return;
4228: }
4229:
4230: function helpdeskAccess(num) {
4231: var curraccess = null;
4232: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4233: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4234: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4235: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4236: }
4237: }
4238: }
4239: var shown = Array();
4240: var hidden = Array();
4241: if (curraccess == 'none') {
4242: hidden = Array('$hiddenstr');
4243: } else {
4244: if (curraccess == 'status') {
4245: shown = Array('bystatus');
4246: hidden = Array('notinc','notexc');
4247: } else {
4248: if (curraccess == 'exc') {
4249: shown = Array('notexc');
4250: hidden = Array('notinc','bystatus');
4251: }
4252: if (curraccess == 'inc') {
4253: shown = Array('notinc');
4254: hidden = Array('notexc','bystatus');
4255: }
1.160.6.79 raeburn 4256: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 4257: hidden = Array('notinc','notexc','bystatus');
4258: }
4259: }
4260: }
4261: if (hidden.length > 0) {
4262: for (var i=0; i<hidden.length; i++) {
4263: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4264: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4265: }
4266: }
4267: }
4268: if (shown.length > 0) {
4269: for (var i=0; i<shown.length; i++) {
4270: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4271: if (shown[i] == 'privs') {
4272: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4273: } else {
4274: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4275: }
4276: }
4277: }
4278: }
4279: return;
4280: }
4281:
4282: function toggleHelpdeskItem(num,field) {
4283: if (document.getElementById('helproles_'+num+'_'+field)) {
4284: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
4285: document.getElementById('helproles_'+num+'_'+field).className =
4286: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4287: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4288: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4289: }
4290: } else {
4291: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4292: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4293: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4294: }
4295: }
4296: }
4297: return;
4298: }
4299:
4300: // ]]>
4301: </script>
4302:
4303: ENDSCRIPT
4304: }
4305:
4306: sub helpdeskroles_access {
4307: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4308: $usertypes,$types,$domhelpdesk) = @_;
4309: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4310: my %lt = &Apache::lonlocal::texthash(
4311: 'rou' => 'Role usage',
4312: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 4313: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4314: 'dh' => 'All with domain helpdesk role',
4315: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 4316: 'none' => 'None',
4317: 'status' => 'Determined based on institutional status',
4318: 'inc' => 'Include all, but exclude specific personnel',
4319: 'exc' => 'Exclude all, but include specific personnel',
4320: );
4321: my %usecheck = (
4322: all => ' checked="checked"',
4323: );
4324: my %displaydiv = (
4325: status => 'none',
4326: inc => 'none',
4327: exc => 'none',
4328: priv => 'block',
4329: );
4330: my $output;
4331: if (ref($current) eq 'HASH') {
4332: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4333: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4334: $usecheck{$current->{access}} = $usecheck{'all'};
4335: delete($usecheck{'all'});
4336: if ($current->{access} =~ /^(status|inc|exc)$/) {
4337: my $access = $1;
4338: $displaydiv{$access} = 'inline';
4339: } elsif ($current->{access} eq 'none') {
4340: $displaydiv{'priv'} = 'none';
4341: }
4342: }
4343: }
4344: }
4345: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4346: '<p>'.$lt{'whi'}.'</p>';
4347: foreach my $access (@{$accesstypes}) {
4348: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4349: ' onclick="helpdeskAccess('."'$num'".');" />'.
4350: $lt{$access}.'</label>';
4351: if ($access eq 'status') {
4352: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4353: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4354: $othertitle,$usertypes,$types).
4355: '</div>';
4356: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4357: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4358: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4359: '</div>';
4360: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4361: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4362: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4363: '</div>';
4364: }
4365: $output .= '</p>';
4366: }
4367: $output .= '</fieldset>';
4368: return $output;
4369: }
4370:
1.121 raeburn 4371: sub radiobutton_prefs {
1.160.6.16 raeburn 4372: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.113! raeburn 4373: $additional,$align,$firstval) = @_;
1.121 raeburn 4374: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4375: (ref($choices) eq 'HASH'));
4376:
4377: my (%checkedon,%checkedoff,$datatable,$css_class);
4378:
4379: foreach my $item (@{$toggles}) {
4380: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4381: $checkedon{$item} = ' checked="checked" ';
4382: $checkedoff{$item} = ' ';
1.121 raeburn 4383: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4384: $checkedoff{$item} = ' checked="checked" ';
4385: $checkedon{$item} = ' ';
4386: }
4387: }
4388: if (ref($settings) eq 'HASH') {
1.121 raeburn 4389: foreach my $item (@{$toggles}) {
1.118 jms 4390: if ($settings->{$item} eq '1') {
4391: $checkedon{$item} = ' checked="checked" ';
4392: $checkedoff{$item} = ' ';
4393: } elsif ($settings->{$item} eq '0') {
4394: $checkedoff{$item} = ' checked="checked" ';
4395: $checkedon{$item} = ' ';
4396: }
4397: }
1.121 raeburn 4398: }
1.160.6.16 raeburn 4399: if ($onclick) {
4400: $onclick = ' onclick="'.$onclick.'"';
4401: }
1.121 raeburn 4402: foreach my $item (@{$toggles}) {
1.118 jms 4403: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4404: $datatable .=
1.160.6.16 raeburn 4405: '<tr'.$css_class.'><td valign="top">'.
4406: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 4407: '</span></td>';
4408: if ($align eq 'left') {
4409: $datatable .= '<td class="LC_left_item">';
4410: } else {
4411: $datatable .= '<td class="LC_right_item">';
4412: }
1.160.6.113! raeburn 4413: $datatable .= '<span class="LC_nobreak">';
! 4414: if ($firstval eq 'no') {
! 4415: $datatable .=
! 4416: '<label><input type="radio" name="'.
! 4417: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
! 4418: '</label> <label><input type="radio" name="'.$item.'" '.
! 4419: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
! 4420: } else {
! 4421: $datatable .=
1.118 jms 4422: '<label><input type="radio" name="'.
1.160.6.16 raeburn 4423: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4424: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.113! raeburn 4425: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
! 4426: }
! 4427: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 4428: $itemcount ++;
1.121 raeburn 4429: }
4430: return ($datatable,$itemcount);
4431: }
4432:
4433: sub print_coursedefaults {
1.139 raeburn 4434: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 4435: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4436: my $itemcount = 1;
1.160.6.16 raeburn 4437: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 4438: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 4439: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4440: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 4441: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4442: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.90 raeburn 4443: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 4444: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 4445: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 4446: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 4447: );
1.160.6.21 raeburn 4448: my %staticdefaults = (
4449: anonsurvey_threshold => 10,
4450: uploadquota => 500,
1.160.6.57 raeburn 4451: postsubmit => 60,
1.160.6.70 raeburn 4452: mysqltables => 172800,
1.160.6.21 raeburn 4453: );
1.139 raeburn 4454: if ($position eq 'top') {
1.160.6.57 raeburn 4455: %defaultchecked = (
4456: 'uselcmath' => 'on',
4457: 'usejsme' => 'on',
1.160.6.64 raeburn 4458: 'canclone' => 'none',
1.160.6.57 raeburn 4459: );
4460: @toggles = ('uselcmath','usejsme');
1.160.6.90 raeburn 4461: my $deftex = $Apache::lonnet::deftex;
4462: if (ref($settings) eq 'HASH') {
4463: if ($settings->{'texengine'}) {
4464: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
4465: $deftex = $settings->{'texengine'};
4466: }
4467: }
4468: }
4469: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4470: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
4471: '<span class="LC_nobreak">'.$choices{'texengine'}.
4472: '</span></td><td class="LC_right_item">'.
4473: '<select name="texengine">'."\n";
4474: my %texoptions = (
4475: MathJax => 'MathJax',
4476: mimetex => &mt('Convert to Images'),
4477: tth => &mt('TeX to HTML'),
4478: );
4479: foreach my $renderer ('MathJax','mimetex','tth') {
4480: my $selected = '';
4481: if ($renderer eq $deftex) {
4482: $selected = ' selected="selected"';
4483: }
4484: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
4485: }
4486: $mathdisp .= '</select></td></tr>'."\n";
4487: $itemcount ++;
1.139 raeburn 4488: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4489: \%choices,$itemcount);
1.160.6.90 raeburn 4490: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 4491: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4492: $datatable .=
4493: '<tr'.$css_class.'><td valign="top">'.
4494: '<span class="LC_nobreak">'.$choices{'canclone'}.
4495: '</span></td><td class="LC_left_item">';
4496: my $currcanclone = 'none';
4497: my $onclick;
4498: my @cloneoptions = ('none','domain');
1.160.6.111 raeburn 4499: my %clonetitles = &Apache::lonlocal::texthash (
1.160.6.64 raeburn 4500: none => 'No additional course requesters',
4501: domain => "Any course requester in course's domain",
4502: instcode => 'Course requests for official courses ...',
4503: );
4504: my (%codedefaults,@code_order,@posscodes);
4505: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4506: \@code_order) eq 'ok') {
4507: if (@code_order > 0) {
4508: push(@cloneoptions,'instcode');
4509: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4510: }
4511: }
4512: if (ref($settings) eq 'HASH') {
4513: if ($settings->{'canclone'}) {
4514: if (ref($settings->{'canclone'}) eq 'HASH') {
4515: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4516: if (@code_order > 0) {
4517: $currcanclone = 'instcode';
4518: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4519: }
4520: }
4521: } elsif ($settings->{'canclone'} eq 'domain') {
4522: $currcanclone = $settings->{'canclone'};
4523: }
4524: }
4525: }
4526: foreach my $option (@cloneoptions) {
4527: my ($checked,$additional);
4528: if ($currcanclone eq $option) {
4529: $checked = ' checked="checked"';
4530: }
4531: if ($option eq 'instcode') {
4532: if (@code_order) {
4533: my $show = 'none';
4534: if ($checked) {
4535: $show = 'block';
4536: }
4537: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4538: &mt('Institutional codes for new and cloned course have identical:').
4539: '<br />';
4540: foreach my $item (@code_order) {
4541: my $codechk;
4542: if ($checked) {
4543: if (grep(/^\Q$item\E$/,@posscodes)) {
4544: $codechk = ' checked="checked"';
4545: }
4546: }
4547: $additional .= '<label>'.
4548: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4549: $item.'</label>';
4550: }
4551: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4552: }
4553: }
4554: $datatable .=
4555: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4556: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4557: '</label> '.$additional.'</span><br />';
4558: }
4559: $datatable .= '</td>'.
4560: '</tr>';
4561: $itemcount ++;
1.139 raeburn 4562: } else {
4563: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 4564: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 4565: my $currusecredits = 0;
1.160.6.57 raeburn 4566: my $postsubmitclient = 1;
1.160.6.30 raeburn 4567: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 4568: if (ref($settings) eq 'HASH') {
4569: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 4570: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4571: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4572: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4573: }
4574: }
1.160.6.16 raeburn 4575: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 4576: foreach my $type (@types) {
4577: next if ($type eq 'community');
4578: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4579: if ($defcredits{$type} ne '') {
4580: $currusecredits = 1;
4581: }
4582: }
4583: }
4584: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4585: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4586: $postsubmitclient = 0;
4587: foreach my $type (@types) {
4588: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4589: }
4590: } else {
4591: foreach my $type (@types) {
4592: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4593: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
4594: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
4595: } else {
4596: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4597: }
4598: } else {
4599: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4600: }
4601: }
4602: }
4603: } else {
4604: foreach my $type (@types) {
4605: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 4606: }
4607: }
1.160.6.70 raeburn 4608: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4609: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4610: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4611: }
4612: } else {
4613: foreach my $type (@types) {
4614: $currmysql{$type} = $staticdefaults{'mysqltables'};
4615: }
4616: }
1.160.6.58 raeburn 4617: } else {
4618: foreach my $type (@types) {
4619: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4620: }
1.139 raeburn 4621: }
4622: if (!$currdefresponder) {
1.160.6.21 raeburn 4623: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4624: } elsif ($currdefresponder < 1) {
4625: $currdefresponder = 1;
4626: }
1.160.6.21 raeburn 4627: foreach my $type (@types) {
4628: if ($curruploadquota{$type} eq '') {
4629: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4630: }
4631: }
1.139 raeburn 4632: $datatable .=
1.160.6.16 raeburn 4633: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4634: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4635: '</span></td>'.
4636: '<td class="LC_right_item"><span class="LC_nobreak">'.
4637: '<input type="text" name="anonsurvey_threshold"'.
4638: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 4639: '</td></tr>'."\n";
4640: $itemcount ++;
4641: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4642: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4643: $choices{'uploadquota'}.
4644: '</span></td>'.
4645: '<td align="right" class="LC_right_item">'.
4646: '<table><tr>';
1.160.6.21 raeburn 4647: foreach my $type (@types) {
4648: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4649: '<input type="text" name="uploadquota_'.$type.'"'.
4650: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4651: }
4652: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 4653: $itemcount ++;
1.160.6.40 raeburn 4654: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 4655: my $display = 'none';
4656: if ($currusecredits) {
4657: $display = 'block';
4658: }
4659: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 4660: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4661: foreach my $type (@types) {
4662: next if ($type eq 'community');
4663: $additional .= '<td align="center">'.&mt($type).'<br />'.
4664: '<input type="text" name="'.$type.'_credits"'.
4665: ' value="'.$defcredits{$type}.'" size="3" /></td>';
4666: }
4667: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 4668: %defaultchecked = ('coursecredits' => 'off');
4669: @toggles = ('coursecredits');
4670: my $current = {
4671: 'coursecredits' => $currusecredits,
4672: };
4673: (my $table,$itemcount) =
4674: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4675: \%choices,$itemcount,$onclick,$additional,'left');
4676: $datatable .= $table;
4677: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4678: my $display = 'none';
4679: if ($postsubmitclient) {
4680: $display = 'block';
4681: }
4682: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 4683: &mt('Number of seconds submit is disabled').'<br />'.
4684: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4685: '<table><tr>';
1.160.6.57 raeburn 4686: foreach my $type (@types) {
4687: $additional .= '<td align="center">'.&mt($type).'<br />'.
4688: '<input type="text" name="'.$type.'_timeout" value="'.
4689: $deftimeout{$type}.'" size="5" /></td>';
4690: }
4691: $additional .= '</tr></table></div>'."\n";
4692: %defaultchecked = ('postsubmit' => 'on');
4693: @toggles = ('postsubmit');
1.160.6.70 raeburn 4694: $current = {
4695: 'postsubmit' => $postsubmitclient,
4696: };
1.160.6.57 raeburn 4697: ($table,$itemcount) =
4698: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4699: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 4700: $datatable .= $table;
1.160.6.70 raeburn 4701: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4702: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4703: $choices{'mysqltables'}.
4704: '</span></td>'.
4705: '<td align="right" class="LC_right_item">'.
4706: '<table><tr>';
4707: foreach my $type (@types) {
4708: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4709: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 4710: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 4711: }
4712: $datatable .= '</tr></table></td></tr>'."\n";
4713: $itemcount ++;
4714:
1.160.6.37 raeburn 4715: }
4716: $$rowtotal += $itemcount;
4717: return $datatable;
4718: }
4719:
4720: sub print_selfenrollment {
4721: my ($position,$dom,$settings,$rowtotal) = @_;
4722: my ($css_class,$datatable);
4723: my $itemcount = 1;
4724: my @types = ('official','unofficial','community','textbook');
4725: if (($position eq 'top') || ($position eq 'middle')) {
4726: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4727: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
4728: my @rows;
4729: my $key;
4730: if ($position eq 'top') {
4731: $key = 'admin';
4732: if (ref($rowsref) eq 'ARRAY') {
4733: @rows = @{$rowsref};
4734: }
4735: } elsif ($position eq 'middle') {
4736: $key = 'default';
4737: @rows = ('types','registered','approval','limit');
4738: }
4739: foreach my $row (@rows) {
4740: if (defined($titlesref->{$row})) {
4741: $itemcount ++;
4742: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4743: $datatable .= '<tr'.$css_class.'>'.
4744: '<td>'.$titlesref->{$row}.'</td>'.
4745: '<td class="LC_left_item">'.
4746: '<table><tr>';
4747: my (%current,%currentcap);
4748: if (ref($settings) eq 'HASH') {
4749: if (ref($settings->{$key}) eq 'HASH') {
4750: foreach my $type (@types) {
4751: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4752: $current{$type} = $settings->{$key}->{$type}->{$row};
4753: }
4754: if (($row eq 'limit') && ($key eq 'default')) {
4755: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4756: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4757: }
4758: }
4759: }
4760: }
4761: }
4762: my %roles = (
4763: '0' => &Apache::lonnet::plaintext('dc'),
4764: );
4765:
4766: foreach my $type (@types) {
4767: unless (($row eq 'registered') && ($key eq 'default')) {
4768: $datatable .= '<th>'.&mt($type).'</th>';
4769: }
4770: }
4771: unless (($row eq 'registered') && ($key eq 'default')) {
4772: $datatable .= '</tr><tr>';
4773: }
4774: foreach my $type (@types) {
4775: if ($type eq 'community') {
4776: $roles{'1'} = &mt('Community personnel');
4777: } else {
4778: $roles{'1'} = &mt('Course personnel');
4779: }
4780: $datatable .= '<td style="vertical-align: top">';
4781: if ($position eq 'top') {
4782: my %checked;
4783: if ($current{$type} eq '0') {
4784: $checked{'0'} = ' checked="checked"';
4785: } else {
4786: $checked{'1'} = ' checked="checked"';
4787: }
4788: foreach my $role ('1','0') {
4789: $datatable .= '<span class="LC_nobreak"><label>'.
4790: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4791: 'value="'.$role.'"'.$checked{$role}.' />'.
4792: $roles{$role}.'</label></span> ';
4793: }
4794: } else {
4795: if ($row eq 'types') {
4796: my %checked;
4797: if ($current{$type} =~ /^(all|dom)$/) {
4798: $checked{$1} = ' checked="checked"';
4799: } else {
4800: $checked{''} = ' checked="checked"';
4801: }
4802: foreach my $val ('','dom','all') {
4803: $datatable .= '<span class="LC_nobreak"><label>'.
4804: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4805: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4806: }
4807: } elsif ($row eq 'registered') {
4808: my %checked;
4809: if ($current{$type} eq '1') {
4810: $checked{'1'} = ' checked="checked"';
4811: } else {
4812: $checked{'0'} = ' checked="checked"';
4813: }
4814: foreach my $val ('0','1') {
4815: $datatable .= '<span class="LC_nobreak"><label>'.
4816: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4817: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4818: }
4819: } elsif ($row eq 'approval') {
4820: my %checked;
4821: if ($current{$type} =~ /^([12])$/) {
4822: $checked{$1} = ' checked="checked"';
4823: } else {
4824: $checked{'0'} = ' checked="checked"';
4825: }
4826: for my $val (0..2) {
4827: $datatable .= '<span class="LC_nobreak"><label>'.
4828: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4829: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4830: }
4831: } elsif ($row eq 'limit') {
4832: my %checked;
4833: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4834: $checked{$1} = ' checked="checked"';
4835: } else {
4836: $checked{'none'} = ' checked="checked"';
4837: }
4838: my $cap;
4839: if ($currentcap{$type} =~ /^\d+$/) {
4840: $cap = $currentcap{$type};
4841: }
4842: foreach my $val ('none','allstudents','selfenrolled') {
4843: $datatable .= '<span class="LC_nobreak"><label>'.
4844: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4845: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4846: }
4847: $datatable .= '<br />'.
4848: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4849: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4850: '</span>';
4851: }
4852: }
4853: $datatable .= '</td>';
4854: }
4855: $datatable .= '</tr>';
4856: }
4857: $datatable .= '</table></td></tr>';
4858: }
4859: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 4860: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4861: }
4862: $$rowtotal += $itemcount;
4863: return $datatable;
4864: }
4865:
4866: sub print_validation_rows {
4867: my ($caller,$dom,$settings,$rowtotal) = @_;
4868: my ($itemsref,$namesref,$fieldsref);
4869: if ($caller eq 'selfenroll') {
4870: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4871: } elsif ($caller eq 'requestcourses') {
4872: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4873: }
4874: my %currvalidation;
4875: if (ref($settings) eq 'HASH') {
4876: if (ref($settings->{'validation'}) eq 'HASH') {
4877: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 4878: }
1.160.6.39 raeburn 4879: }
4880: my $datatable;
4881: my $itemcount = 0;
4882: foreach my $item (@{$itemsref}) {
4883: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4884: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4885: $namesref->{$item}.
4886: '</span></td>'.
4887: '<td class="LC_left_item">';
4888: if (($item eq 'url') || ($item eq 'button')) {
4889: $datatable .= '<span class="LC_nobreak">'.
4890: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4891: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4892: } elsif ($item eq 'fields') {
4893: my @currfields;
4894: if (ref($currvalidation{$item}) eq 'ARRAY') {
4895: @currfields = @{$currvalidation{$item}};
4896: }
4897: foreach my $field (@{$fieldsref}) {
4898: my $check = '';
4899: if (grep(/^\Q$field\E$/,@currfields)) {
4900: $check = ' checked="checked"';
4901: }
4902: $datatable .= '<span class="LC_nobreak"><label>'.
4903: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4904: ' value="'.$field.'"'.$check.' />'.$field.
4905: '</label></span> ';
4906: }
4907: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 4908: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 4909: $currvalidation{$item}.
1.160.6.37 raeburn 4910: '</textarea>';
1.160.6.39 raeburn 4911: }
4912: $datatable .= '</td></tr>'."\n";
4913: if (ref($rowtotal)) {
1.160.6.37 raeburn 4914: $itemcount ++;
4915: }
1.139 raeburn 4916: }
1.160.6.39 raeburn 4917: if ($caller eq 'requestcourses') {
4918: my %currhash;
1.160.6.51 raeburn 4919: if (ref($settings) eq 'HASH') {
4920: if (ref($settings->{'validation'}) eq 'HASH') {
4921: if ($settings->{'validation'}{'dc'} ne '') {
4922: $currhash{$settings->{'validation'}{'dc'}} = 1;
4923: }
1.160.6.39 raeburn 4924: }
4925: }
4926: my $numinrow = 2;
4927: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4928: 'validationdc',%currhash);
1.160.6.50 raeburn 4929: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 4930: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 4931: if ($numdc > 1) {
1.160.6.50 raeburn 4932: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 4933: } else {
1.160.6.50 raeburn 4934: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 4935: }
1.160.6.50 raeburn 4936: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 4937: $itemcount ++;
4938: }
4939: if (ref($rowtotal)) {
4940: $$rowtotal += $itemcount;
4941: }
1.121 raeburn 4942: return $datatable;
1.118 jms 4943: }
4944:
1.160.6.98 raeburn 4945: sub print_passwords {
4946: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
4947: my ($datatable,$css_class);
4948: my $itemcount = 0;
4949: my %titles = &Apache::lonlocal::texthash (
4950: captcha => '"Forgot Password" CAPTCHA validation',
4951: link => 'Reset link expiration (hours)',
4952: case => 'Case-sensitive usernames/e-mail',
4953: prelink => 'Information required (form 1)',
4954: postlink => 'Information required (form 2)',
4955: emailsrc => 'LON-CAPA e-mail address type(s)',
4956: customtext => 'Domain specific text (HTML)',
4957: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
4958: intauth_check => 'Check bcrypt cost if authenticated',
4959: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
4960: permanent => 'Permanent e-mail address',
4961: critical => 'Critical notification address',
4962: notify => 'Notification address',
4963: min => 'Minimum password length',
4964: max => 'Maximum password length',
4965: chars => 'Required characters',
4966: numsaved => 'Number of previous passwords to save and disallow reuse',
4967: );
4968: if ($position eq 'top') {
4969: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4970: my $shownlinklife = 2;
4971: my $prelink = 'both';
4972: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
4973: if (ref($settings) eq 'HASH') {
4974: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
4975: $shownlinklife = $settings->{resetlink};
4976: }
4977: if (ref($settings->{resetcase}) eq 'ARRAY') {
4978: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
4979: }
4980: if ($settings->{resetprelink} =~ /^(both|either)$/) {
4981: $prelink = $settings->{resetprelink};
4982: }
4983: if (ref($settings->{resetpostlink}) eq 'HASH') {
4984: %postlink = %{$settings->{resetpostlink}};
4985: }
4986: if (ref($settings->{resetemail}) eq 'ARRAY') {
4987: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
4988: }
4989: if ($settings->{resetremove}) {
4990: $nostdtext = 1;
4991: }
4992: if ($settings->{resetcustom}) {
4993: $customurl = $settings->{resetcustom};
4994: }
4995: } else {
4996: if (ref($types) eq 'ARRAY') {
4997: foreach my $item (@{$types}) {
4998: $casesens{$item} = 1;
4999: $postlink{$item} = ['username','email'];
5000: }
5001: }
5002: $casesens{'default'} = 1;
5003: $postlink{'default'} = ['username','email'];
5004: $prelink = 'both';
5005: %emailsrc = (
5006: permanent => 1,
5007: critical => 1,
5008: notify => 1,
5009: );
5010: }
5011: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
5012: $itemcount ++;
5013: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5014: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
5015: '<td class="LC_left_item">'.
5016: '<input type="textbox" value="'.$shownlinklife.'" '.
5017: 'name="passwords_link" size="3" /></td></tr>';
5018: $itemcount ++;
5019: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5020: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
5021: '<td class="LC_left_item">';
5022: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5023: foreach my $item (@{$types}) {
5024: my $checkedcase;
5025: if ($casesens{$item}) {
5026: $checkedcase = ' checked="checked"';
5027: }
5028: $datatable .= '<span class="LC_nobreak"><label>'.
5029: '<input type="checkbox" name="passwords_case_sensitive" value="'.
5030: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.160.6.104 raeburn 5031: '</span> ';
1.160.6.98 raeburn 5032: }
5033: }
5034: my $checkedcase;
5035: if ($casesens{'default'}) {
5036: $checkedcase = ' checked="checked"';
5037: }
5038: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5039: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
5040: $othertitle.'</label></span></td>';
5041: $itemcount ++;
5042: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5043: my %checkedpre = (
5044: both => ' checked="checked"',
5045: either => '',
5046: );
5047: if ($prelink eq 'either') {
5048: $checkedpre{either} = ' checked="checked"';
5049: $checkedpre{both} = '';
5050: }
5051: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
5052: '<td class="LC_left_item"><span class="LC_nobreak">'.
5053: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
5054: &mt('Both username and e-mail address').'</label></span> '.
5055: '<span class="LC_nobreak"><label>'.
5056: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
5057: &mt('Either username or e-mail address').'</label></span></td></tr>';
5058: $itemcount ++;
5059: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5060: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
5061: '<td class="LC_left_item">';
5062: my %postlinked;
5063: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5064: foreach my $item (@{$types}) {
5065: undef(%postlinked);
5066: $datatable .= '<fieldset style="display: inline-block;">'.
5067: '<legend>'.$usertypes->{$item}.'</legend>';
5068: if (ref($postlink{$item}) eq 'ARRAY') {
5069: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
5070: }
5071: foreach my $field ('email','username') {
5072: my $checked;
5073: if ($postlinked{$field}) {
5074: $checked = ' checked="checked"';
5075: }
5076: $datatable .= '<span class="LC_nobreak"><label>'.
5077: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
5078: $field.'"'.$checked.' />'.$field.'</label>'.
5079: '<span> ';
5080: }
5081: $datatable .= '</fieldset>';
5082: }
5083: }
5084: if (ref($postlink{'default'}) eq 'ARRAY') {
5085: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
5086: }
5087: $datatable .= '<fieldset style="display: inline-block;">'.
5088: '<legend>'.$othertitle.'</legend>';
5089: foreach my $field ('email','username') {
5090: my $checked;
5091: if ($postlinked{$field}) {
5092: $checked = ' checked="checked"';
5093: }
5094: $datatable .= '<span class="LC_nobreak"><label>'.
5095: '<input type="checkbox" name="passwords_postlink_default" value="'.
5096: $field.'"'.$checked.' />'.$field.'</label>'.
5097: '<span> ';
5098: }
5099: $datatable .= '</fieldset></td></tr>';
5100: $itemcount ++;
5101: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5102: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
5103: '<td class="LC_left_item">';
5104: foreach my $type ('permanent','critical','notify') {
5105: my $checkedemail;
5106: if ($emailsrc{$type}) {
5107: $checkedemail = ' checked="checked"';
5108: }
5109: $datatable .= '<span class="LC_nobreak"><label>'.
5110: '<input type="checkbox" name="passwords_emailsrc" value="'.
5111: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
5112: '<span> ';
5113: }
5114: $datatable .= '</td></tr>';
5115: $itemcount ++;
5116: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5117: my $switchserver = &check_switchserver($dom,$confname);
5118: my ($showstd,$noshowstd);
5119: if ($nostdtext) {
5120: $noshowstd = ' checked="checked"';
5121: } else {
5122: $showstd = ' checked="checked"';
5123: }
5124: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
5125: '<td class="LC_left_item"><span class="LC_nobreak">'.
5126: &mt('Retain standard text:').
5127: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
5128: &mt('Yes').'</label>'.' '.
5129: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
5130: &mt('No').'</label></span><br />'.
5131: '<span class="LC_fontsize_small">'.
5132: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
5133: &mt('Include custom text:');
5134: if ($customurl) {
1.160.6.104 raeburn 5135: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.160.6.98 raeburn 5136: undef,undef,undef,undef,'background-color:#ffffff');
5137: $datatable .= '<span class="LC_nobreak"> '.$link.
5138: '<label><input type="checkbox" name="passwords_custom_del"'.
5139: ' value="1" />'.&mt('Delete?').'</label></span>'.
5140: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
5141: }
5142: if ($switchserver) {
5143: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
5144: } else {
5145: $datatable .='<span class="LC_nobreak"> '.
5146: '<input type="file" name="passwords_customfile" /></span>';
5147: }
5148: $datatable .= '</td></tr>';
5149: } elsif ($position eq 'middle') {
5150: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
5151: my @items = ('intauth_cost','intauth_check','intauth_switch');
5152: my %defaults;
5153: if (ref($domconf{'defaults'}) eq 'HASH') {
5154: %defaults = %{$domconf{'defaults'}};
5155: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
5156: $defaults{'intauth_cost'} = 10;
5157: }
5158: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
5159: $defaults{'intauth_check'} = 0;
5160: }
5161: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
5162: $defaults{'intauth_switch'} = 0;
5163: }
5164: } else {
5165: %defaults = (
5166: 'intauth_cost' => 10,
5167: 'intauth_check' => 0,
5168: 'intauth_switch' => 0,
5169: );
5170: }
5171: foreach my $item (@items) {
5172: if ($itemcount%2) {
5173: $css_class = '';
5174: } else {
5175: $css_class = ' class="LC_odd_row" ';
5176: }
5177: $datatable .= '<tr'.$css_class.'>'.
5178: '<td><span class="LC_nobreak">'.$titles{$item}.
5179: '</span></td><td class="LC_left_item" colspan="3">';
5180: if ($item eq 'intauth_switch') {
5181: my @options = (0,1,2);
5182: my %optiondesc = &Apache::lonlocal::texthash (
5183: 0 => 'No',
5184: 1 => 'Yes',
5185: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
5186: );
5187: $datatable .= '<table width="100%">';
5188: foreach my $option (@options) {
5189: my $checked = ' ';
5190: if ($defaults{$item} eq $option) {
5191: $checked = ' checked="checked"';
5192: }
5193: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5194: '<label><input type="radio" name="'.$item.
5195: '" value="'.$option.'"'.$checked.' />'.
5196: $optiondesc{$option}.'</label></span></td></tr>';
5197: }
5198: $datatable .= '</table>';
5199: } elsif ($item eq 'intauth_check') {
5200: my @options = (0,1,2);
5201: my %optiondesc = &Apache::lonlocal::texthash (
5202: 0 => 'No',
5203: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
5204: 2 => 'Yes, disallow login if stored cost is less than domain default',
5205: );
5206: $datatable .= '<table width="100%">';
5207: foreach my $option (@options) {
5208: my $checked = ' ';
5209: my $onclick;
5210: if ($defaults{$item} eq $option) {
5211: $checked = ' checked="checked"';
5212: }
5213: if ($option == 2) {
5214: $onclick = ' onclick="javascript:warnIntAuth(this);"';
5215: }
5216: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5217: '<label><input type="radio" name="'.$item.
5218: '" value="'.$option.'"'.$checked.$onclick.' />'.
5219: $optiondesc{$option}.'</label></span></td></tr>';
5220: }
5221: $datatable .= '</table>';
5222: } else {
5223: $datatable .= '<input type="text" name="'.$item.'" value="'.
5224: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
5225: }
5226: $datatable .= '</td></tr>';
5227: $itemcount ++;
5228: }
5229: } elsif ($position eq 'lower') {
5230: my ($min,$max,%chars,$numsaved);
1.160.6.99 raeburn 5231: $min = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 5232: if (ref($settings) eq 'HASH') {
5233: if ($settings->{min}) {
5234: $min = $settings->{min};
5235: }
5236: if ($settings->{max}) {
5237: $max = $settings->{max};
5238: }
5239: if (ref($settings->{chars}) eq 'ARRAY') {
5240: map { $chars{$_} = 1; } (@{$settings->{chars}});
5241: }
5242: if ($settings->{numsaved}) {
5243: $numsaved = $settings->{numsaved};
5244: }
5245: }
5246: my %rulenames = &Apache::lonlocal::texthash(
5247: uc => 'At least one upper case letter',
5248: lc => 'At least one lower case letter',
5249: num => 'At least one number',
5250: spec => 'At least one non-alphanumeric',
5251: );
5252: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5253: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
5254: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 5255: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
5256: 'onblur="javascript:warnIntPass(this);" />'.
5257: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.160.6.98 raeburn 5258: '</span></td></tr>';
5259: $itemcount ++;
5260: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5261: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
5262: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 5263: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
5264: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 5265: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
5266: '</span></td></tr>';
5267: $itemcount ++;
5268: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5269: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
5270: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
5271: '</span></td>';
5272: my $numinrow = 2;
5273: my @possrules = ('uc','lc','num','spec');
5274: $datatable .= '<td class="LC_left_item"><table>';
5275: for (my $i=0; $i<@possrules; $i++) {
5276: my ($rem,$checked);
5277: if ($chars{$possrules[$i]}) {
5278: $checked = ' checked="checked"';
5279: }
5280: $rem = $i%($numinrow);
5281: if ($rem == 0) {
5282: if ($i > 0) {
5283: $datatable .= '</tr>';
5284: }
5285: $datatable .= '<tr>';
5286: }
5287: $datatable .= '<td><span class="LC_nobreak"><label>'.
5288: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
5289: $rulenames{$possrules[$i]}.'</label></span></td>';
5290: }
5291: my $rem = @possrules%($numinrow);
5292: my $colsleft = $numinrow - $rem;
5293: if ($colsleft > 1 ) {
5294: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5295: ' </td>';
5296: } elsif ($colsleft == 1) {
5297: $datatable .= '<td class="LC_left_item"> </td>';
5298: }
5299: $datatable .='</table></td></tr>';
5300: $itemcount ++;
5301: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5302: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
5303: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.100 raeburn 5304: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
1.160.6.99 raeburn 5305: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 5306: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
5307: '</span></td></tr>';
5308: } else {
5309: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5310: my %ownerchg = (
5311: by => {},
5312: for => {},
5313: );
5314: my %ownertitles = &Apache::lonlocal::texthash (
5315: by => 'Course owner status(es) allowed',
5316: for => 'Student status(es) allowed',
5317: );
5318: if (ref($settings) eq 'HASH') {
5319: if (ref($settings->{crsownerchg}) eq 'HASH') {
5320: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
5321: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
5322: }
5323: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
5324: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
5325: }
5326: }
5327: }
5328: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5329: $datatable .= '<tr '.$css_class.'>'.
5330: '<td>'.
5331: &mt('Requirements').'<ul>'.
5332: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
5333: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
5334: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
5335: '<li>'.&mt('User, course, and student share same domain').'</li>'.
5336: '</ul>'.
5337: '</td>'.
5338: '<td class="LC_left_item">';
5339: foreach my $item ('by','for') {
5340: $datatable .= '<fieldset style="display: inline-block;">'.
5341: '<legend>'.$ownertitles{$item}.'</legend>';
5342: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5343: foreach my $type (@{$types}) {
5344: my $checked;
5345: if ($ownerchg{$item}{$type}) {
5346: $checked = ' checked="checked"';
5347: }
5348: $datatable .= '<span class="LC_nobreak"><label>'.
5349: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
5350: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.160.6.104 raeburn 5351: '</span> ';
1.160.6.98 raeburn 5352: }
5353: }
5354: my $checked;
5355: if ($ownerchg{$item}{'default'}) {
5356: $checked = ' checked="checked"';
5357: }
5358: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5359: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
5360: $othertitle.'</label></span></fieldset>';
5361: }
5362: $datatable .= '</td></tr>';
5363: }
5364: return $datatable;
5365: }
5366:
1.160.6.113! raeburn 5367: sub print_wafproxy {
! 5368: my ($position,$dom,$settings,$rowtotal) = @_;
! 5369: my $css_class;
! 5370: my $itemcount = 0;
! 5371: my $datatable;
! 5372: my %servers = &Apache::lonnet::internet_dom_servers($dom);
! 5373: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
! 5374: my %lt = &wafproxy_titles();
! 5375: foreach my $server (sort(keys(%servers))) {
! 5376: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
! 5377: next if ($serverhome eq '');
! 5378: my $serverdom;
! 5379: if ($serverhome ne $server) {
! 5380: $serverdom = &Apache::lonnet::host_domain($serverhome);
! 5381: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
! 5382: $othercontrol{$server} = $serverdom;
! 5383: }
! 5384: } else {
! 5385: $serverdom = &Apache::lonnet::host_domain($server);
! 5386: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
! 5387: if ($serverdom ne $dom) {
! 5388: $othercontrol{$server} = $serverdom;
! 5389: } else {
! 5390: $setdom = 1;
! 5391: if (ref($settings) eq 'HASH') {
! 5392: if (ref($settings->{'alias'}) eq 'HASH') {
! 5393: $aliases{$dom} = $settings->{'alias'};
! 5394: if ($aliases{$dom} ne '') {
! 5395: $showdom = 1;
! 5396: }
! 5397: }
! 5398: if (ref($settings->{'saml'}) eq 'HASH') {
! 5399: $saml{$dom} = $settings->{'saml'};
! 5400: }
! 5401: }
! 5402: }
! 5403: }
! 5404: }
! 5405: if ($setdom) {
! 5406: %{$values{$dom}} = ();
! 5407: if (ref($settings) eq 'HASH') {
! 5408: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
! 5409: $values{$dom}{$item} = $settings->{$item};
! 5410: }
! 5411: }
! 5412: }
! 5413: if (keys(%othercontrol)) {
! 5414: %otherdoms = reverse(%othercontrol);
! 5415: foreach my $domain (keys(%otherdoms)) {
! 5416: %{$values{$domain}} = ();
! 5417: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
! 5418: if (ref($config{'wafproxy'}) eq 'HASH') {
! 5419: $aliases{$domain} = $config{'wafproxy'}{'alias'};
! 5420: if (exists($config{'wafproxy'}{'saml'})) {
! 5421: $saml{$domain} = $config{'wafproxy'}{'saml'};
! 5422: }
! 5423: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
! 5424: $values{$domain}{$item} = $config{'wafproxy'}{$item};
! 5425: }
! 5426: }
! 5427: }
! 5428: }
! 5429: if ($position eq 'top') {
! 5430: my %servers = &Apache::lonnet::internet_dom_servers($dom);
! 5431: my %aliasinfo;
! 5432: foreach my $server (sort(keys(%servers))) {
! 5433: $itemcount ++;
! 5434: my $dom_in_effect;
! 5435: my $aliasrows = '<tr>'.
! 5436: '<td class="LC_left_item" style="vertical-align: baseline;">'.
! 5437: &mt('Hostname').': '.
! 5438: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
! 5439: if ($othercontrol{$server}) {
! 5440: $dom_in_effect = $othercontrol{$server};
! 5441: my ($current,$forsaml);
! 5442: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
! 5443: $current = $aliases{$dom_in_effect}{$server};
! 5444: }
! 5445: if (ref($saml{$dom_in_effect}) eq 'HASH') {
! 5446: if ($saml{$dom_in_effect}{$server}) {
! 5447: $forsaml = 1;
! 5448: }
! 5449: }
! 5450: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
! 5451: &mt('Alias').': ';
! 5452: if ($current) {
! 5453: $aliasrows .= $current;
! 5454: if ($forsaml) {
! 5455: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
! 5456: }
! 5457: } else {
! 5458: $aliasrows .= &mt('None');
! 5459: }
! 5460: $aliasrows .= ' <span class="LC_small">('.
! 5461: &mt('controlled by domain: [_1]',
! 5462: '<b>'.$dom_in_effect.'</b>').')</span></td>';
! 5463: } else {
! 5464: $dom_in_effect = $dom;
! 5465: my ($current,$samlon,$samloff);
! 5466: $samloff = ' checked="checked"';
! 5467: if (ref($aliases{$dom}) eq 'HASH') {
! 5468: if ($aliases{$dom}{$server}) {
! 5469: $current = $aliases{$dom}{$server};
! 5470: }
! 5471: }
! 5472: if (ref($saml{$dom}) eq 'HASH') {
! 5473: if ($saml{$dom}{$server}) {
! 5474: $samlon = $samloff;
! 5475: undef($samloff);
! 5476: }
! 5477: }
! 5478: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
! 5479: &mt('Alias').': '.
! 5480: '<input type="text" name="wafproxy_alias_'.$server.'" '.
! 5481: 'value="'.$current.'" size="30" />'.
! 5482: (' 'x2).'<span class="LC_nobreak">'.
! 5483: &mt('Alias used for SSO Auth').': <label>'.
! 5484: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
! 5485: &mt('No').'</label> <label>'.
! 5486: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
! 5487: &mt('Yes').'</label></span>'.
! 5488: '</td>';
! 5489: }
! 5490: $aliasrows .= '</tr>';
! 5491: $aliasinfo{$dom_in_effect} .= $aliasrows;
! 5492: }
! 5493: if ($aliasinfo{$dom}) {
! 5494: my ($onclick,$wafon,$wafoff,$showtable);
! 5495: $onclick = ' onclick="javascript:toggleWAF();"';
! 5496: $wafoff = ' checked="checked"';
! 5497: $showtable = ' style="display:none";';
! 5498: if ($showdom) {
! 5499: $wafon = $wafoff;
! 5500: $wafoff = '';
! 5501: $showtable = ' style="display:inline;"';
! 5502: }
! 5503: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
! 5504: $datatable = '<tr'.$css_class.'>'.
! 5505: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
! 5506: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
! 5507: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
! 5508: &mt('Yes').'</label>'.(' 'x2).'<label>'.
! 5509: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
! 5510: &mt('No').'</label></span></td>'.
! 5511: '<td class="LC_left_item">'.
! 5512: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
! 5513: '</table></td></tr>';
! 5514: $itemcount++;
! 5515: }
! 5516: if (keys(%otherdoms)) {
! 5517: foreach my $key (sort(keys(%otherdoms))) {
! 5518: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
! 5519: $datatable .= '<tr'.$css_class.'>'.
! 5520: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
! 5521: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
! 5522: '</table></td></tr>';
! 5523: $itemcount++;
! 5524: }
! 5525: }
! 5526: } else {
! 5527: my %ip_methods = &remoteip_methods();
! 5528: if ($setdom) {
! 5529: $itemcount ++;
! 5530: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
! 5531: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
! 5532: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
! 5533: $wafstyle = ' style="display:none;"';
! 5534: $nowafstyle = ' style="display:table-row;"';
! 5535: $currwafdisplay = ' style="display: none"';
! 5536: $wafrangestyle = ' style="display: none"';
! 5537: $curr_remotip = 'n';
! 5538: $ssltossl = ' checked="checked"';
! 5539: if ($showdom) {
! 5540: $wafstyle = ' style="display:table-row;"';
! 5541: $nowafstyle = ' style="display:none;"';
! 5542: if (keys(%{$values{$dom}})) {
! 5543: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
! 5544: $curr_remotip = $values{$dom}{remoteip};
! 5545: }
! 5546: if ($curr_remotip eq 'h') {
! 5547: $currwafdisplay = ' style="display:table-row"';
! 5548: $wafrangestyle = ' style="display:inline-block;"';
! 5549: }
! 5550: if ($values{$dom}{'sslopt'}) {
! 5551: $alltossl = ' checked="checked"';
! 5552: $ssltossl = '';
! 5553: }
! 5554: }
! 5555: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
! 5556: $vpndircheck = ' checked="checked"';
! 5557: $currwafvpn = ' style="display:table-row;"';
! 5558: $wafrangestyle = ' style="display:inline-block;"';
! 5559: } else {
! 5560: $vpnaliascheck = ' checked="checked"';
! 5561: $currwafvpn = ' style="display:none;"';
! 5562: }
! 5563: }
! 5564: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
! 5565: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
! 5566: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
! 5567: '</tr>'.
! 5568: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
! 5569: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
! 5570: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
! 5571: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
! 5572: &mt('Range(s) stored in CIDR notation').'</div></td>'.
! 5573: '<td class="LC_left_item"><table>'.
! 5574: '<tr>'.
! 5575: '<td valign="top">'.$lt{'remoteip'}.': '.
! 5576: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
! 5577: foreach my $option ('m','h','n') {
! 5578: my $sel;
! 5579: '<tr>'.
! 5580: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
! 5581: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
! 5582: $lt{'vpndirect'}.'</label>'.(' 'x2).
! 5583: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
! 5584: $lt{'vpnaliased'}.'</label></span></td></tr>';
! 5585: foreach my $item ('vpnint','vpnext') {
! 5586: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
! 5587: '<td valign="top">'.$lt{$item}.':<br />'.
! 5588: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
! 5589: $values{$dom}{$item}.'</textarea>'.
! 5590: '</td></tr>'."\n";
! 5591: }
! 5592: $datatable .= '<tr><td><hr /></td></tr>'."\n".
! 5593: '<tr>'.
! 5594: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
! 5595: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
! 5596: $lt{'alltossl'}.'</label>'.(' 'x2).
! 5597: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
! 5598: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
! 5599: '</table></td></tr>';
! 5600: }
! 5601: if (keys(%otherdoms)) {
! 5602: foreach my $domain (sort(keys(%otherdoms))) {
! 5603: $itemcount ++;
! 5604: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
! 5605: $datatable .= '<tr'.$css_class.'>'.
! 5606: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
! 5607: '<td class="LC_left_item"><table>';
! 5608: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
! 5609: my $showval = &mt('None');
! 5610: if ($item eq 'ssl') {
! 5611: $showval = $lt{'ssltossl'};
! 5612: }
! 5613: if ($values{$domain}{$item}) {
! 5614: $showval = $values{$domain}{$item};
! 5615: if ($item eq 'ssl') {
! 5616: $showval = $lt{'alltossl'};
! 5617: } elsif ($item eq 'remoteip') {
! 5618: $showval = $ip_methods{$values{$domain}{$item}};
! 5619: }
! 5620: }
! 5621: $datatable .= '<tr>'.
! 5622: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
! 5623: }
! 5624: $datatable .= '</table></td></tr>';
! 5625: }
! 5626: }
! 5627: }
! 5628: $$rowtotal += $itemcount;
! 5629: return $datatable;
! 5630: }
! 5631:
! 5632: sub wafproxy_titles {
! 5633: return &Apache::lonlocal::texthash(
! 5634: remoteip => "Method for determining user's IP",
! 5635: ipheader => 'Request header containing remote IP',
! 5636: trusted => 'Trusted IP range(s)',
! 5637: vpnaccess => 'Access from institutional VPN',
! 5638: vpndirect => 'via regular hostname (no WAF)',
! 5639: vpnaliased => 'via aliased hostname (WAF)',
! 5640: vpnint => 'Internal IP Range(s) for VPN sessions',
! 5641: vpnext => 'IP Range(s) for backend WAF connections',
! 5642: sslopt => 'Forwarding http/https',
! 5643: alltossl => 'WAF forwards both http and https requests to https',
! 5644: ssltossl => 'WAF forwards http requests to http and https to https',
! 5645: );
! 5646: }
! 5647:
! 5648: sub remoteip_methods {
! 5649: return &Apache::lonlocal::texthash(
! 5650: m => 'Use Apache mod_remoteip',
! 5651: h => 'Use headers parsed by LON-CAPA',
! 5652: n => 'Not in use',
! 5653: );
! 5654: }
! 5655:
1.137 raeburn 5656: sub print_usersessions {
5657: my ($position,$dom,$settings,$rowtotal) = @_;
5658: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 5659: my (%by_ip,%by_location,@intdoms);
5660: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 5661:
5662: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 5663: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 5664: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 5665: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 5666: my $itemcount = 1;
5667: if ($position eq 'top') {
1.152 raeburn 5668: if (keys(%serverhomes) > 1) {
1.145 raeburn 5669: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.105 raeburn 5670: my ($curroffloadnow,$curroffloadoth);
1.160.6.61 raeburn 5671: if (ref($settings) eq 'HASH') {
5672: if (ref($settings->{'offloadnow'}) eq 'HASH') {
5673: $curroffloadnow = $settings->{'offloadnow'};
5674: }
1.160.6.105 raeburn 5675: if (ref($settings->{'offloadoth'}) eq 'HASH') {
5676: $curroffloadoth = $settings->{'offloadoth'};
5677: }
1.160.6.61 raeburn 5678: }
1.160.6.105 raeburn 5679: my $other_insts = scalar(keys(%by_location));
5680: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
5681: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 5682: } else {
1.140 raeburn 5683: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 5684: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 5685: }
1.137 raeburn 5686: } else {
1.145 raeburn 5687: if (keys(%by_location) == 0) {
5688: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 5689: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 5690: } else {
5691: my %lt = &usersession_titles();
5692: my $numinrow = 5;
5693: my $prefix;
5694: my @types;
5695: if ($position eq 'bottom') {
5696: $prefix = 'remote';
5697: @types = ('version','excludedomain','includedomain');
5698: } else {
5699: $prefix = 'hosted';
5700: @types = ('excludedomain','includedomain');
5701: }
5702: my (%current,%checkedon,%checkedoff);
5703: my @lcversions = &Apache::lonnet::all_loncaparevs();
5704: my @locations = sort(keys(%by_location));
5705: foreach my $type (@types) {
5706: $checkedon{$type} = '';
5707: $checkedoff{$type} = ' checked="checked"';
5708: }
5709: if (ref($settings) eq 'HASH') {
5710: if (ref($settings->{$prefix}) eq 'HASH') {
5711: foreach my $key (keys(%{$settings->{$prefix}})) {
5712: $current{$key} = $settings->{$prefix}{$key};
5713: if ($key eq 'version') {
5714: if ($current{$key} ne '') {
5715: $checkedon{$key} = ' checked="checked"';
5716: $checkedoff{$key} = '';
5717: }
5718: } elsif (ref($current{$key}) eq 'ARRAY') {
5719: $checkedon{$key} = ' checked="checked"';
5720: $checkedoff{$key} = '';
5721: }
1.137 raeburn 5722: }
5723: }
5724: }
1.145 raeburn 5725: foreach my $type (@types) {
5726: next if ($type ne 'version' && !@locations);
5727: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5728: $datatable .= '<tr'.$css_class.'>
5729: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
5730: <span class="LC_nobreak">
5731: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
5732: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
5733: if ($type eq 'version') {
5734: my $selector = '<select name="'.$prefix.'_version">';
5735: foreach my $version (@lcversions) {
5736: my $selected = '';
5737: if ($current{'version'} eq $version) {
5738: $selected = ' selected="selected"';
5739: }
5740: $selector .= ' <option value="'.$version.'"'.
5741: $selected.'>'.$version.'</option>';
5742: }
5743: $selector .= '</select> ';
5744: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
5745: } else {
5746: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
5747: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
5748: ' />'.(' 'x2).
5749: '<input type="button" value="'.&mt('uncheck all').'" '.
5750: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
5751: "\n".
5752: '</div><div><table>';
5753: my $rem;
5754: for (my $i=0; $i<@locations; $i++) {
5755: my ($showloc,$value,$checkedtype);
5756: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
5757: my $ip = $by_location{$locations[$i]}->[0];
5758: if (ref($by_ip{$ip}) eq 'ARRAY') {
5759: $value = join(':',@{$by_ip{$ip}});
5760: $showloc = join(', ',@{$by_ip{$ip}});
5761: if (ref($current{$type}) eq 'ARRAY') {
5762: foreach my $loc (@{$by_ip{$ip}}) {
5763: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
5764: $checkedtype = ' checked="checked"';
5765: last;
5766: }
5767: }
1.138 raeburn 5768: }
5769: }
5770: }
1.145 raeburn 5771: $rem = $i%($numinrow);
5772: if ($rem == 0) {
5773: if ($i > 0) {
5774: $datatable .= '</tr>';
5775: }
5776: $datatable .= '<tr>';
5777: }
5778: $datatable .= '<td class="LC_left_item">'.
5779: '<span class="LC_nobreak"><label>'.
5780: '<input type="checkbox" name="'.$prefix.'_'.$type.
5781: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
5782: '</label></span></td>';
1.137 raeburn 5783: }
1.145 raeburn 5784: $rem = @locations%($numinrow);
5785: my $colsleft = $numinrow - $rem;
5786: if ($colsleft > 1 ) {
5787: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5788: ' </td>';
5789: } elsif ($colsleft == 1) {
5790: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 5791: }
1.145 raeburn 5792: $datatable .= '</tr></table>';
1.137 raeburn 5793: }
1.145 raeburn 5794: $datatable .= '</td></tr>';
5795: $itemcount ++;
1.137 raeburn 5796: }
5797: }
5798: }
5799: $$rowtotal += $itemcount;
5800: return $datatable;
5801: }
5802:
1.138 raeburn 5803: sub build_location_hashes {
5804: my ($intdoms,$by_ip,$by_location) = @_;
5805: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
5806: (ref($by_location) eq 'HASH'));
5807: my %iphost = &Apache::lonnet::get_iphost();
5808: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
5809: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
5810: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
5811: foreach my $id (@{$iphost{$primary_ip}}) {
5812: my $intdom = &Apache::lonnet::internet_dom($id);
5813: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
5814: push(@{$intdoms},$intdom);
5815: }
5816: }
5817: }
5818: foreach my $ip (keys(%iphost)) {
5819: if (ref($iphost{$ip}) eq 'ARRAY') {
5820: foreach my $id (@{$iphost{$ip}}) {
5821: my $location = &Apache::lonnet::internet_dom($id);
5822: if ($location) {
5823: next if (grep(/^\Q$location\E$/,@{$intdoms}));
5824: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5825: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
5826: push(@{$by_ip->{$ip}},$location);
5827: }
5828: } else {
5829: $by_ip->{$ip} = [$location];
5830: }
5831: }
5832: }
5833: }
5834: }
5835: foreach my $ip (sort(keys(%{$by_ip}))) {
5836: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5837: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
5838: my $first = $by_ip->{$ip}->[0];
5839: if (ref($by_location->{$first}) eq 'ARRAY') {
5840: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
5841: push(@{$by_location->{$first}},$ip);
5842: }
5843: } else {
5844: $by_location->{$first} = [$ip];
5845: }
5846: }
5847: }
5848: return;
5849: }
5850:
1.145 raeburn 5851: sub current_offloads_to {
5852: my ($dom,$settings,$servers) = @_;
5853: my (%spareid,%otherdomconfigs);
1.152 raeburn 5854: if (ref($servers) eq 'HASH') {
1.145 raeburn 5855: foreach my $lonhost (sort(keys(%{$servers}))) {
5856: my $gotspares;
1.152 raeburn 5857: if (ref($settings) eq 'HASH') {
5858: if (ref($settings->{'spares'}) eq 'HASH') {
5859: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
5860: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
5861: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
5862: $gotspares = 1;
5863: }
1.145 raeburn 5864: }
5865: }
5866: unless ($gotspares) {
5867: my $gotspares;
5868: my $serverhomeID =
5869: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
5870: my $serverhomedom =
5871: &Apache::lonnet::host_domain($serverhomeID);
5872: if ($serverhomedom ne $dom) {
5873: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
5874: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5875: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5876: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5877: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5878: $gotspares = 1;
5879: }
5880: }
5881: } else {
5882: $otherdomconfigs{$serverhomedom} =
5883: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
5884: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
5885: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5886: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5887: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
5888: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5889: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5890: $gotspares = 1;
5891: }
5892: }
5893: }
5894: }
5895: }
5896: }
5897: }
5898: unless ($gotspares) {
5899: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
5900: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5901: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5902: } else {
5903: my $server_hostname = &Apache::lonnet::hostname($lonhost);
5904: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
5905: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
5906: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5907: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5908: } else {
1.150 raeburn 5909: my %what = (
5910: spareid => 1,
5911: );
5912: my ($result,$returnhash) =
5913: &Apache::lonnet::get_remote_globals($lonhost,\%what);
5914: if ($result eq 'ok') {
5915: if (ref($returnhash) eq 'HASH') {
5916: if (ref($returnhash->{'spareid'}) eq 'HASH') {
5917: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
5918: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
5919: }
5920: }
1.145 raeburn 5921: }
5922: }
5923: }
5924: }
5925: }
5926: }
5927: return %spareid;
5928: }
5929:
5930: sub spares_row {
1.160.6.105 raeburn 5931: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
5932: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 5933: my $css_class;
5934: my $numinrow = 4;
5935: my $itemcount = 1;
5936: my $datatable;
1.152 raeburn 5937: my %typetitles = &sparestype_titles();
5938: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 5939: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 5940: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
5941: my ($othercontrol,$serverdom);
5942: if ($serverhome ne $server) {
5943: $serverdom = &Apache::lonnet::host_domain($serverhome);
5944: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5945: } else {
5946: $serverdom = &Apache::lonnet::host_domain($server);
5947: if ($serverdom ne $dom) {
5948: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5949: }
5950: }
5951: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.105 raeburn 5952: my ($checkednow,$checkedoth);
1.160.6.61 raeburn 5953: if (ref($curroffloadnow) eq 'HASH') {
5954: if ($curroffloadnow->{$server}) {
5955: $checkednow = ' checked="checked"';
5956: }
5957: }
1.160.6.105 raeburn 5958: if (ref($curroffloadoth) eq 'HASH') {
5959: if ($curroffloadoth->{$server}) {
5960: $checkedoth = ' checked="checked"';
5961: }
5962: }
1.145 raeburn 5963: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5964: $datatable .= '<tr'.$css_class.'>
5965: <td rowspan="2">
1.160.6.13 raeburn 5966: <span class="LC_nobreak">'.
5967: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 5968: ,'<b>'.$server.'</b>').'</span><br />'.
5969: '<span class="LC_nobreak">'."\n".
5970: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.160.6.105 raeburn 5971: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.160.6.13 raeburn 5972: "\n";
1.160.6.105 raeburn 5973: if ($other_insts) {
5974: $datatable .= '<br />'.
5975: '<span class="LC_nobreak">'."\n".
5976: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
5977: ' '.&mt('Switch other institutions on next access').'</label></span>'.
5978: "\n";
5979: }
1.145 raeburn 5980: my (%current,%canselect);
1.152 raeburn 5981: my @choices =
5982: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
5983: foreach my $type ('primary','default') {
5984: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 5985: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
5986: my @spares = @{$spareid->{$server}{$type}};
5987: if (@spares > 0) {
1.152 raeburn 5988: if ($othercontrol) {
5989: $current{$type} = join(', ',@spares);
5990: } else {
5991: $current{$type} .= '<table>';
5992: my $numspares = scalar(@spares);
5993: for (my $i=0; $i<@spares; $i++) {
5994: my $rem = $i%($numinrow);
5995: if ($rem == 0) {
5996: if ($i > 0) {
5997: $current{$type} .= '</tr>';
5998: }
5999: $current{$type} .= '<tr>';
1.145 raeburn 6000: }
1.152 raeburn 6001: $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'".');" /> '.
6002: $spareid->{$server}{$type}[$i].
6003: '</label></td>'."\n";
6004: }
6005: my $rem = @spares%($numinrow);
6006: my $colsleft = $numinrow - $rem;
6007: if ($colsleft > 1 ) {
6008: $current{$type} .= '<td colspan="'.$colsleft.
6009: '" class="LC_left_item">'.
6010: ' </td>';
6011: } elsif ($colsleft == 1) {
6012: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 6013: }
1.152 raeburn 6014: $current{$type} .= '</tr></table>';
1.150 raeburn 6015: }
1.145 raeburn 6016: }
6017: }
6018: if ($current{$type} eq '') {
6019: $current{$type} = &mt('None specified');
6020: }
1.152 raeburn 6021: if ($othercontrol) {
6022: if ($type eq 'primary') {
6023: $canselect{$type} = $othercontrol;
6024: }
6025: } else {
6026: $canselect{$type} =
6027: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
6028: '<select name="newspare_'.$type.'_'.$server.'" '.
6029: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
6030: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
6031: if (@choices > 0) {
6032: foreach my $lonhost (@choices) {
6033: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
6034: }
6035: }
6036: $canselect{$type} .= '</select>'."\n";
6037: }
6038: } else {
6039: $current{$type} = &mt('Could not be determined');
6040: if ($type eq 'primary') {
6041: $canselect{$type} = $othercontrol;
6042: }
1.145 raeburn 6043: }
1.152 raeburn 6044: if ($type eq 'default') {
6045: $datatable .= '<tr'.$css_class.'>';
6046: }
6047: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
6048: '<td>'.$current{$type}.'</td>'."\n".
6049: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 6050: }
6051: $itemcount ++;
6052: }
6053: }
6054: $$rowtotal += $itemcount;
6055: return $datatable;
6056: }
6057:
1.152 raeburn 6058: sub possible_newspares {
6059: my ($server,$currspares,$serverhomes,$altids) = @_;
6060: my $serverhostname = &Apache::lonnet::hostname($server);
6061: my %excluded;
6062: if ($serverhostname ne '') {
6063: %excluded = (
6064: $serverhostname => 1,
6065: );
6066: }
6067: if (ref($currspares) eq 'HASH') {
6068: foreach my $type (keys(%{$currspares})) {
6069: if (ref($currspares->{$type}) eq 'ARRAY') {
6070: if (@{$currspares->{$type}} > 0) {
6071: foreach my $curr (@{$currspares->{$type}}) {
6072: my $hostname = &Apache::lonnet::hostname($curr);
6073: $excluded{$hostname} = 1;
6074: }
6075: }
6076: }
6077: }
6078: }
6079: my @choices;
6080: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
6081: if (keys(%{$serverhomes}) > 1) {
6082: foreach my $name (sort(keys(%{$serverhomes}))) {
6083: unless ($excluded{$name}) {
6084: if (exists($altids->{$serverhomes->{$name}})) {
6085: push(@choices,$altids->{$serverhomes->{$name}});
6086: } else {
6087: push(@choices,$serverhomes->{$name});
1.145 raeburn 6088: }
6089: }
6090: }
6091: }
6092: }
1.152 raeburn 6093: return sort(@choices);
1.145 raeburn 6094: }
6095:
1.150 raeburn 6096: sub print_loadbalancing {
6097: my ($dom,$settings,$rowtotal) = @_;
6098: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6099: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6100: my $numinrow = 1;
6101: my $datatable;
6102: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 6103: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 6104: if (ref($settings) eq 'HASH') {
6105: %existing = %{$settings};
6106: }
6107: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
6108: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 6109: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 6110: } else {
6111: return;
6112: }
6113: my ($othertitle,$usertypes,$types) =
6114: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 6115: my $rownum = 8;
1.150 raeburn 6116: if (ref($types) eq 'ARRAY') {
6117: $rownum += scalar(@{$types});
6118: }
1.160.6.7 raeburn 6119: my @css_class = ('LC_odd_row','LC_even_row');
6120: my $balnum = 0;
6121: my $islast;
6122: my (@toshow,$disabledtext);
6123: if (keys(%currbalancer) > 0) {
6124: @toshow = sort(keys(%currbalancer));
6125: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
6126: push(@toshow,'');
6127: }
6128: } else {
6129: @toshow = ('');
6130: $disabledtext = &mt('No existing load balancer');
6131: }
6132: foreach my $lonhost (@toshow) {
6133: if ($balnum == scalar(@toshow)-1) {
6134: $islast = 1;
6135: } else {
6136: $islast = 0;
6137: }
6138: my $cssidx = $balnum%2;
6139: my $targets_div_style = 'display: none';
6140: my $disabled_div_style = 'display: block';
6141: my $homedom_div_style = 'display: none';
6142: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
6143: '<td rowspan="'.$rownum.'" valign="top">'.
6144: '<p>';
6145: if ($lonhost eq '') {
6146: $datatable .= '<span class="LC_nobreak">';
6147: if (keys(%currbalancer) > 0) {
6148: $datatable .= &mt('Add balancer:');
6149: } else {
6150: $datatable .= &mt('Enable balancer:');
6151: }
6152: $datatable .= ' '.
6153: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
6154: ' id="loadbalancing_lonhost_'.$balnum.'"'.
6155: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
6156: '<option value="" selected="selected">'.&mt('None').
6157: '</option>'."\n";
6158: foreach my $server (sort(keys(%servers))) {
6159: next if ($currbalancer{$server});
6160: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
6161: }
6162: $datatable .=
6163: '</select>'."\n".
6164: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
6165: } else {
6166: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
6167: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
6168: &mt('Stop balancing').'</label>'.
6169: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
6170: $targets_div_style = 'display: block';
6171: $disabled_div_style = 'display: none';
6172: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
6173: $homedom_div_style = 'display: block';
6174: }
6175: }
6176: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
6177: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
6178: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
6179: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
6180: my ($numspares,@spares) = &count_servers($lonhost,%servers);
6181: my @sparestypes = ('primary','default');
6182: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 6183: my %hostherechecked = (
6184: no => ' checked="checked"',
6185: );
1.160.6.94 raeburn 6186: my %balcookiechecked = (
6187: no => ' checked="checked"',
6188: );
1.160.6.7 raeburn 6189: foreach my $sparetype (@sparestypes) {
6190: my $targettable;
6191: for (my $i=0; $i<$numspares; $i++) {
6192: my $checked;
6193: if (ref($currtargets{$lonhost}) eq 'HASH') {
6194: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6195: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6196: $checked = ' checked="checked"';
6197: }
6198: }
6199: }
6200: my ($chkboxval,$disabled);
6201: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
6202: $chkboxval = $spares[$i];
6203: }
6204: if (exists($currbalancer{$spares[$i]})) {
6205: $disabled = ' disabled="disabled"';
6206: }
6207: $targettable .=
1.160.6.55 raeburn 6208: '<td><span class="LC_nobreak"><label>'.
6209: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 6210: $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 6211: '</span></label></span></td>';
1.160.6.7 raeburn 6212: my $rem = $i%($numinrow);
6213: if ($rem == 0) {
6214: if (($i > 0) && ($i < $numspares-1)) {
6215: $targettable .= '</tr>';
6216: }
6217: if ($i < $numspares-1) {
6218: $targettable .= '<tr>';
1.150 raeburn 6219: }
6220: }
6221: }
1.160.6.7 raeburn 6222: if ($targettable ne '') {
6223: my $rem = $numspares%($numinrow);
6224: my $colsleft = $numinrow - $rem;
6225: if ($colsleft > 1 ) {
6226: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6227: ' </td>';
6228: } elsif ($colsleft == 1) {
6229: $targettable .= '<td class="LC_left_item"> </td>';
6230: }
6231: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
6232: '<table><tr>'.$targettable.'</tr></table><br />';
6233: }
1.160.6.76 raeburn 6234: $hostherechecked{$sparetype} = '';
6235: if (ref($currtargets{$lonhost}) eq 'HASH') {
6236: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6237: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6238: $hostherechecked{$sparetype} = ' checked="checked"';
6239: $hostherechecked{'no'} = '';
6240: }
6241: }
6242: }
6243: }
1.160.6.94 raeburn 6244: if ($currcookies{$lonhost}) {
6245: %balcookiechecked = (
6246: yes => ' checked="checked"',
6247: );
6248: }
1.160.6.76 raeburn 6249: $datatable .= &mt('Hosting on balancer itself').'<br />'.
6250: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
6251: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
6252: foreach my $sparetype (@sparestypes) {
6253: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
6254: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
6255: '</i></label><br />';
1.160.6.7 raeburn 6256: }
1.160.6.94 raeburn 6257: $datatable .= &mt('Use balancer cookie').'<br />'.
6258: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
6259: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
6260: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
6261: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
6262: '</div></td></tr>'.
1.160.6.7 raeburn 6263: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
6264: $othertitle,$usertypes,$types,\%servers,
6265: \%currbalancer,$lonhost,
6266: $targets_div_style,$homedom_div_style,
6267: $css_class[$cssidx],$balnum,$islast);
6268: $$rowtotal += $rownum;
6269: $balnum ++;
6270: }
6271: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
6272: return $datatable;
6273: }
6274:
6275: sub get_loadbalancers_config {
1.160.6.94 raeburn 6276: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 6277: return unless ((ref($servers) eq 'HASH') &&
6278: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 6279: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
6280: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 6281: if (keys(%{$existing}) > 0) {
6282: my $oldlonhost;
6283: foreach my $key (sort(keys(%{$existing}))) {
6284: if ($key eq 'lonhost') {
6285: $oldlonhost = $existing->{'lonhost'};
6286: $currbalancer->{$oldlonhost} = 1;
6287: } elsif ($key eq 'targets') {
6288: if ($oldlonhost) {
6289: $currtargets->{$oldlonhost} = $existing->{'targets'};
6290: }
6291: } elsif ($key eq 'rules') {
6292: if ($oldlonhost) {
6293: $currrules->{$oldlonhost} = $existing->{'rules'};
6294: }
6295: } elsif (ref($existing->{$key}) eq 'HASH') {
6296: $currbalancer->{$key} = 1;
6297: $currtargets->{$key} = $existing->{$key}{'targets'};
6298: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 6299: if ($existing->{$key}{'cookie'}) {
6300: $currcookies->{$key} = 1;
6301: }
1.150 raeburn 6302: }
6303: }
1.160.6.7 raeburn 6304: } else {
6305: my ($balancerref,$targetsref) =
6306: &Apache::lonnet::get_lonbalancer_config($servers);
6307: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
6308: foreach my $server (sort(keys(%{$balancerref}))) {
6309: $currbalancer->{$server} = 1;
6310: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 6311: }
6312: }
6313: }
1.160.6.7 raeburn 6314: return;
1.150 raeburn 6315: }
6316:
6317: sub loadbalancing_rules {
6318: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 6319: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
6320: $css_class,$balnum,$islast) = @_;
1.150 raeburn 6321: my $output;
1.160.6.7 raeburn 6322: my $num = 0;
6323: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 6324: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
6325: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
6326: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 6327: $num ++;
1.150 raeburn 6328: my $current;
6329: if (ref($currrules) eq 'HASH') {
6330: $current = $currrules->{$type};
6331: }
1.160.6.55 raeburn 6332: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 6333: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 6334: $current = '';
6335: }
6336: }
6337: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 6338: $servers,$currbalancer,$lonhost,$dom,
6339: $targets_div_style,$homedom_div_style,
6340: $css_class,$balnum,$num,$islast);
1.150 raeburn 6341: }
6342: }
6343: return $output;
6344: }
6345:
6346: sub loadbalancing_titles {
6347: my ($dom,$intdom,$usertypes,$types) = @_;
6348: my %othertypes = (
6349: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
6350: '_LC_author' => &mt('Users from [_1] with author role',$dom),
6351: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
6352: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 6353: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
6354: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 6355: );
1.160.6.26 raeburn 6356: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 6357: my @available;
1.150 raeburn 6358: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 6359: @available = @{$types};
1.150 raeburn 6360: }
1.160.6.89 raeburn 6361: unless (grep(/^default$/,@available)) {
6362: push(@available,'default');
6363: }
6364: unshift(@alltypes,@available);
1.150 raeburn 6365: my %titles;
6366: foreach my $type (@alltypes) {
6367: if ($type =~ /^_LC_/) {
6368: $titles{$type} = $othertypes{$type};
6369: } elsif ($type eq 'default') {
6370: $titles{$type} = &mt('All users from [_1]',$dom);
6371: if (ref($types) eq 'ARRAY') {
6372: if (@{$types} > 0) {
6373: $titles{$type} = &mt('Other users from [_1]',$dom);
6374: }
6375: }
6376: } elsif (ref($usertypes) eq 'HASH') {
6377: $titles{$type} = $usertypes->{$type};
6378: }
6379: }
6380: return (\@alltypes,\%othertypes,\%titles);
6381: }
6382:
6383: sub loadbalance_rule_row {
1.160.6.7 raeburn 6384: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
6385: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 6386: my @rulenames;
1.150 raeburn 6387: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 6388: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 6389: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 6390: } else {
1.160.6.26 raeburn 6391: @rulenames = ('default','homeserver');
6392: if ($type eq '_LC_external') {
6393: push(@rulenames,'externalbalancer');
6394: } else {
6395: push(@rulenames,'specific');
6396: }
6397: push(@rulenames,'none');
1.150 raeburn 6398: }
6399: my $style = $targets_div_style;
1.160.6.55 raeburn 6400: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 6401: $style = $homedom_div_style;
6402: }
1.160.6.7 raeburn 6403: my $space;
6404: if ($islast && $num == 1) {
6405: $space = '<div display="inline-block"> </div>';
6406: }
6407: my $output =
6408: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
6409: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
6410: '<td valaign="top">'.$space.
6411: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 6412: for (my $i=0; $i<@rulenames; $i++) {
6413: my $rule = $rulenames[$i];
6414: my ($checked,$extra);
6415: if ($rulenames[$i] eq 'default') {
6416: $rule = '';
6417: }
6418: if ($rulenames[$i] eq 'specific') {
6419: if (ref($servers) eq 'HASH') {
6420: my $default;
6421: if (($current ne '') && (exists($servers->{$current}))) {
6422: $checked = ' checked="checked"';
6423: }
6424: unless ($checked) {
6425: $default = ' selected="selected"';
6426: }
1.160.6.7 raeburn 6427: $extra =
6428: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
6429: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
6430: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
6431: '<option value=""'.$default.'></option>'."\n";
6432: foreach my $server (sort(keys(%{$servers}))) {
6433: if (ref($currbalancer) eq 'HASH') {
6434: next if (exists($currbalancer->{$server}));
6435: }
1.150 raeburn 6436: my $selected;
1.160.6.7 raeburn 6437: if ($server eq $current) {
1.150 raeburn 6438: $selected = ' selected="selected"';
6439: }
1.160.6.7 raeburn 6440: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 6441: }
6442: $extra .= '</select>';
6443: }
6444: } elsif ($rule eq $current) {
6445: $checked = ' checked="checked"';
6446: }
6447: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 6448: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
6449: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
6450: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 6451: ')"'.$checked.' /> ';
1.160.6.56 raeburn 6452: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 6453: $output .= $ruletitles{'particular'};
6454: } else {
6455: $output .= $ruletitles{$rulenames[$i]};
6456: }
6457: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 6458: }
6459: $output .= '</div></td></tr>'."\n";
6460: return $output;
6461: }
6462:
6463: sub offloadtype_text {
6464: my %ruletitles = &Apache::lonlocal::texthash (
6465: 'default' => 'Offloads to default destinations',
6466: 'homeserver' => "Offloads to user's home server",
6467: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
6468: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 6469: 'none' => 'No offload',
1.160.6.26 raeburn 6470: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
6471: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 6472: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 6473: );
6474: return %ruletitles;
6475: }
6476:
6477: sub sparestype_titles {
6478: my %typestitles = &Apache::lonlocal::texthash (
6479: 'primary' => 'primary',
6480: 'default' => 'default',
6481: );
6482: return %typestitles;
6483: }
6484:
1.28 raeburn 6485: sub contact_titles {
6486: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 6487: 'supportemail' => 'Support E-mail address',
6488: 'adminemail' => 'Default Server Admin E-mail address',
6489: 'errormail' => 'Error reports to be e-mailed to',
6490: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.101 raeburn 6491: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
6492: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 6493: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
6494: 'requestsmail' => 'E-mail from course requests requiring approval',
6495: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 6496: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 6497: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.160.6.109 raeburn 6498: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
6499: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.160.6.107 raeburn 6500: 'errorweights' => 'Weights used to compute error count',
6501: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 6502: );
6503: my %short_titles = &Apache::lonlocal::texthash (
6504: adminemail => 'Admin E-mail address',
6505: supportemail => 'Support E-mail',
6506: );
6507: return (\%titles,\%short_titles);
6508: }
6509:
1.160.6.78 raeburn 6510: sub helpform_fields {
6511: my %titles = &Apache::lonlocal::texthash (
6512: 'username' => 'Name',
6513: 'user' => 'Username/domain',
6514: 'phone' => 'Phone',
6515: 'cc' => 'Cc e-mail',
6516: 'course' => 'Course Details',
6517: 'section' => 'Sections',
6518: 'screenshot' => 'File upload',
6519: );
6520: my @fields = ('username','phone','user','course','section','cc','screenshot');
6521: my %possoptions = (
6522: username => ['yes','no','req'],
6523: phone => ['yes','no','req'],
6524: user => ['yes','no'],
6525: cc => ['yes','no'],
6526: course => ['yes','no'],
6527: section => ['yes','no'],
6528: screenshot => ['yes','no'],
6529: );
6530: my %fieldoptions = &Apache::lonlocal::texthash (
6531: 'yes' => 'Optional',
6532: 'req' => 'Required',
6533: 'no' => "Not shown",
6534: );
6535: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
6536: }
6537:
1.72 raeburn 6538: sub tool_titles {
6539: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 6540: aboutme => 'Personal web page',
1.86 raeburn 6541: blog => 'Blog',
1.160.6.4 raeburn 6542: webdav => 'WebDAV',
1.86 raeburn 6543: portfolio => 'Portfolio',
1.88 bisitz 6544: official => 'Official courses (with institutional codes)',
6545: unofficial => 'Unofficial courses',
1.98 raeburn 6546: community => 'Communities',
1.160.6.30 raeburn 6547: textbook => 'Textbook courses',
1.86 raeburn 6548: );
1.72 raeburn 6549: return %titles;
6550: }
6551:
1.101 raeburn 6552: sub courserequest_titles {
6553: my %titles = &Apache::lonlocal::texthash (
6554: official => 'Official',
6555: unofficial => 'Unofficial',
6556: community => 'Communities',
1.160.6.30 raeburn 6557: textbook => 'Textbook',
1.101 raeburn 6558: norequest => 'Not allowed',
1.104 raeburn 6559: approval => 'Approval by Dom. Coord.',
1.101 raeburn 6560: validate => 'With validation',
6561: autolimit => 'Numerical limit',
1.103 raeburn 6562: unlimited => '(blank for unlimited)',
1.101 raeburn 6563: );
6564: return %titles;
6565: }
6566:
1.160.6.5 raeburn 6567: sub authorrequest_titles {
6568: my %titles = &Apache::lonlocal::texthash (
6569: norequest => 'Not allowed',
6570: approval => 'Approval by Dom. Coord.',
6571: automatic => 'Automatic approval',
6572: );
6573: return %titles;
6574: }
6575:
1.101 raeburn 6576: sub courserequest_conditions {
6577: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 6578: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 6579: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 6580: );
6581: return %conditions;
6582: }
6583:
6584:
1.27 raeburn 6585: sub print_usercreation {
1.30 raeburn 6586: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 6587: my $numinrow = 4;
1.28 raeburn 6588: my $datatable;
6589: if ($position eq 'top') {
1.30 raeburn 6590: $$rowtotal ++;
1.34 raeburn 6591: my $rowcount = 0;
1.32 raeburn 6592: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 6593: if (ref($rules) eq 'HASH') {
6594: if (keys(%{$rules}) > 0) {
1.32 raeburn 6595: $datatable .= &user_formats_row('username',$settings,$rules,
6596: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 6597: $$rowtotal ++;
1.32 raeburn 6598: $rowcount ++;
6599: }
6600: }
6601: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
6602: if (ref($idrules) eq 'HASH') {
6603: if (keys(%{$idrules}) > 0) {
6604: $datatable .= &user_formats_row('id',$settings,$idrules,
6605: $idruleorder,$numinrow,$rowcount);
6606: $$rowtotal ++;
6607: $rowcount ++;
1.28 raeburn 6608: }
6609: }
1.39 raeburn 6610: if ($rowcount == 0) {
6611: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
6612: $$rowtotal ++;
6613: $rowcount ++;
6614: }
1.34 raeburn 6615: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 6616: my @creators = ('author','course','requestcrs');
1.37 raeburn 6617: my ($rules,$ruleorder) =
6618: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 6619: my %lt = &usercreation_types();
6620: my %checked;
6621: if (ref($settings) eq 'HASH') {
6622: if (ref($settings->{'cancreate'}) eq 'HASH') {
6623: foreach my $item (@creators) {
6624: $checked{$item} = $settings->{'cancreate'}{$item};
6625: }
6626: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
6627: foreach my $item (@creators) {
6628: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
6629: $checked{$item} = 'none';
6630: }
6631: }
6632: }
6633: }
6634: my $rownum = 0;
6635: foreach my $item (@creators) {
6636: $rownum ++;
1.160.6.34 raeburn 6637: if ($checked{$item} eq '') {
6638: $checked{$item} = 'any';
1.34 raeburn 6639: }
6640: my $css_class;
6641: if ($rownum%2) {
6642: $css_class = '';
6643: } else {
6644: $css_class = ' class="LC_odd_row" ';
6645: }
6646: $datatable .= '<tr'.$css_class.'>'.
6647: '<td><span class="LC_nobreak">'.$lt{$item}.
6648: '</span></td><td align="right">';
1.160.6.34 raeburn 6649: my @options = ('any');
6650: if (ref($rules) eq 'HASH') {
6651: if (keys(%{$rules}) > 0) {
6652: push(@options,('official','unofficial'));
1.37 raeburn 6653: }
6654: }
1.160.6.34 raeburn 6655: push(@options,'none');
1.37 raeburn 6656: foreach my $option (@options) {
1.50 raeburn 6657: my $type = 'radio';
1.34 raeburn 6658: my $check = ' ';
1.160.6.34 raeburn 6659: if ($checked{$item} eq $option) {
6660: $check = ' checked="checked" ';
1.34 raeburn 6661: }
6662: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 6663: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 6664: $item.'" value="'.$option.'"'.$check.'/> '.
6665: $lt{$option}.'</label> </span>';
6666: }
6667: $datatable .= '</td></tr>';
6668: }
1.28 raeburn 6669: } else {
6670: my @contexts = ('author','course','domain');
6671: my @authtypes = ('int','krb4','krb5','loc');
6672: my %checked;
6673: if (ref($settings) eq 'HASH') {
6674: if (ref($settings->{'authtypes'}) eq 'HASH') {
6675: foreach my $item (@contexts) {
6676: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
6677: foreach my $auth (@authtypes) {
6678: if ($settings->{'authtypes'}{$item}{$auth}) {
6679: $checked{$item}{$auth} = ' checked="checked" ';
6680: }
6681: }
6682: }
6683: }
1.27 raeburn 6684: }
1.35 raeburn 6685: } else {
6686: foreach my $item (@contexts) {
1.36 raeburn 6687: foreach my $auth (@authtypes) {
1.35 raeburn 6688: $checked{$item}{$auth} = ' checked="checked" ';
6689: }
6690: }
1.27 raeburn 6691: }
1.28 raeburn 6692: my %title = &context_names();
6693: my %authname = &authtype_names();
6694: my $rownum = 0;
6695: my $css_class;
6696: foreach my $item (@contexts) {
6697: if ($rownum%2) {
6698: $css_class = '';
6699: } else {
6700: $css_class = ' class="LC_odd_row" ';
6701: }
1.30 raeburn 6702: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 6703: '<td>'.$title{$item}.
6704: '</td><td class="LC_left_item">'.
6705: '<span class="LC_nobreak">';
6706: foreach my $auth (@authtypes) {
6707: $datatable .= '<label>'.
6708: '<input type="checkbox" name="'.$item.'_auth" '.
6709: $checked{$item}{$auth}.' value="'.$auth.'" />'.
6710: $authname{$auth}.'</label> ';
6711: }
6712: $datatable .= '</span></td></tr>';
6713: $rownum ++;
1.27 raeburn 6714: }
1.30 raeburn 6715: $$rowtotal += $rownum;
1.27 raeburn 6716: }
6717: return $datatable;
6718: }
6719:
1.160.6.34 raeburn 6720: sub print_selfcreation {
6721: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 6722: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
6723: $emaildomain,$datatable);
1.160.6.34 raeburn 6724: if (ref($settings) eq 'HASH') {
6725: if (ref($settings->{'cancreate'}) eq 'HASH') {
6726: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 6727: if (ref($createsettings) eq 'HASH') {
6728: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
6729: @selfcreate = @{$createsettings->{'selfcreate'}};
6730: } elsif ($createsettings->{'selfcreate'} ne '') {
6731: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
6732: @selfcreate = ('email','login','sso');
6733: } elsif ($createsettings->{'selfcreate'} ne 'none') {
6734: @selfcreate = ($createsettings->{'selfcreate'});
6735: }
6736: }
6737: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
6738: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 6739: }
1.160.6.93 raeburn 6740: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
6741: $emailoptions = $createsettings->{'emailoptions'};
6742: }
6743: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
6744: $emailverified = $createsettings->{'emailverified'};
6745: }
6746: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
6747: $emaildomain = $createsettings->{'emaildomain'};
6748: }
1.160.6.34 raeburn 6749: }
6750: }
6751: }
6752: my %radiohash;
6753: my $numinrow = 4;
6754: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 6755: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 6756: if ($position eq 'top') {
6757: my %choices = &Apache::lonlocal::texthash (
6758: cancreate_login => 'Institutional Login',
6759: cancreate_sso => 'Institutional Single Sign On',
6760: );
6761: my @toggles = sort(keys(%choices));
6762: my %defaultchecked = (
6763: 'cancreate_login' => 'off',
6764: 'cancreate_sso' => 'off',
6765: );
1.160.6.35 raeburn 6766: my ($onclick,$itemcount);
1.160.6.34 raeburn 6767: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6768: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 6769: $$rowtotal += $itemcount;
1.160.6.34 raeburn 6770:
6771: if (ref($usertypes) eq 'HASH') {
6772: if (keys(%{$usertypes}) > 0) {
6773: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
6774: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 6775: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 6776: $$rowtotal ++;
6777: }
6778: }
1.160.6.44 raeburn 6779: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
6780: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6781: $fieldtitles{'inststatus'} = &mt('Institutional status');
6782: my $rem;
6783: my $numperrow = 2;
6784: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
6785: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 6786: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 6787: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 6788: '<table>'."\n";
1.160.6.44 raeburn 6789: for (my $i=0; $i<@fields; $i++) {
6790: $rem = $i%($numperrow);
6791: if ($rem == 0) {
6792: if ($i > 0) {
6793: $datatable .= '</tr>';
6794: }
6795: $datatable .= '<tr>';
6796: }
6797: my $currval;
1.160.6.51 raeburn 6798: if (ref($createsettings) eq 'HASH') {
6799: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
6800: $currval = $createsettings->{'shibenv'}{$fields[$i]};
6801: }
1.160.6.44 raeburn 6802: }
6803: $datatable .= '<td class="LC_left_item">'.
6804: '<span class="LC_nobreak">'.
6805: '<input type="text" name="shibenv_'.$fields[$i].'" '.
6806: 'value="'.$currval.'" size="10" /> '.
6807: $fieldtitles{$fields[$i]}.'</span></td>';
6808: }
6809: my $colsleft = $numperrow - $rem;
6810: if ($colsleft > 1 ) {
6811: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6812: ' </td>';
6813: } elsif ($colsleft == 1) {
6814: $datatable .= '<td class="LC_left_item"> </td>';
6815: }
6816: $datatable .= '</tr></table></td></tr>';
6817: $$rowtotal ++;
1.160.6.34 raeburn 6818: } elsif ($position eq 'middle') {
6819: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 6820: my @posstypes;
1.160.6.34 raeburn 6821: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 6822: @posstypes = @{$types};
6823: }
6824: unless (grep(/^default$/,@posstypes)) {
6825: push(@posstypes,'default');
6826: }
6827: my %usertypeshash;
6828: if (ref($usertypes) eq 'HASH') {
6829: %usertypeshash = %{$usertypes};
6830: }
6831: $usertypeshash{'default'} = $othertitle;
6832: foreach my $status (@posstypes) {
6833: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
6834: $numinrow,$$rowtotal,\%usertypeshash);
6835: $$rowtotal ++;
1.160.6.34 raeburn 6836: }
6837: } else {
1.160.6.40 raeburn 6838: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 6839: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 6840: );
6841: my @toggles = sort(keys(%choices));
6842: my %defaultchecked = (
6843: 'cancreate_email' => 'off',
6844: );
1.160.6.93 raeburn 6845: my $customclass = 'LC_selfcreate_email';
6846: my $classprefix = 'LC_canmodify_emailusername_';
6847: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 6848: my $display = 'none';
1.160.6.93 raeburn 6849: my $rowstyle = 'display:none';
1.160.6.40 raeburn 6850: if (grep(/^\Qemail\E$/,@selfcreate)) {
6851: $display = 'block';
1.160.6.93 raeburn 6852: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 6853: }
1.160.6.93 raeburn 6854: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
6855: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6856: \%choices,$$rowtotal,$onclick);
6857: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
6858: $rowstyle);
6859: $$rowtotal ++;
6860: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
6861: $rowstyle);
6862: $$rowtotal ++;
6863: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 6864: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 6865: my ($emailrules,$emailruleorder) =
6866: &Apache::lonnet::inst_userrules($dom,'email');
6867: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6868: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6869: if (ref($types) eq 'ARRAY') {
6870: @posstypes = @{$types};
6871: }
6872: if (@posstypes) {
6873: unless (grep(/^default$/,@posstypes)) {
6874: push(@posstypes,'default');
1.160.6.89 raeburn 6875: }
6876: if (ref($usertypes) eq 'HASH') {
6877: %usertypeshash = %{$usertypes};
6878: }
1.160.6.93 raeburn 6879: my $currassign;
6880: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
6881: $currassign = {
6882: selfassign => $domdefaults{'inststatusguest'},
6883: };
6884: @ordered = @{$domdefaults{'inststatusguest'}};
6885: } else {
6886: $currassign = { selfassign => [] };
6887: }
6888: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
6889: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
6890: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
6891: $numinrow,$othertitle,'selfassign',
6892: $rowtotal,$onclicktypes,$customclass,
6893: $rowstyle);
6894: $$rowtotal ++;
1.160.6.89 raeburn 6895: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 6896: foreach my $status (@posstypes) {
6897: my $css_class;
6898: if ($$rowtotal%2) {
6899: $css_class = 'LC_odd_row ';
6900: }
6901: $css_class .= $customclass;
6902: my $rowid = $optionsprefix.$status;
6903: my $hidden = 1;
6904: my $currstyle = 'display:none';
6905: if (grep(/^\Q$status\E$/,@ordered)) {
6906: $currstyle = $rowstyle;
6907: $hidden = 0;
6908: }
6909: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6910: $emailrules,$emailruleorder,$settings,$status,$rowid,
6911: $usertypeshash{$status},$css_class,$currstyle,$intdom);
6912: unless ($hidden) {
6913: $$rowtotal ++;
6914: }
1.160.6.89 raeburn 6915: }
6916: } else {
1.160.6.93 raeburn 6917: my $css_class;
6918: if ($$rowtotal%2) {
6919: $css_class = 'LC_odd_row ';
6920: }
6921: $css_class .= $customclass;
1.160.6.89 raeburn 6922: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 6923: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6924: $emailrules,$emailruleorder,$settings,'default','',
6925: $othertitle,$css_class,$rowstyle,$intdom);
6926: $$rowtotal ++;
1.160.6.34 raeburn 6927: }
1.160.6.35 raeburn 6928: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
6929: $numinrow = 1;
1.160.6.93 raeburn 6930: if (@posstypes) {
6931: foreach my $status (@posstypes) {
6932: my $rowid = $classprefix.$status;
6933: my $datarowstyle = 'display:none';
6934: if (grep(/^\Q$status\E$/,@ordered)) {
6935: $datarowstyle = $rowstyle;
6936: }
6937: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
6938: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6939: $infotitles,$rowid,$customclass,$datarowstyle);
6940: unless ($datarowstyle eq 'display:none') {
6941: $$rowtotal ++;
6942: }
1.160.6.34 raeburn 6943: }
1.160.6.93 raeburn 6944: } else {
6945: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
6946: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6947: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 6948: }
6949: }
6950: return $datatable;
6951: }
6952:
1.160.6.93 raeburn 6953: sub selfcreate_javascript {
6954: return <<"ENDSCRIPT";
6955:
6956: <script type="text/javascript">
6957: // <![CDATA[
6958:
6959: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
6960: var x = document.getElementsByClassName(target);
6961: var insttypes = 0;
6962: var insttypeRegExp = new RegExp(prefix);
6963: if ((x.length != undefined) && (x.length > 0)) {
6964: if (form.elements[radio].length != undefined) {
6965: for (var i=0; i<form.elements[radio].length; i++) {
6966: if (form.elements[radio][i].checked) {
6967: if (form.elements[radio][i].value == 1) {
6968: for (var j=0; j<x.length; j++) {
6969: if (x[j].id == 'undefined') {
6970: x[j].style.display = 'table-row';
6971: } else if (insttypeRegExp.test(x[j].id)) {
6972: insttypes ++;
6973: } else {
6974: x[j].style.display = 'table-row';
6975: }
6976: }
6977: } else {
6978: for (var j=0; j<x.length; j++) {
6979: x[j].style.display = 'none';
6980: }
1.160.6.40 raeburn 6981: }
1.160.6.93 raeburn 6982: break;
6983: }
6984: }
6985: if (insttypes > 0) {
6986: toggleDataRow(form,checkbox,target,altprefix);
6987: toggleDataRow(form,checkbox,target,prefix,1);
6988: }
6989: }
6990: }
6991: return;
6992: }
6993:
6994: function toggleDataRow(form,checkbox,target,prefix,docount) {
6995: if (form.elements[checkbox].length != undefined) {
6996: var count = 0;
6997: if (docount) {
6998: for (var i=0; i<form.elements[checkbox].length; i++) {
6999: if (form.elements[checkbox][i].checked) {
7000: count ++;
7001: }
7002: }
7003: }
7004: for (var i=0; i<form.elements[checkbox].length; i++) {
7005: var type = form.elements[checkbox][i].value;
7006: if (document.getElementById(prefix+type)) {
7007: if (form.elements[checkbox][i].checked) {
7008: document.getElementById(prefix+type).style.display = 'table-row';
7009: if (count % 2 == 1) {
7010: document.getElementById(prefix+type).className = target+' LC_odd_row';
7011: } else {
7012: document.getElementById(prefix+type).className = target;
7013: }
7014: count ++;
1.160.6.40 raeburn 7015: } else {
1.160.6.93 raeburn 7016: document.getElementById(prefix+type).style.display = 'none';
7017: }
7018: }
7019: }
7020: }
7021: return;
7022: }
7023:
7024: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
7025: var caller = radio+'_'+status;
7026: if (form.elements[caller].length != undefined) {
7027: for (var i=0; i<form.elements[caller].length; i++) {
7028: if (form.elements[caller][i].checked) {
7029: if (document.getElementById(altprefix+'_inst_'+status)) {
7030: var curr = form.elements[caller][i].value;
7031: if (prefix) {
7032: document.getElementById(prefix+'_'+status).style.display = 'none';
7033: }
7034: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
7035: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
7036: if (curr == 'custom') {
7037: if (prefix) {
7038: document.getElementById(prefix+'_'+status).style.display = 'inline';
7039: }
7040: } else if (curr == 'inst') {
7041: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
7042: } else if (curr == 'noninst') {
7043: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 7044: }
1.160.6.93 raeburn 7045: break;
1.160.6.40 raeburn 7046: }
1.160.6.93 raeburn 7047: }
7048: }
7049: }
7050: }
7051:
7052: // ]]>
7053: </script>
7054:
7055: ENDSCRIPT
7056: }
7057:
7058: sub noninst_users {
7059: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
7060: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
7061: my $class = 'LC_left_item';
7062: if ($css_class) {
7063: $css_class = ' class="'.$css_class.'"';
7064: }
7065: if ($rowid) {
7066: $rowid = ' id="'.$rowid.'"';
7067: }
7068: if ($rowstyle) {
7069: $rowstyle = ' style="'.$rowstyle.'"';
7070: }
7071: my ($output,$description);
7072: if ($type eq 'default') {
7073: $description = &mt('Requests for: [_1]',$typetitle);
7074: } else {
7075: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
7076: }
7077: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
7078: "<td>$description</td>\n".
7079: '<td class="'.$class.'" colspan="2">'.
7080: '<table><tr>';
7081: my %headers = &Apache::lonlocal::texthash(
7082: approve => 'Processing',
7083: email => 'E-mail',
7084: username => 'Username',
7085: );
7086: foreach my $item ('approve','email','username') {
7087: $output .= '<th>'.$headers{$item}.'</th>';
7088: }
7089: $output .= '</tr><tr>';
7090: foreach my $item ('approve','email','username') {
7091: $output .= '<td valign="top">';
7092: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
7093: if ($item eq 'approve') {
7094: %choices = &Apache::lonlocal::texthash (
7095: automatic => 'Automatically approved',
7096: approval => 'Queued for approval',
7097: );
7098: @options = ('automatic','approval');
7099: $hashref = $processing;
7100: $defoption = 'automatic';
7101: $name = 'cancreate_emailprocess_'.$type;
7102: } elsif ($item eq 'email') {
7103: %choices = &Apache::lonlocal::texthash (
7104: any => 'Any e-mail',
7105: inst => 'Institutional only',
7106: noninst => 'Non-institutional only',
7107: custom => 'Custom restrictions',
7108: );
7109: @options = ('any','inst','noninst');
7110: my $showcustom;
7111: if (ref($emailrules) eq 'HASH') {
7112: if (keys(%{$emailrules}) > 0) {
7113: push(@options,'custom');
7114: $showcustom = 'cancreate_emailrule';
7115: if (ref($settings) eq 'HASH') {
7116: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
7117: foreach my $rule (@{$settings->{'email_rule'}}) {
7118: if (exists($emailrules->{$rule})) {
7119: $hascustom ++;
7120: }
7121: }
7122: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
7123: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
7124: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
7125: if (exists($emailrules->{$rule})) {
7126: $hascustom ++;
7127: }
7128: }
7129: }
7130: }
7131: }
7132: }
7133: }
7134: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
7135: "'cancreate_emaildomain','$type'".');"';
7136: $hashref = $emailoptions;
7137: $defoption = 'any';
7138: $name = 'cancreate_emailoptions_'.$type;
7139: } elsif ($item eq 'username') {
7140: %choices = &Apache::lonlocal::texthash (
7141: all => 'Same as e-mail',
7142: first => 'Omit @domain',
7143: free => 'Free to choose',
7144: );
7145: @options = ('all','first','free');
7146: $hashref = $emailverified;
7147: $defoption = 'all';
7148: $name = 'cancreate_usernameoptions_'.$type;
7149: }
7150: foreach my $option (@options) {
7151: my $checked;
7152: if (ref($hashref) eq 'HASH') {
7153: if ($type eq '') {
7154: if (!exists($hashref->{'default'})) {
7155: if ($option eq $defoption) {
7156: $checked = ' checked="checked"';
7157: }
7158: } else {
7159: if ($hashref->{'default'} eq $option) {
7160: $checked = ' checked="checked"';
7161: }
1.160.6.40 raeburn 7162: }
7163: } else {
1.160.6.93 raeburn 7164: if (!exists($hashref->{$type})) {
7165: if ($option eq $defoption) {
7166: $checked = ' checked="checked"';
7167: }
7168: } else {
7169: if ($hashref->{$type} eq $option) {
7170: $checked = ' checked="checked"';
7171: }
1.160.6.40 raeburn 7172: }
7173: }
1.160.6.93 raeburn 7174: } elsif (($item eq 'email') && ($hascustom)) {
7175: if ($option eq 'custom') {
7176: $checked = ' checked="checked"';
7177: }
7178: } elsif ($option eq $defoption) {
7179: $checked = ' checked="checked"';
7180: }
7181: $output .= '<span class="LC_nobreak"><label>'.
7182: '<input type="radio" name="'.$name.'"'.
7183: $checked.' value="'.$option.'"'.$onclick.' />'.
7184: $choices{$option}.'</label></span><br />';
7185: if ($item eq 'email') {
7186: if ($option eq 'custom') {
7187: my $id = 'cancreate_emailrule_'.$type;
7188: my $display = 'none';
7189: if ($checked) {
7190: $display = 'inline';
7191: }
7192: my $numinrow = 2;
7193: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
7194: '<legend>'.&mt('Disallow').'</legend><table>'.
7195: &user_formats_row('email',$settings,$emailrules,
7196: $emailruleorder,$numinrow,'',$type);
7197: '</table></fieldset>';
7198: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
7199: my %text = &Apache::lonlocal::texthash (
7200: inst => 'must end:',
7201: noninst => 'cannot end:',
7202: );
7203: my $value;
7204: if (ref($emaildomain) eq 'HASH') {
7205: if (ref($emaildomain->{$type}) eq 'HASH') {
7206: $value = $emaildomain->{$type}->{$option};
7207: }
7208: }
7209: if ($value eq '') {
7210: $value = '@'.$intdom;
7211: }
7212: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
7213: my $display = 'none';
7214: if ($checked) {
7215: $display = 'inline';
7216: }
7217: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
7218: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
7219: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
7220: '</div>';
7221: }
1.160.6.40 raeburn 7222: }
7223: }
1.160.6.93 raeburn 7224: $output .= '</td>'."\n";
1.160.6.40 raeburn 7225: }
1.160.6.93 raeburn 7226: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 7227: return $output;
7228: }
7229:
1.160.6.5 raeburn 7230: sub captcha_choice {
1.160.6.93 raeburn 7231: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 7232: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
7233: $vertext,$currver);
1.160.6.5 raeburn 7234: my %lt = &captcha_phrases();
7235: $keyentry = 'hidden';
1.160.6.98 raeburn 7236: my $colspan=2;
1.160.6.5 raeburn 7237: if ($context eq 'cancreate') {
1.160.6.34 raeburn 7238: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 7239: } elsif ($context eq 'login') {
7240: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98 raeburn 7241: } elsif ($context eq 'passwords') {
7242: $rowname = &mt('"Forgot Password" CAPTCHA validation');
7243: $colspan=1;
1.160.6.5 raeburn 7244: }
7245: if (ref($settings) eq 'HASH') {
7246: if ($settings->{'captcha'}) {
7247: $checked{$settings->{'captcha'}} = ' checked="checked"';
7248: } else {
7249: $checked{'original'} = ' checked="checked"';
7250: }
7251: if ($settings->{'captcha'} eq 'recaptcha') {
7252: $pubtext = $lt{'pub'};
7253: $privtext = $lt{'priv'};
7254: $keyentry = 'text';
1.160.6.69 raeburn 7255: $vertext = $lt{'ver'};
7256: $currver = $settings->{'recaptchaversion'};
7257: if ($currver ne '2') {
7258: $currver = 1;
7259: }
1.160.6.5 raeburn 7260: }
7261: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
7262: $currpub = $settings->{'recaptchakeys'}{'public'};
7263: $currpriv = $settings->{'recaptchakeys'}{'private'};
7264: }
7265: } else {
7266: $checked{'original'} = ' checked="checked"';
7267: }
1.160.6.93 raeburn 7268: my $css_class;
7269: if ($itemcount%2) {
7270: $css_class = 'LC_odd_row';
7271: }
7272: if ($customcss) {
7273: $css_class .= " $customcss";
7274: }
7275: $css_class =~ s/^\s+//;
7276: if ($css_class) {
7277: $css_class = ' class="'.$css_class.'"';
7278: }
7279: if ($rowstyle) {
7280: $css_class .= ' style="'.$rowstyle.'"';
7281: }
1.160.6.5 raeburn 7282: my $output = '<tr'.$css_class.'>'.
1.160.6.98 raeburn 7283: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 7284: '<table><tr><td>'."\n";
7285: foreach my $option ('original','recaptcha','notused') {
7286: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
7287: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
7288: $lt{$option}.'</label></span>';
7289: unless ($option eq 'notused') {
7290: $output .= (' 'x2)."\n";
7291: }
7292: }
7293: #
7294: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
7295: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
7296: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
7297: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
7298: #
7299: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 7300: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 7301: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
7302: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
7303: $currpub.'" size="40" /></span><br />'."\n".
7304: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
7305: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 7306: $currpriv.'" size="40" /></span><br />'.
7307: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
7308: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
7309: $currver.'" size="3" /></span><br />'.
7310: '</td></tr></table>'."\n".
1.160.6.5 raeburn 7311: '</td></tr>';
7312: return $output;
7313: }
7314:
1.32 raeburn 7315: sub user_formats_row {
1.160.6.93 raeburn 7316: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 7317: my $output;
7318: my %text = (
7319: 'username' => 'new usernames',
7320: 'id' => 'IDs',
7321: );
1.160.6.93 raeburn 7322: unless ($type eq 'email') {
7323: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7324: $output = '<tr '.$css_class.'>'.
7325: '<td><span class="LC_nobreak">'.
7326: &mt("Format rules to check for $text{$type}: ").
7327: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 7328: }
1.27 raeburn 7329: my $rem;
7330: if (ref($ruleorder) eq 'ARRAY') {
7331: for (my $i=0; $i<@{$ruleorder}; $i++) {
7332: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
7333: my $rem = $i%($numinrow);
7334: if ($rem == 0) {
7335: if ($i > 0) {
7336: $output .= '</tr>';
7337: }
7338: $output .= '<tr>';
7339: }
7340: my $check = ' ';
1.39 raeburn 7341: if (ref($settings) eq 'HASH') {
7342: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
7343: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
7344: $check = ' checked="checked" ';
7345: }
1.160.6.93 raeburn 7346: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
7347: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
7348: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
7349: $check = ' checked="checked" ';
7350: }
7351: }
1.27 raeburn 7352: }
7353: }
1.160.6.93 raeburn 7354: my $name = $type.'_rule';
7355: if ($type eq 'email') {
7356: $name .= '_'.$status;
7357: }
1.27 raeburn 7358: $output .= '<td class="LC_left_item">'.
7359: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 7360: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 7361: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
7362: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
7363: }
7364: }
7365: $rem = @{$ruleorder}%($numinrow);
7366: }
1.160.6.93 raeburn 7367: my $colsleft;
7368: if ($rem) {
7369: $colsleft = $numinrow - $rem;
7370: }
1.27 raeburn 7371: if ($colsleft > 1 ) {
7372: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7373: ' </td>';
7374: } elsif ($colsleft == 1) {
7375: $output .= '<td class="LC_left_item"> </td>';
7376: }
1.160.6.93 raeburn 7377: $output .= '</tr></table>';
7378: unless ($type eq 'email') {
7379: $output .= '</td></tr>';
7380: }
1.27 raeburn 7381: return $output;
7382: }
7383:
1.34 raeburn 7384: sub usercreation_types {
7385: my %lt = &Apache::lonlocal::texthash (
7386: author => 'When adding a co-author',
7387: course => 'When adding a user to a course',
1.100 raeburn 7388: requestcrs => 'When requesting a course',
1.34 raeburn 7389: any => 'Any',
7390: official => 'Institutional only ',
7391: unofficial => 'Non-institutional only',
7392: none => 'None',
7393: );
7394: return %lt;
1.48 raeburn 7395: }
1.34 raeburn 7396:
1.160.6.34 raeburn 7397: sub selfcreation_types {
7398: my %lt = &Apache::lonlocal::texthash (
7399: selfcreate => 'User creates own account',
7400: any => 'Any',
7401: official => 'Institutional only ',
7402: unofficial => 'Non-institutional only',
7403: email => 'E-mail address',
7404: login => 'Institutional Login',
7405: sso => 'SSO',
7406: );
7407: }
7408:
1.28 raeburn 7409: sub authtype_names {
7410: my %lt = &Apache::lonlocal::texthash(
7411: int => 'Internal',
7412: krb4 => 'Kerberos 4',
7413: krb5 => 'Kerberos 5',
7414: loc => 'Local',
7415: );
7416: return %lt;
7417: }
7418:
7419: sub context_names {
7420: my %context_title = &Apache::lonlocal::texthash(
7421: author => 'Creating users when an Author',
7422: course => 'Creating users when in a course',
7423: domain => 'Creating users when a Domain Coordinator',
7424: );
7425: return %context_title;
7426: }
7427:
1.33 raeburn 7428: sub print_usermodification {
7429: my ($position,$dom,$settings,$rowtotal) = @_;
7430: my $numinrow = 4;
7431: my ($context,$datatable,$rowcount);
7432: if ($position eq 'top') {
7433: $rowcount = 0;
7434: $context = 'author';
7435: foreach my $role ('ca','aa') {
7436: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7437: $numinrow,$rowcount);
7438: $$rowtotal ++;
7439: $rowcount ++;
7440: }
1.160.6.37 raeburn 7441: } elsif ($position eq 'bottom') {
1.33 raeburn 7442: $context = 'course';
7443: $rowcount = 0;
7444: foreach my $role ('st','ep','ta','in','cr') {
7445: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7446: $numinrow,$rowcount);
7447: $$rowtotal ++;
7448: $rowcount ++;
7449: }
7450: }
7451: return $datatable;
7452: }
7453:
1.43 raeburn 7454: sub print_defaults {
1.160.6.40 raeburn 7455: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 7456: my $rownum = 0;
1.160.6.80 raeburn 7457: my ($datatable,$css_class,$titles);
7458: unless ($position eq 'bottom') {
7459: $titles = &defaults_titles($dom);
7460: }
1.160.6.40 raeburn 7461: if ($position eq 'top') {
7462: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
7463: 'datelocale_def','portal_def');
7464: my %defaults;
7465: if (ref($settings) eq 'HASH') {
7466: %defaults = %{$settings};
1.43 raeburn 7467: } else {
1.160.6.40 raeburn 7468: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7469: foreach my $item (@items) {
7470: $defaults{$item} = $domdefaults{$item};
7471: }
1.43 raeburn 7472: }
1.160.6.40 raeburn 7473: foreach my $item (@items) {
7474: if ($rownum%2) {
7475: $css_class = '';
7476: } else {
7477: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 7478: }
1.160.6.40 raeburn 7479: $datatable .= '<tr'.$css_class.'>'.
7480: '<td><span class="LC_nobreak">'.$titles->{$item}.
7481: '</span></td><td class="LC_right_item" colspan="3">';
7482: if ($item eq 'auth_def') {
7483: my @authtypes = ('internal','krb4','krb5','localauth');
7484: my %shortauth = (
7485: internal => 'int',
7486: krb4 => 'krb4',
7487: krb5 => 'krb5',
7488: localauth => 'loc'
7489: );
7490: my %authnames = &authtype_names();
7491: foreach my $auth (@authtypes) {
7492: my $checked = ' ';
7493: if ($defaults{$item} eq $auth) {
7494: $checked = ' checked="checked" ';
7495: }
7496: $datatable .= '<label><input type="radio" name="'.$item.
7497: '" value="'.$auth.'"'.$checked.'/>'.
7498: $authnames{$shortauth{$auth}}.'</label> ';
7499: }
7500: } elsif ($item eq 'timezone_def') {
7501: my $includeempty = 1;
7502: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
7503: } elsif ($item eq 'datelocale_def') {
1.160.6.98 raeburn 7504: my $includeempty = 1;
7505: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
7506: } elsif ($item eq 'lang_def') {
7507: my $includeempty = 1;
7508: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.80 raeburn 7509: } else {
1.160.6.98 raeburn 7510: my $size;
7511: if ($item eq 'portal_def') {
7512: $size = ' size="25"';
7513: }
1.160.6.80 raeburn 7514: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.98 raeburn 7515: $defaults{$item}.'"'.$size.' />';
1.160.6.80 raeburn 7516: }
7517: $datatable .= '</td></tr>';
7518: $rownum ++;
7519: }
1.160.6.40 raeburn 7520: } else {
1.160.6.80 raeburn 7521: my %defaults;
1.160.6.40 raeburn 7522: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 7523: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 7524: my $maxnum = @{$settings->{'inststatusorder'}};
7525: for (my $i=0; $i<$maxnum; $i++) {
7526: $css_class = $rownum%2?' class="LC_odd_row"':'';
7527: my $item = $settings->{'inststatusorder'}->[$i];
7528: my $title = $settings->{'inststatustypes'}->{$item};
7529: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
7530: $datatable .= '<tr'.$css_class.'>'.
7531: '<td><span class="LC_nobreak">'.
7532: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
7533: for (my $k=0; $k<=$maxnum; $k++) {
7534: my $vpos = $k+1;
7535: my $selstr;
7536: if ($k == $i) {
7537: $selstr = ' selected="selected" ';
7538: }
7539: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7540: }
7541: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
7542: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
7543: &mt('delete').'</span></td>'.
1.160.6.112 raeburn 7544: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.160.6.40 raeburn 7545: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 7546: '</span></td></tr>';
1.160.6.40 raeburn 7547: }
7548: $css_class = $rownum%2?' class="LC_odd_row"':'';
7549: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
7550: $datatable .= '<tr '.$css_class.'>'.
7551: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
7552: for (my $k=0; $k<=$maxnum; $k++) {
7553: my $vpos = $k+1;
7554: my $selstr;
7555: if ($k == $maxnum) {
7556: $selstr = ' selected="selected" ';
7557: }
7558: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7559: }
7560: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 7561: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 7562: ' '.&mt('(new)').
7563: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.112 raeburn 7564: &mt('Name displayed').':'.
1.160.6.40 raeburn 7565: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
7566: '</tr>'."\n";
7567: $rownum ++;
1.141 raeburn 7568: }
1.43 raeburn 7569: }
7570: }
7571: $$rowtotal += $rownum;
7572: return $datatable;
7573: }
7574:
1.160.6.5 raeburn 7575: sub get_languages_hash {
7576: my %langchoices;
7577: foreach my $id (&Apache::loncommon::languageids()) {
7578: my $code = &Apache::loncommon::supportedlanguagecode($id);
7579: if ($code ne '') {
7580: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
7581: }
7582: }
7583: return %langchoices;
7584: }
7585:
1.43 raeburn 7586: sub defaults_titles {
1.141 raeburn 7587: my ($dom) = @_;
1.43 raeburn 7588: my %titles = &Apache::lonlocal::texthash (
7589: 'auth_def' => 'Default authentication type',
7590: 'auth_arg_def' => 'Default authentication argument',
7591: 'lang_def' => 'Default language',
1.54 raeburn 7592: 'timezone_def' => 'Default timezone',
1.68 raeburn 7593: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 7594: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 7595: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
7596: 'intauth_check' => 'Check bcrypt cost if authenticated',
7597: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 7598: );
1.141 raeburn 7599: if ($dom) {
7600: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
7601: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
7602: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
7603: $protocol = 'http' if ($protocol ne 'https');
7604: if ($uint_dom) {
7605: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
7606: $uint_dom);
7607: }
7608: }
1.43 raeburn 7609: return (\%titles);
7610: }
7611:
1.160.6.97 raeburn 7612: sub print_scantron {
7613: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
7614: if ($position eq 'top') {
7615: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
7616: } else {
7617: return &print_scantronconfig($dom,$settings,\$rowtotal);
7618: }
7619: }
7620:
7621: sub scantron_javascript {
7622: return <<"ENDSCRIPT";
7623:
7624: <script type="text/javascript">
7625: // <![CDATA[
7626:
7627: function toggleScantron(form) {
7628: var csvfieldset = new Array();
7629: if (document.getElementById('scantroncsv_cols')) {
7630: csvfieldset.push(document.getElementById('scantroncsv_cols'));
7631: }
7632: if (document.getElementById('scantroncsv_options')) {
7633: csvfieldset.push(document.getElementById('scantroncsv_options'));
7634: }
7635: if (csvfieldset.length) {
7636: if (document.getElementById('scantronconfcsv')) {
7637: var scantroncsv = document.getElementById('scantronconfcsv');
7638: if (scantroncsv.checked) {
7639: for (var i=0; i<csvfieldset.length; i++) {
7640: csvfieldset[i].style.display = 'block';
7641: }
7642: } else {
7643: for (var i=0; i<csvfieldset.length; i++) {
7644: csvfieldset[i].style.display = 'none';
7645: }
7646: var csvselects = document.getElementsByClassName('scantronconfig_csv');
7647: if (csvselects.length) {
7648: for (var j=0; j<csvselects.length; j++) {
7649: csvselects[j].selectedIndex = 0;
7650: }
7651: }
7652: }
7653: }
7654: }
7655: return;
7656: }
7657: // ]]>
7658: </script>
7659:
7660: ENDSCRIPT
7661:
7662: }
7663:
1.46 raeburn 7664: sub print_scantronformat {
7665: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
7666: my $itemcount = 1;
1.60 raeburn 7667: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
7668: %confhash);
1.46 raeburn 7669: my $switchserver = &check_switchserver($dom,$confname);
7670: my %lt = &Apache::lonlocal::texthash (
1.95 www 7671: default => 'Default bubblesheet format file error',
7672: custom => 'Custom bubblesheet format file error',
1.46 raeburn 7673: );
7674: my %scantronfiles = (
7675: default => 'default.tab',
7676: custom => 'custom.tab',
7677: );
7678: foreach my $key (keys(%scantronfiles)) {
7679: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
7680: .$scantronfiles{$key};
7681: }
7682: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
7683: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
7684: if (!$switchserver) {
7685: my $servadm = $r->dir_config('lonAdmEMail');
7686: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
7687: if ($configuserok eq 'ok') {
7688: if ($author_ok eq 'ok') {
7689: my %legacyfile = (
1.160.6.97 raeburn 7690: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
7691: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 7692: );
7693: my %md5chk;
7694: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7695: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
7696: chomp($md5chk{$type});
1.46 raeburn 7697: }
7698: if ($md5chk{'default'} ne $md5chk{'custom'}) {
7699: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 7700: ($scantronurls{$type},my $error) =
1.46 raeburn 7701: &legacy_scantronformat($r,$dom,$confname,
7702: $type,$legacyfile{$type},
7703: $scantronurls{$type},
7704: $scantronfiles{$type});
1.60 raeburn 7705: if ($error ne '') {
7706: $error{$type} = $error;
7707: }
7708: }
7709: if (keys(%error) == 0) {
7710: $is_custom = 1;
1.160.6.97 raeburn 7711: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 7712: $scantronurls{'custom'};
1.160.6.97 raeburn 7713: my $putresult =
1.60 raeburn 7714: &Apache::lonnet::put_dom('configuration',
7715: \%confhash,$dom);
7716: if ($putresult ne 'ok') {
1.160.6.97 raeburn 7717: $error{'custom'} =
1.60 raeburn 7718: '<span class="LC_error">'.
7719: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7720: }
1.46 raeburn 7721: }
7722: } else {
1.60 raeburn 7723: ($scantronurls{'default'},my $error) =
1.46 raeburn 7724: &legacy_scantronformat($r,$dom,$confname,
7725: 'default',$legacyfile{'default'},
7726: $scantronurls{'default'},
7727: $scantronfiles{'default'});
1.60 raeburn 7728: if ($error eq '') {
7729: $confhash{'scantron'}{'scantronformat'} = '';
7730: my $putresult =
7731: &Apache::lonnet::put_dom('configuration',
7732: \%confhash,$dom);
7733: if ($putresult ne 'ok') {
7734: $error{'default'} =
7735: '<span class="LC_error">'.
7736: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7737: }
7738: } else {
7739: $error{'default'} = $error;
7740: }
1.46 raeburn 7741: }
7742: }
7743: }
7744: } else {
1.95 www 7745: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 7746: }
7747: }
7748: if (ref($settings) eq 'HASH') {
7749: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
7750: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
7751: if ((!@info) || ($info[0] eq 'no_such_dir')) {
7752: $scantronurl = '';
7753: } else {
7754: $scantronurl = $settings->{'scantronformat'};
7755: }
7756: $is_custom = 1;
7757: } else {
7758: $scantronurl = $scantronurls{'default'};
7759: }
7760: } else {
1.60 raeburn 7761: if ($is_custom) {
7762: $scantronurl = $scantronurls{'custom'};
7763: } else {
7764: $scantronurl = $scantronurls{'default'};
7765: }
1.46 raeburn 7766: }
7767: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7768: $datatable .= '<tr'.$css_class.'>';
7769: if (!$is_custom) {
1.65 raeburn 7770: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
7771: '<span class="LC_nobreak">';
1.46 raeburn 7772: if ($scantronurl) {
1.160.6.21 raeburn 7773: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
7774: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 7775: } else {
7776: $datatable = &mt('File unavailable for display');
7777: }
1.65 raeburn 7778: $datatable .= '</span></td>';
1.60 raeburn 7779: if (keys(%error) == 0) {
7780: $datatable .= '<td valign="bottom">';
7781: if (!$switchserver) {
7782: $datatable .= &mt('Upload:').'<br />';
7783: }
7784: } else {
7785: my $errorstr;
7786: foreach my $key (sort(keys(%error))) {
7787: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7788: }
7789: $datatable .= '<td>'.$errorstr;
7790: }
1.46 raeburn 7791: } else {
7792: if (keys(%error) > 0) {
7793: my $errorstr;
7794: foreach my $key (sort(keys(%error))) {
7795: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7796: }
1.60 raeburn 7797: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 7798: } elsif ($scantronurl) {
1.160.6.26 raeburn 7799: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 7800: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 7801: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 7802: $link.
7803: '<label><input type="checkbox" name="scantronformat_del"'.
7804: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 7805: '<td><span class="LC_nobreak"> '.
7806: &mt('Replace:').'</span><br />';
1.46 raeburn 7807: }
7808: }
7809: if (keys(%error) == 0) {
7810: if ($switchserver) {
7811: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
7812: } else {
1.65 raeburn 7813: $datatable .='<span class="LC_nobreak"> '.
7814: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 7815: }
7816: }
7817: $datatable .= '</td></tr>';
7818: $$rowtotal ++;
7819: return $datatable;
7820: }
7821:
7822: sub legacy_scantronformat {
7823: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
7824: my ($url,$error);
7825: my @statinfo = &Apache::lonnet::stat_file($newurl);
7826: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
7827: (my $result,$url) =
7828: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
7829: '','',$newfile);
7830: if ($result ne 'ok') {
1.130 raeburn 7831: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 7832: }
7833: }
7834: return ($url,$error);
7835: }
1.43 raeburn 7836:
1.160.6.97 raeburn 7837: sub print_scantronconfig {
7838: my ($dom,$settings,$rowtotal) = @_;
7839: my $itemcount = 2;
7840: my $is_checked = ' checked="checked"';
7841: my %optionson = (
7842: hdr => ' checked="checked"',
7843: pad => ' checked="checked"',
7844: rem => ' checked="checked"',
7845: );
7846: my %optionsoff = (
7847: hdr => '',
7848: pad => '',
7849: rem => '',
7850: );
7851: my $currcsvsty = 'none';
7852: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
7853: my @fields = &scantroncsv_fields();
7854: my %titles = &scantronconfig_titles();
7855: if (ref($settings) eq 'HASH') {
7856: if (ref($settings->{config}) eq 'HASH') {
7857: if ($settings->{config}->{dat}) {
7858: $checked{'dat'} = $is_checked;
7859: }
7860: if (ref($settings->{config}->{csv}) eq 'HASH') {
7861: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
7862: %csvfields = %{$settings->{config}->{csv}->{fields}};
7863: if (keys(%csvfields) > 0) {
7864: $checked{'csv'} = $is_checked;
7865: $currcsvsty = 'block';
7866: }
7867: }
7868: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
7869: %csvoptions = %{$settings->{config}->{csv}->{options}};
7870: foreach my $option (keys(%optionson)) {
7871: unless ($csvoptions{$option}) {
7872: $optionsoff{$option} = $optionson{$option};
7873: $optionson{$option} = '';
7874: }
7875: }
7876: }
7877: }
7878: } else {
7879: $checked{'dat'} = $is_checked;
7880: }
7881: } else {
7882: $checked{'dat'} = $is_checked;
7883: }
7884: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
7885: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7886: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
7887: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
7888: foreach my $item ('dat','csv') {
7889: my $id;
7890: if ($item eq 'csv') {
7891: $id = 'id="scantronconfcsv" ';
7892: }
7893: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
7894: $titles{$item}.'</label>'.(' 'x3);
7895: if ($item eq 'csv') {
7896: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
7897: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
7898: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
7899: foreach my $col (@fields) {
7900: my $selnone;
7901: if ($csvfields{$col} eq '') {
7902: $selnone = ' selected="selected"';
7903: }
7904: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
7905: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
7906: '<option value=""'.$selnone.'></option>';
7907: for (my $i=0; $i<20; $i++) {
7908: my $shown = $i+1;
7909: my $sel;
7910: unless ($selnone) {
7911: if (exists($csvfields{$col})) {
7912: if ($csvfields{$col} == $i) {
7913: $sel = ' selected="selected"';
7914: }
7915: }
7916: }
7917: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
7918: }
7919: $datatable .= '</select></td></tr>';
7920: }
7921: $datatable .= '</table></fieldset>'.
7922: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
7923: '<legend>'.&mt('CSV Options').'</legend>';
7924: foreach my $option ('hdr','pad','rem') {
7925: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
7926: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
7927: &mt('Yes').'</label>'.(' 'x2)."\n".
7928: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
7929: }
7930: $datatable .= '</fieldset>';
7931: $itemcount ++;
7932: }
7933: }
7934: $datatable .= '</td></tr>';
7935: $$rowtotal ++;
7936: return $datatable;
7937: }
7938:
7939: sub scantronconfig_titles {
7940: return &Apache::lonlocal::texthash(
7941: dat => 'Standard format (.dat)',
7942: csv => 'Comma separated values (.csv)',
7943: hdr => 'Remove first line in file (contains column titles)',
7944: pad => 'Prepend 0s to PaperID',
7945: rem => 'Remove leading spaces (except Question Response columns)',
7946: CODE => 'CODE',
7947: ID => 'Student ID',
7948: PaperID => 'Paper ID',
7949: FirstName => 'First Name',
7950: LastName => 'Last Name',
7951: FirstQuestion => 'First Question Response',
7952: Section => 'Section',
7953: );
7954: }
7955:
7956: sub scantroncsv_fields {
7957: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
7958: }
7959:
1.49 raeburn 7960: sub print_coursecategories {
1.57 raeburn 7961: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
7962: my $datatable;
7963: if ($position eq 'top') {
1.160.6.42 raeburn 7964: my (%checked);
7965: my @catitems = ('unauth','auth');
7966: my @cattypes = ('std','domonly','codesrch','none');
7967: $checked{'unauth'} = 'std';
7968: $checked{'auth'} = 'std';
7969: if (ref($settings) eq 'HASH') {
7970: foreach my $type (@cattypes) {
7971: if ($type eq $settings->{'unauth'}) {
7972: $checked{'unauth'} = $type;
7973: }
7974: if ($type eq $settings->{'auth'}) {
7975: $checked{'auth'} = $type;
7976: }
7977: }
7978: }
7979: my %lt = &Apache::lonlocal::texthash (
7980: unauth => 'Catalog type for unauthenticated users',
7981: auth => 'Catalog type for authenticated users',
7982: none => 'No catalog',
7983: std => 'Standard catalog',
7984: domonly => 'Domain-only catalog',
7985: codesrch => "Code search form",
7986: );
7987: my $itemcount = 0;
7988: foreach my $item (@catitems) {
7989: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7990: $datatable .= '<tr '.$css_class.'>'.
7991: '<td>'.$lt{$item}.'</td>'.
7992: '<td class="LC_right_item"><span class="LC_nobreak">';
7993: foreach my $type (@cattypes) {
7994: my $ischecked;
7995: if ($checked{$item} eq $type) {
7996: $ischecked=' checked="checked"';
7997: }
7998: $datatable .= '<label>'.
7999: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
8000: ' />'.$lt{$type}.'</label> ';
8001: }
1.160.6.87 raeburn 8002: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 8003: $itemcount ++;
8004: }
8005: $$rowtotal += $itemcount;
8006: } elsif ($position eq 'middle') {
1.57 raeburn 8007: my $toggle_cats_crs = ' ';
8008: my $toggle_cats_dom = ' checked="checked" ';
8009: my $can_cat_crs = ' ';
8010: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 8011: my $toggle_catscomm_comm = ' ';
8012: my $toggle_catscomm_dom = ' checked="checked" ';
8013: my $can_catcomm_comm = ' ';
8014: my $can_catcomm_dom = ' checked="checked" ';
8015:
1.57 raeburn 8016: if (ref($settings) eq 'HASH') {
8017: if ($settings->{'togglecats'} eq 'crs') {
8018: $toggle_cats_crs = $toggle_cats_dom;
8019: $toggle_cats_dom = ' ';
8020: }
8021: if ($settings->{'categorize'} eq 'crs') {
8022: $can_cat_crs = $can_cat_dom;
8023: $can_cat_dom = ' ';
8024: }
1.120 raeburn 8025: if ($settings->{'togglecatscomm'} eq 'comm') {
8026: $toggle_catscomm_comm = $toggle_catscomm_dom;
8027: $toggle_catscomm_dom = ' ';
8028: }
8029: if ($settings->{'categorizecomm'} eq 'comm') {
8030: $can_catcomm_comm = $can_catcomm_dom;
8031: $can_catcomm_dom = ' ';
8032: }
1.57 raeburn 8033: }
8034: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 8035: togglecats => 'Show/Hide a course in catalog',
8036: togglecatscomm => 'Show/Hide a community in catalog',
8037: categorize => 'Assign a category to a course',
8038: categorizecomm => 'Assign a category to a community',
1.57 raeburn 8039: );
8040: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 8041: dom => 'Set in Domain',
8042: crs => 'Set in Course',
8043: comm => 'Set in Community',
1.57 raeburn 8044: );
8045: $datatable = '<tr class="LC_odd_row">'.
8046: '<td>'.$title{'togglecats'}.'</td>'.
8047: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8048: '<input type="radio" name="togglecats"'.
8049: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8050: '<label><input type="radio" name="togglecats"'.
8051: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
8052: '</tr><tr>'.
8053: '<td>'.$title{'categorize'}.'</td>'.
8054: '<td class="LC_right_item"><span class="LC_nobreak">'.
8055: '<label><input type="radio" name="categorize"'.
8056: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8057: '<label><input type="radio" name="categorize"'.
8058: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 8059: '</tr><tr class="LC_odd_row">'.
8060: '<td>'.$title{'togglecatscomm'}.'</td>'.
8061: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8062: '<input type="radio" name="togglecatscomm"'.
8063: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8064: '<label><input type="radio" name="togglecatscomm"'.
8065: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
8066: '</tr><tr>'.
8067: '<td>'.$title{'categorizecomm'}.'</td>'.
8068: '<td class="LC_right_item"><span class="LC_nobreak">'.
8069: '<label><input type="radio" name="categorizecomm"'.
8070: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8071: '<label><input type="radio" name="categorizecomm"'.
8072: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 8073: '</tr>';
1.120 raeburn 8074: $$rowtotal += 4;
1.57 raeburn 8075: } else {
8076: my $css_class;
8077: my $itemcount = 1;
8078: my $cathash;
8079: if (ref($settings) eq 'HASH') {
8080: $cathash = $settings->{'cats'};
8081: }
8082: if (ref($cathash) eq 'HASH') {
8083: my (@cats,@trails,%allitems,%idx,@jsarray);
8084: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
8085: \%allitems,\%idx,\@jsarray);
8086: my $maxdepth = scalar(@cats);
8087: my $colattrib = '';
8088: if ($maxdepth > 2) {
8089: $colattrib = ' colspan="2" ';
8090: }
8091: my @path;
8092: if (@cats > 0) {
8093: if (ref($cats[0]) eq 'ARRAY') {
8094: my $numtop = @{$cats[0]};
8095: my $maxnum = $numtop;
1.120 raeburn 8096: my %default_names = (
8097: instcode => &mt('Official courses'),
8098: communities => &mt('Communities'),
8099: );
8100:
8101: if ((!grep(/^instcode$/,@{$cats[0]})) ||
8102: ($cathash->{'instcode::0'} eq '') ||
8103: (!grep(/^communities$/,@{$cats[0]})) ||
8104: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 8105: $maxnum ++;
8106: }
8107: my $lastidx;
8108: for (my $i=0; $i<$numtop; $i++) {
8109: my $parent = $cats[0][$i];
8110: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8111: my $item = &escape($parent).'::0';
8112: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
8113: $lastidx = $idx{$item};
8114: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8115: .'<select name="'.$item.'"'.$chgstr.'>';
8116: for (my $k=0; $k<=$maxnum; $k++) {
8117: my $vpos = $k+1;
8118: my $selstr;
8119: if ($k == $i) {
8120: $selstr = ' selected="selected" ';
8121: }
8122: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8123: }
1.160.6.29 raeburn 8124: $datatable .= '</select></span></td><td>';
1.120 raeburn 8125: if ($parent eq 'instcode' || $parent eq 'communities') {
8126: $datatable .= '<span class="LC_nobreak">'
8127: .$default_names{$parent}.'</span>';
8128: if ($parent eq 'instcode') {
8129: $datatable .= '<br /><span class="LC_nobreak">('
8130: .&mt('with institutional codes')
8131: .')</span></td><td'.$colattrib.'>';
8132: } else {
8133: $datatable .= '<table><tr><td>';
8134: }
8135: $datatable .= '<span class="LC_nobreak">'
8136: .'<label><input type="radio" name="'
8137: .$parent.'" value="1" checked="checked" />'
8138: .&mt('Display').'</label>';
8139: if ($parent eq 'instcode') {
8140: $datatable .= ' ';
8141: } else {
8142: $datatable .= '</span></td></tr><tr><td>'
8143: .'<span class="LC_nobreak">';
8144: }
8145: $datatable .= '<label><input type="radio" name="'
8146: .$parent.'" value="0" />'
8147: .&mt('Do not display').'</label></span>';
8148: if ($parent eq 'communities') {
8149: $datatable .= '</td></tr></table>';
8150: }
8151: $datatable .= '</td>';
1.57 raeburn 8152: } else {
8153: $datatable .= $parent
1.160.6.29 raeburn 8154: .' <span class="LC_nobreak"><label>'
8155: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 8156: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
8157: }
8158: my $depth = 1;
8159: push(@path,$parent);
8160: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
8161: pop(@path);
8162: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8163: $itemcount ++;
8164: }
1.48 raeburn 8165: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 8166: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
8167: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 8168: for (my $k=0; $k<=$maxnum; $k++) {
8169: my $vpos = $k+1;
8170: my $selstr;
1.57 raeburn 8171: if ($k == $numtop) {
1.48 raeburn 8172: $selstr = ' selected="selected" ';
8173: }
8174: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8175: }
1.59 bisitz 8176: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 8177: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
8178: .'</tr>'."\n";
1.48 raeburn 8179: $itemcount ++;
1.120 raeburn 8180: foreach my $default ('instcode','communities') {
8181: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
8182: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8183: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
8184: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
8185: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
8186: for (my $k=0; $k<=$maxnum; $k++) {
8187: my $vpos = $k+1;
8188: my $selstr;
8189: if ($k == $maxnum) {
8190: $selstr = ' selected="selected" ';
8191: }
8192: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 8193: }
1.120 raeburn 8194: $datatable .= '</select></span></td>'.
8195: '<td><span class="LC_nobreak">'.
8196: $default_names{$default}.'</span>';
8197: if ($default eq 'instcode') {
8198: $datatable .= '<br /><span class="LC_nobreak">('
8199: .&mt('with institutional codes').')</span>';
8200: }
8201: $datatable .= '</td>'
8202: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
8203: .&mt('Display').'</label> '
8204: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
8205: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 8206: }
8207: }
8208: }
1.57 raeburn 8209: } else {
8210: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 8211: }
8212: } else {
1.160.6.87 raeburn 8213: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 8214: .&initialize_categories($itemcount);
1.48 raeburn 8215: }
1.57 raeburn 8216: $$rowtotal += $itemcount;
1.48 raeburn 8217: }
8218: return $datatable;
8219: }
8220:
1.69 raeburn 8221: sub print_serverstatuses {
8222: my ($dom,$settings,$rowtotal) = @_;
8223: my $datatable;
8224: my @pages = &serverstatus_pages();
8225: my (%namedaccess,%machineaccess);
8226: foreach my $type (@pages) {
8227: $namedaccess{$type} = '';
8228: $machineaccess{$type}= '';
8229: }
8230: if (ref($settings) eq 'HASH') {
8231: foreach my $type (@pages) {
8232: if (exists($settings->{$type})) {
8233: if (ref($settings->{$type}) eq 'HASH') {
8234: foreach my $key (keys(%{$settings->{$type}})) {
8235: if ($key eq 'namedusers') {
8236: $namedaccess{$type} = $settings->{$type}->{$key};
8237: } elsif ($key eq 'machines') {
8238: $machineaccess{$type} = $settings->{$type}->{$key};
8239: }
8240: }
8241: }
8242: }
8243: }
8244: }
1.81 raeburn 8245: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8246: my $rownum = 0;
8247: my $css_class;
8248: foreach my $type (@pages) {
8249: $rownum ++;
8250: $css_class = $rownum%2?' class="LC_odd_row"':'';
8251: $datatable .= '<tr'.$css_class.'>'.
8252: '<td><span class="LC_nobreak">'.
8253: $titles->{$type}.'</span></td>'.
8254: '<td class="LC_left_item">'.
8255: '<input type="text" name="'.$type.'_namedusers" '.
8256: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
8257: '<td class="LC_right_item">'.
8258: '<span class="LC_nobreak">'.
8259: '<input type="text" name="'.$type.'_machines" '.
8260: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 8261: '</span></td></tr>'."\n";
1.69 raeburn 8262: }
8263: $$rowtotal += $rownum;
8264: return $datatable;
8265: }
8266:
8267: sub serverstatus_pages {
8268: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 8269: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 8270: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 8271: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 8272: }
8273:
1.160.6.40 raeburn 8274: sub defaults_javascript {
8275: my ($settings) = @_;
1.160.6.98 raeburn 8276: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 8277: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8278: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
8279: if ($maxnum eq '') {
8280: $maxnum = 0;
8281: }
8282: $maxnum ++;
1.160.6.51 raeburn 8283: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 8284: return <<"ENDSCRIPT";
8285: <script type="text/javascript">
8286: // <![CDATA[
8287: function reorderTypes(form,caller) {
8288: var changedVal;
8289: $jstext
8290: var newpos = 'addinststatus_pos';
8291: var current = new Array;
8292: var maxh = $maxnum;
8293: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8294: var oldVal;
8295: if (caller == newpos) {
8296: changedVal = newitemVal;
8297: } else {
8298: var curritem = 'inststatus_pos_'+caller;
8299: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
8300: current[newitemVal] = newpos;
8301: }
8302: for (var i=0; i<inststatuses.length; i++) {
8303: if (inststatuses[i] != caller) {
8304: var elementName = 'inststatus_pos_'+inststatuses[i];
8305: if (form.elements[elementName]) {
8306: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8307: current[currVal] = elementName;
8308: }
8309: }
8310: }
8311: for (var j=0; j<maxh; j++) {
8312: if (current[j] == undefined) {
8313: oldVal = j;
8314: }
8315: }
8316: if (oldVal < changedVal) {
8317: for (var k=oldVal+1; k<=changedVal ; k++) {
8318: var elementName = current[k];
8319: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8320: }
8321: } else {
8322: for (var k=changedVal; k<oldVal; k++) {
8323: var elementName = current[k];
8324: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8325: }
8326: }
8327: return;
8328: }
8329:
8330: // ]]>
8331: </script>
8332:
8333: ENDSCRIPT
8334: }
8335: }
8336:
1.160.6.98 raeburn 8337: sub passwords_javascript {
1.160.6.99 raeburn 8338: my %intalert = &Apache::lonlocal::texthash (
8339: 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.',
8340: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
8341: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
8342: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
8343: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
8344: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
8345: );
8346: &js_escape(\%intalert);
8347: my $defmin = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 8348: my $intauthjs = <<"ENDSCRIPT";
8349:
8350: function warnIntAuth(field) {
8351: if (field.name == 'intauth_check') {
8352: if (field.value == '2') {
1.160.6.99 raeburn 8353: alert('$intalert{authcheck}');
1.160.6.98 raeburn 8354: }
8355: }
8356: if (field.name == 'intauth_cost') {
8357: field.value.replace(/\s/g,'');
8358: if (field.value != '') {
8359: var regexdigit=/^\\d+\$/;
8360: if (!regexdigit.test(field.value)) {
1.160.6.99 raeburn 8361: alert('$intalert{authcost}');
8362: }
8363: }
8364: }
8365: return;
8366: }
8367:
8368: function warnIntPass(field) {
8369: field.value.replace(/^\s+/,'');
8370: field.value.replace(/\s+\$/,'');
8371: var regexdigit=/^\\d+\$/;
8372: if (field.name == 'passwords_min') {
8373: if (field.value == '') {
8374: alert('$intalert{passmin}');
8375: field.value = '$defmin';
8376: } else {
8377: if (!regexdigit.test(field.value)) {
8378: alert('$intalert{passmin}');
8379: field.value = '$defmin';
8380: }
8381: var minval = parseInt(field.value,10);
8382: if (minval < $defmin) {
8383: alert('$intalert{passmin}');
8384: field.value = '$defmin';
8385: }
8386: }
8387: } else {
8388: if (field.value == '0') {
8389: field.value = '';
8390: }
8391: if (field.value != '') {
8392: if (field.name == 'passwords_expire') {
8393: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
8394: if (!regexpposnum.test(field.value)) {
8395: alert('$intalert{passexp}');
8396: field.value = '';
8397: } else {
8398: var expval = parseFloat(field.value);
8399: if (expval == 0) {
8400: alert('$intalert{passexp}');
8401: field.value = '';
8402: }
8403: }
8404: } else {
8405: if (!regexdigit.test(field.value)) {
8406: if (field.name == 'passwords_max') {
8407: alert('$intalert{passmax}');
8408: } else {
8409: if (field.name == 'passwords_numsaved') {
8410: alert('$intalert{passnum}');
8411: }
8412: }
1.160.6.104 raeburn 8413: field.value = '';
1.160.6.99 raeburn 8414: }
1.160.6.98 raeburn 8415: }
8416: }
8417: }
8418: return;
8419: }
8420:
8421: ENDSCRIPT
8422: return &Apache::lonhtmlcommon::scripttag($intauthjs);
8423: }
8424:
1.49 raeburn 8425: sub coursecategories_javascript {
8426: my ($settings) = @_;
1.57 raeburn 8427: my ($output,$jstext,$cathash);
1.49 raeburn 8428: if (ref($settings) eq 'HASH') {
1.57 raeburn 8429: $cathash = $settings->{'cats'};
8430: }
8431: if (ref($cathash) eq 'HASH') {
1.49 raeburn 8432: my (@cats,@jsarray,%idx);
1.57 raeburn 8433: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 8434: if (@jsarray > 0) {
8435: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
8436: for (my $i=0; $i<@jsarray; $i++) {
8437: if (ref($jsarray[$i]) eq 'ARRAY') {
8438: my $catstr = join('","',@{$jsarray[$i]});
8439: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
8440: }
8441: }
8442: }
8443: } else {
8444: $jstext = ' var categories = Array(1);'."\n".
8445: ' categories[0] = Array("instcode_pos");'."\n";
8446: }
1.160.6.42 raeburn 8447: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
8448: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 8449: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
8450: &js_escape(\$instcode_reserved);
8451: &js_escape(\$communities_reserved);
8452: &js_escape(\$choose_again);
1.49 raeburn 8453: $output = <<"ENDSCRIPT";
8454: <script type="text/javascript">
1.109 raeburn 8455: // <![CDATA[
1.49 raeburn 8456: function reorderCats(form,parent,item,idx) {
8457: var changedVal;
8458: $jstext
8459: var newpos = 'addcategory_pos';
8460: if (parent == '') {
8461: var has_instcode = 0;
8462: var maxtop = categories[idx].length;
8463: for (var j=0; j<maxtop; j++) {
8464: if (categories[idx][j] == 'instcode::0') {
8465: has_instcode == 1;
8466: }
8467: }
8468: if (has_instcode == 0) {
8469: categories[idx][maxtop] = 'instcode_pos';
8470: }
8471: } else {
8472: newpos += '_'+parent;
8473: }
8474: var maxh = 1 + categories[idx].length;
8475: var current = new Array;
8476: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8477: if (item == newpos) {
8478: changedVal = newitemVal;
8479: } else {
8480: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
8481: current[newitemVal] = newpos;
8482: }
8483: for (var i=0; i<categories[idx].length; i++) {
8484: var elementName = categories[idx][i];
8485: if (elementName != item) {
8486: if (form.elements[elementName]) {
8487: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8488: current[currVal] = elementName;
8489: }
8490: }
8491: }
8492: var oldVal;
8493: for (var j=0; j<maxh; j++) {
8494: if (current[j] == undefined) {
8495: oldVal = j;
8496: }
8497: }
8498: if (oldVal < changedVal) {
8499: for (var k=oldVal+1; k<=changedVal ; k++) {
8500: var elementName = current[k];
8501: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8502: }
8503: } else {
8504: for (var k=changedVal; k<oldVal; k++) {
8505: var elementName = current[k];
8506: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8507: }
8508: }
8509: return;
8510: }
1.120 raeburn 8511:
8512: function categoryCheck(form) {
8513: if (form.elements['addcategory_name'].value == 'instcode') {
8514: alert('$instcode_reserved\\n$choose_again');
8515: return false;
8516: }
8517: if (form.elements['addcategory_name'].value == 'communities') {
8518: alert('$communities_reserved\\n$choose_again');
8519: return false;
8520: }
8521: return true;
8522: }
8523:
1.109 raeburn 8524: // ]]>
1.49 raeburn 8525: </script>
8526:
8527: ENDSCRIPT
8528: return $output;
8529: }
8530:
1.48 raeburn 8531: sub initialize_categories {
8532: my ($itemcount) = @_;
1.120 raeburn 8533: my ($datatable,$css_class,$chgstr);
1.160.6.111 raeburn 8534: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 8535: instcode => 'Official courses (with institutional codes)',
8536: communities => 'Communities',
8537: );
8538: my $select0 = ' selected="selected"';
8539: my $select1 = '';
8540: foreach my $default ('instcode','communities') {
8541: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 8542: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 8543: if ($default eq 'communities') {
8544: $select1 = $select0;
8545: $select0 = '';
8546: }
8547: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8548: .'<select name="'.$default.'_pos">'
8549: .'<option value="0"'.$select0.'>1</option>'
8550: .'<option value="1"'.$select1.'>2</option>'
8551: .'<option value="2">3</option></select> '
8552: .$default_names{$default}
8553: .'</span></td><td><span class="LC_nobreak">'
8554: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
8555: .&mt('Display').'</label> <label>'
8556: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 8557: .'</label></span></td></tr>';
1.120 raeburn 8558: $itemcount ++;
8559: }
1.48 raeburn 8560: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 8561: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 8562: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 8563: .'<select name="addcategory_pos"'.$chgstr.'>'
8564: .'<option value="0">1</option>'
8565: .'<option value="1">2</option>'
8566: .'<option value="2" selected="selected">3</option></select> '
1.160.6.103 raeburn 8567: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
1.160.6.87 raeburn 8568: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
8569: .'</td></tr>';
1.48 raeburn 8570: return $datatable;
8571: }
8572:
8573: sub build_category_rows {
1.49 raeburn 8574: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
8575: my ($text,$name,$item,$chgstr);
1.48 raeburn 8576: if (ref($cats) eq 'ARRAY') {
8577: my $maxdepth = scalar(@{$cats});
8578: if (ref($cats->[$depth]) eq 'HASH') {
8579: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8580: my $numchildren = @{$cats->[$depth]{$parent}};
8581: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 8582: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 8583: my ($idxnum,$parent_name,$parent_item);
8584: my $higher = $depth - 1;
8585: if ($higher == 0) {
8586: $parent_name = &escape($parent).'::'.$higher;
8587: } else {
8588: if (ref($path) eq 'ARRAY') {
8589: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8590: }
8591: }
8592: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 8593: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 8594: if ($j < $numchildren) {
1.48 raeburn 8595: $name = $cats->[$depth]{$parent}[$j];
8596: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 8597: $idxnum = $idx->{$item};
8598: } else {
8599: $name = $parent_name;
8600: $item = $parent_item;
1.48 raeburn 8601: }
1.49 raeburn 8602: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8603: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 8604: for (my $i=0; $i<=$numchildren; $i++) {
8605: my $vpos = $i+1;
8606: my $selstr;
8607: if ($j == $i) {
8608: $selstr = ' selected="selected" ';
8609: }
8610: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8611: }
8612: $text .= '</select> ';
8613: if ($j < $numchildren) {
8614: my $deeper = $depth+1;
8615: $text .= $name.' '
8616: .'<label><input type="checkbox" name="deletecategory" value="'
8617: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8618: if(ref($path) eq 'ARRAY') {
8619: push(@{$path},$name);
1.49 raeburn 8620: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 8621: pop(@{$path});
8622: }
8623: } else {
1.160.6.87 raeburn 8624: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 8625: if ($j == $numchildren) {
8626: $text .= $name;
8627: } else {
8628: $text .= $item;
8629: }
8630: $text .= '" value="" />';
8631: }
8632: $text .= '</td></tr>';
8633: }
8634: $text .= '</table></td>';
8635: } else {
8636: my $higher = $depth-1;
8637: if ($higher == 0) {
8638: $name = &escape($parent).'::'.$higher;
8639: } else {
8640: if (ref($path) eq 'ARRAY') {
8641: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8642: }
8643: }
8644: my $colspan;
8645: if ($parent ne 'instcode') {
8646: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 8647: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 8648: }
8649: }
8650: }
8651: }
8652: return $text;
8653: }
8654:
1.33 raeburn 8655: sub modifiable_userdata_row {
1.160.6.93 raeburn 8656: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
8657: $rowid,$customcss,$rowstyle) = @_;
1.160.6.35 raeburn 8658: my ($role,$rolename,$statustype);
8659: $role = $item;
1.160.6.34 raeburn 8660: if ($context eq 'cancreate') {
1.160.6.93 raeburn 8661: if ($item =~ /^(emailusername)_(.+)$/) {
8662: $role = $1;
8663: $statustype = $2;
1.160.6.35 raeburn 8664: if (ref($usertypes) eq 'HASH') {
8665: if ($usertypes->{$statustype}) {
8666: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
8667: } else {
8668: $rolename = &mt('Data provided by user');
8669: }
8670: }
1.160.6.34 raeburn 8671: }
8672: } elsif ($context eq 'selfcreate') {
1.63 raeburn 8673: if (ref($usertypes) eq 'HASH') {
8674: $rolename = $usertypes->{$role};
8675: } else {
8676: $rolename = $role;
8677: }
1.33 raeburn 8678: } else {
1.63 raeburn 8679: if ($role eq 'cr') {
8680: $rolename = &mt('Custom role');
8681: } else {
8682: $rolename = &Apache::lonnet::plaintext($role);
8683: }
1.33 raeburn 8684: }
1.160.6.34 raeburn 8685: my (@fields,%fieldtitles);
8686: if (ref($fieldsref) eq 'ARRAY') {
8687: @fields = @{$fieldsref};
8688: } else {
8689: @fields = ('lastname','firstname','middlename','generation',
8690: 'permanentemail','id');
8691: }
8692: if ((ref($titlesref) eq 'HASH')) {
8693: %fieldtitles = %{$titlesref};
8694: } else {
8695: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8696: }
1.33 raeburn 8697: my $output;
1.160.6.93 raeburn 8698: my $css_class;
8699: if ($rowcount%2) {
8700: $css_class = 'LC_odd_row';
8701: }
8702: if ($customcss) {
8703: $css_class .= " $customcss";
8704: }
8705: $css_class =~ s/^\s+//;
8706: if ($css_class) {
8707: $css_class = ' class="'.$css_class.'"';
8708: }
8709: if ($rowstyle) {
8710: $css_class .= ' style="'.$rowstyle.'"';
8711: }
8712: if ($rowid) {
8713: $rowid = ' id="'.$rowid.'"';
8714: }
8715:
8716: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 8717: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
8718: '<td class="LC_left_item" colspan="2"><table>';
8719: my $rem;
8720: my %checks;
8721: if (ref($settings) eq 'HASH') {
8722: if (ref($settings->{$context}) eq 'HASH') {
8723: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 8724: my $hashref = $settings->{$context}->{$role};
8725: if ($role eq 'emailusername') {
8726: if ($statustype) {
8727: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
8728: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 8729: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 8730: foreach my $field (@fields) {
8731: if ($hashref->{$field}) {
8732: $checks{$field} = $hashref->{$field};
8733: }
8734: }
8735: }
8736: }
8737: }
8738: } else {
8739: if (ref($hashref) eq 'HASH') {
8740: foreach my $field (@fields) {
8741: if ($hashref->{$field}) {
8742: $checks{$field} = ' checked="checked" ';
8743: }
8744: }
1.33 raeburn 8745: }
8746: }
8747: }
8748: }
8749: }
1.160.6.93 raeburn 8750:
8751: my $total = scalar(@fields);
8752: for (my $i=0; $i<$total; $i++) {
8753: $rem = $i%($numinrow);
1.33 raeburn 8754: if ($rem == 0) {
8755: if ($i > 0) {
8756: $output .= '</tr>';
8757: }
8758: $output .= '<tr>';
8759: }
8760: my $check = ' ';
1.160.6.35 raeburn 8761: unless ($role eq 'emailusername') {
8762: if (exists($checks{$fields[$i]})) {
1.160.6.98 raeburn 8763: $check = $checks{$fields[$i]};
1.160.6.35 raeburn 8764: } else {
8765: if ($role eq 'st') {
8766: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 8767: $check = ' checked="checked" ';
1.160.6.35 raeburn 8768: }
1.33 raeburn 8769: }
8770: }
8771: }
8772: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 8773: '<span class="LC_nobreak">';
8774: if ($role eq 'emailusername') {
8775: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
8776: $checks{$fields[$i]} = 'omit';
8777: }
8778: foreach my $option ('required','optional','omit') {
8779: my $checked='';
8780: if ($checks{$fields[$i]} eq $option) {
8781: $checked='checked="checked" ';
8782: }
8783: $output .= '<label>'.
8784: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
8785: &mt($option).'</label>'.(' ' x2);
8786: }
8787: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
8788: } else {
8789: $output .= '<label>'.
8790: '<input type="checkbox" name="canmodify_'.$role.'" '.
8791: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
8792: '</label>';
8793: }
8794: $output .= '</span></td>';
1.33 raeburn 8795: }
1.160.6.93 raeburn 8796: $rem = $total%$numinrow;
8797: my $colsleft;
8798: if ($rem) {
8799: $colsleft = $numinrow - $rem;
8800: }
8801: if ($colsleft > 1) {
1.33 raeburn 8802: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8803: ' </td>';
8804: } elsif ($colsleft == 1) {
8805: $output .= '<td class="LC_left_item"> </td>';
8806: }
8807: $output .= '</tr></table></td></tr>';
8808: return $output;
8809: }
1.28 raeburn 8810:
1.93 raeburn 8811: sub insttypes_row {
1.160.6.93 raeburn 8812: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
8813: $customcss,$rowstyle) = @_;
1.93 raeburn 8814: my %lt = &Apache::lonlocal::texthash (
8815: cansearch => 'Users allowed to search',
8816: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 8817: lockablenames => 'User preference to lock name',
1.160.6.93 raeburn 8818: selfassign => 'Self-reportable affiliations',
1.160.6.101 raeburn 8819: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 8820: );
8821: my $showdom;
8822: if ($context eq 'cansearch') {
8823: $showdom = ' ('.$dom.')';
8824: }
1.160.6.5 raeburn 8825: my $class = 'LC_left_item';
8826: if ($context eq 'statustocreate') {
8827: $class = 'LC_right_item';
8828: }
1.160.6.93 raeburn 8829: my $css_class;
8830: if ($$rowtotal%2) {
8831: $css_class = 'LC_odd_row';
8832: }
8833: if ($customcss) {
8834: $css_class .= ' '.$customcss;
8835: }
8836: $css_class =~ s/^\s+//;
8837: if ($css_class) {
8838: $css_class = ' class="'.$css_class.'"';
8839: }
8840: if ($rowstyle) {
8841: $css_class .= ' style="'.$rowstyle.'"';
8842: }
8843: if ($onclick) {
8844: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 8845: }
8846: my $output = '<tr'.$css_class.'>'.
8847: '<td>'.$lt{$context}.$showdom.
8848: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 8849: my $rem;
8850: if (ref($types) eq 'ARRAY') {
8851: for (my $i=0; $i<@{$types}; $i++) {
8852: if (defined($usertypes->{$types->[$i]})) {
8853: my $rem = $i%($numinrow);
8854: if ($rem == 0) {
8855: if ($i > 0) {
8856: $output .= '</tr>';
8857: }
8858: $output .= '<tr>';
1.23 raeburn 8859: }
1.26 raeburn 8860: my $check = ' ';
1.99 raeburn 8861: if (ref($settings) eq 'HASH') {
8862: if (ref($settings->{$context}) eq 'ARRAY') {
8863: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
8864: $check = ' checked="checked" ';
8865: }
1.160.6.101 raeburn 8866: } elsif (ref($settings->{$context}) eq 'HASH') {
8867: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
8868: $check = ' checked="checked" ';
8869: }
1.99 raeburn 8870: } elsif ($context eq 'statustocreate') {
1.26 raeburn 8871: $check = ' checked="checked" ';
8872: }
1.23 raeburn 8873: }
1.26 raeburn 8874: $output .= '<td class="LC_left_item">'.
8875: '<span class="LC_nobreak"><label>'.
1.93 raeburn 8876: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 8877: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
1.26 raeburn 8878: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 8879: }
8880: }
1.26 raeburn 8881: $rem = @{$types}%($numinrow);
1.23 raeburn 8882: }
8883: my $colsleft = $numinrow - $rem;
1.160.6.101 raeburn 8884: if ($context eq 'overrides') {
8885: if ($colsleft > 1) {
8886: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8887: } else {
8888: $output .= '<td class="LC_left_item">';
8889: }
8890: $output .= ' ';
1.23 raeburn 8891: } else {
1.160.6.101 raeburn 8892: if ($rem == 0) {
8893: $output .= '<tr>';
8894: }
8895: if ($colsleft > 1) {
8896: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8897: } else {
8898: $output .= '<td class="LC_left_item">';
8899: }
8900: my $defcheck = ' ';
8901: if (ref($settings) eq 'HASH') {
8902: if (ref($settings->{$context}) eq 'ARRAY') {
8903: if (grep(/^default$/,@{$settings->{$context}})) {
8904: $defcheck = ' checked="checked" ';
8905: }
8906: } elsif ($context eq 'statustocreate') {
1.99 raeburn 8907: $defcheck = ' checked="checked" ';
8908: }
1.26 raeburn 8909: }
1.160.6.101 raeburn 8910: $output .= '<span class="LC_nobreak"><label>'.
8911: '<input type="checkbox" name="'.$context.'" '.
8912: 'value="default"'.$defcheck.$onclick.' />'.
8913: $othertitle.'</label></span>';
1.23 raeburn 8914: }
1.160.6.101 raeburn 8915: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 8916: return $output;
1.23 raeburn 8917: }
8918:
8919: sub sorted_searchtitles {
8920: my %searchtitles = &Apache::lonlocal::texthash(
8921: 'uname' => 'username',
8922: 'lastname' => 'last name',
8923: 'lastfirst' => 'last name, first name',
8924: );
8925: my @titleorder = ('uname','lastname','lastfirst');
8926: return (\%searchtitles,\@titleorder);
8927: }
8928:
1.25 raeburn 8929: sub sorted_searchtypes {
8930: my %srchtypes_desc = (
8931: exact => 'is exact match',
8932: contains => 'contains ..',
8933: begins => 'begins with ..',
8934: );
8935: my @srchtypeorder = ('exact','begins','contains');
8936: return (\%srchtypes_desc,\@srchtypeorder);
8937: }
8938:
1.3 raeburn 8939: sub usertype_update_row {
8940: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
8941: my $datatable;
8942: my $numinrow = 4;
8943: foreach my $type (@{$types}) {
8944: if (defined($usertypes->{$type})) {
8945: $$rownums ++;
8946: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
8947: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
8948: '</td><td class="LC_left_item"><table>';
8949: for (my $i=0; $i<@{$fields}; $i++) {
8950: my $rem = $i%($numinrow);
8951: if ($rem == 0) {
8952: if ($i > 0) {
8953: $datatable .= '</tr>';
8954: }
8955: $datatable .= '<tr>';
8956: }
8957: my $check = ' ';
1.39 raeburn 8958: if (ref($settings) eq 'HASH') {
8959: if (ref($settings->{'fields'}) eq 'HASH') {
8960: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
8961: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
8962: $check = ' checked="checked" ';
8963: }
1.3 raeburn 8964: }
8965: }
8966: }
8967:
8968: if ($i == @{$fields}-1) {
8969: my $colsleft = $numinrow - $rem;
8970: if ($colsleft > 1) {
8971: $datatable .= '<td colspan="'.$colsleft.'">';
8972: } else {
8973: $datatable .= '<td>';
8974: }
8975: } else {
8976: $datatable .= '<td>';
8977: }
1.8 raeburn 8978: $datatable .= '<span class="LC_nobreak"><label>'.
8979: '<input type="checkbox" name="updateable_'.$type.
8980: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
8981: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 8982: }
8983: $datatable .= '</tr></table></td></tr>';
8984: }
8985: }
8986: return $datatable;
1.1 raeburn 8987: }
8988:
8989: sub modify_login {
1.160.6.24 raeburn 8990: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 8991: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.160.6.113! raeburn 8992: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
! 8993: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso);
1.160.6.5 raeburn 8994: %title = ( coursecatalog => 'Display course catalog',
8995: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 8996: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 8997: newuser => 'Link for visitors to create a user account',
1.160.6.113! raeburn 8998: loginheader => 'Log-in box header',
! 8999: saml => 'Dual SSO and non-SSO login');
1.160.6.5 raeburn 9000: @offon = ('off','on');
1.112 raeburn 9001: if (ref($domconfig{login}) eq 'HASH') {
9002: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
9003: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
9004: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
9005: }
9006: }
1.160.6.113! raeburn 9007: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
! 9008: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
! 9009: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
! 9010: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
! 9011: $saml{$lonhost} = 1;
! 9012: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
! 9013: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
! 9014: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
! 9015: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
! 9016: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
! 9017: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
! 9018: }
! 9019: }
! 9020: }
1.112 raeburn 9021: }
1.9 raeburn 9022: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
9023: \%domconfig,\%loginhash);
1.160.6.14 raeburn 9024: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9025: foreach my $item (@toggles) {
9026: $loginhash{login}{$item} = $env{'form.'.$item};
9027: }
1.41 raeburn 9028: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 9029: if (ref($colchanges{'login'}) eq 'HASH') {
9030: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
9031: \%loginhash);
9032: }
1.110 raeburn 9033:
1.149 raeburn 9034: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 9035: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 9036: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 9037: if (keys(%servers) > 1) {
9038: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 9039: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
9040: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
9041: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
9042: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
9043: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
9044: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9045: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9046: $changes{'loginvia'}{$lonhost} = 1;
9047: } else {
9048: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
9049: $changes{'loginvia'}{$lonhost} = 1;
9050: }
9051: } else {
9052: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9053: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9054: $changes{'loginvia'}{$lonhost} = 1;
9055: }
9056: }
9057: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
9058: foreach my $item (@loginvia_attribs) {
9059: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
9060: }
9061: } else {
9062: foreach my $item (@loginvia_attribs) {
9063: my $new = $env{'form.'.$lonhost.'_'.$item};
9064: if (($item eq 'serverpath') && ($new eq 'custom')) {
9065: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
9066: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9067: $new = '/';
9068: }
9069: }
9070: if (($item eq 'custompath') &&
9071: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9072: $new = '';
9073: }
9074: if ($new ne $curr_loginvia{$lonhost}{$item}) {
9075: $changes{'loginvia'}{$lonhost} = 1;
9076: }
9077: if ($item eq 'exempt') {
1.160.6.56 raeburn 9078: $new = &check_exempt_addresses($new);
1.128 raeburn 9079: }
9080: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9081: }
9082: }
1.112 raeburn 9083: } else {
1.128 raeburn 9084: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9085: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 9086: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 9087: foreach my $item (@loginvia_attribs) {
9088: my $new = $env{'form.'.$lonhost.'_'.$item};
9089: if (($item eq 'serverpath') && ($new eq 'custom')) {
9090: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9091: $new = '/';
9092: }
9093: }
9094: if (($item eq 'custompath') &&
9095: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9096: $new = '';
9097: }
9098: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9099: }
1.110 raeburn 9100: }
9101: }
9102: }
9103: }
1.119 raeburn 9104:
1.160.6.5 raeburn 9105: my $servadm = $r->dir_config('lonAdmEMail');
9106: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
9107: if (ref($domconfig{'login'}) eq 'HASH') {
9108: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
9109: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
9110: if ($lang eq 'nolang') {
9111: push(@currlangs,$lang);
9112: } elsif (defined($langchoices{$lang})) {
9113: push(@currlangs,$lang);
9114: } else {
9115: next;
9116: }
9117: }
9118: }
9119: }
9120: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
9121: if (@currlangs > 0) {
9122: foreach my $lang (@currlangs) {
9123: if (grep(/^\Q$lang\E$/,@delurls)) {
9124: $changes{'helpurl'}{$lang} = 1;
9125: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
9126: $changes{'helpurl'}{$lang} = 1;
9127: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
9128: push(@newlangs,$lang);
9129: } else {
9130: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9131: }
9132: }
9133: }
9134: unless (grep(/^nolang$/,@currlangs)) {
9135: if ($env{'form.loginhelpurl_nolang.filename'}) {
9136: $changes{'helpurl'}{'nolang'} = 1;
9137: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
9138: push(@newlangs,'nolang');
9139: }
9140: }
9141: if ($env{'form.loginhelpurl_add_lang'}) {
9142: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
9143: ($env{'form.loginhelpurl_add_file.filename'})) {
9144: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
9145: $addedfile = $env{'form.loginhelpurl_add_lang'};
9146: }
9147: }
9148: if ((@newlangs > 0) || ($addedfile)) {
9149: my $error;
9150: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9151: if ($configuserok eq 'ok') {
9152: if ($switchserver) {
9153: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
9154: } elsif ($author_ok eq 'ok') {
9155: my @allnew = @newlangs;
9156: if ($addedfile ne '') {
9157: push(@allnew,$addedfile);
9158: }
9159: foreach my $lang (@allnew) {
9160: my $formelem = 'loginhelpurl_'.$lang;
9161: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
9162: $formelem = 'loginhelpurl_add_file';
9163: }
9164: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9165: "help/$lang",'','',$newfile{$lang});
9166: if ($result eq 'ok') {
9167: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
9168: $changes{'helpurl'}{$lang} = 1;
9169: } else {
9170: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
9171: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9172: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
9173: (!grep(/^\Q$lang\E$/,@delurls))) {
9174: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9175: }
9176: }
9177: }
9178: } else {
9179: $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);
9180: }
9181: } else {
9182: $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);
9183: }
9184: if ($error) {
9185: &Apache::lonnet::logthis($error);
9186: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9187: }
9188: }
1.160.6.56 raeburn 9189:
9190: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
9191: if (ref($domconfig{'login'}) eq 'HASH') {
9192: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
9193: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
9194: if ($domservers{$lonhost}) {
9195: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9196: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 9197: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 9198: }
9199: }
9200: }
9201: }
9202: }
9203: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
9204: foreach my $lonhost (sort(keys(%domservers))) {
9205: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9206: $changes{'headtag'}{$lonhost} = 1;
9207: } else {
9208: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
9209: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
9210: }
9211: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
9212: push(@newhosts,$lonhost);
9213: } elsif ($currheadtagurls{$lonhost}) {
9214: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
9215: if ($currexempt{$lonhost}) {
9216: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
9217: $changes{'headtag'}{$lonhost} = 1;
9218: }
9219: } elsif ($possexempt{$lonhost}) {
9220: $changes{'headtag'}{$lonhost} = 1;
9221: }
9222: if ($possexempt{$lonhost}) {
9223: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9224: }
9225: }
9226: }
9227: }
9228: if (@newhosts) {
9229: my $error;
9230: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9231: if ($configuserok eq 'ok') {
9232: if ($switchserver) {
9233: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
9234: } elsif ($author_ok eq 'ok') {
9235: foreach my $lonhost (@newhosts) {
9236: my $formelem = 'loginheadtag_'.$lonhost;
9237: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9238: "login/headtag/$lonhost",'','',
9239: $env{'form.loginheadtag_'.$lonhost.'.filename'});
9240: if ($result eq 'ok') {
1.160.6.113! raeburn 9241: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
! 9242: $changes{'headtag'}{$lonhost} = 1;
! 9243: if ($possexempt{$lonhost}) {
! 9244: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
! 9245: }
! 9246: } else {
! 9247: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
! 9248: $newheadtagurls{$lonhost},$result);
! 9249: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
! 9250: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
! 9251: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
! 9252: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
! 9253: }
! 9254: }
! 9255: }
! 9256: } else {
! 9257: $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);
! 9258: }
! 9259: } else {
! 9260: $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);
! 9261: }
! 9262: if ($error) {
! 9263: &Apache::lonnet::logthis($error);
! 9264: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
! 9265: }
! 9266: }
! 9267: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
! 9268: my @newsamlimgs;
! 9269: foreach my $lonhost (keys(%domservers)) {
! 9270: if ($env{'form.saml_'.$lonhost}) {
! 9271: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
! 9272: push(@newsamlimgs,$lonhost);
! 9273: }
! 9274: foreach my $item ('text','alt','url','title','notsso') {
! 9275: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
! 9276: }
! 9277: if ($saml{$lonhost}) {
! 9278: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
! 9279: #FIXME Need to obsolete published image
! 9280: delete($currsaml{$lonhost}{'img'});
! 9281: $changes{'saml'}{$lonhost} = 1;
! 9282: }
! 9283: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
! 9284: $changes{'saml'}{$lonhost} = 1;
! 9285: }
! 9286: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
! 9287: $changes{'saml'}{$lonhost} = 1;
! 9288: }
! 9289: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
! 9290: $changes{'saml'}{$lonhost} = 1;
! 9291: }
! 9292: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
! 9293: $changes{'saml'}{$lonhost} = 1;
! 9294: }
! 9295: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
! 9296: $changes{'saml'}{$lonhost} = 1;
! 9297: }
! 9298: } else {
! 9299: $changes{'saml'}{$lonhost} = 1;
! 9300: }
! 9301: foreach my $item ('text','alt','url','title','notsso') {
! 9302: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
! 9303: }
! 9304: } else {
! 9305: if ($saml{$lonhost}) {
! 9306: $changes{'saml'}{$lonhost} = 1;
! 9307: delete($currsaml{$lonhost});
! 9308: }
! 9309: }
! 9310: }
! 9311: foreach my $posshost (keys(%currsaml)) {
! 9312: unless (exists($domservers{$posshost})) {
! 9313: delete($currsaml{$posshost});
! 9314: }
! 9315: }
! 9316: %{$loginhash{'login'}{'saml'}} = %currsaml;
! 9317: if (@newsamlimgs) {
! 9318: my $error;
! 9319: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
! 9320: if ($configuserok eq 'ok') {
! 9321: if ($switchserver) {
! 9322: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
! 9323: } elsif ($author_ok eq 'ok') {
! 9324: foreach my $lonhost (@newsamlimgs) {
! 9325: my $formelem = 'saml_img_'.$lonhost;
! 9326: my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
! 9327: "login/saml/$lonhost",'','',
! 9328: $env{'form.saml_img_'.$lonhost.'.filename'});
! 9329: if ($result eq 'ok') {
! 9330: $currsaml{$lonhost}{'img'} = $imgurl;
! 9331: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
! 9332: $changes{'saml'}{$lonhost} = 1;
1.160.6.56 raeburn 9333: } else {
1.160.6.113! raeburn 9334: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
! 9335: $lonhost,$result);
1.160.6.56 raeburn 9336: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9337: }
9338: }
9339: } else {
1.160.6.113! raeburn 9340: $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 9341: }
9342: } else {
1.160.6.113! raeburn 9343: $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 9344: }
9345: if ($error) {
9346: &Apache::lonnet::logthis($error);
9347: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9348: }
9349: }
1.160.6.5 raeburn 9350: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
9351:
9352: my $defaulthelpfile = '/adm/loginproblems.html';
9353: my $defaulttext = &mt('Default in use');
9354:
1.1 raeburn 9355: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
9356: $dom);
9357: if ($putresult eq 'ok') {
1.160.6.14 raeburn 9358: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9359: my %defaultchecked = (
9360: 'coursecatalog' => 'on',
1.160.6.14 raeburn 9361: 'helpdesk' => 'on',
1.42 raeburn 9362: 'adminmail' => 'off',
1.43 raeburn 9363: 'newuser' => 'off',
1.42 raeburn 9364: );
1.55 raeburn 9365: if (ref($domconfig{'login'}) eq 'HASH') {
9366: foreach my $item (@toggles) {
9367: if ($defaultchecked{$item} eq 'on') {
9368: if (($domconfig{'login'}{$item} eq '0') &&
9369: ($env{'form.'.$item} eq '1')) {
9370: $changes{$item} = 1;
9371: } elsif (($domconfig{'login'}{$item} eq '' ||
9372: $domconfig{'login'}{$item} eq '1') &&
9373: ($env{'form.'.$item} eq '0')) {
9374: $changes{$item} = 1;
9375: }
9376: } elsif ($defaultchecked{$item} eq 'off') {
9377: if (($domconfig{'login'}{$item} eq '1') &&
9378: ($env{'form.'.$item} eq '0')) {
9379: $changes{$item} = 1;
9380: } elsif (($domconfig{'login'}{$item} eq '' ||
9381: $domconfig{'login'}{$item} eq '0') &&
9382: ($env{'form.'.$item} eq '1')) {
9383: $changes{$item} = 1;
9384: }
1.42 raeburn 9385: }
9386: }
1.41 raeburn 9387: }
1.6 raeburn 9388: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 9389: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.113! raeburn 9390: if (exists($changes{'saml'})) {
! 9391: my $hostid_in_use;
! 9392: my @hosts = &Apache::lonnet::current_machine_ids();
! 9393: if (@hosts > 1) {
! 9394: foreach my $hostid (@hosts) {
! 9395: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
! 9396: $hostid_in_use = $hostid;
! 9397: last;
! 9398: }
! 9399: }
! 9400: } else {
! 9401: $hostid_in_use = $r->dir_config('lonHostID');
! 9402: }
! 9403: if (($hostid_in_use) &&
! 9404: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
! 9405: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
! 9406: }
! 9407: if (ref($lastactref) eq 'HASH') {
! 9408: if (ref($changes{'saml'}) eq 'HASH') {
! 9409: my %updates;
! 9410: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
! 9411: $lastactref->{'samllanding'} = \%updates;
! 9412: }
! 9413: }
! 9414: }
1.160.6.27 raeburn 9415: if (ref($lastactref) eq 'HASH') {
9416: $lastactref->{'domainconfig'} = 1;
9417: }
1.1 raeburn 9418: $resulttext = &mt('Changes made:').'<ul>';
9419: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 9420: if ($item eq 'loginvia') {
1.112 raeburn 9421: if (ref($changes{$item}) eq 'HASH') {
9422: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
9423: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 9424: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
9425: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
9426: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
9427: $protocol = 'http' if ($protocol ne 'https');
9428: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
9429:
9430: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
9431: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
9432: } else {
9433: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
9434: }
9435: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
9436: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
9437: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
9438: }
9439: $resulttext .= '</li>';
9440: } else {
9441: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
9442: }
1.112 raeburn 9443: } else {
1.128 raeburn 9444: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 9445: }
9446: }
1.128 raeburn 9447: $resulttext .= '</ul></li>';
1.112 raeburn 9448: }
1.160.6.5 raeburn 9449: } elsif ($item eq 'helpurl') {
9450: if (ref($changes{$item}) eq 'HASH') {
9451: foreach my $lang (sort(keys(%{$changes{$item}}))) {
9452: if (grep(/^\Q$lang\E$/,@delurls)) {
9453: my ($chg,$link);
9454: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
9455: if ($lang eq 'nolang') {
9456: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
9457: } else {
9458: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
9459: }
9460: $resulttext .= '<li>'.$chg.'</li>';
9461: } else {
9462: my $chg;
9463: if ($lang eq 'nolang') {
9464: $chg = &mt('custom log-in help file for no preferred language');
9465: } else {
9466: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
9467: }
9468: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
9469: $loginhash{'login'}{'helpurl'}{$lang}.
9470: '?inhibitmenu=yes',$chg,600,500).
9471: '</li>';
9472: }
9473: }
9474: }
1.160.6.56 raeburn 9475: } elsif ($item eq 'headtag') {
9476: if (ref($changes{$item}) eq 'HASH') {
9477: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9478: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9479: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
9480: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9481: $resulttext .= '<li><a href="'.
9482: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
9483: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
9484: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
9485: if ($possexempt{$lonhost}) {
9486: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
9487: } else {
9488: $resulttext .= &mt('included for any client IP');
9489: }
9490: $resulttext .= '</li>';
9491: }
9492: }
9493: }
1.160.6.113! raeburn 9494: } elsif ($item eq 'saml') {
! 9495: if (ref($changes{$item}) eq 'HASH') {
! 9496: my %notlt = (
! 9497: text => 'Text for log-in by SSO',
! 9498: img => 'SSO button image',
! 9499: alt => 'Alt text for button image',
! 9500: url => 'SSO URL',
! 9501: title => 'Tooltip for SSO link',
! 9502: notsso => 'Text for non-SSO log-in',
! 9503: );
! 9504: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
! 9505: if (ref($currsaml{$lonhost}) eq 'HASH') {
! 9506: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
! 9507: '<ul>';
! 9508: foreach my $key ('text','img','alt','url','title','notsso') {
! 9509: if ($currsaml{$lonhost}{$key} eq '') {
! 9510: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
! 9511: } else {
! 9512: my $value = "'$currsaml{$lonhost}{$key}'";
! 9513: if ($key eq 'img') {
! 9514: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
! 9515: }
! 9516: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
! 9517: $value).'</li>';
! 9518: }
! 9519: }
! 9520: $resulttext .= '</ul></li>';
! 9521: } else {
! 9522: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
! 9523: }
! 9524: }
! 9525: }
1.160.6.5 raeburn 9526: } elsif ($item eq 'captcha') {
9527: if (ref($loginhash{'login'}) eq 'HASH') {
9528: my $chgtxt;
9529: if ($loginhash{'login'}{$item} eq 'notused') {
9530: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
9531: } else {
9532: my %captchas = &captcha_phrases();
9533: if ($captchas{$loginhash{'login'}{$item}}) {
9534: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
9535: } else {
9536: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
9537: }
9538: }
9539: $resulttext .= '<li>'.$chgtxt.'</li>';
9540: }
9541: } elsif ($item eq 'recaptchakeys') {
9542: if (ref($loginhash{'login'}) eq 'HASH') {
9543: my ($privkey,$pubkey);
9544: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
9545: $pubkey = $loginhash{'login'}{$item}{'public'};
9546: $privkey = $loginhash{'login'}{$item}{'private'};
9547: }
9548: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
9549: if (!$pubkey) {
9550: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
9551: } else {
9552: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9553: }
9554: if (!$privkey) {
9555: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
9556: } else {
1.160.6.53 raeburn 9557: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 9558: }
9559: $chgtxt .= '</ul>';
9560: $resulttext .= '<li>'.$chgtxt.'</li>';
9561: }
1.160.6.69 raeburn 9562: } elsif ($item eq 'recaptchaversion') {
9563: if (ref($loginhash{'login'}) eq 'HASH') {
9564: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
9565: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
9566: '</li>';
9567: }
9568: }
1.41 raeburn 9569: } else {
9570: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
9571: }
1.1 raeburn 9572: }
1.6 raeburn 9573: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 9574: } else {
9575: $resulttext = &mt('No changes made to log-in page settings');
9576: }
9577: } else {
1.11 albertel 9578: $resulttext = '<span class="LC_error">'.
9579: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9580: }
1.6 raeburn 9581: if ($errors) {
1.9 raeburn 9582: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 9583: $errors.'</ul>';
9584: }
9585: return $resulttext;
9586: }
9587:
1.160.6.56 raeburn 9588: sub check_exempt_addresses {
9589: my ($iplist) = @_;
9590: $iplist =~ s/^\s+//;
9591: $iplist =~ s/\s+$//;
9592: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
9593: my (@okips,$new);
9594: foreach my $ip (@poss_ips) {
9595: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
9596: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
9597: push(@okips,$ip);
9598: }
9599: }
9600: }
9601: if (@okips > 0) {
9602: $new = join(',',@okips);
9603: } else {
9604: $new = '';
9605: }
9606: return $new;
9607: }
9608:
1.6 raeburn 9609: sub color_font_choices {
9610: my %choices =
9611: &Apache::lonlocal::texthash (
9612: img => "Header",
9613: bgs => "Background colors",
9614: links => "Link colors",
1.55 raeburn 9615: images => "Images",
1.6 raeburn 9616: font => "Font color",
1.160.6.22 raeburn 9617: fontmenu => "Font menu",
1.76 raeburn 9618: pgbg => "Page",
1.6 raeburn 9619: tabbg => "Header",
9620: sidebg => "Border",
9621: link => "Link",
9622: alink => "Active link",
9623: vlink => "Visited link",
9624: );
9625: return %choices;
9626: }
9627:
1.160.6.113! raeburn 9628: sub modify_ipaccess {
! 9629: my ($dom,$lastactref,%domconfig) = @_;
! 9630: my (@allpos,%changes,%confhash,$errors,$resulttext);
! 9631: my (@items,%deletions,%itemids,@warnings);
! 9632: my ($typeorder,$types) = &commblocktype_text();
! 9633: if ($env{'form.ipaccess_add'}) {
! 9634: my $name = $env{'form.ipaccess_name_add'};
! 9635: my ($newid,$error) = &get_ipaccess_id($dom,$name);
! 9636: if ($newid) {
! 9637: $itemids{'add'} = $newid;
! 9638: push(@items,'add');
! 9639: $changes{$newid} = 1;
! 9640: } else {
! 9641: $error = &mt('Failed to acquire unique ID for new IP access control item');
! 9642: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
! 9643: }
! 9644: }
! 9645: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
! 9646: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
! 9647: if (@todelete) {
! 9648: map { $deletions{$_} = 1; } @todelete;
! 9649: }
! 9650: my $maxnum = $env{'form.ipaccess_maxnum'};
! 9651: for (my $i=0; $i<$maxnum; $i++) {
! 9652: my $itemid = $env{'form.ipaccess_id_'.$i};
! 9653: $itemid =~ s/\D+//g;
! 9654: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
! 9655: if ($deletions{$itemid}) {
! 9656: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
! 9657: } else {
! 9658: push(@items,$i);
! 9659: $itemids{$i} = $itemid;
! 9660: }
! 9661: }
! 9662: }
! 9663: }
! 9664: foreach my $idx (@items) {
! 9665: my $itemid = $itemids{$idx};
! 9666: next unless ($itemid);
! 9667: my %current;
! 9668: unless ($idx eq 'add') {
! 9669: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
! 9670: %current = %{$domconfig{'ipaccess'}{$itemid}};
! 9671: }
! 9672: }
! 9673: my $position = $env{'form.ipaccess_pos_'.$itemid};
! 9674: $position =~ s/\D+//g;
! 9675: if ($position ne '') {
! 9676: $allpos[$position] = $itemid;
! 9677: }
! 9678: my $name = $env{'form.ipaccess_name_'.$idx};
! 9679: $name =~ s/^\s+|\s+$//g;
! 9680: $confhash{$itemid}{'name'} = $name;
! 9681: my $possrange = $env{'form.ipaccess_range_'.$idx};
! 9682: $possrange =~ s/^\s+|\s+$//g;
! 9683: unless ($possrange eq '') {
! 9684: $possrange =~ s/[\r\n]+/\s/g;
! 9685: $possrange =~ s/\s*-\s*/-/g;
! 9686: $possrange =~ s/\s+/,/g;
! 9687: $possrange =~ s/,+/,/g;
! 9688: if ($possrange ne '') {
! 9689: my (@ok,$count);
! 9690: $count = 0;
! 9691: foreach my $poss (split(/\,/,$possrange)) {
! 9692: $count ++;
! 9693: $poss = &validate_ip_pattern($poss);
! 9694: if ($poss ne '') {
! 9695: push(@ok,$poss);
! 9696: }
! 9697: }
! 9698: my $diff = $count - scalar(@ok);
! 9699: if ($diff) {
! 9700: $errors .= '<li><span class="LC_error">'.
! 9701: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
! 9702: $diff,$name).
! 9703: '</span></li>';
! 9704: }
! 9705: if (@ok) {
! 9706: my @cidr_list;
! 9707: foreach my $item (@ok) {
! 9708: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
! 9709: }
! 9710: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
! 9711: }
! 9712: }
! 9713: }
! 9714: foreach my $field ('name','ip') {
! 9715: unless (($idx eq 'add') || ($changes{$itemid})) {
! 9716: if ($current{$field} ne $confhash{$itemid}{$field}) {
! 9717: $changes{$itemid} = 1;
! 9718: last;
! 9719: }
! 9720: }
! 9721: }
! 9722: $confhash{$itemid}{'commblocks'} = {};
! 9723:
! 9724: my %commblocks;
! 9725: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
! 9726: foreach my $type (@{$typeorder}) {
! 9727: if ($commblocks{$type}) {
! 9728: $confhash{$itemid}{'commblocks'}{$type} = 'on';
! 9729: }
! 9730: unless (($idx eq 'add') || ($changes{$itemid})) {
! 9731: if (ref($current{'commblocks'}) eq 'HASH') {
! 9732: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
! 9733: $changes{$itemid} = 1;
! 9734: }
! 9735: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
! 9736: $changes{$itemid} = 1;
! 9737: }
! 9738: }
! 9739: }
! 9740: $confhash{$itemid}{'courses'} = {};
! 9741: my %crsdeletions;
! 9742: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
! 9743: if (@delcrs) {
! 9744: map { $crsdeletions{$_} = 1; } @delcrs;
! 9745: }
! 9746: if (ref($current{'courses'}) eq 'HASH') {
! 9747: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
! 9748: if ($crsdeletions{$cid}) {
! 9749: $changes{$itemid} = 1;
! 9750: } else {
! 9751: $confhash{$itemid}{'courses'}{$cid} = 1;
! 9752: }
! 9753: }
! 9754: }
! 9755: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
! 9756: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
! 9757: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
! 9758: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
! 9759: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
! 9760: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
! 9761: $errors .= '<li><span class="LC_error">'.
! 9762: &mt('Invalid courseID [_1] omitted from list of allowed courses',
! 9763: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
! 9764: '</span></li>';
! 9765: } else {
! 9766: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
! 9767: $changes{$itemid} = 1;
! 9768: }
! 9769: }
! 9770: }
! 9771: if (@allpos > 0) {
! 9772: my $idx = 0;
! 9773: foreach my $itemid (@allpos) {
! 9774: if ($itemid ne '') {
! 9775: $confhash{$itemid}{'order'} = $idx;
! 9776: unless ($changes{$itemid}) {
! 9777: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
! 9778: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
! 9779: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
! 9780: $changes{$itemid} = 1;
! 9781: }
! 9782: }
! 9783: }
! 9784: }
! 9785: $idx ++;
! 9786: }
! 9787: }
! 9788: }
! 9789: if (keys(%changes)) {
! 9790: my %defaultshash = (
! 9791: ipaccess => \%confhash,
! 9792: );
! 9793: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
! 9794: $dom);
! 9795: if ($putresult eq 'ok') {
! 9796: my $cachetime = 1800;
! 9797: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
! 9798: if (ref($lastactref) eq 'HASH') {
! 9799: $lastactref->{'ipaccess'} = 1;
! 9800: }
! 9801: $resulttext = &mt('Changes made:').'<ul>';
! 9802: my %bynum;
! 9803: foreach my $itemid (sort(keys(%changes))) {
! 9804: if (ref($confhash{$itemid}) eq 'HASH') {
! 9805: my $position = $confhash{$itemid}{'order'};
! 9806: if ($position =~ /^\d+$/) {
! 9807: $bynum{$position} = $itemid;
! 9808: }
! 9809: }
! 9810: }
! 9811: if (keys(%deletions)) {
! 9812: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
! 9813: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
! 9814: }
! 9815: }
! 9816: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
! 9817: my $itemid = $bynum{$pos};
! 9818: if (ref($confhash{$itemid}) eq 'HASH') {
! 9819: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
! 9820: my $position = $pos + 1;
! 9821: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
! 9822: if ($confhash{$itemid}{'ip'} eq '') {
! 9823: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
! 9824: } else {
! 9825: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
! 9826: }
! 9827: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
! 9828: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
! 9829: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
! 9830: '</li>';
! 9831: } else {
! 9832: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
! 9833: }
! 9834: if (keys(%{$confhash{$itemid}{'courses'}})) {
! 9835: my @courses;
! 9836: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
! 9837: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
! 9838: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
! 9839: }
! 9840: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
! 9841: join('</li><li>',@courses).'</li></ul>';
! 9842: } else {
! 9843: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
! 9844: }
! 9845: $resulttext .= '</ul></li>';
! 9846: }
! 9847: }
! 9848: $resulttext .= '</ul>';
! 9849: } else {
! 9850: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
! 9851: }
! 9852: } else {
! 9853: $resulttext = &mt('No changes made');
! 9854: }
! 9855: if ($errors) {
! 9856: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
! 9857: $errors.'</ul></p>';
! 9858: }
! 9859: return $resulttext;
! 9860: }
! 9861:
! 9862: sub get_ipaccess_id {
! 9863: my ($domain,$location) = @_;
! 9864: # get lock on ipaccess db
! 9865: my $lockhash = {
! 9866: lock => $env{'user.name'}.
! 9867: ':'.$env{'user.domain'},
! 9868: };
! 9869: my $tries = 0;
! 9870: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
! 9871: my ($id,$error);
! 9872:
! 9873: while (($gotlock ne 'ok') && ($tries<10)) {
! 9874: $tries ++;
! 9875: sleep (0.1);
! 9876: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
! 9877: }
! 9878: if ($gotlock eq 'ok') {
! 9879: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
! 9880: if ($currids{'lock'}) {
! 9881: delete($currids{'lock'});
! 9882: if (keys(%currids)) {
! 9883: my @curr = sort { $a <=> $b } keys(%currids);
! 9884: if ($curr[-1] =~ /^\d+$/) {
! 9885: $id = 1 + $curr[-1];
! 9886: }
! 9887: } else {
! 9888: $id = 1;
! 9889: }
! 9890: if ($id) {
! 9891: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
! 9892: $error = 'nostore';
! 9893: }
! 9894: } else {
! 9895: $error = 'nonumber';
! 9896: }
! 9897: }
! 9898: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
! 9899: } else {
! 9900: $error = 'nolock';
! 9901: }
! 9902: return ($id,$error);
! 9903: }
! 9904:
1.6 raeburn 9905: sub modify_rolecolors {
1.160.6.24 raeburn 9906: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 9907: my ($resulttext,%rolehash);
9908: $rolehash{'rolecolors'} = {};
1.55 raeburn 9909: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
9910: if ($domconfig{'rolecolors'} eq '') {
9911: $domconfig{'rolecolors'} = {};
9912: }
9913: }
1.9 raeburn 9914: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 9915: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
9916: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
9917: $dom);
9918: if ($putresult eq 'ok') {
9919: if (keys(%changes) > 0) {
1.41 raeburn 9920: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9921: if (ref($lastactref) eq 'HASH') {
9922: $lastactref->{'domainconfig'} = 1;
9923: }
1.6 raeburn 9924: $resulttext = &display_colorchgs($dom,\%changes,$roles,
9925: $rolehash{'rolecolors'});
9926: } else {
9927: $resulttext = &mt('No changes made to default color schemes');
9928: }
9929: } else {
1.11 albertel 9930: $resulttext = '<span class="LC_error">'.
9931: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 9932: }
9933: if ($errors) {
9934: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9935: $errors.'</ul>';
9936: }
9937: return $resulttext;
9938: }
9939:
9940: sub modify_colors {
1.9 raeburn 9941: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 9942: my (%changes,%choices);
1.51 raeburn 9943: my @bgs;
1.6 raeburn 9944: my @links = ('link','alink','vlink');
1.41 raeburn 9945: my @logintext;
1.6 raeburn 9946: my @images;
9947: my $servadm = $r->dir_config('lonAdmEMail');
9948: my $errors;
1.160.6.22 raeburn 9949: my %defaults;
1.6 raeburn 9950: foreach my $role (@{$roles}) {
9951: if ($role eq 'login') {
1.12 raeburn 9952: %choices = &login_choices();
1.41 raeburn 9953: @logintext = ('textcol','bgcol');
1.12 raeburn 9954: } else {
9955: %choices = &color_font_choices();
9956: }
9957: if ($role eq 'login') {
1.41 raeburn 9958: @images = ('img','logo','domlogo','login');
1.51 raeburn 9959: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 9960: } else {
9961: @images = ('img');
1.160.6.22 raeburn 9962: @bgs = ('pgbg','tabbg','sidebg');
9963: }
9964: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
9965: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
9966: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
9967: }
9968: if ($role eq 'login') {
9969: foreach my $item (@logintext) {
1.160.6.39 raeburn 9970: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9971: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9972: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9973: }
9974: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 9975: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9976: }
9977: }
9978: } else {
1.160.6.39 raeburn 9979: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
9980: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
9981: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
9982: }
9983: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 9984: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
9985: }
1.6 raeburn 9986: }
1.160.6.22 raeburn 9987: foreach my $item (@bgs) {
1.160.6.39 raeburn 9988: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9989: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9990: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9991: }
9992: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 9993: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9994: }
9995: }
9996: foreach my $item (@links) {
1.160.6.39 raeburn 9997: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9998: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9999: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10000: }
10001: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 10002: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10003: }
1.6 raeburn 10004: }
1.46 raeburn 10005: my ($configuserok,$author_ok,$switchserver) =
10006: &config_check($dom,$confname,$servadm);
1.9 raeburn 10007: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 10008: if (ref($domconfig->{$role}) ne 'HASH') {
10009: $domconfig->{$role} = {};
10010: }
1.8 raeburn 10011: foreach my $img (@images) {
1.70 raeburn 10012: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
10013: if (defined($env{'form.login_showlogo_'.$img})) {
10014: $confhash->{$role}{'showlogo'}{$img} = 1;
10015: } else {
10016: $confhash->{$role}{'showlogo'}{$img} = 0;
10017: }
10018: }
1.18 albertel 10019: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
10020: && !defined($domconfig->{$role}{$img})
10021: && !$env{'form.'.$role.'_del_'.$img}
10022: && $env{'form.'.$role.'_import_'.$img}) {
10023: # import the old configured image from the .tab setting
10024: # if they haven't provided a new one
10025: $domconfig->{$role}{$img} =
10026: $env{'form.'.$role.'_import_'.$img};
10027: }
1.6 raeburn 10028: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 10029: my $error;
1.6 raeburn 10030: if ($configuserok eq 'ok') {
1.9 raeburn 10031: if ($switchserver) {
1.12 raeburn 10032: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 10033: } else {
10034: if ($author_ok eq 'ok') {
10035: my ($result,$logourl) =
10036: &publishlogo($r,'upload',$role.'_'.$img,
10037: $dom,$confname,$img,$width,$height);
10038: if ($result eq 'ok') {
10039: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 10040: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10041: } else {
1.12 raeburn 10042: $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 10043: }
10044: } else {
1.46 raeburn 10045: $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 10046: }
10047: }
10048: } else {
1.46 raeburn 10049: $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 10050: }
10051: if ($error) {
1.8 raeburn 10052: &Apache::lonnet::logthis($error);
1.11 albertel 10053: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 10054: }
10055: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 10056: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
10057: my $error;
10058: if ($configuserok eq 'ok') {
10059: # is confname an author?
10060: if ($switchserver eq '') {
10061: if ($author_ok eq 'ok') {
10062: my ($result,$logourl) =
10063: &publishlogo($r,'copy',$domconfig->{$role}{$img},
10064: $dom,$confname,$img,$width,$height);
10065: if ($result eq 'ok') {
10066: $confhash->{$role}{$img} = $logourl;
1.18 albertel 10067: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10068: }
10069: }
10070: }
10071: }
1.6 raeburn 10072: }
10073: }
10074: }
10075: if (ref($domconfig) eq 'HASH') {
10076: if (ref($domconfig->{$role}) eq 'HASH') {
10077: foreach my $img (@images) {
10078: if ($domconfig->{$role}{$img} ne '') {
10079: if ($env{'form.'.$role.'_del_'.$img}) {
10080: $confhash->{$role}{$img} = '';
1.12 raeburn 10081: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10082: } else {
1.9 raeburn 10083: if ($confhash->{$role}{$img} eq '') {
10084: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
10085: }
1.6 raeburn 10086: }
10087: } else {
10088: if ($env{'form.'.$role.'_del_'.$img}) {
10089: $confhash->{$role}{$img} = '';
1.12 raeburn 10090: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10091: }
10092: }
1.70 raeburn 10093: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
10094: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
10095: if ($confhash->{$role}{'showlogo'}{$img} ne
10096: $domconfig->{$role}{'showlogo'}{$img}) {
10097: $changes{$role}{'showlogo'}{$img} = 1;
10098: }
10099: } else {
10100: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10101: $changes{$role}{'showlogo'}{$img} = 1;
10102: }
10103: }
10104: }
10105: }
1.6 raeburn 10106: if ($domconfig->{$role}{'font'} ne '') {
10107: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
10108: $changes{$role}{'font'} = 1;
10109: }
10110: } else {
10111: if ($confhash->{$role}{'font'}) {
10112: $changes{$role}{'font'} = 1;
10113: }
10114: }
1.107 raeburn 10115: if ($role ne 'login') {
10116: if ($domconfig->{$role}{'fontmenu'} ne '') {
10117: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
10118: $changes{$role}{'fontmenu'} = 1;
10119: }
10120: } else {
10121: if ($confhash->{$role}{'fontmenu'}) {
10122: $changes{$role}{'fontmenu'} = 1;
10123: }
1.97 tempelho 10124: }
10125: }
1.6 raeburn 10126: foreach my $item (@bgs) {
10127: if ($domconfig->{$role}{$item} ne '') {
10128: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10129: $changes{$role}{'bgs'}{$item} = 1;
10130: }
10131: } else {
10132: if ($confhash->{$role}{$item}) {
10133: $changes{$role}{'bgs'}{$item} = 1;
10134: }
10135: }
10136: }
10137: foreach my $item (@links) {
10138: if ($domconfig->{$role}{$item} ne '') {
10139: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10140: $changes{$role}{'links'}{$item} = 1;
10141: }
10142: } else {
10143: if ($confhash->{$role}{$item}) {
10144: $changes{$role}{'links'}{$item} = 1;
10145: }
10146: }
10147: }
1.41 raeburn 10148: foreach my $item (@logintext) {
10149: if ($domconfig->{$role}{$item} ne '') {
10150: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10151: $changes{$role}{'logintext'}{$item} = 1;
10152: }
10153: } else {
10154: if ($confhash->{$role}{$item}) {
10155: $changes{$role}{'logintext'}{$item} = 1;
10156: }
10157: }
10158: }
1.6 raeburn 10159: } else {
10160: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10161: \@logintext,$confhash,\%changes);
1.6 raeburn 10162: }
10163: } else {
10164: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10165: \@logintext,$confhash,\%changes);
1.6 raeburn 10166: }
10167: }
10168: return ($errors,%changes);
10169: }
10170:
1.46 raeburn 10171: sub config_check {
10172: my ($dom,$confname,$servadm) = @_;
10173: my ($configuserok,$author_ok,$switchserver,%currroles);
10174: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
10175: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
10176: $confname,$servadm);
10177: if ($configuserok eq 'ok') {
10178: $switchserver = &check_switchserver($dom,$confname);
10179: if ($switchserver eq '') {
10180: $author_ok = &check_authorstatus($dom,$confname,%currroles);
10181: }
10182: }
10183: return ($configuserok,$author_ok,$switchserver);
10184: }
10185:
1.6 raeburn 10186: sub default_change_checker {
1.41 raeburn 10187: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 10188: foreach my $item (@{$links}) {
10189: if ($confhash->{$role}{$item}) {
10190: $changes->{$role}{'links'}{$item} = 1;
10191: }
10192: }
10193: foreach my $item (@{$bgs}) {
10194: if ($confhash->{$role}{$item}) {
10195: $changes->{$role}{'bgs'}{$item} = 1;
10196: }
10197: }
1.41 raeburn 10198: foreach my $item (@{$logintext}) {
10199: if ($confhash->{$role}{$item}) {
10200: $changes->{$role}{'logintext'}{$item} = 1;
10201: }
10202: }
1.6 raeburn 10203: foreach my $img (@{$images}) {
10204: if ($env{'form.'.$role.'_del_'.$img}) {
10205: $confhash->{$role}{$img} = '';
1.12 raeburn 10206: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 10207: }
1.70 raeburn 10208: if ($role eq 'login') {
10209: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10210: $changes->{$role}{'showlogo'}{$img} = 1;
10211: }
10212: }
1.6 raeburn 10213: }
10214: if ($confhash->{$role}{'font'}) {
10215: $changes->{$role}{'font'} = 1;
10216: }
1.48 raeburn 10217: }
1.6 raeburn 10218:
10219: sub display_colorchgs {
10220: my ($dom,$changes,$roles,$confhash) = @_;
10221: my (%choices,$resulttext);
10222: if (!grep(/^login$/,@{$roles})) {
10223: $resulttext = &mt('Changes made:').'<br />';
10224: }
10225: foreach my $role (@{$roles}) {
10226: if ($role eq 'login') {
10227: %choices = &login_choices();
10228: } else {
10229: %choices = &color_font_choices();
10230: }
10231: if (ref($changes->{$role}) eq 'HASH') {
10232: if ($role ne 'login') {
10233: $resulttext .= '<h4>'.&mt($role).'</h4>';
10234: }
10235: foreach my $key (sort(keys(%{$changes->{$role}}))) {
10236: if ($role ne 'login') {
10237: $resulttext .= '<ul>';
10238: }
10239: if (ref($changes->{$role}{$key}) eq 'HASH') {
10240: if ($role ne 'login') {
10241: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
10242: }
10243: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 10244: if (($role eq 'login') && ($key eq 'showlogo')) {
10245: if ($confhash->{$role}{$key}{$item}) {
10246: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
10247: } else {
10248: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
10249: }
10250: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 10251: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
10252: } else {
1.12 raeburn 10253: my $newitem = $confhash->{$role}{$item};
10254: if ($key eq 'images') {
10255: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
10256: }
10257: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 10258: }
10259: }
10260: if ($role ne 'login') {
10261: $resulttext .= '</ul></li>';
10262: }
10263: } else {
10264: if ($confhash->{$role}{$key} eq '') {
10265: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
10266: } else {
10267: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
10268: }
10269: }
10270: if ($role ne 'login') {
10271: $resulttext .= '</ul>';
10272: }
10273: }
10274: }
10275: }
1.3 raeburn 10276: return $resulttext;
1.1 raeburn 10277: }
10278:
1.9 raeburn 10279: sub thumb_dimensions {
10280: return ('200','50');
10281: }
10282:
1.16 raeburn 10283: sub check_dimensions {
10284: my ($inputfile) = @_;
10285: my ($fullwidth,$fullheight);
10286: if ($inputfile =~ m|^[/\w.\-]+$|) {
10287: if (open(PIPE,"identify $inputfile 2>&1 |")) {
10288: my $imageinfo = <PIPE>;
10289: if (!close(PIPE)) {
10290: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
10291: }
10292: chomp($imageinfo);
10293: my ($fullsize) =
1.21 raeburn 10294: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 10295: if ($fullsize) {
10296: ($fullwidth,$fullheight) = split(/x/,$fullsize);
10297: }
10298: }
10299: }
10300: return ($fullwidth,$fullheight);
10301: }
10302:
1.9 raeburn 10303: sub check_configuser {
10304: my ($uhome,$dom,$confname,$servadm) = @_;
10305: my ($configuserok,%currroles);
10306: if ($uhome eq 'no_host') {
10307: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98 raeburn 10308: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 10309: $configuserok =
10310: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
10311: $configpass,'','','','','',undef,$servadm);
10312: } else {
10313: $configuserok = 'ok';
10314: %currroles =
10315: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
10316: }
10317: return ($configuserok,%currroles);
10318: }
10319:
10320: sub check_authorstatus {
10321: my ($dom,$confname,%currroles) = @_;
10322: my $author_ok;
1.40 raeburn 10323: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 10324: my $start = time;
10325: my $end = 0;
10326: $author_ok =
10327: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 10328: 'au',$end,$start,'','','domconfig');
1.9 raeburn 10329: } else {
10330: $author_ok = 'ok';
10331: }
10332: return $author_ok;
10333: }
10334:
10335: sub publishlogo {
1.46 raeburn 10336: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 10337: my ($output,$fname,$logourl);
10338: if ($action eq 'upload') {
10339: $fname=$env{'form.'.$formname.'.filename'};
10340: chop($env{'form.'.$formname});
10341: } else {
10342: ($fname) = ($formname =~ /([^\/]+)$/);
10343: }
1.46 raeburn 10344: if ($savefileas ne '') {
10345: $fname = $savefileas;
10346: }
1.9 raeburn 10347: $fname=&Apache::lonnet::clean_filename($fname);
10348: # See if there is anything left
10349: unless ($fname) { return ('error: no uploaded file'); }
10350: $fname="$subdir/$fname";
1.160.6.5 raeburn 10351: my $docroot=$r->dir_config('lonDocRoot');
10352: my $filepath="$docroot/priv";
10353: my $relpath = "$dom/$confname";
1.9 raeburn 10354: my ($fnamepath,$file,$fetchthumb);
10355: $file=$fname;
10356: if ($fname=~m|/|) {
10357: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
10358: }
1.160.6.26 raeburn 10359: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 10360: my $count;
1.160.6.5 raeburn 10361: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 10362: $filepath.="/$parts[$count]";
10363: if ((-e $filepath)!=1) {
10364: mkdir($filepath,02770);
10365: }
10366: }
10367: # Check for bad extension and disallow upload
10368: if ($file=~/\.(\w+)$/ &&
10369: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
10370: $output =
1.160.6.25 raeburn 10371: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 10372: } elsif ($file=~/\.(\w+)$/ &&
10373: !defined(&Apache::loncommon::fileembstyle($1))) {
10374: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
10375: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 10376: $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 10377: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 10378: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 10379: } else {
10380: my $source = $filepath.'/'.$file;
10381: my $logfile;
1.160.6.88 raeburn 10382: if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 10383: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 10384: }
10385: print $logfile
10386: "\n================= Publish ".localtime()." ================\n".
10387: $env{'user.name'}.':'.$env{'user.domain'}."\n";
10388: # Save the file
1.160.6.88 raeburn 10389: if (!open(FH,">",$source)) {
1.9 raeburn 10390: &Apache::lonnet::logthis('Failed to create '.$source);
10391: return (&mt('Failed to create file'));
10392: }
10393: if ($action eq 'upload') {
10394: if (!print FH ($env{'form.'.$formname})) {
10395: &Apache::lonnet::logthis('Failed to write to '.$source);
10396: return (&mt('Failed to write file'));
10397: }
10398: } else {
10399: my $original = &Apache::lonnet::filelocation('',$formname);
10400: if(!copy($original,$source)) {
10401: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
10402: return (&mt('Failed to write file'));
10403: }
10404: }
10405: close(FH);
10406: chmod(0660, $source); # Permissions to rw-rw---.
10407:
10408: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
10409: my $copyfile=$targetdir.'/'.$file;
10410:
10411: my @parts=split(/\//,$targetdir);
10412: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
10413: for (my $count=5;$count<=$#parts;$count++) {
10414: $path.="/$parts[$count]";
10415: if (!-e $path) {
10416: print $logfile "\nCreating directory ".$path;
10417: mkdir($path,02770);
10418: }
10419: }
10420: my $versionresult;
10421: if (-e $copyfile) {
10422: $versionresult = &logo_versioning($targetdir,$file,$logfile);
10423: } else {
10424: $versionresult = 'ok';
10425: }
10426: if ($versionresult eq 'ok') {
10427: if (copy($source,$copyfile)) {
10428: print $logfile "\nCopied original source to ".$copyfile."\n";
10429: $output = 'ok';
10430: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 10431: push(@{$modified_urls},[$copyfile,$source]);
10432: my $metaoutput =
10433: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
10434: unless ($registered_cleanup) {
10435: my $handlers = $r->get_handlers('PerlCleanupHandler');
10436: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10437: $registered_cleanup=1;
10438: }
1.9 raeburn 10439: } else {
10440: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
10441: $output = &mt('Failed to copy file to RES space').", $!";
10442: }
10443: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
10444: my $inputfile = $filepath.'/'.$file;
10445: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 10446: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
10447: if ($fullwidth ne '' && $fullheight ne '') {
10448: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
10449: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88 raeburn 10450: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
10451: system({$args[0]} @args);
1.16 raeburn 10452: chmod(0660, $filepath.'/tn-'.$file);
10453: if (-e $outfile) {
10454: my $copyfile=$targetdir.'/tn-'.$file;
10455: if (copy($outfile,$copyfile)) {
10456: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 10457: my $thumb_metaoutput =
10458: &write_metadata($dom,$confname,$formname,
10459: $targetdir,'tn-'.$file,$logfile);
10460: push(@{$modified_urls},[$copyfile,$outfile]);
10461: unless ($registered_cleanup) {
10462: my $handlers = $r->get_handlers('PerlCleanupHandler');
10463: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10464: $registered_cleanup=1;
10465: }
1.16 raeburn 10466: } else {
10467: print $logfile "\nUnable to write ".$copyfile.
10468: ':'.$!."\n";
10469: }
10470: }
1.9 raeburn 10471: }
10472: }
10473: }
10474: } else {
10475: $output = $versionresult;
10476: }
10477: }
10478: return ($output,$logourl);
10479: }
10480:
10481: sub logo_versioning {
10482: my ($targetdir,$file,$logfile) = @_;
10483: my $target = $targetdir.'/'.$file;
10484: my ($maxversion,$fn,$extn,$output);
10485: $maxversion = 0;
10486: if ($file =~ /^(.+)\.(\w+)$/) {
10487: $fn=$1;
10488: $extn=$2;
10489: }
10490: opendir(DIR,$targetdir);
10491: while (my $filename=readdir(DIR)) {
10492: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
10493: $maxversion=($1>$maxversion)?$1:$maxversion;
10494: }
10495: }
10496: $maxversion++;
10497: print $logfile "\nCreating old version ".$maxversion."\n";
10498: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
10499: if (copy($target,$copyfile)) {
10500: print $logfile "Copied old target to ".$copyfile."\n";
10501: $copyfile=$copyfile.'.meta';
10502: if (copy($target.'.meta',$copyfile)) {
10503: print $logfile "Copied old target metadata to ".$copyfile."\n";
10504: $output = 'ok';
10505: } else {
10506: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
10507: $output = &mt('Failed to copy old meta').", $!, ";
10508: }
10509: } else {
10510: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
10511: $output = &mt('Failed to copy old target').", $!, ";
10512: }
10513: return $output;
10514: }
10515:
10516: sub write_metadata {
10517: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
10518: my (%metadatafields,%metadatakeys,$output);
10519: $metadatafields{'title'}=$formname;
10520: $metadatafields{'creationdate'}=time;
10521: $metadatafields{'lastrevisiondate'}=time;
10522: $metadatafields{'copyright'}='public';
10523: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
10524: $env{'user.domain'};
10525: $metadatafields{'authorspace'}=$confname.':'.$dom;
10526: $metadatafields{'domain'}=$dom;
10527: {
10528: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
10529: my $mfh;
1.160.6.88 raeburn 10530: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 10531: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 10532: unless ($_=~/\./) {
10533: my $unikey=$_;
10534: $unikey=~/^([A-Za-z]+)/;
10535: my $tag=$1;
10536: $tag=~tr/A-Z/a-z/;
10537: print $mfh "\n\<$tag";
10538: foreach (split(/\,/,$metadatakeys{$unikey})) {
10539: my $value=$metadatafields{$unikey.'.'.$_};
10540: $value=~s/\"/\'\'/g;
10541: print $mfh ' '.$_.'="'.$value.'"';
10542: }
10543: print $mfh '>'.
10544: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
10545: .'</'.$tag.'>';
10546: }
10547: }
10548: $output = 'ok';
10549: print $logfile "\nWrote metadata";
10550: close($mfh);
10551: } else {
10552: print $logfile "\nFailed to open metadata file";
1.9 raeburn 10553: $output = &mt('Could not write metadata');
10554: }
10555: }
1.155 raeburn 10556: return $output;
10557: }
10558:
10559: sub notifysubscribed {
10560: foreach my $targetsource (@{$modified_urls}){
10561: next unless (ref($targetsource) eq 'ARRAY');
10562: my ($target,$source)=@{$targetsource};
10563: if ($source ne '') {
1.160.6.88 raeburn 10564: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 10565: print $logfh "\nCleanup phase: Notifications\n";
10566: my @subscribed=&subscribed_hosts($target);
10567: foreach my $subhost (@subscribed) {
10568: print $logfh "\nNotifying host ".$subhost.':';
10569: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
10570: print $logfh $reply;
10571: }
10572: my @subscribedmeta=&subscribed_hosts("$target.meta");
10573: foreach my $subhost (@subscribedmeta) {
10574: print $logfh "\nNotifying host for metadata only ".$subhost.':';
10575: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
10576: $subhost);
10577: print $logfh $reply;
10578: }
10579: print $logfh "\n============ Done ============\n";
1.160 raeburn 10580: close($logfh);
1.155 raeburn 10581: }
10582: }
10583: }
10584: return OK;
10585: }
10586:
10587: sub subscribed_hosts {
10588: my ($target) = @_;
10589: my @subscribed;
1.160.6.88 raeburn 10590: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 10591: while (my $subline=<$fh>) {
10592: if ($subline =~ /^($match_lonid):/) {
10593: my $host = $1;
10594: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
10595: unless (grep(/^\Q$host\E$/,@subscribed)) {
10596: push(@subscribed,$host);
10597: }
10598: }
10599: }
10600: }
10601: }
10602: return @subscribed;
1.9 raeburn 10603: }
10604:
10605: sub check_switchserver {
10606: my ($dom,$confname) = @_;
10607: my ($allowed,$switchserver);
10608: my $home = &Apache::lonnet::homeserver($confname,$dom);
10609: if ($home eq 'no_host') {
10610: $home = &Apache::lonnet::domain($dom,'primary');
10611: }
10612: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 10613: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
10614: if (!$allowed) {
1.160.6.11 raeburn 10615: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 10616: }
10617: return $switchserver;
10618: }
10619:
1.1 raeburn 10620: sub modify_quotas {
1.160.6.30 raeburn 10621: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 10622: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 10623: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 10624: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
10625: $validationfieldsref);
1.86 raeburn 10626: if ($action eq 'quotas') {
10627: $context = 'tools';
1.160.6.26 raeburn 10628: } else {
1.86 raeburn 10629: $context = $action;
10630: }
10631: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 10632: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 10633: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 10634: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
10635: %titles = &courserequest_titles();
10636: $toolregexp = join('|',@usertools);
10637: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 10638: $confname = $dom.'-domainconfig';
10639: my $servadm = $r->dir_config('lonAdmEMail');
10640: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 10641: ($validationitemsref,$validationnamesref,$validationfieldsref) =
10642: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 10643: } elsif ($context eq 'requestauthor') {
10644: @usertools = ('author');
10645: %titles = &authorrequest_titles();
1.86 raeburn 10646: } else {
1.160.6.4 raeburn 10647: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 10648: %titles = &tool_titles();
1.86 raeburn 10649: }
1.160.6.27 raeburn 10650: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 10651: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10652: foreach my $key (keys(%env)) {
1.101 raeburn 10653: if ($context eq 'requestcourses') {
10654: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
10655: my $item = $1;
10656: my $type = $2;
10657: if ($type =~ /^limit_(.+)/) {
10658: $limithash{$item}{$1} = $env{$key};
10659: } else {
10660: $confhash{$item}{$type} = $env{$key};
10661: }
10662: }
1.160.6.5 raeburn 10663: } elsif ($context eq 'requestauthor') {
10664: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
10665: $confhash{$1} = $env{$key};
10666: }
1.101 raeburn 10667: } else {
1.86 raeburn 10668: if ($key =~ /^form\.quota_(.+)$/) {
10669: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 10670: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
10671: $confhash{'authorquota'}{$1} = $env{$key};
10672: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 10673: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
10674: }
1.72 raeburn 10675: }
10676: }
1.160.6.5 raeburn 10677: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 10678: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 10679: @approvalnotify = sort(@approvalnotify);
10680: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 10681: my @crstypes = ('official','unofficial','community','textbook');
10682: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
10683: foreach my $type (@hasuniquecode) {
10684: if (grep(/^\Q$type\E$/,@crstypes)) {
10685: $confhash{'uniquecode'}{$type} = 1;
10686: }
10687: }
1.160.6.46 raeburn 10688: my (%newbook,%allpos);
1.160.6.30 raeburn 10689: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 10690: foreach my $type ('textbooks','templates') {
10691: @{$allpos{$type}} = ();
10692: my $invalid;
10693: if ($type eq 'textbooks') {
10694: $invalid = &mt('Invalid LON-CAPA course for textbook');
10695: } else {
10696: $invalid = &mt('Invalid LON-CAPA course for template');
10697: }
10698: if ($env{'form.'.$type.'_addbook'}) {
10699: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
10700: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
10701: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
10702: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
10703: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
10704: } else {
10705: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
10706: my $position = $env{'form.'.$type.'_addbook_pos'};
10707: $position =~ s/\D+//g;
10708: if ($position ne '') {
10709: $allpos{$type}[$position] = $newbook{$type};
10710: }
1.160.6.30 raeburn 10711: }
1.160.6.46 raeburn 10712: } else {
10713: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 10714: }
10715: }
1.160.6.46 raeburn 10716: }
1.160.6.30 raeburn 10717: }
1.102 raeburn 10718: if (ref($domconfig{$action}) eq 'HASH') {
10719: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
10720: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
10721: $changes{'notify'}{'approval'} = 1;
10722: }
10723: } else {
1.144 raeburn 10724: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10725: $changes{'notify'}{'approval'} = 1;
10726: }
10727: }
1.160.6.30 raeburn 10728: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
10729: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10730: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
10731: unless ($confhash{'uniquecode'}{$crstype}) {
10732: $changes{'uniquecode'} = 1;
10733: }
10734: }
10735: unless ($changes{'uniquecode'}) {
10736: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
10737: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
10738: $changes{'uniquecode'} = 1;
10739: }
10740: }
10741: }
10742: } else {
10743: $changes{'uniquecode'} = 1;
10744: }
10745: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
10746: $changes{'uniquecode'} = 1;
10747: }
10748: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 10749: foreach my $type ('textbooks','templates') {
10750: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10751: my %deletions;
10752: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
10753: if (@todelete) {
10754: map { $deletions{$_} = 1; } @todelete;
10755: }
10756: my %imgdeletions;
10757: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
10758: if (@todeleteimages) {
10759: map { $imgdeletions{$_} = 1; } @todeleteimages;
10760: }
10761: my $maxnum = $env{'form.'.$type.'_maxnum'};
10762: for (my $i=0; $i<=$maxnum; $i++) {
10763: my $itemid = $env{'form.'.$type.'_id_'.$i};
10764: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
10765: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
10766: if ($deletions{$key}) {
10767: if ($domconfig{$action}{$type}{$key}{'image'}) {
10768: #FIXME need to obsolete item in RES space
10769: }
10770: next;
10771: } else {
10772: my $newpos = $env{'form.'.$itemid};
10773: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 10774: foreach my $item ('subject','title','publisher','author') {
10775: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10776: ($type eq 'templates'));
1.160.6.46 raeburn 10777: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
10778: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
10779: $changes{$type}{$key} = 1;
10780: }
10781: }
10782: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 10783: }
1.160.6.46 raeburn 10784: if ($imgdeletions{$key}) {
10785: $changes{$type}{$key} = 1;
10786: #FIXME need to obsolete item in RES space
10787: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
10788: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 10789: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10790: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10791: } else {
10792: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
10793: $cdom,$cnum,$type,$configuserok,
10794: $switchserver,$author_ok);
10795: if ($imgurl) {
10796: $confhash{$type}{$key}{'image'} = $imgurl;
10797: $changes{$type}{$key} = 1;
10798: }
10799: if ($error) {
10800: &Apache::lonnet::logthis($error);
10801: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10802: }
1.160.6.46 raeburn 10803: }
10804: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
10805: $confhash{$type}{$key}{'image'} =
10806: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 10807: }
10808: }
10809: }
10810: }
10811: }
10812: }
1.102 raeburn 10813: } else {
1.144 raeburn 10814: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10815: $changes{'notify'}{'approval'} = 1;
10816: }
1.160.6.30 raeburn 10817: if (ref($confhash{'uniquecode'} eq 'HASH')) {
10818: $changes{'uniquecode'} = 1;
10819: }
10820: }
10821: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 10822: foreach my $type ('textbooks','templates') {
10823: if ($newbook{$type}) {
10824: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 10825: foreach my $item ('subject','title','publisher','author') {
10826: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10827: ($type eq 'template'));
1.160.6.46 raeburn 10828: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
10829: if ($env{'form.'.$type.'_addbook_'.$item}) {
10830: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
10831: }
10832: }
10833: if ($type eq 'textbooks') {
10834: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
10835: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 10836: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10837: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10838: } else {
10839: my ($imageurl,$error) =
10840: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
10841: $configuserok,$switchserver,$author_ok);
10842: if ($imageurl) {
10843: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
10844: }
10845: if ($error) {
10846: &Apache::lonnet::logthis($error);
10847: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10848: }
1.160.6.46 raeburn 10849: }
10850: }
1.160.6.30 raeburn 10851: }
10852: }
1.160.6.46 raeburn 10853: if (@{$allpos{$type}} > 0) {
10854: my $idx = 0;
10855: foreach my $item (@{$allpos{$type}}) {
10856: if ($item ne '') {
10857: $confhash{$type}{$item}{'order'} = $idx;
10858: if (ref($domconfig{$action}) eq 'HASH') {
10859: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10860: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
10861: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
10862: $changes{$type}{$item} = 1;
10863: }
1.160.6.30 raeburn 10864: }
10865: }
10866: }
1.160.6.46 raeburn 10867: $idx ++;
1.160.6.30 raeburn 10868: }
10869: }
10870: }
10871: }
1.160.6.39 raeburn 10872: if (ref($validationitemsref) eq 'ARRAY') {
10873: foreach my $item (@{$validationitemsref}) {
10874: if ($item eq 'fields') {
10875: my @changed;
10876: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
10877: if (@{$confhash{'validation'}{$item}} > 0) {
10878: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
10879: }
1.160.6.65 raeburn 10880: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10881: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10882: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
10883: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
10884: $domconfig{'requestcourses'}{'validation'}{$item});
10885: } else {
10886: @changed = @{$confhash{'validation'}{$item}};
10887: }
1.160.6.39 raeburn 10888: } else {
10889: @changed = @{$confhash{'validation'}{$item}};
10890: }
10891: } else {
10892: @changed = @{$confhash{'validation'}{$item}};
10893: }
10894: if (@changed) {
10895: if ($confhash{'validation'}{$item}) {
10896: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
10897: } else {
10898: $changes{'validation'}{$item} = &mt('None');
10899: }
10900: }
10901: } else {
10902: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
10903: if ($item eq 'markup') {
10904: if ($env{'form.requestcourses_validation_'.$item}) {
10905: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10906: }
10907: }
1.160.6.65 raeburn 10908: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10909: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10910: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
10911: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10912: }
10913: } else {
10914: if ($confhash{'validation'}{$item} ne '') {
10915: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10916: }
1.160.6.39 raeburn 10917: }
10918: } else {
10919: if ($confhash{'validation'}{$item} ne '') {
10920: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10921: }
10922: }
10923: }
10924: }
10925: }
10926: if ($env{'form.validationdc'}) {
10927: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 10928: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 10929: if (exists($domcoords{$newval})) {
10930: $confhash{'validation'}{'dc'} = $newval;
10931: }
10932: }
10933: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 10934: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10935: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10936: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10937: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
10938: if ($confhash{'validation'}{'dc'} eq '') {
10939: $changes{'validation'}{'dc'} = &mt('None');
10940: } else {
10941: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10942: }
1.160.6.39 raeburn 10943: }
1.160.6.65 raeburn 10944: } elsif ($confhash{'validation'}{'dc'} ne '') {
10945: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 10946: }
10947: } elsif ($confhash{'validation'}{'dc'} ne '') {
10948: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10949: }
10950: } elsif ($confhash{'validation'}{'dc'} ne '') {
10951: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10952: }
1.160.6.65 raeburn 10953: } else {
10954: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10955: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10956: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10957: $changes{'validation'}{'dc'} = &mt('None');
10958: }
10959: }
1.160.6.39 raeburn 10960: }
10961: }
1.102 raeburn 10962: }
10963: } else {
1.86 raeburn 10964: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 10965: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 10966: }
1.72 raeburn 10967: foreach my $item (@usertools) {
10968: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 10969: my $unset;
1.101 raeburn 10970: if ($context eq 'requestcourses') {
1.104 raeburn 10971: $unset = '0';
10972: if ($type eq '_LC_adv') {
10973: $unset = '';
10974: }
1.101 raeburn 10975: if ($confhash{$item}{$type} eq 'autolimit') {
10976: $confhash{$item}{$type} .= '=';
10977: unless ($limithash{$item}{$type} =~ /\D/) {
10978: $confhash{$item}{$type} .= $limithash{$item}{$type};
10979: }
10980: }
1.160.6.5 raeburn 10981: } elsif ($context eq 'requestauthor') {
10982: $unset = '0';
10983: if ($type eq '_LC_adv') {
10984: $unset = '';
10985: }
1.72 raeburn 10986: } else {
1.101 raeburn 10987: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
10988: $confhash{$item}{$type} = 1;
10989: } else {
10990: $confhash{$item}{$type} = 0;
10991: }
1.72 raeburn 10992: }
1.86 raeburn 10993: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 10994: if ($action eq 'requestauthor') {
10995: if ($domconfig{$action}{$type} ne $confhash{$type}) {
10996: $changes{$type} = 1;
10997: }
10998: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 10999: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
11000: $changes{$item}{$type} = 1;
11001: }
11002: } else {
11003: if ($context eq 'requestcourses') {
1.104 raeburn 11004: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 11005: $changes{$item}{$type} = 1;
11006: }
11007: } else {
11008: if (!$confhash{$item}{$type}) {
11009: $changes{$item}{$type} = 1;
11010: }
11011: }
11012: }
11013: } else {
11014: if ($context eq 'requestcourses') {
1.104 raeburn 11015: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 11016: $changes{$item}{$type} = 1;
11017: }
1.160.6.5 raeburn 11018: } elsif ($context eq 'requestauthor') {
11019: if ($confhash{$type} ne $unset) {
11020: $changes{$type} = 1;
11021: }
1.72 raeburn 11022: } else {
11023: if (!$confhash{$item}{$type}) {
11024: $changes{$item}{$type} = 1;
11025: }
11026: }
11027: }
1.1 raeburn 11028: }
11029: }
1.160.6.5 raeburn 11030: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 11031: if (ref($domconfig{'quotas'}) eq 'HASH') {
11032: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11033: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
11034: if (exists($confhash{'defaultquota'}{$key})) {
11035: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
11036: $changes{'defaultquota'}{$key} = 1;
11037: }
11038: } else {
11039: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 11040: }
11041: }
1.86 raeburn 11042: } else {
11043: foreach my $key (keys(%{$domconfig{'quotas'}})) {
11044: if (exists($confhash{'defaultquota'}{$key})) {
11045: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
11046: $changes{'defaultquota'}{$key} = 1;
11047: }
11048: } else {
11049: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 11050: }
1.1 raeburn 11051: }
11052: }
1.160.6.20 raeburn 11053: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11054: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
11055: if (exists($confhash{'authorquota'}{$key})) {
11056: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
11057: $changes{'authorquota'}{$key} = 1;
11058: }
11059: } else {
11060: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
11061: }
11062: }
11063: }
1.1 raeburn 11064: }
1.86 raeburn 11065: if (ref($confhash{'defaultquota'}) eq 'HASH') {
11066: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
11067: if (ref($domconfig{'quotas'}) eq 'HASH') {
11068: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11069: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
11070: $changes{'defaultquota'}{$key} = 1;
11071: }
11072: } else {
11073: if (!exists($domconfig{'quotas'}{$key})) {
11074: $changes{'defaultquota'}{$key} = 1;
11075: }
1.72 raeburn 11076: }
11077: } else {
1.86 raeburn 11078: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 11079: }
1.1 raeburn 11080: }
11081: }
1.160.6.20 raeburn 11082: if (ref($confhash{'authorquota'}) eq 'HASH') {
11083: foreach my $key (keys(%{$confhash{'authorquota'}})) {
11084: if (ref($domconfig{'quotas'}) eq 'HASH') {
11085: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11086: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
11087: $changes{'authorquota'}{$key} = 1;
11088: }
11089: } else {
11090: $changes{'authorquota'}{$key} = 1;
11091: }
11092: } else {
11093: $changes{'authorquota'}{$key} = 1;
11094: }
11095: }
11096: }
1.1 raeburn 11097: }
1.72 raeburn 11098:
1.160.6.5 raeburn 11099: if ($context eq 'requestauthor') {
11100: $domdefaults{'requestauthor'} = \%confhash;
11101: } else {
11102: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 11103: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 11104: $domdefaults{$key} = $confhash{$key};
11105: }
1.160.6.5 raeburn 11106: }
1.72 raeburn 11107: }
1.160.6.5 raeburn 11108:
1.1 raeburn 11109: my %quotahash = (
1.86 raeburn 11110: $action => { %confhash }
1.1 raeburn 11111: );
11112: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
11113: $dom);
11114: if ($putresult eq 'ok') {
11115: if (keys(%changes) > 0) {
1.72 raeburn 11116: my $cachetime = 24*60*60;
11117: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11118: if (ref($lastactref) eq 'HASH') {
11119: $lastactref->{'domdefaults'} = 1;
11120: }
1.1 raeburn 11121: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 11122: unless (($context eq 'requestcourses') ||
11123: ($context eq 'requestauthor')) {
1.86 raeburn 11124: if (ref($changes{'defaultquota'}) eq 'HASH') {
11125: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
11126: foreach my $type (@{$types},'default') {
11127: if (defined($changes{'defaultquota'}{$type})) {
11128: my $typetitle = $usertypes->{$type};
11129: if ($type eq 'default') {
11130: $typetitle = $othertitle;
11131: }
1.160.6.28 raeburn 11132: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 11133: }
11134: }
1.86 raeburn 11135: $resulttext .= '</ul></li>';
1.72 raeburn 11136: }
1.160.6.20 raeburn 11137: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 11138: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 11139: foreach my $type (@{$types},'default') {
11140: if (defined($changes{'authorquota'}{$type})) {
11141: my $typetitle = $usertypes->{$type};
11142: if ($type eq 'default') {
11143: $typetitle = $othertitle;
11144: }
1.160.6.28 raeburn 11145: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 11146: }
11147: }
11148: $resulttext .= '</ul></li>';
11149: }
1.72 raeburn 11150: }
1.80 raeburn 11151: my %newenv;
1.72 raeburn 11152: foreach my $item (@usertools) {
1.160.6.5 raeburn 11153: my (%haschgs,%inconf);
11154: if ($context eq 'requestauthor') {
11155: %haschgs = %changes;
11156: %inconf = %confhash;
11157: } else {
11158: if (ref($changes{$item}) eq 'HASH') {
11159: %haschgs = %{$changes{$item}};
11160: }
11161: if (ref($confhash{$item}) eq 'HASH') {
11162: %inconf = %{$confhash{$item}};
11163: }
11164: }
11165: if (keys(%haschgs) > 0) {
1.80 raeburn 11166: my $newacc =
11167: &Apache::lonnet::usertools_access($env{'user.name'},
11168: $env{'user.domain'},
1.86 raeburn 11169: $item,'reload',$context);
1.160.6.5 raeburn 11170: if (($context eq 'requestcourses') ||
11171: ($context eq 'requestauthor')) {
1.108 raeburn 11172: if ($env{'environment.canrequest.'.$item} ne $newacc) {
11173: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 11174: }
11175: } else {
11176: if ($env{'environment.availabletools.'.$item} ne $newacc) {
11177: $newenv{'environment.availabletools.'.$item} = $newacc;
11178: }
1.80 raeburn 11179: }
1.160.6.5 raeburn 11180: unless ($context eq 'requestauthor') {
11181: $resulttext .= '<li>'.$titles{$item}.'<ul>';
11182: }
1.72 raeburn 11183: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 11184: if ($haschgs{$type}) {
1.72 raeburn 11185: my $typetitle = $usertypes->{$type};
11186: if ($type eq 'default') {
11187: $typetitle = $othertitle;
11188: } elsif ($type eq '_LC_adv') {
11189: $typetitle = 'LON-CAPA Advanced Users';
11190: }
1.160.6.5 raeburn 11191: if ($inconf{$type}) {
1.101 raeburn 11192: if ($context eq 'requestcourses') {
11193: my $cond;
1.160.6.5 raeburn 11194: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 11195: if ($1 eq '') {
11196: $cond = &mt('(Automatic processing of any request).');
11197: } else {
11198: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
11199: }
11200: } else {
1.160.6.5 raeburn 11201: $cond = $conditions{$inconf{$type}};
1.101 raeburn 11202: }
11203: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 11204: } elsif ($context eq 'requestauthor') {
11205: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
11206: $titles{$inconf{$type}},$typetitle);
11207:
1.101 raeburn 11208: } else {
11209: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
11210: }
1.72 raeburn 11211: } else {
1.104 raeburn 11212: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 11213: if ($inconf{$type} eq '0') {
1.104 raeburn 11214: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11215: } else {
11216: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
11217: }
11218: } else {
11219: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11220: }
1.72 raeburn 11221: }
11222: }
1.26 raeburn 11223: }
1.160.6.5 raeburn 11224: unless ($context eq 'requestauthor') {
11225: $resulttext .= '</ul></li>';
11226: }
1.26 raeburn 11227: }
1.1 raeburn 11228: }
1.160.6.5 raeburn 11229: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 11230: if (ref($changes{'notify'}) eq 'HASH') {
11231: if ($changes{'notify'}{'approval'}) {
11232: if (ref($confhash{'notify'}) eq 'HASH') {
11233: if ($confhash{'notify'}{'approval'}) {
11234: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
11235: } else {
1.160.6.5 raeburn 11236: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 11237: }
11238: }
11239: }
11240: }
11241: }
1.160.6.30 raeburn 11242: if ($action eq 'requestcourses') {
11243: my @offon = ('off','on');
11244: if ($changes{'uniquecode'}) {
11245: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11246: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
11247: $resulttext .= '<li>'.
11248: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
11249: '</li>';
11250: } else {
11251: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
11252: '</li>';
11253: }
11254: }
1.160.6.46 raeburn 11255: foreach my $type ('textbooks','templates') {
11256: if (ref($changes{$type}) eq 'HASH') {
11257: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
11258: foreach my $key (sort(keys(%{$changes{$type}}))) {
11259: my %coursehash = &Apache::lonnet::coursedescription($key);
11260: my $coursetitle = $coursehash{'description'};
11261: my $position = $confhash{$type}{$key}{'order'} + 1;
11262: $resulttext .= '<li>';
1.160.6.47 raeburn 11263: foreach my $item ('subject','title','publisher','author') {
11264: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11265: ($type eq 'templates'));
1.160.6.46 raeburn 11266: my $name = $item.':';
11267: $name =~ s/^(\w)/\U$1/;
11268: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
11269: }
11270: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
11271: if ($type eq 'textbooks') {
11272: if ($confhash{$type}{$key}{'image'}) {
11273: $resulttext .= ' '.&mt('Image: [_1]',
11274: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
11275: ' alt="Textbook cover" />').'<br />';
11276: }
11277: }
11278: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 11279: }
1.160.6.46 raeburn 11280: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 11281: }
11282: }
1.160.6.39 raeburn 11283: if (ref($changes{'validation'}) eq 'HASH') {
11284: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
11285: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
11286: foreach my $item (@{$validationitemsref}) {
11287: if (exists($changes{'validation'}{$item})) {
11288: if ($item eq 'markup') {
11289: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11290: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
11291: } else {
11292: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11293: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
11294: }
11295: }
11296: }
11297: if (exists($changes{'validation'}{'dc'})) {
11298: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
11299: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
11300: }
11301: }
11302: }
1.160.6.30 raeburn 11303: }
1.1 raeburn 11304: $resulttext .= '</ul>';
1.80 raeburn 11305: if (keys(%newenv)) {
11306: &Apache::lonnet::appenv(\%newenv);
11307: }
1.1 raeburn 11308: } else {
1.86 raeburn 11309: if ($context eq 'requestcourses') {
11310: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 11311: } elsif ($context eq 'requestauthor') {
11312: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 11313: } else {
1.90 weissno 11314: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 11315: }
1.1 raeburn 11316: }
11317: } else {
1.11 albertel 11318: $resulttext = '<span class="LC_error">'.
11319: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11320: }
1.160.6.30 raeburn 11321: if ($errors) {
11322: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
11323: '<ul>'.$errors.'</ul></p>';
11324: }
1.3 raeburn 11325: return $resulttext;
1.1 raeburn 11326: }
11327:
1.160.6.30 raeburn 11328: sub process_textbook_image {
1.160.6.46 raeburn 11329: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 11330: my $filename = $env{'form.'.$caller.'.filename'};
11331: my ($error,$url);
11332: my ($width,$height) = (50,50);
11333: if ($configuserok eq 'ok') {
11334: if ($switchserver) {
11335: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
11336: $switchserver);
11337: } elsif ($author_ok eq 'ok') {
11338: my ($result,$imageurl) =
11339: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88 raeburn 11340: "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 11341: if ($result eq 'ok') {
11342: $url = $imageurl;
11343: } else {
11344: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11345: }
11346: } else {
11347: $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);
11348: }
11349: } else {
11350: $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);
11351: }
11352: return ($url,$error);
11353: }
11354:
1.3 raeburn 11355: sub modify_autoenroll {
1.160.6.24 raeburn 11356: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 11357: my ($resulttext,%changes);
11358: my %currautoenroll;
11359: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
11360: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
11361: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
11362: }
11363: }
11364: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
11365: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 11366: sender => 'Sender for notification messages',
1.160.6.68 raeburn 11367: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
11368: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 11369: my @offon = ('off','on');
1.17 raeburn 11370: my $sender_uname = $env{'form.sender_uname'};
11371: my $sender_domain = $env{'form.sender_domain'};
11372: if ($sender_domain eq '') {
11373: $sender_uname = '';
11374: } elsif ($sender_uname eq '') {
11375: $sender_domain = '';
11376: }
1.129 raeburn 11377: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 11378: my $failsafe = $env{'form.autoenroll_failsafe'};
11379: $failsafe =~ s{^\s+|\s+$}{}g;
11380: if ($failsafe =~ /\D/) {
11381: undef($failsafe);
11382: }
1.1 raeburn 11383: my %autoenrollhash = (
1.129 raeburn 11384: autoenroll => { 'run' => $env{'form.autoenroll_run'},
11385: 'sender_uname' => $sender_uname,
11386: 'sender_domain' => $sender_domain,
11387: 'co-owners' => $coowners,
1.160.6.68 raeburn 11388: 'autofailsafe' => $failsafe,
1.1 raeburn 11389: }
11390: );
1.4 raeburn 11391: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
11392: $dom);
1.1 raeburn 11393: if ($putresult eq 'ok') {
11394: if (exists($currautoenroll{'run'})) {
11395: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
11396: $changes{'run'} = 1;
11397: }
11398: } elsif ($autorun) {
11399: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 11400: $changes{'run'} = 1;
1.1 raeburn 11401: }
11402: }
1.17 raeburn 11403: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 11404: $changes{'sender'} = 1;
11405: }
1.17 raeburn 11406: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 11407: $changes{'sender'} = 1;
11408: }
1.129 raeburn 11409: if ($currautoenroll{'co-owners'} ne '') {
11410: if ($currautoenroll{'co-owners'} ne $coowners) {
11411: $changes{'coowners'} = 1;
11412: }
11413: } elsif ($coowners) {
11414: $changes{'coowners'} = 1;
1.160.6.68 raeburn 11415: }
11416: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
11417: $changes{'autofailsafe'} = 1;
11418: }
1.1 raeburn 11419: if (keys(%changes) > 0) {
11420: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 11421: if ($changes{'run'}) {
1.1 raeburn 11422: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
11423: }
11424: if ($changes{'sender'}) {
1.17 raeburn 11425: if ($sender_uname eq '' || $sender_domain eq '') {
11426: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
11427: } else {
11428: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
11429: }
1.1 raeburn 11430: }
1.129 raeburn 11431: if ($changes{'coowners'}) {
11432: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
11433: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 11434: if (ref($lastactref) eq 'HASH') {
11435: $lastactref->{'domainconfig'} = 1;
11436: }
1.129 raeburn 11437: }
1.160.6.68 raeburn 11438: if ($changes{'autofailsafe'}) {
11439: if ($failsafe ne '') {
1.160.6.82 raeburn 11440: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68 raeburn 11441: } else {
1.160.6.82 raeburn 11442: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68 raeburn 11443: }
11444: &Apache::lonnet::get_domain_defaults($dom,1);
11445: if (ref($lastactref) eq 'HASH') {
11446: $lastactref->{'domdefaults'} = 1;
11447: }
11448: }
1.1 raeburn 11449: $resulttext .= '</ul>';
11450: } else {
11451: $resulttext = &mt('No changes made to auto-enrollment settings');
11452: }
11453: } else {
1.11 albertel 11454: $resulttext = '<span class="LC_error">'.
11455: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11456: }
1.3 raeburn 11457: return $resulttext;
1.1 raeburn 11458: }
11459:
11460: sub modify_autoupdate {
1.3 raeburn 11461: my ($dom,%domconfig) = @_;
1.1 raeburn 11462: my ($resulttext,%currautoupdate,%fields,%changes);
11463: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
11464: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
11465: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
11466: }
11467: }
11468: my @offon = ('off','on');
11469: my %title = &Apache::lonlocal::texthash (
1.160.6.113! raeburn 11470: run => 'Auto-update:',
! 11471: classlists => 'Updates to user information in classlists?',
! 11472: unexpired => 'Skip updates for users without active or future roles?',
! 11473: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 11474: );
1.44 raeburn 11475: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 11476: my %fieldtitles = &Apache::lonlocal::texthash (
11477: id => 'Student/Employee ID',
1.20 raeburn 11478: permanentemail => 'E-mail address',
1.1 raeburn 11479: lastname => 'Last Name',
11480: firstname => 'First Name',
11481: middlename => 'Middle Name',
1.132 raeburn 11482: generation => 'Generation',
1.1 raeburn 11483: );
1.142 raeburn 11484: $othertitle = &mt('All users');
1.1 raeburn 11485: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 11486: $othertitle = &mt('Other users');
1.1 raeburn 11487: }
11488: foreach my $key (keys(%env)) {
11489: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 11490: my ($usertype,$item) = ($1,$2);
11491: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
11492: if ($usertype eq 'default') {
11493: push(@{$fields{$1}},$2);
11494: } elsif (ref($types) eq 'ARRAY') {
11495: if (grep(/^\Q$usertype\E$/,@{$types})) {
11496: push(@{$fields{$1}},$2);
11497: }
11498: }
11499: }
1.1 raeburn 11500: }
11501: }
1.131 raeburn 11502: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
11503: @lockablenames = sort(@lockablenames);
11504: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
11505: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11506: if (@changed) {
11507: $changes{'lockablenames'} = 1;
11508: }
11509: } else {
11510: if (@lockablenames) {
11511: $changes{'lockablenames'} = 1;
11512: }
11513: }
1.1 raeburn 11514: my %updatehash = (
11515: autoupdate => { run => $env{'form.autoupdate_run'},
11516: classlists => $env{'form.classlists'},
1.160.6.113! raeburn 11517: unexpired => $env{'form.unexpired'},
1.1 raeburn 11518: fields => {%fields},
1.131 raeburn 11519: lockablenames => \@lockablenames,
1.1 raeburn 11520: }
11521: );
1.160.6.113! raeburn 11522: my $lastactivedays;
! 11523: if ($env{'form.lastactive'}) {
! 11524: $lastactivedays = $env{'form.lastactivedays'};
! 11525: $lastactivedays =~ s/^\s+|\s+$//g;
! 11526: unless ($lastactivedays =~ /^\d+$/) {
! 11527: undef($lastactivedays);
! 11528: $env{'form.lastactive'} = 0;
! 11529: }
! 11530: }
! 11531: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 11532: foreach my $key (keys(%currautoupdate)) {
1.160.6.113! raeburn 11533: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 11534: if (exists($updatehash{autoupdate}{$key})) {
11535: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
11536: $changes{$key} = 1;
11537: }
11538: }
11539: } elsif ($key eq 'fields') {
11540: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 11541: foreach my $item (@{$types},'default') {
1.1 raeburn 11542: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
11543: my $change = 0;
11544: foreach my $type (@{$currautoupdate{$key}{$item}}) {
11545: if (!exists($fields{$item})) {
11546: $change = 1;
1.132 raeburn 11547: last;
1.1 raeburn 11548: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 11549: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 11550: $change = 1;
1.132 raeburn 11551: last;
1.1 raeburn 11552: }
11553: }
11554: }
11555: if ($change) {
11556: push(@{$changes{$key}},$item);
11557: }
1.26 raeburn 11558: }
1.1 raeburn 11559: }
11560: }
1.131 raeburn 11561: } elsif ($key eq 'lockablenames') {
11562: if (ref($currautoupdate{$key}) eq 'ARRAY') {
11563: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11564: if (@changed) {
11565: $changes{'lockablenames'} = 1;
11566: }
11567: } else {
11568: if (@lockablenames) {
11569: $changes{'lockablenames'} = 1;
11570: }
11571: }
11572: }
11573: }
11574: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
11575: if (@lockablenames) {
11576: $changes{'lockablenames'} = 1;
1.1 raeburn 11577: }
11578: }
1.160.6.113! raeburn 11579: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
! 11580: if ($updatehash{'autoupdate'}{'unexpired'}) {
! 11581: $changes{'unexpired'} = 1;
! 11582: }
! 11583: }
! 11584: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
! 11585: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
! 11586: $changes{'lastactive'} = 1;
! 11587: }
! 11588: }
1.26 raeburn 11589: foreach my $item (@{$types},'default') {
11590: if (defined($fields{$item})) {
11591: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 11592: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
11593: my $change = 0;
11594: if (ref($fields{$item}) eq 'ARRAY') {
11595: foreach my $type (@{$fields{$item}}) {
11596: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
11597: $change = 1;
11598: last;
11599: }
11600: }
11601: }
11602: if ($change) {
11603: push(@{$changes{'fields'}},$item);
11604: }
11605: } else {
1.26 raeburn 11606: push(@{$changes{'fields'}},$item);
11607: }
11608: } else {
11609: push(@{$changes{'fields'}},$item);
1.1 raeburn 11610: }
11611: }
11612: }
11613: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
11614: $dom);
11615: if ($putresult eq 'ok') {
11616: if (keys(%changes) > 0) {
11617: $resulttext = &mt('Changes made:').'<ul>';
11618: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 11619: if ($key eq 'lockablenames') {
11620: $resulttext .= '<li>';
11621: if (@lockablenames) {
11622: $usertypes->{'default'} = $othertitle;
11623: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
11624: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
11625: } else {
11626: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
11627: }
11628: $resulttext .= '</li>';
11629: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 11630: foreach my $item (@{$changes{$key}}) {
11631: my @newvalues;
11632: foreach my $type (@{$fields{$item}}) {
11633: push(@newvalues,$fieldtitles{$type});
11634: }
1.3 raeburn 11635: my $newvaluestr;
11636: if (@newvalues > 0) {
11637: $newvaluestr = join(', ',@newvalues);
11638: } else {
11639: $newvaluestr = &mt('none');
1.6 raeburn 11640: }
1.1 raeburn 11641: if ($item eq 'default') {
1.26 raeburn 11642: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 11643: } else {
1.26 raeburn 11644: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 11645: }
11646: }
11647: } else {
11648: my $newvalue;
11649: if ($key eq 'run') {
11650: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.160.6.113! raeburn 11651: } elsif ($key eq 'lastactive') {
! 11652: $newvalue = $offon[$env{'form.lastactive'}];
! 11653: unless ($lastactivedays eq '') {
! 11654: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
! 11655: }
1.1 raeburn 11656: } else {
11657: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 11658: }
1.1 raeburn 11659: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
11660: }
11661: }
11662: $resulttext .= '</ul>';
11663: } else {
1.3 raeburn 11664: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 11665: }
11666: } else {
1.11 albertel 11667: $resulttext = '<span class="LC_error">'.
11668: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11669: }
1.3 raeburn 11670: return $resulttext;
1.1 raeburn 11671: }
11672:
1.125 raeburn 11673: sub modify_autocreate {
11674: my ($dom,%domconfig) = @_;
11675: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
11676: if (ref($domconfig{'autocreate'}) eq 'HASH') {
11677: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
11678: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
11679: }
11680: }
11681: my %title= ( xml => 'Auto-creation of courses in XML course description files',
11682: req => 'Auto-creation of validated requests for official courses',
11683: xmldc => 'Identity of course creator of courses from XML files',
11684: );
11685: my @types = ('xml','req');
11686: foreach my $item (@types) {
11687: $newvals{$item} = $env{'form.autocreate_'.$item};
11688: $newvals{$item} =~ s/\D//g;
11689: $newvals{$item} = 0 if ($newvals{$item} eq '');
11690: }
11691: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 11692: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 11693: unless (exists($domcoords{$newvals{'xmldc'}})) {
11694: $newvals{'xmldc'} = '';
11695: }
11696: %autocreatehash = (
11697: autocreate => { xml => $newvals{'xml'},
11698: req => $newvals{'req'},
11699: }
11700: );
11701: if ($newvals{'xmldc'} ne '') {
11702: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
11703: }
11704: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
11705: $dom);
11706: if ($putresult eq 'ok') {
11707: my @items = @types;
11708: if ($newvals{'xml'}) {
11709: push(@items,'xmldc');
11710: }
11711: foreach my $item (@items) {
11712: if (exists($currautocreate{$item})) {
11713: if ($currautocreate{$item} ne $newvals{$item}) {
11714: $changes{$item} = 1;
11715: }
11716: } elsif ($newvals{$item}) {
11717: $changes{$item} = 1;
11718: }
11719: }
11720: if (keys(%changes) > 0) {
11721: my @offon = ('off','on');
11722: $resulttext = &mt('Changes made:').'<ul>';
11723: foreach my $item (@types) {
11724: if ($changes{$item}) {
11725: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 11726: $resulttext .= '<li>'.
11727: &mt("$title{$item} set to [_1]$newtxt [_2]",
11728: '<b>','</b>').
11729: '</li>';
1.125 raeburn 11730: }
11731: }
11732: if ($changes{'xmldc'}) {
11733: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
11734: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 11735: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 11736: }
11737: $resulttext .= '</ul>';
11738: } else {
11739: $resulttext = &mt('No changes made to auto-creation settings');
11740: }
11741: } else {
11742: $resulttext = '<span class="LC_error">'.
11743: &mt('An error occurred: [_1]',$putresult).'</span>';
11744: }
11745: return $resulttext;
11746: }
11747:
1.23 raeburn 11748: sub modify_directorysrch {
1.160.6.81 raeburn 11749: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 11750: my ($resulttext,%changes);
11751: my %currdirsrch;
11752: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
11753: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
11754: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
11755: }
11756: }
1.160.6.72 raeburn 11757: my %title = ( available => 'Institutional directory search available',
11758: localonly => 'Other domains can search institution',
11759: lcavailable => 'LON-CAPA directory search available',
11760: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 11761: searchby => 'Search types',
11762: searchtypes => 'Search latitude');
11763: my @offon = ('off','on');
1.24 raeburn 11764: my @otherdoms = ('Yes','No');
1.23 raeburn 11765:
1.25 raeburn 11766: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 11767: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
11768: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
11769:
1.44 raeburn 11770: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 11771: if (keys(%{$usertypes}) == 0) {
11772: @cansearch = ('default');
11773: } else {
11774: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
11775: foreach my $type (@{$currdirsrch{'cansearch'}}) {
11776: if (!grep(/^\Q$type\E$/,@cansearch)) {
11777: push(@{$changes{'cansearch'}},$type);
11778: }
1.23 raeburn 11779: }
1.26 raeburn 11780: foreach my $type (@cansearch) {
11781: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
11782: push(@{$changes{'cansearch'}},$type);
11783: }
1.23 raeburn 11784: }
1.26 raeburn 11785: } else {
11786: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 11787: }
11788: }
11789:
11790: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
11791: foreach my $by (@{$currdirsrch{'searchby'}}) {
11792: if (!grep(/^\Q$by\E$/,@searchby)) {
11793: push(@{$changes{'searchby'}},$by);
11794: }
11795: }
11796: foreach my $by (@searchby) {
11797: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
11798: push(@{$changes{'searchby'}},$by);
11799: }
11800: }
11801: } else {
11802: push(@{$changes{'searchby'}},@searchby);
11803: }
1.25 raeburn 11804:
11805: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
11806: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
11807: if (!grep(/^\Q$type\E$/,@searchtypes)) {
11808: push(@{$changes{'searchtypes'}},$type);
11809: }
11810: }
11811: foreach my $type (@searchtypes) {
11812: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
11813: push(@{$changes{'searchtypes'}},$type);
11814: }
11815: }
11816: } else {
11817: if (exists($currdirsrch{'searchtypes'})) {
11818: foreach my $type (@searchtypes) {
11819: if ($type ne $currdirsrch{'searchtypes'}) {
11820: push(@{$changes{'searchtypes'}},$type);
11821: }
11822: }
11823: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
11824: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
11825: }
11826: } else {
11827: push(@{$changes{'searchtypes'}},@searchtypes);
11828: }
11829: }
11830:
1.23 raeburn 11831: my %dirsrch_hash = (
11832: directorysrch => { available => $env{'form.dirsrch_available'},
11833: cansearch => \@cansearch,
1.160.6.72 raeburn 11834: localonly => $env{'form.dirsrch_instlocalonly'},
11835: lclocalonly => $env{'form.dirsrch_domlocalonly'},
11836: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 11837: searchby => \@searchby,
1.25 raeburn 11838: searchtypes => \@searchtypes,
1.23 raeburn 11839: }
11840: );
11841: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
11842: $dom);
11843: if ($putresult eq 'ok') {
11844: if (exists($currdirsrch{'available'})) {
11845: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
11846: $changes{'available'} = 1;
11847: }
11848: } else {
11849: if ($env{'form.dirsrch_available'} eq '1') {
11850: $changes{'available'} = 1;
11851: }
11852: }
1.160.6.72 raeburn 11853: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 11854: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
11855: $changes{'lcavailable'} = 1;
11856: }
1.24 raeburn 11857: } else {
1.160.6.72 raeburn 11858: if ($env{'form.dirsrch_lcavailable'} eq '1') {
11859: $changes{'lcavailable'} = 1;
11860: }
11861: }
11862: if (exists($currdirsrch{'localonly'})) {
11863: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 11864: $changes{'localonly'} = 1;
11865: }
1.160.6.72 raeburn 11866: } else {
11867: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
11868: $changes{'localonly'} = 1;
11869: }
11870: }
11871: if (exists($currdirsrch{'lclocalonly'})) {
11872: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
11873: $changes{'lclocalonly'} = 1;
11874: }
11875: } else {
11876: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
11877: $changes{'lclocalonly'} = 1;
11878: }
1.24 raeburn 11879: }
1.23 raeburn 11880: if (keys(%changes) > 0) {
11881: $resulttext = &mt('Changes made:').'<ul>';
11882: if ($changes{'available'}) {
11883: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
11884: }
1.160.6.72 raeburn 11885: if ($changes{'lcavailable'}) {
11886: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
11887: }
1.24 raeburn 11888: if ($changes{'localonly'}) {
1.160.6.72 raeburn 11889: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
11890: }
11891: if ($changes{'lclocalonly'}) {
11892: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 11893: }
1.23 raeburn 11894: if (ref($changes{'cansearch'}) eq 'ARRAY') {
11895: my $chgtext;
1.26 raeburn 11896: if (ref($usertypes) eq 'HASH') {
11897: if (keys(%{$usertypes}) > 0) {
11898: foreach my $type (@{$types}) {
11899: if (grep(/^\Q$type\E$/,@cansearch)) {
11900: $chgtext .= $usertypes->{$type}.'; ';
11901: }
11902: }
11903: if (grep(/^default$/,@cansearch)) {
11904: $chgtext .= $othertitle;
11905: } else {
11906: $chgtext =~ s/\; $//;
11907: }
1.160.6.13 raeburn 11908: $resulttext .=
11909: '<li>'.
11910: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
11911: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
11912: '</li>';
1.23 raeburn 11913: }
11914: }
11915: }
11916: if (ref($changes{'searchby'}) eq 'ARRAY') {
11917: my ($searchtitles,$titleorder) = &sorted_searchtitles();
11918: my $chgtext;
11919: foreach my $type (@{$titleorder}) {
11920: if (grep(/^\Q$type\E$/,@searchby)) {
11921: if (defined($searchtitles->{$type})) {
11922: $chgtext .= $searchtitles->{$type}.'; ';
11923: }
11924: }
11925: }
11926: $chgtext =~ s/\; $//;
11927: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
11928: }
1.25 raeburn 11929: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
11930: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
11931: my $chgtext;
11932: foreach my $type (@{$srchtypeorder}) {
11933: if (grep(/^\Q$type\E$/,@searchtypes)) {
11934: if (defined($srchtypes_desc->{$type})) {
11935: $chgtext .= $srchtypes_desc->{$type}.'; ';
11936: }
11937: }
11938: }
11939: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 11940: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 11941: }
11942: $resulttext .= '</ul>';
1.160.6.81 raeburn 11943: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
11944: if (ref($lastactref) eq 'HASH') {
11945: $lastactref->{'directorysrch'} = 1;
11946: }
1.23 raeburn 11947: } else {
1.160.6.72 raeburn 11948: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 11949: }
11950: } else {
11951: $resulttext = '<span class="LC_error">'.
1.27 raeburn 11952: &mt('An error occurred: [_1]',$putresult).'</span>';
11953: }
11954: return $resulttext;
11955: }
11956:
1.28 raeburn 11957: sub modify_contacts {
1.160.6.24 raeburn 11958: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 11959: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
11960: if (ref($domconfig{'contacts'}) eq 'HASH') {
11961: foreach my $key (keys(%{$domconfig{'contacts'}})) {
11962: $currsetting{$key} = $domconfig{'contacts'}{$key};
11963: }
11964: }
1.160.6.78 raeburn 11965: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 11966: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 11967: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 11968: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.107 raeburn 11969: my @toggles = ('reporterrors','reportupdates','reportstatus');
11970: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.160.6.78 raeburn 11971: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 11972: foreach my $type (@mailings) {
11973: @{$newsetting{$type}} =
11974: &Apache::loncommon::get_env_multiple('form.'.$type);
11975: foreach my $item (@contacts) {
11976: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
11977: $contacts_hash{contacts}{$type}{$item} = 1;
11978: } else {
11979: $contacts_hash{contacts}{$type}{$item} = 0;
11980: }
1.160.6.78 raeburn 11981: }
1.28 raeburn 11982: $others{$type} = $env{'form.'.$type.'_others'};
11983: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 11984: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11985: $bcc{$type} = $env{'form.'.$type.'_bcc'};
11986: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 11987: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
11988: $includestr{$type} = $env{'form.'.$type.'_includestr'};
11989: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
11990: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
11991: }
1.134 raeburn 11992: }
1.28 raeburn 11993: }
11994: foreach my $item (@contacts) {
11995: $to{$item} = $env{'form.'.$item};
11996: $contacts_hash{'contacts'}{$item} = $to{$item};
11997: }
1.160.6.23 raeburn 11998: foreach my $item (@toggles) {
11999: if ($env{'form.'.$item} =~ /^(0|1)$/) {
12000: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
12001: }
12002: }
1.160.6.107 raeburn 12003: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
12004: foreach my $item (@lonstatus) {
12005: if ($item eq 'excluded') {
12006: my (%serverhomes,@excluded);
12007: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
12008: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
12009: if (@possexcluded) {
12010: foreach my $id (sort(@possexcluded)) {
12011: if ($serverhomes{$id}) {
12012: push(@excluded,$id);
12013: }
12014: }
12015: }
12016: if (@excluded) {
12017: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
12018: }
12019: } elsif ($item eq 'weights') {
12020: foreach my $type ('E','W','N','U') {
12021: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
12022: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
12023: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
12024: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
12025: $env{'form.error'.$item.'_'.$type};
12026: }
12027: }
12028: }
12029: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
12030: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
12031: if ($env{'form.error'.$item} =~ /^\d+$/) {
12032: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
12033: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
12034: }
12035: }
12036: }
12037: }
1.160.6.78 raeburn 12038: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
12039: foreach my $field (@{$fields}) {
12040: if (ref($possoptions->{$field}) eq 'ARRAY') {
12041: my $value = $env{'form.helpform_'.$field};
12042: $value =~ s/^\s+|\s+$//g;
12043: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101 raeburn 12044: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 12045: if ($field eq 'screenshot') {
12046: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
12047: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101 raeburn 12048: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 12049: }
12050: }
12051: }
12052: }
12053: }
12054: }
1.160.6.101 raeburn 12055: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12056: my (@statuses,%usertypeshash,@overrides);
12057: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
12058: @statuses = @{$types};
12059: if (ref($usertypes) eq 'HASH') {
12060: %usertypeshash = %{$usertypes};
12061: }
12062: }
12063: if (@statuses) {
12064: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
12065: foreach my $type (@possoverrides) {
12066: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
12067: push(@overrides,$type);
12068: }
12069: }
12070: if (@overrides) {
12071: foreach my $type (@overrides) {
12072: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
12073: foreach my $item (@contacts) {
12074: if (grep(/^\Q$item\E$/,@standard)) {
12075: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
12076: $newsetting{'override_'.$type}{$item} = 1;
12077: } else {
12078: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
12079: $newsetting{'override_'.$type}{$item} = 0;
12080: }
12081: }
12082: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
12083: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12084: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
12085: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12086: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
12087: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
12088: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
12089: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12090: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
12091: }
12092: }
12093: }
12094: }
1.28 raeburn 12095: if (keys(%currsetting) > 0) {
12096: foreach my $item (@contacts) {
12097: if ($to{$item} ne $currsetting{$item}) {
12098: $changes{$item} = 1;
12099: }
12100: }
12101: foreach my $type (@mailings) {
12102: foreach my $item (@contacts) {
12103: if (ref($currsetting{$type}) eq 'HASH') {
12104: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
12105: push(@{$changes{$type}},$item);
12106: }
12107: } else {
12108: push(@{$changes{$type}},@{$newsetting{$type}});
12109: }
12110: }
12111: if ($others{$type} ne $currsetting{$type}{'others'}) {
12112: push(@{$changes{$type}},'others');
12113: }
1.160.6.78 raeburn 12114: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12115: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
12116: push(@{$changes{$type}},'bcc');
12117: }
1.160.6.78 raeburn 12118: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
12119: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
12120: push(@{$changes{$type}},'include');
12121: }
12122: }
12123: }
12124: if (ref($fields) eq 'ARRAY') {
12125: if (ref($currsetting{'helpform'}) eq 'HASH') {
12126: foreach my $field (@{$fields}) {
12127: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
12128: push(@{$changes{'helpform'}},$field);
12129: }
12130: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12131: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
12132: push(@{$changes{'helpform'}},'maxsize');
12133: }
12134: }
12135: }
12136: } else {
12137: foreach my $field (@{$fields}) {
12138: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12139: push(@{$changes{'helpform'}},$field);
12140: }
12141: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12142: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12143: push(@{$changes{'helpform'}},'maxsize');
12144: }
12145: }
12146: }
1.134 raeburn 12147: }
1.28 raeburn 12148: }
1.160.6.101 raeburn 12149: if (@statuses) {
12150: if (ref($currsetting{'overrides'}) eq 'HASH') {
12151: foreach my $key (keys(%{$currsetting{'overrides'}})) {
12152: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
12153: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
12154: foreach my $item (@contacts,'bcc','others','include') {
12155: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
12156: push(@{$changes{'overrides'}},$key);
12157: last;
12158: }
12159: }
12160: } else {
12161: push(@{$changes{'overrides'}},$key);
12162: }
12163: }
12164: }
12165: foreach my $key (@overrides) {
12166: unless (exists($currsetting{'overrides'}{$key})) {
12167: push(@{$changes{'overrides'}},$key);
12168: }
12169: }
12170: } else {
12171: foreach my $key (@overrides) {
12172: push(@{$changes{'overrides'}},$key);
12173: }
12174: }
12175: }
1.160.6.107 raeburn 12176: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
12177: foreach my $key ('excluded','weights','threshold','sysmail') {
12178: if ($key eq 'excluded') {
12179: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
12180: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
12181: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
12182: (@{$currsetting{'lonstatus'}{$key}})) {
12183: my @diffs =
12184: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
12185: $currsetting{'lonstatus'}{$key});
12186: if (@diffs) {
12187: push(@{$changes{'lonstatus'}},$key);
12188: }
12189: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
12190: push(@{$changes{'lonstatus'}},$key);
12191: }
12192: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
12193: (@{$currsetting{'lonstatus'}{$key}})) {
12194: push(@{$changes{'lonstatus'}},$key);
12195: }
12196: } elsif ($key eq 'weights') {
12197: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
12198: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
12199: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
12200: foreach my $type ('E','W','N','U') {
12201: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
12202: $currsetting{'lonstatus'}{$key}{$type}) {
12203: push(@{$changes{'lonstatus'}},$key);
12204: last;
12205: }
12206: }
12207: } else {
12208: foreach my $type ('E','W','N','U') {
12209: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
12210: push(@{$changes{'lonstatus'}},$key);
12211: last;
12212: }
12213: }
12214: }
12215: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
12216: foreach my $type ('E','W','N','U') {
12217: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
12218: push(@{$changes{'lonstatus'}},$key);
12219: last;
12220: }
12221: }
12222: }
12223: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
12224: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12225: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
12226: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
12227: push(@{$changes{'lonstatus'}},$key);
12228: }
12229: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
12230: push(@{$changes{'lonstatus'}},$key);
12231: }
12232: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
12233: push(@{$changes{'lonstatus'}},$key);
12234: }
12235: }
12236: }
12237: } else {
12238: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12239: foreach my $key ('excluded','weights','threshold','sysmail') {
12240: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
12241: push(@{$changes{'lonstatus'}},$key);
12242: }
12243: }
12244: }
12245: }
1.28 raeburn 12246: } else {
12247: my %default;
12248: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
12249: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
12250: $default{'errormail'} = 'adminemail';
12251: $default{'packagesmail'} = 'adminemail';
12252: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 12253: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 12254: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 12255: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 12256: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 12257: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 12258: foreach my $item (@contacts) {
12259: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 12260: $changes{$item} = 1;
1.160.6.23 raeburn 12261: }
1.28 raeburn 12262: }
12263: foreach my $type (@mailings) {
12264: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
12265: push(@{$changes{$type}},@{$newsetting{$type}});
12266: }
12267: if ($others{$type} ne '') {
12268: push(@{$changes{$type}},'others');
1.134 raeburn 12269: }
1.160.6.78 raeburn 12270: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12271: if ($bcc{$type} ne '') {
12272: push(@{$changes{$type}},'bcc');
12273: }
1.160.6.78 raeburn 12274: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
12275: push(@{$changes{$type}},'include');
12276: }
12277: }
12278: }
12279: if (ref($fields) eq 'ARRAY') {
12280: foreach my $field (@{$fields}) {
12281: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12282: push(@{$changes{'helpform'}},$field);
12283: }
12284: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12285: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12286: push(@{$changes{'helpform'}},'maxsize');
12287: }
12288: }
1.134 raeburn 12289: }
1.28 raeburn 12290: }
1.160.6.107 raeburn 12291: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12292: foreach my $key ('excluded','weights','threshold','sysmail') {
12293: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
12294: push(@{$changes{'lonstatus'}},$key);
12295: }
12296: }
12297: }
1.28 raeburn 12298: }
1.160.6.23 raeburn 12299: foreach my $item (@toggles) {
12300: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
12301: $changes{$item} = 1;
12302: } elsif ((!$env{'form.'.$item}) &&
12303: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
12304: $changes{$item} = 1;
12305: }
12306: }
1.28 raeburn 12307: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
12308: $dom);
12309: if ($putresult eq 'ok') {
12310: if (keys(%changes) > 0) {
1.160.6.24 raeburn 12311: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 12312: if (ref($lastactref) eq 'HASH') {
12313: $lastactref->{'domainconfig'} = 1;
12314: }
1.28 raeburn 12315: my ($titles,$short_titles) = &contact_titles();
12316: $resulttext = &mt('Changes made:').'<ul>';
12317: foreach my $item (@contacts) {
12318: if ($changes{$item}) {
12319: $resulttext .= '<li>'.$titles->{$item}.
12320: &mt(' set to: ').
12321: '<span class="LC_cusr_emph">'.
12322: $to{$item}.'</span></li>';
12323: }
12324: }
12325: foreach my $type (@mailings) {
12326: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 12327: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
12328: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
12329: } else {
12330: $resulttext .= '<li>'.$titles->{$type}.': ';
12331: }
1.28 raeburn 12332: my @text;
12333: foreach my $item (@{$newsetting{$type}}) {
12334: push(@text,$short_titles->{$item});
12335: }
12336: if ($others{$type} ne '') {
12337: push(@text,$others{$type});
12338: }
1.160.6.78 raeburn 12339: if (@text) {
12340: $resulttext .= '<span class="LC_cusr_emph">'.
12341: join(', ',@text).'</span>';
12342: }
12343: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12344: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 12345: my $bcctext;
12346: if (@text) {
12347: $bcctext = ' '.&mt('with Bcc to');
12348: } else {
12349: $bcctext = '(Bcc)';
12350: }
12351: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
12352: } elsif (!@text) {
12353: $resulttext .= &mt('No one');
1.134 raeburn 12354: }
1.160.6.78 raeburn 12355: if ($includestr{$type} ne '') {
12356: if ($includeloc{$type} eq 'b') {
12357: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
12358: } elsif ($includeloc{$type} eq 's') {
12359: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
12360: }
12361: }
12362: } elsif (!@text) {
12363: $resulttext .= &mt('No recipients');
1.134 raeburn 12364: }
12365: $resulttext .= '</li>';
1.28 raeburn 12366: }
12367: }
1.160.6.101 raeburn 12368: if (ref($changes{'overrides'}) eq 'ARRAY') {
12369: my @deletions;
12370: foreach my $type (@{$changes{'overrides'}}) {
12371: if ($usertypeshash{$type}) {
12372: if (grep(/^\Q$type\E/,@overrides)) {
12373: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
12374: $usertypeshash{$type}).'<ul><li>';
12375: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
12376: my @text;
12377: foreach my $item (@contacts) {
12378: if ($newsetting{'override_'.$type}{$item}) {
12379: push(@text,$short_titles->{$item});
12380: }
12381: }
12382: if ($newsetting{'override_'.$type}{'others'} ne '') {
12383: push(@text,$newsetting{'override_'.$type}{'others'});
12384: }
12385:
12386: if (@text) {
12387: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
12388: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
12389: }
12390: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
12391: my $bcctext;
12392: if (@text) {
12393: $bcctext = ' '.&mt('with Bcc to');
12394: } else {
12395: $bcctext = '(Bcc)';
12396: }
12397: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
12398: } elsif (!@text) {
12399: $resulttext .= &mt('Helpdesk e-mail sent to no one');
12400: }
12401: $resulttext .= '</li>';
12402: if ($newsetting{'override_'.$type}{'include'} ne '') {
12403: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
12404: if ($loc eq 'b') {
12405: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
12406: } elsif ($loc eq 's') {
12407: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
12408: }
12409: }
12410: }
12411: $resulttext .= '</li></ul></li>';
12412: } else {
12413: push(@deletions,$usertypeshash{$type});
12414: }
12415: }
12416: }
12417: if (@deletions) {
12418: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
12419: join(', ',@deletions)).'</li>';
12420: }
12421: }
1.160.6.23 raeburn 12422: my @offon = ('off','on');
1.160.6.107 raeburn 12423: my $corelink = &core_link_msu();
1.160.6.23 raeburn 12424: if ($changes{'reporterrors'}) {
12425: $resulttext .= '<li>'.
12426: &mt('E-mail error reports to [_1] set to "'.
12427: $offon[$env{'form.reporterrors'}].'".',
1.160.6.107 raeburn 12428: $corelink).
1.160.6.23 raeburn 12429: '</li>';
12430: }
12431: if ($changes{'reportupdates'}) {
12432: $resulttext .= '<li>'.
12433: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
12434: $offon[$env{'form.reportupdates'}].'".',
1.160.6.107 raeburn 12435: $corelink).
1.160.6.23 raeburn 12436: '</li>';
12437: }
1.160.6.107 raeburn 12438: if ($changes{'reportstatus'}) {
12439: $resulttext .= '<li>'.
12440: &mt('E-mail status if errors above threshold to [_1] set to "'.
12441: $offon[$env{'form.reportstatus'}].'".',
12442: $corelink).
12443: '</li>';
12444: }
12445: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
12446: $resulttext .= '<li>'.
12447: &mt('Nightly status check e-mail settings').':<ul>';
12448: my (%defval,%use_def,%shown);
12449: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
12450: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
12451: $defval{'weights'} =
12452: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
12453: $defval{'excluded'} = &mt('None');
12454: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
12455: foreach my $item ('threshold','sysmail','weights','excluded') {
12456: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
12457: if (($item eq 'threshold') || ($item eq 'sysmail')) {
12458: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
12459: } elsif ($item eq 'weights') {
12460: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
12461: foreach my $type ('E','W','N','U') {
12462: $shown{$item} .= $lonstatus_names->{$type}.'=';
12463: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
12464: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
12465: } else {
12466: $shown{$item} .= $lonstatus_defs->{$type};
12467: }
12468: $shown{$item} .= ', ';
12469: }
12470: $shown{$item} =~ s/, $//;
12471: } else {
12472: $shown{$item} = $defval{$item};
12473: }
12474: } elsif ($item eq 'excluded') {
12475: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
12476: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
12477: } else {
12478: $shown{$item} = $defval{$item};
12479: }
12480: }
12481: } else {
12482: $shown{$item} = $defval{$item};
12483: }
12484: }
12485: } else {
12486: foreach my $item ('threshold','weights','excluded','sysmail') {
12487: $shown{$item} = $defval{$item};
12488: }
12489: }
12490: foreach my $item ('threshold','weights','excluded','sysmail') {
12491: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
12492: $shown{$item}).'</li>';
12493: }
12494: $resulttext .= '</ul></li>';
12495: }
1.160.6.78 raeburn 12496: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
12497: my (@optional,@required,@unused,$maxsizechg);
12498: foreach my $field (@{$changes{'helpform'}}) {
12499: if ($field eq 'maxsize') {
12500: $maxsizechg = 1;
12501: next;
12502: }
12503: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
12504: push(@optional,$field);
12505: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
12506: push(@unused,$field);
12507: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
12508: push(@required,$field);
12509: }
12510: }
12511: if (@optional) {
12512: $resulttext .= '<li>'.
12513: &mt('Help form fields changed to "Optional": [_1].',
12514: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
12515: '</li>';
12516: }
12517: if (@required) {
12518: $resulttext .= '<li>'.
12519: &mt('Help form fields changed to "Required": [_1].',
12520: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
12521: '</li>';
12522: }
12523: if (@unused) {
12524: $resulttext .= '<li>'.
12525: &mt('Help form fields changed to "Not shown": [_1].',
12526: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
12527: '</li>';
12528: }
12529: if ($maxsizechg) {
12530: $resulttext .= '<li>'.
12531: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
12532: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
12533: '</li>';
12534: }
12535: }
1.28 raeburn 12536: $resulttext .= '</ul>';
12537: } else {
1.160.6.78 raeburn 12538: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 12539: }
12540: } else {
12541: $resulttext = '<span class="LC_error">'.
12542: &mt('An error occurred: [_1].',$putresult).'</span>';
12543: }
12544: return $resulttext;
12545: }
12546:
1.160.6.98 raeburn 12547: sub modify_passwords {
12548: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
12549: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
12550: $updatedefaults,$updateconf);
12551: my $customfn = 'resetpw.html';
12552: if (ref($domconfig{'passwords'}) eq 'HASH') {
12553: %current = %{$domconfig{'passwords'}};
12554: }
12555: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12556: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12557: if (ref($types) eq 'ARRAY') {
12558: @oktypes = @{$types};
12559: }
12560: push(@oktypes,'default');
12561:
12562: my %titles = &Apache::lonlocal::texthash (
12563: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
12564: intauth_check => 'Check bcrypt cost if authenticated',
12565: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
12566: permanent => 'Permanent e-mail address',
12567: critical => 'Critical notification address',
12568: notify => 'Notification address',
12569: min => 'Minimum password length',
12570: max => 'Maximum password length',
12571: chars => 'Required characters',
12572: numsaved => 'Number of previous passwords to save',
12573: reset => 'Resetting Forgotten Password',
12574: intauth => 'Encryption of Stored Passwords (Internal Auth)',
12575: rules => 'Rules for LON-CAPA Passwords',
12576: crsownerchg => 'Course Owner Changing Student Passwords',
12577: username => 'Username',
12578: email => 'E-mail address',
12579: );
12580:
12581: #
12582: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
12583: #
12584: my (%curr_defaults,%save_defaults);
12585: if (ref($domconfig{'defaults'}) eq 'HASH') {
12586: foreach my $key (keys(%{$domconfig{'defaults'}})) {
12587: if ($key =~ /^intauth_(cost|check|switch)$/) {
12588: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
12589: } else {
12590: $save_defaults{$key} = $domconfig{'defaults'}{$key};
12591: }
12592: }
12593: }
12594: my %staticdefaults = (
12595: 'resetlink' => 2,
12596: 'resetcase' => \@oktypes,
12597: 'resetprelink' => 'both',
12598: 'resetemail' => ['critical','notify','permanent'],
12599: 'intauth_cost' => 10,
12600: 'intauth_check' => 0,
12601: 'intauth_switch' => 0,
12602: );
1.160.6.99 raeburn 12603: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 12604: foreach my $type (@oktypes) {
12605: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
12606: }
12607: my $linklife = $env{'form.passwords_link'};
12608: $linklife =~ s/^\s+|\s+$//g;
12609: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
12610: $newvalues{'resetlink'} = $linklife;
12611: if ($current{'resetlink'}) {
12612: if ($current{'resetlink'} ne $linklife) {
12613: $changes{'reset'} = 1;
12614: }
1.160.6.102 raeburn 12615: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12616: if ($staticdefaults{'resetlink'} ne $linklife) {
12617: $changes{'reset'} = 1;
12618: }
12619: }
12620: } elsif ($current{'resetlink'}) {
12621: $changes{'reset'} = 1;
12622: }
12623: my @casesens;
12624: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
12625: foreach my $case (sort(@posscase)) {
12626: if (grep(/^\Q$case\E$/,@oktypes)) {
12627: push(@casesens,$case);
12628: }
12629: }
12630: $newvalues{'resetcase'} = \@casesens;
12631: if (ref($current{'resetcase'}) eq 'ARRAY') {
12632: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
12633: if (@diffs > 0) {
12634: $changes{'reset'} = 1;
12635: }
1.160.6.102 raeburn 12636: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12637: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
12638: if (@diffs > 0) {
12639: $changes{'reset'} = 1;
12640: }
12641: }
12642: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
12643: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
12644: if (exists($current{'resetprelink'})) {
12645: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
12646: $changes{'reset'} = 1;
12647: }
1.160.6.102 raeburn 12648: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12649: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
12650: $changes{'reset'} = 1;
12651: }
12652: }
12653: } elsif ($current{'resetprelink'}) {
12654: $changes{'reset'} = 1;
12655: }
12656: foreach my $type (@oktypes) {
12657: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
12658: my @postlink;
12659: foreach my $item (sort(@possplink)) {
12660: if ($item =~ /^(email|username)$/) {
12661: push(@postlink,$item);
12662: }
12663: }
12664: $newvalues{'resetpostlink'}{$type} = \@postlink;
12665: unless ($changes{'reset'}) {
12666: if (ref($current{'resetpostlink'}) eq 'HASH') {
12667: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
12668: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
12669: if (@diffs > 0) {
12670: $changes{'reset'} = 1;
12671: }
12672: } else {
12673: $changes{'reset'} = 1;
12674: }
1.160.6.102 raeburn 12675: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12676: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
12677: if (@diffs > 0) {
12678: $changes{'reset'} = 1;
12679: }
12680: }
12681: }
12682: }
12683: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
12684: my @resetemail;
12685: foreach my $item (sort(@possemailsrc)) {
12686: if ($item =~ /^(permanent|critical|notify)$/) {
12687: push(@resetemail,$item);
12688: }
12689: }
12690: $newvalues{'resetemail'} = \@resetemail;
12691: unless ($changes{'reset'}) {
12692: if (ref($current{'resetemail'}) eq 'ARRAY') {
12693: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
12694: if (@diffs > 0) {
12695: $changes{'reset'} = 1;
12696: }
1.160.6.102 raeburn 12697: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 12698: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
12699: if (@diffs > 0) {
12700: $changes{'reset'} = 1;
12701: }
12702: }
12703: }
12704: if ($env{'form.passwords_stdtext'} == 0) {
12705: $newvalues{'resetremove'} = 1;
12706: unless ($current{'resetremove'}) {
12707: $changes{'reset'} = 1;
12708: }
12709: } elsif ($current{'resetremove'}) {
12710: $changes{'reset'} = 1;
12711: }
12712: if ($env{'form.passwords_customfile.filename'} ne '') {
12713: my $servadm = $r->dir_config('lonAdmEMail');
12714: my $servadm = $r->dir_config('lonAdmEMail');
12715: my ($configuserok,$author_ok,$switchserver) =
12716: &config_check($dom,$confname,$servadm);
12717: my $error;
12718: if ($configuserok eq 'ok') {
12719: if ($switchserver) {
12720: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
12721: } else {
12722: if ($author_ok eq 'ok') {
12723: my ($result,$customurl) =
12724: &publishlogo($r,'upload','passwords_customfile',$dom,
12725: $confname,'customtext/resetpw','','',$customfn);
12726: if ($result eq 'ok') {
12727: $newvalues{'resetcustom'} = $customurl;
12728: $changes{'reset'} = 1;
12729: } else {
12730: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
12731: }
12732: } else {
12733: $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);
12734: }
12735: }
12736: } else {
12737: $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);
12738: }
12739: if ($error) {
12740: &Apache::lonnet::logthis($error);
12741: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12742: }
12743: } elsif ($current{'resetcustom'}) {
12744: if ($env{'form.passwords_custom_del'}) {
12745: $changes{'reset'} = 1;
12746: } else {
12747: $newvalues{'resetcustom'} = $current{'resetcustom'};
12748: }
12749: }
12750: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
12751: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
12752: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
12753: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
12754: $changes{'intauth'} = 1;
12755: }
12756: } else {
12757: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
12758: }
12759: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
12760: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
12761: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
12762: $changes{'intauth'} = 1;
12763: }
12764: } else {
12765: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
12766: }
12767: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
12768: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
12769: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
12770: $changes{'intauth'} = 1;
12771: }
12772: } else {
12773: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
12774: }
12775: foreach my $item ('cost','check','switch') {
12776: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
12777: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
12778: $updatedefaults = 1;
12779: }
12780: }
12781: foreach my $rule ('min','max','numsaved') {
12782: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.160.6.99 raeburn 12783: my $ruleok;
12784: if ($rule eq 'min') {
12785: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
12786: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
12787: $ruleok = 1;
12788: }
12789: }
12790: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
12791: ($env{'form.passwords_'.$rule} ne '0')) {
12792: $ruleok = 1;
12793: }
12794: if ($ruleok) {
1.160.6.98 raeburn 12795: $newvalues{$rule} = $env{'form.passwords_'.$rule};
12796: if (exists($current{$rule})) {
12797: if ($newvalues{$rule} ne $current{$rule}) {
12798: $changes{'rules'} = 1;
12799: }
12800: } elsif ($rule eq 'min') {
12801: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
12802: $changes{'rules'} = 1;
12803: }
1.160.6.104 raeburn 12804: } else {
12805: $changes{'rules'} = 1;
1.160.6.98 raeburn 12806: }
12807: } elsif (exists($current{$rule})) {
12808: $changes{'rules'} = 1;
12809: }
12810: }
12811: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
12812: my @chars;
12813: foreach my $item (sort(@posschars)) {
12814: if ($item =~ /^(uc|lc|num|spec)$/) {
12815: push(@chars,$item);
12816: }
12817: }
12818: $newvalues{'chars'} = \@chars;
12819: unless ($changes{'rules'}) {
12820: if (ref($current{'chars'}) eq 'ARRAY') {
12821: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
12822: if (@diffs > 0) {
12823: $changes{'rules'} = 1;
12824: }
12825: } else {
12826: if (@chars > 0) {
12827: $changes{'rules'} = 1;
12828: }
12829: }
12830: }
12831: my %crsownerchg = (
12832: by => [],
12833: for => [],
12834: );
12835: foreach my $item ('by','for') {
12836: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
12837: foreach my $type (sort(@posstypes)) {
12838: if (grep(/^\Q$type\E$/,@oktypes)) {
12839: push(@{$crsownerchg{$item}},$type);
12840: }
12841: }
12842: }
12843: $newvalues{'crsownerchg'} = \%crsownerchg;
12844: if (ref($current{'crsownerchg'}) eq 'HASH') {
12845: foreach my $item ('by','for') {
12846: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
12847: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
12848: if (@diffs > 0) {
12849: $changes{'crsownerchg'} = 1;
12850: last;
12851: }
12852: }
12853: }
1.160.6.102 raeburn 12854: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98 raeburn 12855: foreach my $item ('by','for') {
12856: if (@{$crsownerchg{$item}} > 0) {
12857: $changes{'crsownerchg'} = 1;
12858: last;
12859: }
12860: }
12861: }
12862:
12863: my %confighash = (
12864: defaults => \%save_defaults,
12865: passwords => \%newvalues,
12866: );
12867: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
12868:
12869: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
12870: if ($putresult eq 'ok') {
12871: if (keys(%changes) > 0) {
12872: $resulttext = &mt('Changes made: ').'<ul>';
12873: foreach my $key ('reset','intauth','rules','crsownerchg') {
12874: if ($changes{$key}) {
12875: unless ($key eq 'intauth') {
12876: $updateconf = 1;
12877: }
12878: $resulttext .= '<li>'.$titles{$key}.':<ul>';
12879: if ($key eq 'reset') {
12880: if ($confighash{'passwords'}{'captcha'} eq 'original') {
12881: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
12882: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
12883: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.160.6.104 raeburn 12884: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
12885: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
12886: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
12887: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
12888: }
1.160.6.98 raeburn 12889: } else {
12890: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
12891: }
12892: if ($confighash{'passwords'}{'resetlink'}) {
12893: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
12894: } else {
12895: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
12896: &mt('Will default to 2 hours').'</li>';
12897: }
12898: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
12899: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
12900: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
12901: } else {
12902: my $casesens;
12903: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
12904: if ($type eq 'default') {
12905: $casesens .= $othertitle.', ';
12906: } elsif ($usertypes->{$type} ne '') {
12907: $casesens .= $usertypes->{$type}.', ';
12908: }
12909: }
12910: $casesens =~ s/\Q, \E$//;
12911: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
12912: }
12913: } else {
12914: $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>';
12915: }
12916: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
12917: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
12918: } else {
12919: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
12920: }
12921: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
12922: my $output;
12923: if (ref($types) eq 'ARRAY') {
12924: foreach my $type (@{$types}) {
12925: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
12926: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
12927: $output .= $usertypes->{$type}.' -- '.&mt('none');
12928: } else {
12929: $output .= $usertypes->{$type}.' -- '.
12930: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
12931: }
12932: }
12933: }
12934: }
12935: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
12936: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
12937: $output .= $othertitle.' -- '.&mt('none');
12938: } else {
12939: $output .= $othertitle.' -- '.
12940: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
12941: }
12942: }
12943: if ($output) {
12944: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
12945: } else {
12946: $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>';
12947: }
12948: } else {
12949: $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>';
12950: }
12951: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
12952: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
12953: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
12954: } else {
12955: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
12956: }
12957: } else {
1.160.6.110 raeburn 12958: $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 12959: }
12960: if ($confighash{'passwords'}{'resetremove'}) {
12961: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
12962: } else {
12963: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
12964: }
12965: if ($confighash{'passwords'}{'resetcustom'}) {
12966: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.160.6.104 raeburn 12967: &mt('custom text'),600,500,undef,undef,
12968: undef,undef,'background-color:#ffffff');
12969: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.160.6.98 raeburn 12970: } else {
12971: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
12972: }
12973: } elsif ($key eq 'intauth') {
12974: foreach my $item ('cost','switch','check') {
12975: my $value = $save_defaults{$key.'_'.$item};
12976: if ($item eq 'switch') {
12977: my %optiondesc = &Apache::lonlocal::texthash (
12978: 0 => 'No',
12979: 1 => 'Yes',
12980: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
12981: );
12982: if ($value =~ /^(0|1|2)$/) {
12983: $value = $optiondesc{$value};
12984: } else {
12985: $value = &mt('none -- defaults to No');
12986: }
12987: } elsif ($item eq 'check') {
12988: my %optiondesc = &Apache::lonlocal::texthash (
12989: 0 => 'No',
12990: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
12991: 2 => 'Yes, disallow login if stored cost is less than domain default',
12992: );
12993: if ($value =~ /^(0|1|2)$/) {
12994: $value = $optiondesc{$value};
12995: } else {
12996: $value = &mt('none -- defaults to No');
12997: }
12998: }
12999: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
13000: }
13001: } elsif ($key eq 'rules') {
13002: foreach my $rule ('min','max','numsaved') {
13003: if ($confighash{'passwords'}{$rule} eq '') {
13004: if ($rule eq 'min') {
13005: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99 raeburn 13006: ' '.&mt('Default of [_1] will be used',
13007: $Apache::lonnet::passwdmin).'</li>';
1.160.6.98 raeburn 13008: } else {
13009: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
13010: }
13011: } else {
13012: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
13013: }
13014: }
1.160.6.104 raeburn 13015: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
13016: if (@{$confighash{'passwords'}{'chars'}} > 0) {
13017: my %rulenames = &Apache::lonlocal::texthash(
13018: uc => 'At least one upper case letter',
13019: lc => 'At least one lower case letter',
13020: num => 'At least one number',
13021: spec => 'At least one non-alphanumeric',
13022: );
13023: my $needed = '<ul><li>'.
13024: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
13025: '</li></ul>';
13026: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
13027: } else {
13028: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13029: }
13030: } else {
13031: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13032: }
1.160.6.98 raeburn 13033: } elsif ($key eq 'crsownerchg') {
13034: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
13035: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
13036: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
13037: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
13038: } else {
13039: my %crsownerstr;
13040: foreach my $item ('by','for') {
13041: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
13042: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
13043: if ($type eq 'default') {
13044: $crsownerstr{$item} .= $othertitle.', ';
13045: } elsif ($usertypes->{$type} ne '') {
13046: $crsownerstr{$item} .= $usertypes->{$type}.', ';
13047: }
13048: }
13049: $crsownerstr{$item} =~ s/\Q, \E$//;
13050: }
13051: }
13052: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
13053: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
13054: }
13055: } else {
13056: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
13057: }
13058: }
13059: $resulttext .= '</ul></li>';
13060: }
13061: }
13062: $resulttext .= '</ul>';
13063: } else {
13064: $resulttext = &mt('No changes made to password settings');
13065: }
13066: my $cachetime = 24*60*60;
13067: if ($updatedefaults) {
13068: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13069: if (ref($lastactref) eq 'HASH') {
13070: $lastactref->{'domdefaults'} = 1;
13071: }
13072: }
13073: if ($updateconf) {
13074: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
13075: if (ref($lastactref) eq 'HASH') {
13076: $lastactref->{'passwdconf'} = 1;
13077: }
13078: }
13079: } else {
13080: $resulttext = '<span class="LC_error">'.
13081: &mt('An error occurred: [_1]',$putresult).'</span>';
13082: }
13083: if ($errors) {
13084: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13085: $errors.'</ul></p>';
13086: }
13087: return $resulttext;
13088: }
13089:
1.28 raeburn 13090: sub modify_usercreation {
1.27 raeburn 13091: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 13092: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 13093: my $warningmsg;
1.27 raeburn 13094: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13095: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 13096: if ($key eq 'cancreate') {
13097: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13098: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 13099: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 13100: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 13101: } else {
13102: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 13103: }
1.50 raeburn 13104: }
1.43 raeburn 13105: }
1.160.6.34 raeburn 13106: } elsif ($key eq 'email_rule') {
13107: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13108: } else {
13109: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 13110: }
13111: }
1.34 raeburn 13112: }
1.160.6.34 raeburn 13113: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
13114: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
13115: my @contexts = ('author','course','requestcrs');
13116: foreach my $item(@contexts) {
13117: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 13118: }
1.34 raeburn 13119: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13120: foreach my $item (@contexts) {
1.160.6.34 raeburn 13121: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
13122: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 13123: }
1.27 raeburn 13124: }
1.34 raeburn 13125: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
13126: foreach my $item (@contexts) {
1.43 raeburn 13127: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 13128: if ($cancreate{$item} ne 'any') {
13129: push(@{$changes{'cancreate'}},$item);
13130: }
13131: } else {
13132: if ($cancreate{$item} ne 'none') {
13133: push(@{$changes{'cancreate'}},$item);
13134: }
1.27 raeburn 13135: }
13136: }
13137: } else {
1.43 raeburn 13138: foreach my $item (@contexts) {
1.34 raeburn 13139: push(@{$changes{'cancreate'}},$item);
13140: }
1.27 raeburn 13141: }
1.34 raeburn 13142:
1.27 raeburn 13143: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
13144: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
13145: if (!grep(/^\Q$type\E$/,@username_rule)) {
13146: push(@{$changes{'username_rule'}},$type);
13147: }
13148: }
13149: foreach my $type (@username_rule) {
13150: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
13151: push(@{$changes{'username_rule'}},$type);
13152: }
13153: }
13154: } else {
13155: push(@{$changes{'username_rule'}},@username_rule);
13156: }
13157:
1.32 raeburn 13158: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
13159: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
13160: if (!grep(/^\Q$type\E$/,@id_rule)) {
13161: push(@{$changes{'id_rule'}},$type);
13162: }
13163: }
13164: foreach my $type (@id_rule) {
13165: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
13166: push(@{$changes{'id_rule'}},$type);
13167: }
13168: }
13169: } else {
13170: push(@{$changes{'id_rule'}},@id_rule);
13171: }
13172:
1.43 raeburn 13173: my @authen_contexts = ('author','course','domain');
1.28 raeburn 13174: my @authtypes = ('int','krb4','krb5','loc');
13175: my %authhash;
1.43 raeburn 13176: foreach my $item (@authen_contexts) {
1.28 raeburn 13177: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
13178: foreach my $auth (@authtypes) {
13179: if (grep(/^\Q$auth\E$/,@authallowed)) {
13180: $authhash{$item}{$auth} = 1;
13181: } else {
13182: $authhash{$item}{$auth} = 0;
13183: }
13184: }
13185: }
13186: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 13187: foreach my $item (@authen_contexts) {
1.28 raeburn 13188: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
13189: foreach my $auth (@authtypes) {
13190: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
13191: push(@{$changes{'authtypes'}},$item);
13192: last;
13193: }
13194: }
13195: }
13196: }
13197: } else {
1.43 raeburn 13198: foreach my $item (@authen_contexts) {
1.28 raeburn 13199: push(@{$changes{'authtypes'}},$item);
13200: }
13201: }
13202:
1.160.6.34 raeburn 13203: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
13204: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
13205: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
13206: $save_usercreate{'id_rule'} = \@id_rule;
13207: $save_usercreate{'username_rule'} = \@username_rule,
13208: $save_usercreate{'authtypes'} = \%authhash;
13209:
1.27 raeburn 13210: my %usercreation_hash = (
1.160.6.34 raeburn 13211: usercreation => \%save_usercreate,
13212: );
1.27 raeburn 13213:
13214: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
13215: $dom);
1.50 raeburn 13216:
1.160.6.34 raeburn 13217: if ($putresult eq 'ok') {
13218: if (keys(%changes) > 0) {
13219: $resulttext = &mt('Changes made:').'<ul>';
13220: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13221: my %lt = &usercreation_types();
13222: foreach my $type (@{$changes{'cancreate'}}) {
13223: my $chgtext = $lt{$type}.', ';
13224: if ($cancreate{$type} eq 'none') {
13225: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
13226: } elsif ($cancreate{$type} eq 'any') {
13227: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
13228: } elsif ($cancreate{$type} eq 'official') {
13229: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
13230: } elsif ($cancreate{$type} eq 'unofficial') {
13231: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
13232: }
13233: $resulttext .= '<li>'.$chgtext.'</li>';
13234: }
13235: }
13236: if (ref($changes{'username_rule'}) eq 'ARRAY') {
13237: my ($rules,$ruleorder) =
13238: &Apache::lonnet::inst_userrules($dom,'username');
13239: my $chgtext = '<ul>';
13240: foreach my $type (@username_rule) {
13241: if (ref($rules->{$type}) eq 'HASH') {
13242: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
13243: }
13244: }
13245: $chgtext .= '</ul>';
13246: if (@username_rule > 0) {
13247: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13248: } else {
13249: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
13250: }
13251: }
13252: if (ref($changes{'id_rule'}) eq 'ARRAY') {
13253: my ($idrules,$idruleorder) =
13254: &Apache::lonnet::inst_userrules($dom,'id');
13255: my $chgtext = '<ul>';
13256: foreach my $type (@id_rule) {
13257: if (ref($idrules->{$type}) eq 'HASH') {
13258: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
13259: }
13260: }
13261: $chgtext .= '</ul>';
13262: if (@id_rule > 0) {
13263: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13264: } else {
13265: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
13266: }
13267: }
13268: my %authname = &authtype_names();
13269: my %context_title = &context_names();
13270: if (ref($changes{'authtypes'}) eq 'ARRAY') {
13271: my $chgtext = '<ul>';
13272: foreach my $type (@{$changes{'authtypes'}}) {
13273: my @allowed;
13274: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
13275: foreach my $auth (@authtypes) {
13276: if ($authhash{$type}{$auth}) {
13277: push(@allowed,$authname{$auth});
13278: }
13279: }
13280: if (@allowed > 0) {
13281: $chgtext .= join(', ',@allowed).'</li>';
13282: } else {
13283: $chgtext .= &mt('none').'</li>';
13284: }
13285: }
13286: $chgtext .= '</ul>';
13287: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
13288: $resulttext .= '</li>';
13289: }
13290: $resulttext .= '</ul>';
13291: } else {
13292: $resulttext = &mt('No changes made to user creation settings');
13293: }
13294: } else {
13295: $resulttext = '<span class="LC_error">'.
13296: &mt('An error occurred: [_1]',$putresult).'</span>';
13297: }
13298: if ($warningmsg ne '') {
13299: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13300: }
13301: return $resulttext;
13302: }
13303:
13304: sub modify_selfcreation {
1.160.6.93 raeburn 13305: my ($dom,$lastactref,%domconfig) = @_;
13306: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
13307: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
13308: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13309: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
13310: if (ref($typesref) eq 'ARRAY') {
13311: @types = @{$typesref};
13312: }
13313: if (ref($usertypesref) eq 'HASH') {
13314: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 13315: }
1.160.6.93 raeburn 13316: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 13317: #
13318: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
13319: #
13320: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13321: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
13322: if ($key eq 'cancreate') {
13323: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13324: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
13325: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 13326: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
13327: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
13328: ($item eq 'emailusername') || ($item eq 'shibenv') ||
13329: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
13330: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 13331: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13332: } else {
13333: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13334: }
13335: }
13336: }
13337: } elsif ($key eq 'email_rule') {
13338: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13339: } else {
13340: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13341: }
13342: }
13343: }
13344: #
13345: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
13346: #
13347: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13348: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
13349: if ($key eq 'selfcreate') {
13350: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
13351: } else {
13352: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
13353: }
13354: }
13355: }
1.160.6.93 raeburn 13356: #
13357: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
13358: #
13359: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13360: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
13361: if ($key eq 'inststatusguest') {
13362: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
13363: } else {
13364: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
13365: }
13366: }
13367: }
1.160.6.34 raeburn 13368:
13369: my @contexts = ('selfcreate');
13370: @{$cancreate{'selfcreate'}} = ();
13371: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 13372: if (@types) {
13373: @{$cancreate{'statustocreate'}} = ();
13374: }
1.160.6.40 raeburn 13375: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 13376: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 13377: %{$cancreate{'emailverified'}} = ();
13378: %{$cancreate{'emailoptions'}} = ();
13379: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 13380: my %selfcreatetypes = (
13381: sso => 'users authenticated by institutional single sign on',
13382: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 13383: email => 'users verified by e-mail',
1.50 raeburn 13384: );
1.160.6.34 raeburn 13385: #
13386: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
13387: # is permitted.
13388: #
1.160.6.40 raeburn 13389:
1.160.6.93 raeburn 13390: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 13391:
1.160.6.93 raeburn 13392: my (@statuses,%email_rule);
1.160.6.35 raeburn 13393: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 13394: if ($item eq 'email') {
1.160.6.40 raeburn 13395: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 13396: if (@types) {
13397: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
13398: foreach my $status (@poss_statuses) {
13399: if (grep(/^\Q$status\E$/,(@types,'default'))) {
13400: push(@statuses,$status);
13401: }
13402: }
13403: $save_inststatus{'inststatusguest'} = \@statuses;
13404: } else {
13405: push(@statuses,'default');
13406: }
13407: if (@statuses) {
13408: my %curr_rule;
13409: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
13410: foreach my $type (@statuses) {
13411: $curr_rule{$type} = $curr_usercreation{'email_rule'};
13412: }
13413: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
13414: foreach my $type (@statuses) {
13415: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
13416: }
13417: }
13418: push(@{$cancreate{'selfcreate'}},'email');
13419: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
13420: my %curremaildom;
13421: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
13422: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
13423: }
13424: foreach my $type (@statuses) {
13425: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
13426: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
13427: }
13428: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
13429: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
13430: }
13431: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
13432: #
13433: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
13434: #
13435: my $chosen = $1;
13436: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
13437: my $emaildom;
13438: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
13439: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
13440: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
13441: if (ref($curremaildom{$type}) eq 'HASH') {
13442: if (exists($curremaildom{$type}{$chosen})) {
13443: if ($curremaildom{$type}{$chosen} ne $emaildom) {
13444: push(@{$changes{'cancreate'}},'emaildomain');
13445: }
13446: } elsif ($emaildom ne '') {
13447: push(@{$changes{'cancreate'}},'emaildomain');
13448: }
13449: } elsif ($emaildom ne '') {
13450: push(@{$changes{'cancreate'}},'emaildomain');
13451: }
13452: }
13453: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13454: } elsif ($chosen eq 'custom') {
13455: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
13456: $email_rule{$type} = [];
13457: if (ref($emailrules) eq 'HASH') {
13458: foreach my $rule (@possemail_rules) {
13459: if (exists($emailrules->{$rule})) {
13460: push(@{$email_rule{$type}},$rule);
13461: }
13462: }
13463: }
13464: if (@{$email_rule{$type}}) {
13465: $cancreate{'emailoptions'}{$type} = 'custom';
13466: if (ref($curr_rule{$type}) eq 'ARRAY') {
13467: if (@{$curr_rule{$type}} > 0) {
13468: foreach my $rule (@{$curr_rule{$type}}) {
13469: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
13470: push(@{$changes{'email_rule'}},$type);
13471: }
13472: }
13473: }
13474: foreach my $type (@{$email_rule{$type}}) {
13475: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
13476: push(@{$changes{'email_rule'}},$type);
13477: }
13478: }
13479: } else {
13480: push(@{$changes{'email_rule'}},$type);
13481: }
13482: }
13483: } else {
13484: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13485: }
13486: }
13487: }
13488: if (@types) {
13489: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13490: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
13491: if (@changed) {
13492: push(@{$changes{'inststatus'}},'inststatusguest');
13493: }
13494: } else {
13495: push(@{$changes{'inststatus'}},'inststatusguest');
13496: }
13497: }
13498: } else {
13499: delete($env{'form.cancreate_email'});
13500: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13501: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13502: push(@{$changes{'inststatus'}},'inststatusguest');
13503: }
13504: }
13505: }
13506: } else {
13507: $save_inststatus{'inststatusguest'} = [];
13508: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13509: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13510: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 13511: }
13512: }
1.160.6.34 raeburn 13513: }
13514: } else {
13515: if ($env{'form.cancreate_'.$item}) {
13516: push(@{$cancreate{'selfcreate'}},$item);
13517: }
13518: }
13519: }
1.160.6.93 raeburn 13520: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 13521: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
13522: #
1.160.6.35 raeburn 13523: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
13524: # 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 13525: #
1.160.6.40 raeburn 13526:
1.160.6.48 raeburn 13527: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 13528: push(@contexts,'emailusername');
1.160.6.93 raeburn 13529: if (@statuses) {
13530: foreach my $type (@statuses) {
1.160.6.35 raeburn 13531: if (ref($infofields) eq 'ARRAY') {
13532: foreach my $field (@{$infofields}) {
13533: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
13534: $cancreate{'emailusername'}{$type}{$field} = $1;
13535: }
13536: }
1.160.6.34 raeburn 13537: }
13538: }
13539: }
13540: #
13541: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 13542: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 13543: #
13544:
13545: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
13546: @approvalnotify = sort(@approvalnotify);
13547: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
13548: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13549: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
13550: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
13551: push(@{$changes{'cancreate'}},'notify');
13552: }
13553: } else {
13554: if ($cancreate{'notify'}{'approval'}) {
13555: push(@{$changes{'cancreate'}},'notify');
13556: }
13557: }
13558: } elsif ($cancreate{'notify'}{'approval'}) {
13559: push(@{$changes{'cancreate'}},'notify');
13560: }
13561:
13562: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
13563: }
13564: #
1.160.6.40 raeburn 13565: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 13566: # institutional log-in.
13567: #
13568: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
13569: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
13570: ($domdefaults{'auth_def'} eq 'localauth'))) {
13571: $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.').' '.
13572: &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.');
13573: }
13574: }
13575: my @fields = ('lastname','firstname','middlename','generation',
13576: 'permanentemail','id');
1.160.6.44 raeburn 13577: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 13578: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13579: #
13580: # Where usernames may created for institutional log-in and/or institutional single sign on:
13581: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
13582: # may self-create accounts
13583: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
13584: # which the user may supply, if institutional data is unavailable.
13585: #
13586: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 13587: if (@types) {
13588: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
13589: push(@contexts,'statustocreate');
13590: foreach my $type (@types) {
1.160.6.34 raeburn 13591: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
13592: foreach my $field (@fields) {
13593: if (grep(/^\Q$field\E$/,@modifiable)) {
13594: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
13595: } else {
13596: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
13597: }
13598: }
13599: }
13600: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 13601: foreach my $type (@types) {
1.160.6.34 raeburn 13602: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
13603: foreach my $field (@fields) {
13604: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
13605: $curr_usermodify{'selfcreate'}{$type}{$field}) {
13606: push(@{$changes{'selfcreate'}},$type);
13607: last;
13608: }
13609: }
13610: }
13611: }
13612: } else {
1.160.6.93 raeburn 13613: foreach my $type (@types) {
1.160.6.34 raeburn 13614: push(@{$changes{'selfcreate'}},$type);
13615: }
13616: }
13617: }
1.160.6.44 raeburn 13618: foreach my $field (@shibfields) {
13619: if ($env{'form.shibenv_'.$field} ne '') {
13620: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
13621: }
13622: }
13623: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13624: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
13625: foreach my $field (@shibfields) {
13626: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
13627: push(@{$changes{'cancreate'}},'shibenv');
13628: }
13629: }
13630: } else {
13631: foreach my $field (@shibfields) {
13632: if ($env{'form.shibenv_'.$field}) {
13633: push(@{$changes{'cancreate'}},'shibenv');
13634: last;
13635: }
13636: }
13637: }
13638: }
1.160.6.34 raeburn 13639: }
13640: foreach my $item (@contexts) {
13641: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
13642: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
13643: if (ref($cancreate{$item}) eq 'ARRAY') {
13644: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
13645: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13646: push(@{$changes{'cancreate'}},$item);
13647: }
13648: }
13649: }
13650: }
13651: if (ref($cancreate{$item}) eq 'ARRAY') {
13652: foreach my $type (@{$cancreate{$item}}) {
13653: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
13654: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13655: push(@{$changes{'cancreate'}},$item);
13656: }
13657: }
13658: }
13659: }
13660: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
13661: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 13662: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
13663: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13664: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
13665: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 13666: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13667: push(@{$changes{'cancreate'}},$item);
13668: }
13669: }
13670: }
1.160.6.93 raeburn 13671: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13672: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 13673: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13674: push(@{$changes{'cancreate'}},$item);
13675: }
1.160.6.34 raeburn 13676: }
13677: }
13678: }
1.160.6.93 raeburn 13679: foreach my $type (keys(%{$cancreate{$item}})) {
13680: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13681: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13682: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13683: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 13684: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13685: push(@{$changes{'cancreate'}},$item);
13686: }
13687: }
13688: } else {
13689: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13690: push(@{$changes{'cancreate'}},$item);
13691: }
13692: }
13693: }
1.160.6.93 raeburn 13694: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13695: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 13696: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13697: push(@{$changes{'cancreate'}},$item);
13698: }
1.160.6.34 raeburn 13699: }
13700: }
13701: }
13702: }
13703: } elsif ($curr_usercreation{'cancreate'}{$item}) {
13704: if (ref($cancreate{$item}) eq 'ARRAY') {
13705: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
13706: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13707: push(@{$changes{'cancreate'}},$item);
13708: }
13709: }
1.160.6.93 raeburn 13710: }
13711: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13712: if (ref($cancreate{$item}) eq 'HASH') {
13713: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13714: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 13715: }
13716: }
13717: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 13718: if (ref($cancreate{$item}) eq 'HASH') {
13719: foreach my $type (keys(%{$cancreate{$item}})) {
13720: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13721: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13722: if ($cancreate{$item}{$type}{$field}) {
13723: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13724: push(@{$changes{'cancreate'}},$item);
13725: }
13726: last;
13727: }
13728: }
13729: }
13730: }
1.160.6.34 raeburn 13731: }
13732: }
13733: }
13734: #
13735: # Populate %save_usercreate hash with updates to self-creation configuration.
13736: #
13737: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
13738: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 13739: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 13740: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
13741: if (ref($cancreate{'notify'}) eq 'HASH') {
13742: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
13743: }
1.160.6.40 raeburn 13744: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
13745: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
13746: }
1.160.6.93 raeburn 13747: if (ref($cancreate{'emailverified'}) eq 'HASH') {
13748: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
13749: }
13750: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
13751: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
13752: }
13753: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
13754: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
13755: }
1.160.6.34 raeburn 13756: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13757: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
13758: }
1.160.6.44 raeburn 13759: if (ref($cancreate{'shibenv'}) eq 'HASH') {
13760: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
13761: }
1.160.6.34 raeburn 13762: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 13763: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 13764:
13765: my %userconfig_hash = (
13766: usercreation => \%save_usercreate,
13767: usermodification => \%save_usermodify,
1.160.6.93 raeburn 13768: inststatus => \%save_inststatus,
1.160.6.34 raeburn 13769: );
1.160.6.93 raeburn 13770:
1.160.6.34 raeburn 13771: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
13772: $dom);
13773: #
1.160.6.93 raeburn 13774: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 13775: #
1.27 raeburn 13776: if ($putresult eq 'ok') {
13777: if (keys(%changes) > 0) {
13778: $resulttext = &mt('Changes made:').'<ul>';
13779: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 13780: my %lt = &selfcreation_types();
1.34 raeburn 13781: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 13782: my $chgtext = '';
1.45 raeburn 13783: if ($type eq 'selfcreate') {
1.50 raeburn 13784: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 13785: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 13786: } else {
1.160.6.34 raeburn 13787: $chgtext .= &mt('Self-creation of a new account is permitted for:').
13788: '<ul>';
1.50 raeburn 13789: foreach my $case (@{$cancreate{$type}}) {
13790: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
13791: }
13792: $chgtext .= '</ul>';
1.100 raeburn 13793: if (ref($cancreate{$type}) eq 'ARRAY') {
13794: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
13795: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13796: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 13797: $chgtext .= '<span class="LC_warning">'.
13798: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
13799: '</span><br />';
1.100 raeburn 13800: }
13801: }
13802: }
1.160.6.93 raeburn 13803: if (grep(/^email$/,@{$cancreate{$type}})) {
13804: if (!@statuses) {
13805: $chgtext .= '<span class="LC_warning">'.
13806: &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.").
13807: '</span><br />';
13808:
13809: }
13810: }
1.100 raeburn 13811: }
1.43 raeburn 13812: }
1.160.6.44 raeburn 13813: } elsif ($type eq 'shibenv') {
13814: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 13815: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 13816: } else {
13817: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
13818: '<ul>';
13819: foreach my $field (@shibfields) {
13820: next if ($cancreate{$type}{$field} eq '');
13821: if ($field eq 'inststatus') {
13822: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
13823: } else {
13824: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
13825: }
13826: }
13827: $chgtext .= '</ul>';
1.160.6.93 raeburn 13828: }
1.93 raeburn 13829: } elsif ($type eq 'statustocreate') {
1.96 raeburn 13830: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
13831: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
13832: if (@{$cancreate{'selfcreate'}} > 0) {
13833: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 13834: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 13835: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 13836: $chgtext .= '<br />'.
13837: '<span class="LC_warning">'.
13838: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
13839: '</span>';
13840: }
1.160.6.93 raeburn 13841: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 13842: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 13843: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
13844: } else {
13845: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
13846: }
13847: $chgtext .= '<ul>';
13848: foreach my $case (@{$cancreate{$type}}) {
13849: if ($case eq 'default') {
13850: $chgtext .= '<li>'.$othertitle.'</li>';
13851: } else {
1.160.6.93 raeburn 13852: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 13853: }
13854: }
1.100 raeburn 13855: $chgtext .= '</ul>';
13856: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 13857: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 13858: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
13859: '</span>';
1.100 raeburn 13860: }
13861: }
13862: } else {
13863: if (@{$cancreate{$type}} == 0) {
13864: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
13865: } else {
13866: $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 13867: }
13868: }
1.160.6.93 raeburn 13869: $chgtext .= '<br />';
1.93 raeburn 13870: }
1.160.6.40 raeburn 13871: } elsif ($type eq 'selfcreateprocessing') {
13872: my %choices = &Apache::lonlocal::texthash (
13873: automatic => 'Automatic approval',
13874: approval => 'Queued for approval',
13875: );
1.160.6.93 raeburn 13876: if (@types) {
13877: if (@statuses) {
13878: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
13879: '<ul>';
13880: foreach my $status (@statuses) {
13881: if ($status eq 'default') {
13882: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
13883: } else {
13884: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
13885: }
13886: }
13887: $chgtext .= '</ul>';
13888: }
13889: } else {
13890: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
13891: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
13892: }
13893: } elsif ($type eq 'emailverified') {
13894: my %options = &Apache::lonlocal::texthash (
13895: all => 'Same as e-mail',
13896: first => 'Omit @domain',
13897: free => 'Free to choose',
13898: );
13899: if (@types) {
13900: if (@statuses) {
13901: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
13902: '<ul>';
13903: foreach my $status (@statuses) {
13904: if ($status eq 'default') {
13905: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
13906: } else {
13907: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
13908: }
13909: }
13910: $chgtext .= '</ul>';
13911: }
1.160.6.40 raeburn 13912: } else {
1.160.6.93 raeburn 13913: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
13914: $options{$cancreate{'emailverified'}{'default'}});
13915: }
13916: } elsif ($type eq 'emailoptions') {
13917: my %options = &Apache::lonlocal::texthash (
13918: any => 'Any e-mail',
13919: inst => 'Institutional only',
13920: noninst => 'Non-institutional only',
13921: custom => 'Custom restrictions',
13922: );
13923: if (@types) {
13924: if (@statuses) {
13925: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
13926: '<ul>';
13927: foreach my $status (@statuses) {
13928: if ($type eq 'default') {
13929: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13930: } else {
13931: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13932: }
13933: }
13934: $chgtext .= '</ul>';
13935: }
13936: } else {
13937: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
13938: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
13939: } else {
13940: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
13941: $options{$cancreate{'emailoptions'}{'default'}});
13942: }
13943: }
13944: } elsif ($type eq 'emaildomain') {
13945: my $output;
13946: if (@statuses) {
13947: foreach my $type (@statuses) {
13948: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
13949: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
13950: if ($type eq 'default') {
13951: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13952: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13953: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13954: } else {
13955: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
13956: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13957: }
13958: } else {
13959: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13960: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13961: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13962: } else {
13963: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
13964: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13965: }
13966: }
13967: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
13968: if ($type eq 'default') {
13969: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13970: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13971: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13972: } else {
13973: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
13974: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13975: }
13976: } else {
13977: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13978: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13979: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13980: } else {
13981: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
13982: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13983: }
13984: }
13985: }
13986: }
13987: }
13988: }
13989: if ($output ne '') {
13990: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
13991: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 13992: }
1.160.6.5 raeburn 13993: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 13994: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 13995: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
13996: } else {
13997: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 13998: if ($captchas{$savecaptcha{$type}}) {
13999: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 14000: } else {
14001: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
14002: }
14003: }
14004: } elsif ($type eq 'recaptchakeys') {
14005: my ($privkey,$pubkey);
1.160.6.34 raeburn 14006: if (ref($savecaptcha{$type}) eq 'HASH') {
14007: $pubkey = $savecaptcha{$type}{'public'};
14008: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 14009: }
14010: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
14011: if (!$pubkey) {
14012: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
14013: } else {
14014: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
14015: }
14016: if (!$privkey) {
14017: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
14018: } else {
14019: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
14020: }
14021: $chgtext .= '</ul>';
1.160.6.69 raeburn 14022: } elsif ($type eq 'recaptchaversion') {
14023: if ($savecaptcha{'captcha'} eq 'recaptcha') {
14024: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
14025: }
1.160.6.34 raeburn 14026: } elsif ($type eq 'emailusername') {
14027: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 14028: if (@statuses) {
14029: foreach my $type (@statuses) {
1.160.6.35 raeburn 14030: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
14031: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 14032: $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 14033: '<ul>';
14034: foreach my $field (@{$infofields}) {
14035: if ($cancreate{'emailusername'}{$type}{$field}) {
14036: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
14037: }
14038: }
1.160.6.50 raeburn 14039: $chgtext .= '</ul>';
14040: } else {
1.160.6.93 raeburn 14041: $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 14042: }
14043: } else {
1.160.6.93 raeburn 14044: $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 14045: }
14046: }
14047: }
14048: }
14049: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 14050: my $numapprove = 0;
1.160.6.34 raeburn 14051: if (ref($changes{'cancreate'}) eq 'ARRAY') {
14052: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
14053: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 14054: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
14055: $numapprove ++;
1.160.6.34 raeburn 14056: }
14057: }
1.43 raeburn 14058: }
1.160.6.93 raeburn 14059: unless ($numapprove) {
14060: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
14061: }
1.34 raeburn 14062: }
1.160.6.34 raeburn 14063: if ($chgtext) {
14064: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 14065: }
14066: }
14067: }
1.160.6.93 raeburn 14068: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 14069: my ($emailrules,$emailruleorder) =
14070: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 14071: foreach my $type (@{$changes{'email_rule'}}) {
14072: if (ref($email_rule{$type}) eq 'ARRAY') {
14073: my $chgtext = '<ul>';
14074: foreach my $rule (@{$email_rule{$type}}) {
14075: if (ref($emailrules->{$rule}) eq 'HASH') {
14076: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
14077: }
14078: }
14079: $chgtext .= '</ul>';
14080: my $typename;
14081: if (@types) {
14082: if ($type eq 'default') {
14083: $typename = $othertitle;
14084: } else {
14085: $typename = $usertypes{$type};
14086: }
14087: $chgtext .= &mt('(Affiliation: [_1])',$typename);
14088: }
14089: if (@{$email_rule{$type}} > 0) {
14090: $resulttext .= '<li>'.
14091: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
14092: $usertypes{$type}).
14093: $chgtext.
14094: '</li>';
14095: } else {
14096: $resulttext .= '<li>'.
14097: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
14098: '</li>'.
14099: &mt('(Affiliation: [_1])',$typename);
14100: }
1.43 raeburn 14101: }
14102: }
1.160.6.93 raeburn 14103: }
14104: if (ref($changes{'inststatus'}) eq 'ARRAY') {
14105: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
14106: if (@{$save_inststatus{'inststatusguest'}} > 0) {
14107: my $chgtext = '<ul>';
14108: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
14109: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
14110: }
14111: $chgtext .= '</ul>';
14112: $resulttext .= '<li>'.
14113: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
14114: $chgtext.
14115: '</li>';
14116: } else {
14117: $resulttext .= '<li>'.
14118: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
14119: '</li>';
14120: }
1.43 raeburn 14121: }
14122: }
1.160.6.34 raeburn 14123: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
14124: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
14125: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14126: foreach my $type (@{$changes{'selfcreate'}}) {
14127: my $typename = $type;
1.160.6.93 raeburn 14128: if (keys(%usertypes) > 0) {
14129: if ($usertypes{$type} ne '') {
14130: $typename = $usertypes{$type};
1.28 raeburn 14131: }
14132: }
1.160.6.34 raeburn 14133: my @modifiable;
14134: $resulttext .= '<li>'.
14135: &mt('Self-creation of account by users with status: [_1]',
14136: '<span class="LC_cusr_emph">'.$typename.'</span>').
14137: ' - '.&mt('modifiable fields (if institutional data blank): ');
14138: foreach my $field (@fields) {
14139: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
14140: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
14141: }
14142: }
14143: if (@modifiable > 0) {
14144: $resulttext .= join(', ',@modifiable);
1.43 raeburn 14145: } else {
1.160.6.34 raeburn 14146: $resulttext .= &mt('none');
1.43 raeburn 14147: }
1.160.6.34 raeburn 14148: $resulttext .= '</li>';
1.28 raeburn 14149: }
1.160.6.34 raeburn 14150: $resulttext .= '</ul></li>';
1.28 raeburn 14151: }
1.27 raeburn 14152: $resulttext .= '</ul>';
1.160.6.93 raeburn 14153: my $cachetime = 24*60*60;
14154: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
14155: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14156: if (ref($lastactref) eq 'HASH') {
14157: $lastactref->{'domdefaults'} = 1;
14158: }
1.27 raeburn 14159: } else {
1.160.6.34 raeburn 14160: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 14161: }
14162: } else {
14163: $resulttext = '<span class="LC_error">'.
1.23 raeburn 14164: &mt('An error occurred: [_1]',$putresult).'</span>';
14165: }
1.43 raeburn 14166: if ($warningmsg ne '') {
14167: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
14168: }
1.23 raeburn 14169: return $resulttext;
14170: }
14171:
1.160.6.5 raeburn 14172: sub process_captcha {
1.160.6.104 raeburn 14173: my ($container,$changes,$newsettings,$currsettings) = @_;
14174: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.160.6.5 raeburn 14175: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
14176: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
14177: $newsettings->{'captcha'} = 'original';
14178: }
1.160.6.104 raeburn 14179: my %current;
14180: if (ref($currsettings) eq 'HASH') {
14181: %current = %{$currsettings};
14182: }
14183: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.160.6.5 raeburn 14184: if ($container eq 'cancreate') {
14185: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14186: push(@{$changes->{'cancreate'}},'captcha');
14187: } elsif (!defined($changes->{'cancreate'})) {
14188: $changes->{'cancreate'} = ['captcha'];
14189: }
1.160.6.102 raeburn 14190: } elsif ($container eq 'passwords') {
14191: $changes->{'reset'} = 1;
1.160.6.5 raeburn 14192: } else {
14193: $changes->{'captcha'} = 1;
14194: }
14195: }
1.160.6.69 raeburn 14196: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 14197: if ($newsettings->{'captcha'} eq 'recaptcha') {
14198: $newpub = $env{'form.'.$container.'_recaptchapub'};
14199: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 14200: $newpub =~ s/[^\w\-]//g;
14201: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 14202: $newsettings->{'recaptchakeys'} = {
14203: public => $newpub,
14204: private => $newpriv,
14205: };
1.160.6.69 raeburn 14206: $newversion = $env{'form.'.$container.'_recaptchaversion'};
14207: $newversion =~ s/\D//g;
14208: if ($newversion ne '2') {
14209: $newversion = 1;
14210: }
14211: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 14212: }
1.160.6.104 raeburn 14213: if (ref($current{'recaptchakeys'}) eq 'HASH') {
14214: $currpub = $current{'recaptchakeys'}{'public'};
14215: $currpriv = $current{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 14216: unless ($newsettings->{'captcha'} eq 'recaptcha') {
14217: $newsettings->{'recaptchakeys'} = {
14218: public => '',
14219: private => '',
14220: }
14221: }
1.160.6.5 raeburn 14222: }
1.160.6.104 raeburn 14223: if ($current{'captcha'} eq 'recaptcha') {
14224: $currversion = $current{'recaptchaversion'};
1.160.6.69 raeburn 14225: if ($currversion ne '2') {
14226: $currversion = 1;
14227: }
14228: }
14229: if ($currversion ne $newversion) {
14230: if ($container eq 'cancreate') {
14231: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14232: push(@{$changes->{'cancreate'}},'recaptchaversion');
14233: } elsif (!defined($changes->{'cancreate'})) {
14234: $changes->{'cancreate'} = ['recaptchaversion'];
14235: }
1.160.6.102 raeburn 14236: } elsif ($container eq 'passwords') {
14237: $changes->{'reset'} = 1;
1.160.6.69 raeburn 14238: } else {
14239: $changes->{'recaptchaversion'} = 1;
14240: }
14241: }
1.160.6.5 raeburn 14242: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
14243: if ($container eq 'cancreate') {
14244: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14245: push(@{$changes->{'cancreate'}},'recaptchakeys');
14246: } elsif (!defined($changes->{'cancreate'})) {
14247: $changes->{'cancreate'} = ['recaptchakeys'];
14248: }
1.160.6.102 raeburn 14249: } elsif ($container eq 'passwords') {
14250: $changes->{'reset'} = 1;
1.160.6.5 raeburn 14251: } else {
14252: $changes->{'recaptchakeys'} = 1;
14253: }
14254: }
14255: return;
14256: }
14257:
1.33 raeburn 14258: sub modify_usermodification {
14259: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 14260: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 14261: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14262: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 14263: if ($key eq 'selfcreate') {
14264: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
14265: } else {
14266: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
14267: }
1.33 raeburn 14268: }
14269: }
1.160.6.34 raeburn 14270: my @contexts = ('author','course');
1.33 raeburn 14271: my %context_title = (
14272: author => 'In author context',
14273: course => 'In course context',
14274: );
14275: my @fields = ('lastname','firstname','middlename','generation',
14276: 'permanentemail','id');
14277: my %roles = (
14278: author => ['ca','aa'],
14279: course => ['st','ep','ta','in','cr'],
14280: );
14281: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14282: foreach my $context (@contexts) {
14283: foreach my $role (@{$roles{$context}}) {
14284: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
14285: foreach my $item (@fields) {
14286: if (grep(/^\Q$item\E$/,@modifiable)) {
14287: $modifyhash{$context}{$role}{$item} = 1;
14288: } else {
14289: $modifyhash{$context}{$role}{$item} = 0;
14290: }
14291: }
14292: }
14293: if (ref($curr_usermodification{$context}) eq 'HASH') {
14294: foreach my $role (@{$roles{$context}}) {
14295: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
14296: foreach my $field (@fields) {
14297: if ($modifyhash{$context}{$role}{$field} ne
14298: $curr_usermodification{$context}{$role}{$field}) {
14299: push(@{$changes{$context}},$role);
14300: last;
14301: }
14302: }
14303: }
14304: }
14305: } else {
14306: foreach my $context (@contexts) {
14307: foreach my $role (@{$roles{$context}}) {
14308: push(@{$changes{$context}},$role);
14309: }
14310: }
14311: }
14312: }
14313: my %usermodification_hash = (
14314: usermodification => \%modifyhash,
14315: );
14316: my $putresult = &Apache::lonnet::put_dom('configuration',
14317: \%usermodification_hash,$dom);
14318: if ($putresult eq 'ok') {
14319: if (keys(%changes) > 0) {
14320: $resulttext = &mt('Changes made: ').'<ul>';
14321: foreach my $context (@contexts) {
14322: if (ref($changes{$context}) eq 'ARRAY') {
14323: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
14324: if (ref($changes{$context}) eq 'ARRAY') {
14325: foreach my $role (@{$changes{$context}}) {
14326: my $rolename;
1.160.6.34 raeburn 14327: if ($role eq 'cr') {
14328: $rolename = &mt('Custom');
1.33 raeburn 14329: } else {
1.160.6.34 raeburn 14330: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 14331: }
14332: my @modifiable;
1.160.6.34 raeburn 14333: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 14334: foreach my $field (@fields) {
14335: if ($modifyhash{$context}{$role}{$field}) {
14336: push(@modifiable,$fieldtitles{$field});
14337: }
14338: }
14339: if (@modifiable > 0) {
14340: $resulttext .= join(', ',@modifiable);
14341: } else {
14342: $resulttext .= &mt('none');
14343: }
14344: $resulttext .= '</li>';
14345: }
14346: $resulttext .= '</ul></li>';
14347: }
14348: }
14349: }
14350: $resulttext .= '</ul>';
14351: } else {
14352: $resulttext = &mt('No changes made to user modification settings');
14353: }
14354: } else {
14355: $resulttext = '<span class="LC_error">'.
14356: &mt('An error occurred: [_1]',$putresult).'</span>';
14357: }
14358: return $resulttext;
14359: }
14360:
1.43 raeburn 14361: sub modify_defaults {
1.160.6.27 raeburn 14362: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 14363: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 14364: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 14365: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98 raeburn 14366: 'portal_def');
1.43 raeburn 14367: my @authtypes = ('internal','krb4','krb5','localauth');
14368: foreach my $item (@items) {
14369: $newvalues{$item} = $env{'form.'.$item};
14370: if ($item eq 'auth_def') {
14371: if ($newvalues{$item} ne '') {
14372: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
14373: push(@errors,$item);
14374: }
14375: }
14376: } elsif ($item eq 'lang_def') {
14377: if ($newvalues{$item} ne '') {
14378: if ($newvalues{$item} =~ /^(\w+)/) {
14379: my $langcode = $1;
1.103 raeburn 14380: if ($langcode ne 'x_chef') {
14381: if (code2language($langcode) eq '') {
14382: push(@errors,$item);
14383: }
1.43 raeburn 14384: }
14385: } else {
14386: push(@errors,$item);
14387: }
14388: }
1.54 raeburn 14389: } elsif ($item eq 'timezone_def') {
14390: if ($newvalues{$item} ne '') {
1.62 raeburn 14391: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 14392: push(@errors,$item);
14393: }
14394: }
1.68 raeburn 14395: } elsif ($item eq 'datelocale_def') {
14396: if ($newvalues{$item} ne '') {
14397: my @datelocale_ids = DateTime::Locale->ids();
14398: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
14399: push(@errors,$item);
14400: }
14401: }
1.141 raeburn 14402: } elsif ($item eq 'portal_def') {
14403: if ($newvalues{$item} ne '') {
14404: 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])\/?$/) {
14405: push(@errors,$item);
14406: }
14407: }
1.43 raeburn 14408: }
14409: if (grep(/^\Q$item\E$/,@errors)) {
14410: $newvalues{$item} = $domdefaults{$item};
14411: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
14412: $changes{$item} = 1;
14413: }
1.72 raeburn 14414: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 14415: }
1.160.6.98 raeburn 14416: my %staticdefaults = (
14417: 'intauth_cost' => 10,
14418: 'intauth_check' => 0,
14419: 'intauth_switch' => 0,
14420: );
14421: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
14422: if (exists($domdefaults{$item})) {
14423: $newvalues{$item} = $domdefaults{$item};
14424: } else {
14425: $newvalues{$item} = $staticdefaults{$item};
14426: }
14427: }
1.43 raeburn 14428: my %defaults_hash = (
1.72 raeburn 14429: defaults => \%newvalues,
14430: );
1.43 raeburn 14431: my $title = &defaults_titles();
1.160.6.40 raeburn 14432:
14433: my $currinststatus;
14434: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14435: $currinststatus = $domconfig{'inststatus'};
14436: } else {
14437: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14438: $currinststatus = {
14439: inststatustypes => $usertypes,
14440: inststatusorder => $types,
14441: inststatusguest => [],
14442: };
14443: }
14444: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
14445: my @allpos;
14446: my %alltypes;
1.160.6.93 raeburn 14447: my @inststatusguest;
14448: if (ref($currinststatus) eq 'HASH') {
14449: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
14450: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
14451: unless (grep(/^\Q$type\E$/,@todelete)) {
14452: push(@inststatusguest,$type);
14453: }
14454: }
14455: }
14456: }
14457: my ($currtitles,$currorder);
1.160.6.40 raeburn 14458: if (ref($currinststatus) eq 'HASH') {
14459: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
14460: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
14461: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
14462: if ($currinststatus->{inststatustypes}->{$type} ne '') {
14463: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
14464: }
14465: }
14466: unless (grep(/^\Q$type\E$/,@todelete)) {
14467: my $position = $env{'form.inststatus_pos_'.$type};
14468: $position =~ s/\D+//g;
14469: $allpos[$position] = $type;
14470: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
14471: $alltypes{$type} =~ s/`//g;
14472: }
14473: }
14474: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
14475: $currtitles =~ s/,$//;
14476: }
14477: }
14478: if ($env{'form.addinststatus'}) {
14479: my $newtype = $env{'form.addinststatus'};
14480: $newtype =~ s/\W//g;
14481: unless (exists($alltypes{$newtype})) {
14482: $alltypes{$newtype} = $env{'form.addinststatus_title'};
14483: $alltypes{$newtype} =~ s/`//g;
14484: my $position = $env{'form.addinststatus_pos'};
14485: $position =~ s/\D+//g;
14486: if ($position ne '') {
14487: $allpos[$position] = $newtype;
14488: }
14489: }
14490: }
1.160.6.93 raeburn 14491: my @orderedstatus;
1.160.6.40 raeburn 14492: foreach my $type (@allpos) {
14493: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
14494: push(@orderedstatus,$type);
14495: }
14496: }
14497: foreach my $type (keys(%alltypes)) {
14498: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
14499: delete($alltypes{$type});
14500: }
14501: }
14502: $defaults_hash{'inststatus'} = {
14503: inststatustypes => \%alltypes,
14504: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 14505: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 14506: };
14507: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
14508: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
14509: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
14510: }
14511: }
14512: if ($currorder ne join(',',@orderedstatus)) {
14513: $changes{'inststatus'}{'inststatusorder'} = 1;
14514: }
14515: my $newtitles;
14516: foreach my $item (@orderedstatus) {
14517: $newtitles .= $alltypes{$item}.',';
14518: }
14519: $newtitles =~ s/,$//;
14520: if ($currtitles ne $newtitles) {
14521: $changes{'inststatus'}{'inststatustypes'} = 1;
14522: }
1.43 raeburn 14523: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
14524: $dom);
14525: if ($putresult eq 'ok') {
14526: if (keys(%changes) > 0) {
14527: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 14528: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 14529: 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";
14530: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 14531: if ($item eq 'inststatus') {
14532: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 14533: if (@orderedstatus) {
1.160.6.40 raeburn 14534: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
14535: foreach my $type (@orderedstatus) {
14536: $resulttext .= $alltypes{$type}.', ';
14537: }
14538: $resulttext =~ s/, $//;
14539: $resulttext .= '</li>';
1.160.6.93 raeburn 14540: } else {
14541: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 14542: }
14543: }
14544: } else {
14545: my $value = $env{'form.'.$item};
14546: if ($value eq '') {
14547: $value = &mt('none');
14548: } elsif ($item eq 'auth_def') {
14549: my %authnames = &authtype_names();
14550: my %shortauth = (
14551: internal => 'int',
14552: krb4 => 'krb4',
14553: krb5 => 'krb5',
14554: localauth => 'loc',
14555: );
14556: $value = $authnames{$shortauth{$value}};
14557: }
14558: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
14559: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 14560: }
14561: }
14562: $resulttext .= '</ul>';
14563: $mailmsgtext .= "\n";
14564: my $cachetime = 24*60*60;
1.72 raeburn 14565: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 14566: if (ref($lastactref) eq 'HASH') {
14567: $lastactref->{'domdefaults'} = 1;
14568: }
1.68 raeburn 14569: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 14570: my $notify = 1;
14571: if (ref($domconfig{'contacts'}) eq 'HASH') {
14572: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
14573: $notify = 0;
14574: }
14575: }
14576: if ($notify) {
14577: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
14578: "LON-CAPA Domain Settings Change - $dom",
14579: $mailmsgtext);
14580: }
1.54 raeburn 14581: }
1.43 raeburn 14582: } else {
1.54 raeburn 14583: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 14584: }
14585: } else {
14586: $resulttext = '<span class="LC_error">'.
14587: &mt('An error occurred: [_1]',$putresult).'</span>';
14588: }
14589: if (@errors > 0) {
14590: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
14591: foreach my $item (@errors) {
14592: $resulttext .= ' "'.$title->{$item}.'",';
14593: }
14594: $resulttext =~ s/,$//;
14595: }
14596: return $resulttext;
14597: }
14598:
1.46 raeburn 14599: sub modify_scantron {
1.160.6.24 raeburn 14600: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 14601: my ($resulttext,%confhash,%changes,$errors);
14602: my $custom = 'custom.tab';
14603: my $default = 'default.tab';
14604: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 14605: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 14606: &config_check($dom,$confname,$servadm);
14607: if ($env{'form.scantronformat.filename'} ne '') {
14608: my $error;
14609: if ($configuserok eq 'ok') {
14610: if ($switchserver) {
1.130 raeburn 14611: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 14612: } else {
14613: if ($author_ok eq 'ok') {
14614: my ($result,$scantronurl) =
14615: &publishlogo($r,'upload','scantronformat',$dom,
14616: $confname,'scantron','','',$custom);
14617: if ($result eq 'ok') {
14618: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 14619: $changes{'scantronformat'} = 1;
1.46 raeburn 14620: } else {
14621: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
14622: }
14623: } else {
14624: $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);
14625: }
14626: }
14627: } else {
14628: $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);
14629: }
14630: if ($error) {
14631: &Apache::lonnet::logthis($error);
14632: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14633: }
14634: }
1.48 raeburn 14635: if (ref($domconfig{'scantron'}) eq 'HASH') {
14636: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
14637: if ($env{'form.scantronformat_del'}) {
14638: $confhash{'scantron'}{'scantronformat'} = '';
14639: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 14640: } else {
14641: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
14642: }
14643: }
14644: }
14645: my @options = ('hdr','pad','rem');
14646: my @fields = &scantroncsv_fields();
14647: my %titles = &scantronconfig_titles();
14648: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
14649: my ($newdat,$currdat,%newcol,%currcol);
14650: if (grep(/^dat$/,@formats)) {
14651: $confhash{'scantron'}{config}{dat} = 1;
14652: $newdat = 1;
14653: } else {
14654: $newdat = 0;
14655: }
14656: if (grep(/^csv$/,@formats)) {
14657: my %bynum;
14658: foreach my $field (@fields) {
14659: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
14660: my $posscol = $1;
14661: if (($posscol < 20) && (!$bynum{$posscol})) {
14662: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
14663: $bynum{$posscol} = $field;
14664: $newcol{$field} = $posscol;
14665: }
14666: }
14667: }
14668: if (keys(%newcol)) {
14669: foreach my $option (@options) {
14670: if ($env{'form.scantroncsv_'.$option}) {
14671: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
14672: }
14673: }
14674: }
14675: }
14676: $currdat = 1;
14677: if (ref($domconfig{'scantron'}) eq 'HASH') {
14678: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
14679: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
14680: $currdat = 0;
14681: }
14682: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
14683: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
14684: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
14685: }
14686: }
14687: }
14688: }
14689: if ($currdat != $newdat) {
14690: $changes{'config'} = 1;
14691: } else {
14692: foreach my $field (@fields) {
14693: if ($currcol{$field} ne '') {
14694: if ($currcol{$field} ne $newcol{$field}) {
14695: $changes{'config'} = 1;
14696: last;
14697: }
14698: } elsif ($newcol{$field} ne '') {
14699: $changes{'config'} = 1;
14700: last;
1.46 raeburn 14701: }
14702: }
14703: }
14704: if (keys(%confhash) > 0) {
14705: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
14706: $dom);
14707: if ($putresult eq 'ok') {
14708: if (keys(%changes) > 0) {
1.48 raeburn 14709: if (ref($confhash{'scantron'}) eq 'HASH') {
14710: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 14711: if ($changes{'scantronformat'}) {
14712: if ($confhash{'scantron'}{'scantronformat'} eq '') {
14713: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
14714: } else {
14715: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
14716: }
14717: }
14718: if ($changes{'config'}) {
14719: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
14720: if ($confhash{'scantron'}{'config'}{'dat'}) {
14721: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
14722: }
14723: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
14724: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
14725: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
14726: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
14727: foreach my $field (@fields) {
14728: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
14729: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
14730: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
14731: }
14732: }
14733: $resulttext .= '</ul></li>';
14734: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
14735: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
14736: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
14737: foreach my $option (@options) {
14738: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
14739: $resulttext .= '<li>'.$titles{$option}.'</li>';
14740: }
14741: }
14742: $resulttext .= '</ul></li>';
14743: }
14744: }
14745: }
14746: }
14747: }
14748: } else {
14749: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
14750: }
1.46 raeburn 14751: }
1.48 raeburn 14752: $resulttext .= '</ul>';
14753: } else {
1.130 raeburn 14754: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 14755: }
14756: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 14757: if (ref($lastactref) eq 'HASH') {
14758: $lastactref->{'domainconfig'} = 1;
14759: }
1.46 raeburn 14760: } else {
1.160.6.97 raeburn 14761: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 14762: }
14763: } else {
14764: $resulttext = '<span class="LC_error">'.
14765: &mt('An error occurred: [_1]',$putresult).'</span>';
14766: }
14767: } else {
1.160.6.97 raeburn 14768: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 14769: }
14770: if ($errors) {
14771: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14772: $errors.'</ul>';
14773: }
14774: return $resulttext;
14775: }
14776:
1.48 raeburn 14777: sub modify_coursecategories {
1.160.6.43 raeburn 14778: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 14779: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
14780: $cathash);
1.48 raeburn 14781: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 14782: my @catitems = ('unauth','auth');
14783: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 14784: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 14785: $cathash = $domconfig{'coursecategories'}{'cats'};
14786: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
14787: $changes{'togglecats'} = 1;
14788: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
14789: }
14790: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
14791: $changes{'categorize'} = 1;
14792: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
14793: }
1.120 raeburn 14794: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
14795: $changes{'togglecatscomm'} = 1;
14796: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
14797: }
14798: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
14799: $changes{'categorizecomm'} = 1;
14800: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
14801: }
1.160.6.42 raeburn 14802: foreach my $item (@catitems) {
14803: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14804: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
14805: $changes{$item} = 1;
14806: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14807: }
14808: }
14809: }
1.57 raeburn 14810: } else {
14811: $changes{'togglecats'} = 1;
14812: $changes{'categorize'} = 1;
1.124 raeburn 14813: $changes{'togglecatscomm'} = 1;
14814: $changes{'categorizecomm'} = 1;
1.87 raeburn 14815: $domconfig{'coursecategories'} = {
14816: togglecats => $env{'form.togglecats'},
14817: categorize => $env{'form.categorize'},
1.124 raeburn 14818: togglecatscomm => $env{'form.togglecatscomm'},
14819: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 14820: };
1.160.6.42 raeburn 14821: foreach my $item (@catitems) {
14822: if ($env{'form.coursecat_'.$item} ne 'std') {
14823: $changes{$item} = 1;
14824: }
14825: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14826: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14827: }
14828: }
1.57 raeburn 14829: }
14830: if (ref($cathash) eq 'HASH') {
14831: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 14832: push (@deletecategory,'instcode::0');
14833: }
1.120 raeburn 14834: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
14835: push(@deletecategory,'communities::0');
14836: }
1.48 raeburn 14837: }
1.57 raeburn 14838: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
14839: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14840: if (@deletecategory > 0) {
14841: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 14842: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 14843: foreach my $item (@deletecategory) {
1.57 raeburn 14844: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
14845: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 14846: $deletions{$item} = 1;
1.57 raeburn 14847: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 14848: }
14849: }
14850: }
1.57 raeburn 14851: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 14852: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 14853: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 14854: $reorderings{$item} = 1;
1.57 raeburn 14855: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 14856: }
14857: if ($env{'form.addcategory_name_'.$item} ne '') {
14858: my $newcat = $env{'form.addcategory_name_'.$item};
14859: my $newdepth = $depth+1;
14860: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14861: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 14862: $adds{$newitem} = 1;
14863: }
14864: if ($env{'form.subcat_'.$item} ne '') {
14865: my $newcat = $env{'form.subcat_'.$item};
14866: my $newdepth = $depth+1;
14867: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14868: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 14869: $adds{$newitem} = 1;
14870: }
14871: }
14872: }
14873: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 14874: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14875: my $newitem = 'instcode::0';
1.57 raeburn 14876: if ($cathash->{$newitem} eq '') {
14877: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14878: $adds{$newitem} = 1;
14879: }
14880: } else {
14881: my $newitem = 'instcode::0';
1.57 raeburn 14882: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14883: $adds{$newitem} = 1;
14884: }
14885: }
1.120 raeburn 14886: if ($env{'form.communities'} eq '1') {
14887: if (ref($cathash) eq 'HASH') {
14888: my $newitem = 'communities::0';
14889: if ($cathash->{$newitem} eq '') {
14890: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14891: $adds{$newitem} = 1;
14892: }
14893: } else {
14894: my $newitem = 'communities::0';
14895: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14896: $adds{$newitem} = 1;
14897: }
14898: }
1.48 raeburn 14899: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 14900: if (($env{'form.addcategory_name'} ne 'instcode') &&
14901: ($env{'form.addcategory_name'} ne 'communities')) {
14902: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
14903: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
14904: $adds{$newitem} = 1;
14905: }
1.48 raeburn 14906: }
1.57 raeburn 14907: my $putresult;
1.48 raeburn 14908: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14909: if (keys(%deletions) > 0) {
14910: foreach my $key (keys(%deletions)) {
14911: if ($predelallitems{$key} ne '') {
14912: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
14913: }
14914: }
14915: }
14916: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 14917: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 14918: if (ref($chkcats[0]) eq 'ARRAY') {
14919: my $depth = 0;
14920: my $chg = 0;
14921: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
14922: my $name = $chkcats[0][$i];
14923: my $item;
14924: if ($name eq '') {
14925: $chg ++;
14926: } else {
14927: $item = &escape($name).'::0';
14928: if ($chg) {
1.57 raeburn 14929: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 14930: }
14931: $depth ++;
1.57 raeburn 14932: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 14933: $depth --;
14934: }
14935: }
14936: }
1.57 raeburn 14937: }
14938: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14939: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 14940: if ($putresult eq 'ok') {
1.57 raeburn 14941: my %title = (
1.120 raeburn 14942: togglecats => 'Show/Hide a course in catalog',
14943: categorize => 'Assign a category to a course',
14944: togglecatscomm => 'Show/Hide a community in catalog',
14945: categorizecomm => 'Assign a category to a community',
1.57 raeburn 14946: );
14947: my %level = (
1.120 raeburn 14948: dom => 'set in Domain ("Modify Course/Community")',
14949: crs => 'set in Course ("Course Configuration")',
14950: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 14951: none => 'No catalog',
14952: std => 'Standard catalog',
14953: domonly => 'Domain-only catalog',
14954: codesrch => 'Code search form',
1.57 raeburn 14955: );
1.48 raeburn 14956: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 14957: if ($changes{'togglecats'}) {
14958: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
14959: }
14960: if ($changes{'categorize'}) {
14961: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 14962: }
1.120 raeburn 14963: if ($changes{'togglecatscomm'}) {
14964: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
14965: }
14966: if ($changes{'categorizecomm'}) {
14967: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
14968: }
1.160.6.42 raeburn 14969: if ($changes{'unauth'}) {
14970: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
14971: }
14972: if ($changes{'auth'}) {
14973: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
14974: }
1.57 raeburn 14975: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14976: my $cathash;
14977: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
14978: $cathash = $domconfig{'coursecategories'}{'cats'};
14979: } else {
14980: $cathash = {};
14981: }
14982: my (@cats,@trails,%allitems);
14983: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
14984: if (keys(%deletions) > 0) {
14985: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
14986: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
14987: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
14988: }
14989: $resulttext .= '</ul></li>';
14990: }
14991: if (keys(%reorderings) > 0) {
14992: my %sort_by_trail;
14993: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
14994: foreach my $key (keys(%reorderings)) {
14995: if ($allitems{$key} ne '') {
14996: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14997: }
1.48 raeburn 14998: }
1.57 raeburn 14999: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
15000: $resulttext .= '<li>'.$trails[$trail].'</li>';
15001: }
15002: $resulttext .= '</ul></li>';
1.48 raeburn 15003: }
1.57 raeburn 15004: if (keys(%adds) > 0) {
15005: my %sort_by_trail;
15006: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
15007: foreach my $key (keys(%adds)) {
15008: if ($allitems{$key} ne '') {
15009: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
15010: }
15011: }
15012: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
15013: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 15014: }
1.57 raeburn 15015: $resulttext .= '</ul></li>';
1.48 raeburn 15016: }
1.160.6.92 raeburn 15017: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
15018: if (ref($lastactref) eq 'HASH') {
15019: $lastactref->{'cats'} = 1;
15020: }
1.48 raeburn 15021: }
15022: $resulttext .= '</ul>';
1.160.6.43 raeburn 15023: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 15024: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15025: if ($changes{'auth'}) {
15026: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
15027: }
15028: if ($changes{'unauth'}) {
15029: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
15030: }
15031: my $cachetime = 24*60*60;
15032: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 15033: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 15034: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 15035: }
15036: }
1.48 raeburn 15037: } else {
15038: $resulttext = '<span class="LC_error">'.
1.57 raeburn 15039: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 15040: }
15041: } else {
1.120 raeburn 15042: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 15043: }
15044: return $resulttext;
15045: }
15046:
1.69 raeburn 15047: sub modify_serverstatuses {
15048: my ($dom,%domconfig) = @_;
15049: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
15050: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
15051: %currserverstatus = %{$domconfig{'serverstatuses'}};
15052: }
15053: my @pages = &serverstatus_pages();
15054: foreach my $type (@pages) {
15055: $newserverstatus{$type}{'namedusers'} = '';
15056: $newserverstatus{$type}{'machines'} = '';
15057: if (defined($env{'form.'.$type.'_namedusers'})) {
15058: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
15059: my @okusers;
15060: foreach my $user (@users) {
15061: my ($uname,$udom) = split(/:/,$user);
15062: if (($udom =~ /^$match_domain$/) &&
15063: (&Apache::lonnet::domain($udom)) &&
15064: ($uname =~ /^$match_username$/)) {
15065: if (!grep(/^\Q$user\E/,@okusers)) {
15066: push(@okusers,$user);
15067: }
15068: }
15069: }
15070: if (@okusers > 0) {
15071: @okusers = sort(@okusers);
15072: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
15073: }
15074: }
15075: if (defined($env{'form.'.$type.'_machines'})) {
15076: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
15077: my @okmachines;
15078: foreach my $ip (@machines) {
15079: my @parts = split(/\./,$ip);
15080: next if (@parts < 4);
15081: my $badip = 0;
15082: for (my $i=0; $i<4; $i++) {
15083: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
15084: $badip = 1;
15085: last;
15086: }
15087: }
15088: if (!$badip) {
15089: push(@okmachines,$ip);
15090: }
15091: }
15092: @okmachines = sort(@okmachines);
15093: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
15094: }
15095: }
15096: my %serverstatushash = (
15097: serverstatuses => \%newserverstatus,
15098: );
15099: foreach my $type (@pages) {
1.83 raeburn 15100: foreach my $setting ('namedusers','machines') {
1.84 raeburn 15101: my (@current,@new);
1.83 raeburn 15102: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 15103: if ($currserverstatus{$type}{$setting} ne '') {
15104: @current = split(/,/,$currserverstatus{$type}{$setting});
15105: }
15106: }
15107: if ($newserverstatus{$type}{$setting} ne '') {
15108: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 15109: }
15110: if (@current > 0) {
15111: if (@new > 0) {
15112: foreach my $item (@current) {
15113: if (!grep(/^\Q$item\E$/,@new)) {
15114: $changes{$type}{$setting} = 1;
1.82 raeburn 15115: last;
15116: }
15117: }
1.84 raeburn 15118: foreach my $item (@new) {
15119: if (!grep(/^\Q$item\E$/,@current)) {
15120: $changes{$type}{$setting} = 1;
15121: last;
1.82 raeburn 15122: }
15123: }
15124: } else {
1.83 raeburn 15125: $changes{$type}{$setting} = 1;
1.69 raeburn 15126: }
1.83 raeburn 15127: } elsif (@new > 0) {
15128: $changes{$type}{$setting} = 1;
1.69 raeburn 15129: }
15130: }
15131: }
15132: if (keys(%changes) > 0) {
1.81 raeburn 15133: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 15134: my $putresult = &Apache::lonnet::put_dom('configuration',
15135: \%serverstatushash,$dom);
15136: if ($putresult eq 'ok') {
15137: $resulttext .= &mt('Changes made:').'<ul>';
15138: foreach my $type (@pages) {
1.84 raeburn 15139: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 15140: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 15141: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 15142: if ($newserverstatus{$type}{'namedusers'} eq '') {
15143: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
15144: } else {
15145: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
15146: }
1.84 raeburn 15147: }
15148: if ($changes{$type}{'machines'}) {
1.69 raeburn 15149: if ($newserverstatus{$type}{'machines'} eq '') {
15150: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
15151: } else {
15152: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
15153: }
15154:
15155: }
15156: $resulttext .= '</ul></li>';
15157: }
15158: }
15159: $resulttext .= '</ul>';
15160: } else {
15161: $resulttext = '<span class="LC_error">'.
15162: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
15163:
15164: }
15165: } else {
15166: $resulttext = &mt('No changes made to access to server status pages');
15167: }
15168: return $resulttext;
15169: }
15170:
1.118 jms 15171: sub modify_helpsettings {
1.160.6.77 raeburn 15172: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 15173: my ($resulttext,$errors,%changes,%helphash);
15174: my %defaultchecked = ('submitbugs' => 'on');
15175: my @offon = ('off','on');
1.118 jms 15176: my @toggles = ('submitbugs');
1.160.6.77 raeburn 15177: my %current = ('submitbugs' => '',
15178: 'adhoc' => {},
15179: );
1.118 jms 15180: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 15181: %current = %{$domconfig{'helpsettings'}};
15182: }
1.160.6.77 raeburn 15183: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 15184: foreach my $item (@toggles) {
15185: if ($defaultchecked{$item} eq 'on') {
15186: if ($current{$item} eq '') {
15187: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 15188: $changes{$item} = 1;
15189: }
1.160.6.73 raeburn 15190: } elsif ($current{$item} ne $env{'form.'.$item}) {
15191: $changes{$item} = 1;
15192: }
15193: } elsif ($defaultchecked{$item} eq 'off') {
15194: if ($current{$item} eq '') {
15195: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 15196: $changes{$item} = 1;
15197: }
1.160.6.73 raeburn 15198: } elsif ($current{$item} ne $env{'form.'.$item}) {
15199: $changes{$item} = 1;
15200: }
15201: }
15202: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
15203: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
15204: }
15205: }
1.160.6.77 raeburn 15206: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 15207: my $confname = $dom.'-domainconfig';
15208: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 15209: my (@allpos,%newsettings,%changedprivs,$newrole);
15210: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 15211: my @accesstypes = ('all','dh','da','none','status','inc','exc');
15212: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 15213: my %lt = &Apache::lonlocal::texthash(
15214: s => 'system',
15215: d => 'domain',
15216: order => 'Display order',
15217: access => 'Role usage',
1.160.6.79 raeburn 15218: all => 'All with domain helpdesk or helpdesk assistant role',
15219: dh => 'All with domain helpdesk role',
15220: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 15221: none => 'None',
15222: status => 'Determined based on institutional status',
15223: inc => 'Include all, but exclude specific personnel',
15224: exc => 'Exclude all, but include specific personnel',
15225: );
15226: for (my $num=0; $num<=$maxnum; $num++) {
15227: my ($prefix,$identifier,$rolename,%curr);
15228: if ($num == $maxnum) {
15229: next unless ($env{'form.newcusthelp'} == $maxnum);
15230: $identifier = 'custhelp'.$num;
15231: $prefix = 'helproles_'.$num;
15232: $rolename = $env{'form.custhelpname'.$num};
15233: $rolename=~s/[^A-Za-z0-9]//gs;
15234: next if ($rolename eq '');
15235: next if (exists($existing{'rolesdef_'.$rolename}));
15236: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15237: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15238: $newprivs{'c'},$confname,$dom);
15239: if ($result ne 'ok') {
15240: $errors .= '<li><span class="LC_error">'.
15241: &mt('An error occurred storing the new custom role: [_1]',
15242: $result).'</span></li>';
15243: next;
15244: } else {
15245: $changedprivs{$rolename} = \%newprivs;
15246: $newrole = $rolename;
15247: }
15248: } else {
15249: $prefix = 'helproles_'.$num;
15250: $rolename = $env{'form.'.$prefix};
15251: next if ($rolename eq '');
15252: next unless (exists($existing{'rolesdef_'.$rolename}));
15253: $identifier = 'custhelp'.$num;
15254: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15255: my %currprivs;
15256: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
15257: split(/\_/,$existing{'rolesdef_'.$rolename});
15258: foreach my $level ('c','d','s') {
15259: if ($newprivs{$level} ne $currprivs{$level}) {
15260: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15261: $newprivs{'c'},$confname,$dom);
15262: if ($result ne 'ok') {
15263: $errors .= '<li><span class="LC_error">'.
15264: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
15265: $rolename,$result).'</span></li>';
15266: } else {
15267: $changedprivs{$rolename} = \%newprivs;
15268: }
15269: last;
15270: }
15271: }
15272: if (ref($current{'adhoc'}) eq 'HASH') {
15273: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15274: %curr = %{$current{'adhoc'}{$rolename}};
15275: }
15276: }
15277: }
15278: my $newpos = $env{'form.'.$prefix.'_pos'};
15279: $newpos =~ s/\D+//g;
15280: $allpos[$newpos] = $rolename;
15281: my $newdesc = $env{'form.'.$prefix.'_desc'};
15282: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
15283: if ($curr{'desc'}) {
15284: if ($curr{'desc'} ne $newdesc) {
15285: $changes{'customrole'}{$rolename}{'desc'} = 1;
15286: $newsettings{$rolename}{'desc'} = $newdesc;
15287: }
15288: } elsif ($newdesc ne '') {
15289: $changes{'customrole'}{$rolename}{'desc'} = 1;
15290: $newsettings{$rolename}{'desc'} = $newdesc;
15291: }
15292: my $access = $env{'form.'.$prefix.'_access'};
15293: if (grep(/^\Q$access\E$/,@accesstypes)) {
15294: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
15295: if ($access eq 'status') {
15296: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
15297: if (scalar(@statuses) == 0) {
15298: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
15299: } else {
15300: my (@shownstatus,$numtypes);
15301: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15302: if (ref($types) eq 'ARRAY') {
15303: $numtypes = scalar(@{$types});
15304: foreach my $type (sort(@statuses)) {
15305: if ($type eq 'default') {
15306: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15307: } elsif (grep(/^\Q$type\E$/,@{$types})) {
15308: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15309: push(@shownstatus,$usertypes->{$type});
15310: }
1.160.6.73 raeburn 15311: }
15312: }
1.160.6.77 raeburn 15313: if (grep(/^default$/,@statuses)) {
15314: push(@shownstatus,$othertitle);
15315: }
15316: if (scalar(@shownstatus) == 1+$numtypes) {
15317: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
15318: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
15319: } else {
15320: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
15321: if (ref($curr{'status'}) eq 'ARRAY') {
15322: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15323: if (@diffs) {
15324: $changes{'customrole'}{$rolename}{$access} = 1;
15325: }
15326: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15327: $changes{'customrole'}{$rolename}{$access} = 1;
15328: }
15329: }
15330: }
15331: } elsif (($access eq 'inc') || ($access eq 'exc')) {
15332: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
15333: my @newspecstaff;
15334: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15335: foreach my $person (sort(@personnel)) {
15336: if ($domhelpdesk{$person}) {
15337: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
15338: }
15339: }
15340: if (ref($curr{$access}) eq 'ARRAY') {
15341: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15342: if (@diffs) {
15343: $changes{'customrole'}{$rolename}{$access} = 1;
15344: }
15345: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15346: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 15347: }
1.160.6.77 raeburn 15348: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15349: my ($uname,$udom) = split(/:/,$person);
15350: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
15351: }
15352: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 15353: }
1.160.6.77 raeburn 15354: } else {
15355: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
15356: }
15357: unless ($curr{'access'} eq $access) {
15358: $changes{'customrole'}{$rolename}{'access'} = 1;
15359: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 15360: }
15361: }
1.160.6.77 raeburn 15362: if (@allpos > 0) {
15363: my $idx = 0;
15364: foreach my $rolename (@allpos) {
15365: if ($rolename ne '') {
15366: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
15367: if (ref($current{'adhoc'}) eq 'HASH') {
15368: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15369: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
15370: $changes{'customrole'}{$rolename}{'order'} = 1;
15371: $newsettings{$rolename}{'order'} = $idx+1;
15372: }
15373: }
1.160.6.73 raeburn 15374: }
1.160.6.77 raeburn 15375: $idx ++;
1.122 jms 15376: }
15377: }
1.118 jms 15378: }
1.123 jms 15379: my $putresult;
15380: if (keys(%changes) > 0) {
1.160.6.5 raeburn 15381: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
15382: if ($putresult eq 'ok') {
1.160.6.77 raeburn 15383: if (ref($helphash{'helpsettings'}) eq 'HASH') {
15384: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
15385: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
15386: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
15387: }
15388: }
15389: my $cachetime = 24*60*60;
15390: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15391: if (ref($lastactref) eq 'HASH') {
15392: $lastactref->{'domdefaults'} = 1;
15393: }
15394: } else {
15395: $errors .= '<li><span class="LC_error">'.
15396: &mt('An error occurred storing the settings: [_1]',
15397: $putresult).'</span></li>';
15398: }
15399: }
15400: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
15401: $resulttext = &mt('Changes made:').'<ul>';
15402: my (%shownprivs,@levelorder);
15403: @levelorder = ('c','d','s');
15404: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 15405: foreach my $item (sort(keys(%changes))) {
15406: if ($item eq 'submitbugs') {
15407: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
15408: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
15409: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 15410: } elsif ($item eq 'customrole') {
15411: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 15412: my @keyorder = ('order','desc','access','status','exc','inc');
15413: my %keytext = &Apache::lonlocal::texthash(
15414: order => 'Order',
15415: desc => 'Role description',
15416: access => 'Role usage',
1.160.6.83 raeburn 15417: status => 'Allowed institutional types',
1.160.6.77 raeburn 15418: exc => 'Allowed personnel',
15419: inc => 'Disallowed personnel',
15420: );
1.160.6.73 raeburn 15421: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 15422: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
15423: if ($role eq $newrole) {
15424: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
15425: $role).'<ul>';
15426: } else {
15427: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15428: $role).'<ul>';
15429: }
15430: foreach my $key (@keyorder) {
15431: if ($changes{'customrole'}{$role}{$key}) {
15432: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
15433: $keytext{$key},$newsettings{$role}{$key}).
15434: '</li>';
15435: }
15436: }
15437: if (ref($changedprivs{$role}) eq 'HASH') {
15438: $shownprivs{$role} = 1;
15439: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
15440: foreach my $level (@levelorder) {
15441: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15442: next if ($item eq '');
15443: my ($priv) = split(/\&/,$item,2);
15444: if (&Apache::lonnet::plaintext($priv)) {
15445: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15446: unless ($level eq 'c') {
15447: $resulttext .= ' ('.$lt{$level}.')';
15448: }
15449: $resulttext .= '</li>';
15450: }
15451: }
15452: }
15453: $resulttext .= '</ul>';
15454: }
15455: $resulttext .= '</ul></li>';
15456: }
1.160.6.73 raeburn 15457: }
15458: }
1.160.6.5 raeburn 15459: }
15460: }
15461: }
1.160.6.77 raeburn 15462: if (keys(%changedprivs)) {
15463: foreach my $role (sort(keys(%changedprivs))) {
15464: unless ($shownprivs{$role}) {
15465: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15466: $role).'<ul>'.
15467: '<li>'.&mt('Privileges set to :').'<ul>';
15468: foreach my $level (@levelorder) {
15469: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15470: next if ($item eq '');
15471: my ($priv) = split(/\&/,$item,2);
15472: if (&Apache::lonnet::plaintext($priv)) {
15473: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15474: unless ($level eq 'c') {
15475: $resulttext .= ' ('.$lt{$level}.')';
15476: }
15477: $resulttext .= '</li>';
15478: }
15479: }
15480: }
15481: $resulttext .= '</ul></li></ul></li>';
15482: }
15483: }
15484: }
15485: $resulttext .= '</ul>';
15486: } else {
15487: $resulttext = &mt('No changes made to help settings');
1.118 jms 15488: }
15489: if ($errors) {
1.160.6.5 raeburn 15490: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 15491: $errors.'</ul>';
1.118 jms 15492: }
15493: return $resulttext;
15494: }
15495:
1.121 raeburn 15496: sub modify_coursedefaults {
1.160.6.27 raeburn 15497: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 15498: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 15499: my %defaultchecked = (
15500: 'uselcmath' => 'on',
15501: 'usejsme' => 'on'
15502: );
15503: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 15504: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 15505: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
15506: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 15507: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 15508: my %staticdefaults = (
15509: anonsurvey_threshold => 10,
15510: uploadquota => 500,
1.160.6.57 raeburn 15511: postsubmit => 60,
1.160.6.70 raeburn 15512: mysqltables => 172800,
1.160.6.21 raeburn 15513: );
1.160.6.90 raeburn 15514: my %texoptions = (
15515: MathJax => 'MathJax',
15516: mimetex => &mt('Convert to Images'),
15517: tth => &mt('TeX to HTML'),
15518: );
1.121 raeburn 15519: $defaultshash{'coursedefaults'} = {};
15520:
15521: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
15522: if ($domconfig{'coursedefaults'} eq '') {
15523: $domconfig{'coursedefaults'} = {};
15524: }
15525: }
15526:
15527: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
15528: foreach my $item (@toggles) {
15529: if ($defaultchecked{$item} eq 'on') {
15530: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15531: ($env{'form.'.$item} eq '0')) {
15532: $changes{$item} = 1;
1.160.6.16 raeburn 15533: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 15534: $changes{$item} = 1;
15535: }
15536: } elsif ($defaultchecked{$item} eq 'off') {
15537: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15538: ($env{'form.'.$item} eq '1')) {
15539: $changes{$item} = 1;
15540: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
15541: $changes{$item} = 1;
15542: }
15543: }
15544: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
15545: }
1.160.6.21 raeburn 15546: foreach my $item (@numbers) {
15547: my ($currdef,$newdef);
1.160.6.26 raeburn 15548: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 15549: if ($item eq 'anonsurvey_threshold') {
15550: $currdef = $domconfig{'coursedefaults'}{$item};
15551: $newdef =~ s/\D//g;
15552: if ($newdef eq '' || $newdef < 1) {
15553: $newdef = 1;
15554: }
15555: $defaultshash{'coursedefaults'}{$item} = $newdef;
15556: } else {
1.160.6.70 raeburn 15557: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
15558: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
15559: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 15560: }
15561: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 15562: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 15563: }
15564: if ($currdef ne $newdef) {
15565: if ($item eq 'anonsurvey_threshold') {
15566: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
15567: $changes{$item} = 1;
15568: }
1.160.6.70 raeburn 15569: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
15570: my $setting = $1;
15571: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
15572: $changes{$setting} = 1;
1.160.6.21 raeburn 15573: }
15574: }
1.139 raeburn 15575: }
15576: }
1.160.6.90 raeburn 15577: my $texengine;
15578: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
15579: $texengine = $env{'form.texengine'};
15580: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
15581: if ($currdef eq '') {
15582: unless ($texengine eq $Apache::lonnet::deftex) {
15583: $changes{'texengine'} = 1;
15584: }
15585: } elsif ($currdef ne $texengine) {
15586: $changes{'texengine'} = 1;
15587: }
15588: }
15589: if ($texengine ne '') {
15590: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
15591: }
1.160.6.64 raeburn 15592: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
15593: my @currclonecode;
15594: if (ref($currclone) eq 'HASH') {
15595: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
15596: @currclonecode = @{$currclone->{'instcode'}};
15597: }
15598: }
15599: my $newclone;
15600: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
15601: $newclone = $env{'form.canclone'};
15602: }
15603: if ($newclone eq 'instcode') {
15604: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
15605: my (%codedefaults,@code_order,@clonecode);
15606: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
15607: \@code_order);
15608: foreach my $item (@code_order) {
15609: if (grep(/^\Q$item\E$/,@newcodes)) {
15610: push(@clonecode,$item);
15611: }
15612: }
15613: if (@clonecode) {
15614: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
15615: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
15616: if (@diffs) {
15617: $changes{'canclone'} = 1;
15618: }
15619: } else {
15620: $newclone eq '';
15621: }
15622: } elsif ($newclone ne '') {
15623: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
15624: }
15625: if ($newclone ne $currclone) {
15626: $changes{'canclone'} = 1;
15627: }
1.160.6.57 raeburn 15628: my %credits;
15629: foreach my $type (@types) {
15630: unless ($type eq 'community') {
15631: $credits{$type} = $env{'form.'.$type.'_credits'};
15632: $credits{$type} =~ s/[^\d.]+//g;
15633: }
15634: }
15635: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
15636: ($env{'form.coursecredits'} eq '1')) {
15637: $changes{'coursecredits'} = 1;
15638: foreach my $type (keys(%credits)) {
15639: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15640: }
15641: } else {
15642: if ($env{'form.coursecredits'} eq '1') {
15643: foreach my $type (@types) {
15644: unless ($type eq 'community') {
15645: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
15646: $changes{'coursecredits'} = 1;
15647: }
15648: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15649: }
15650: }
15651: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15652: foreach my $type (@types) {
15653: unless ($type eq 'community') {
15654: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
15655: $changes{'coursecredits'} = 1;
15656: last;
15657: }
15658: }
15659: }
15660: }
15661: }
15662: if ($env{'form.postsubmit'} eq '1') {
15663: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
15664: my %currtimeout;
15665: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15666: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
15667: $changes{'postsubmit'} = 1;
15668: }
15669: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15670: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
15671: }
15672: } else {
15673: $changes{'postsubmit'} = 1;
15674: }
15675: foreach my $type (@types) {
15676: my $timeout = $env{'form.'.$type.'_timeout'};
15677: $timeout =~ s/\D//g;
15678: if ($timeout == $staticdefaults{'postsubmit'}) {
15679: $timeout = '';
15680: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
15681: $timeout = '0';
15682: }
15683: unless ($timeout eq '') {
15684: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
15685: }
15686: if (exists($currtimeout{$type})) {
15687: if ($timeout ne $currtimeout{$type}) {
15688: $changes{'postsubmit'} = 1;
15689: }
15690: } elsif ($timeout ne '') {
15691: $changes{'postsubmit'} = 1;
15692: }
15693: }
15694: } else {
15695: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
15696: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15697: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
15698: $changes{'postsubmit'} = 1;
15699: }
15700: } else {
15701: $changes{'postsubmit'} = 1;
15702: }
1.160.6.16 raeburn 15703: }
1.121 raeburn 15704: }
15705: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15706: $dom);
15707: if ($putresult eq 'ok') {
15708: if (keys(%changes) > 0) {
1.160.6.27 raeburn 15709: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 15710: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 15711: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.90 raeburn 15712: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
15713: foreach my $item ('uselcmath','usejsme','texengine') {
1.160.6.57 raeburn 15714: if ($changes{$item}) {
15715: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
15716: }
1.160.6.16 raeburn 15717: }
15718: if ($changes{'coursecredits'}) {
15719: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 15720: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
15721: $domdefaults{$type.'credits'} =
15722: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
15723: }
15724: }
15725: }
15726: if ($changes{'postsubmit'}) {
15727: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15728: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
15729: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15730: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
15731: $domdefaults{$type.'postsubtimeout'} =
15732: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15733: }
15734: }
1.160.6.16 raeburn 15735: }
15736: }
1.160.6.21 raeburn 15737: if ($changes{'uploadquota'}) {
15738: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15739: foreach my $type (@types) {
15740: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
15741: }
15742: }
15743: }
1.160.6.64 raeburn 15744: if ($changes{'canclone'}) {
15745: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15746: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15747: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
15748: if (@clonecodes) {
15749: $domdefaults{'canclone'} = join('+',@clonecodes);
15750: }
15751: }
15752: } else {
15753: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
15754: }
15755: }
1.121 raeburn 15756: my $cachetime = 24*60*60;
15757: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 15758: if (ref($lastactref) eq 'HASH') {
15759: $lastactref->{'domdefaults'} = 1;
15760: }
1.121 raeburn 15761: }
15762: $resulttext = &mt('Changes made:').'<ul>';
15763: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 15764: if ($item eq 'uselcmath') {
1.121 raeburn 15765: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 15766: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 15767: } else {
1.160.6.57 raeburn 15768: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
15769: }
15770: } elsif ($item eq 'usejsme') {
15771: if ($env{'form.'.$item} eq '1') {
15772: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
15773: } else {
15774: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 15775: }
1.160.6.90 raeburn 15776: } elsif ($item eq 'texengine') {
15777: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
15778: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
15779: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
15780: }
1.139 raeburn 15781: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 15782: $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 15783: } elsif ($item eq 'uploadquota') {
15784: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15785: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
15786: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
15787: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 15788: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
15789:
1.160.6.21 raeburn 15790: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
15791: '</ul>'.
15792: '</li>';
15793: } else {
15794: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
15795: }
1.160.6.70 raeburn 15796: } elsif ($item eq 'mysqltables') {
15797: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
15798: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
15799: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
15800: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
15801: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
15802: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
15803: '</ul>'.
15804: '</li>';
15805: } else {
15806: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
15807: }
1.160.6.57 raeburn 15808: } elsif ($item eq 'postsubmit') {
15809: if ($domdefaults{'postsubmit'} eq 'off') {
15810: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
15811: } else {
15812: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
15813: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15814: $resulttext .= &mt('durations:').'<ul>';
15815: foreach my $type (@types) {
15816: $resulttext .= '<li>';
15817: my $timeout;
15818: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15819: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15820: }
15821: my $display;
15822: if ($timeout eq '0') {
15823: $display = &mt('unlimited');
15824: } elsif ($timeout eq '') {
15825: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
15826: } else {
15827: $display = &mt('[quant,_1,second]',$timeout);
15828: }
15829: if ($type eq 'community') {
15830: $resulttext .= &mt('Communities');
15831: } elsif ($type eq 'official') {
15832: $resulttext .= &mt('Official courses');
15833: } elsif ($type eq 'unofficial') {
15834: $resulttext .= &mt('Unofficial courses');
15835: } elsif ($type eq 'textbook') {
15836: $resulttext .= &mt('Textbook courses');
15837: }
15838: $resulttext .= ' -- '.$display.'</li>';
15839: }
15840: $resulttext .= '</ul>';
15841: }
15842: $resulttext .= '</li>';
15843: }
1.160.6.16 raeburn 15844: } elsif ($item eq 'coursecredits') {
15845: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15846: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 15847: ($domdefaults{'unofficialcredits'} eq '') &&
15848: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 15849: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15850: } else {
15851: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
15852: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
15853: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 15854: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 15855: '</ul>'.
15856: '</li>';
15857: }
15858: } else {
15859: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15860: }
1.160.6.64 raeburn 15861: } elsif ($item eq 'canclone') {
15862: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15863: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15864: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
15865: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
15866: }
15867: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
15868: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
15869: } else {
15870: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
15871: }
1.140 raeburn 15872: }
1.121 raeburn 15873: }
15874: $resulttext .= '</ul>';
15875: } else {
15876: $resulttext = &mt('No changes made to course defaults');
15877: }
15878: } else {
15879: $resulttext = '<span class="LC_error">'.
15880: &mt('An error occurred: [_1]',$putresult).'</span>';
15881: }
15882: return $resulttext;
15883: }
15884:
1.160.6.37 raeburn 15885: sub modify_selfenrollment {
15886: my ($dom,$lastactref,%domconfig) = @_;
15887: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
15888: my @types = ('official','unofficial','community','textbook');
15889: my %titles = &tool_titles();
15890: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
15891: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
15892: $ordered{'default'} = ['types','registered','approval','limit'];
15893:
15894: my (%roles,%shown,%toplevel);
15895: $roles{'0'} = &Apache::lonnet::plaintext('dc');
15896:
15897: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
15898: if ($domconfig{'selfenrollment'} eq '') {
15899: $domconfig{'selfenrollment'} = {};
15900: }
15901: }
15902: %toplevel = (
15903: admin => 'Configuration Rights',
15904: default => 'Default settings',
15905: validation => 'Validation of self-enrollment requests',
15906: );
15907: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
15908:
15909: if (ref($ordered{'admin'}) eq 'ARRAY') {
15910: foreach my $item (@{$ordered{'admin'}}) {
15911: foreach my $type (@types) {
15912: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
15913: $selfenrollhash{'admin'}{$type}{$item} = 1;
15914: } else {
15915: $selfenrollhash{'admin'}{$type}{$item} = 0;
15916: }
15917: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
15918: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
15919: if ($selfenrollhash{'admin'}{$type}{$item} ne
15920: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
15921: push(@{$changes{'admin'}{$type}},$item);
15922: }
15923: } else {
15924: if (!$selfenrollhash{'admin'}{$type}{$item}) {
15925: push(@{$changes{'admin'}{$type}},$item);
15926: }
15927: }
15928: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
15929: push(@{$changes{'admin'}{$type}},$item);
15930: }
15931: }
15932: }
15933: }
15934:
15935: foreach my $item (@{$ordered{'default'}}) {
15936: foreach my $type (@types) {
15937: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
15938: if ($item eq 'types') {
15939: unless (($value eq 'all') || ($value eq 'dom')) {
15940: $value = '';
15941: }
15942: } elsif ($item eq 'registered') {
15943: unless ($value eq '1') {
15944: $value = 0;
15945: }
15946: } elsif ($item eq 'approval') {
15947: unless ($value =~ /^[012]$/) {
15948: $value = 0;
15949: }
15950: } else {
15951: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15952: $value = 'none';
15953: }
15954: }
15955: $selfenrollhash{'default'}{$type}{$item} = $value;
15956: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
15957: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15958: if ($selfenrollhash{'default'}{$type}{$item} ne
15959: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
15960: push(@{$changes{'default'}{$type}},$item);
15961: }
15962: } else {
15963: push(@{$changes{'default'}{$type}},$item);
15964: }
15965: } else {
15966: push(@{$changes{'default'}{$type}},$item);
15967: }
15968: if ($item eq 'limit') {
15969: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15970: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
15971: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
15972: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
15973: }
15974: } else {
15975: $selfenrollhash{'default'}{$type}{'cap'} = '';
15976: }
15977: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15978: if ($selfenrollhash{'default'}{$type}{'cap'} ne
15979: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
15980: push(@{$changes{'default'}{$type}},'cap');
15981: }
15982: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
15983: push(@{$changes{'default'}{$type}},'cap');
15984: }
15985: }
15986: }
15987: }
15988:
15989: foreach my $item (@{$itemsref}) {
15990: if ($item eq 'fields') {
15991: my @changed;
15992: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
15993: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
15994: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
15995: }
15996: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15997: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
15998: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
15999: $domconfig{'selfenrollment'}{'validation'}{$item});
16000: } else {
16001: @changed = @{$selfenrollhash{'validation'}{$item}};
16002: }
16003: } else {
16004: @changed = @{$selfenrollhash{'validation'}{$item}};
16005: }
16006: if (@changed) {
16007: if ($selfenrollhash{'validation'}{$item}) {
16008: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
16009: } else {
16010: $changes{'validation'}{$item} = &mt('None');
16011: }
16012: }
16013: } else {
16014: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
16015: if ($item eq 'markup') {
16016: if ($env{'form.selfenroll_validation_'.$item}) {
16017: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
16018: }
16019: }
16020: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
16021: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
16022: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
16023: }
16024: }
16025: }
16026: }
16027:
16028: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
16029: $dom);
16030: if ($putresult eq 'ok') {
16031: if (keys(%changes) > 0) {
16032: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16033: $resulttext = &mt('Changes made:').'<ul>';
16034: foreach my $key ('admin','default','validation') {
16035: if (ref($changes{$key}) eq 'HASH') {
16036: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
16037: if ($key eq 'validation') {
16038: foreach my $item (@{$itemsref}) {
16039: if (exists($changes{$key}{$item})) {
16040: if ($item eq 'markup') {
16041: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
16042: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
16043: } else {
16044: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
16045: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
16046: }
16047: }
16048: }
16049: } else {
16050: foreach my $type (@types) {
16051: if ($type eq 'community') {
16052: $roles{'1'} = &mt('Community personnel');
16053: } else {
16054: $roles{'1'} = &mt('Course personnel');
16055: }
16056: if (ref($changes{$key}{$type}) eq 'ARRAY') {
16057: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
16058: if ($key eq 'admin') {
16059: my @mgrdc = ();
16060: if (ref($ordered{$key}) eq 'ARRAY') {
16061: foreach my $item (@{$ordered{'admin'}}) {
16062: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
16063: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
16064: push(@mgrdc,$item);
16065: }
16066: }
16067: }
16068: if (@mgrdc) {
16069: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
16070: } else {
16071: delete($domdefaults{$type.'selfenrolladmdc'});
16072: }
16073: }
16074: } else {
16075: if (ref($ordered{$key}) eq 'ARRAY') {
16076: foreach my $item (@{$ordered{$key}}) {
16077: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
16078: $domdefaults{$type.'selfenroll'.$item} =
16079: $selfenrollhash{$key}{$type}{$item};
16080: }
16081: }
16082: }
16083: }
16084: }
16085: $resulttext .= '<li>'.$titles{$type}.'<ul>';
16086: foreach my $item (@{$ordered{$key}}) {
16087: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
16088: $resulttext .= '<li>';
16089: if ($key eq 'admin') {
16090: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
16091: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
16092: } else {
16093: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
16094: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
16095: }
16096: $resulttext .= '</li>';
16097: }
16098: }
16099: $resulttext .= '</ul></li>';
16100: }
16101: }
16102: $resulttext .= '</ul></li>';
16103: }
16104: }
1.160.6.93 raeburn 16105: }
16106: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
16107: my $cachetime = 24*60*60;
16108: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16109: if (ref($lastactref) eq 'HASH') {
16110: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 16111: }
16112: }
16113: $resulttext .= '</ul>';
16114: } else {
16115: $resulttext = &mt('No changes made to self-enrollment settings');
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.113! raeburn 16124: sub modify_wafproxy {
! 16125: my ($dom,$action,$lastactref,%domconfig) = @_;
! 16126: my %servers = &Apache::lonnet::internet_dom_servers($dom);
! 16127: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
! 16128: %wafproxy,%changes,%expirecache,%expiresaml);
! 16129: foreach my $server (sort(keys(%servers))) {
! 16130: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
! 16131: if ($serverhome eq $server) {
! 16132: my $serverdom = &Apache::lonnet::host_domain($server);
! 16133: if ($serverdom eq $dom) {
! 16134: $canset{$server} = 1;
! 16135: }
! 16136: }
! 16137: }
! 16138: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
! 16139: %{$values{$dom}} = ();
! 16140: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
! 16141: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
! 16142: }
! 16143: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
! 16144: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
! 16145: }
! 16146: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
! 16147: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
! 16148: }
! 16149: }
! 16150: my $output;
! 16151: if (keys(%canset)) {
! 16152: %{$wafproxy{'alias'}} = ();
! 16153: %{$wafproxy{'saml'}} = ();
! 16154: foreach my $key (sort(keys(%canset))) {
! 16155: if ($env{'form.wafproxy_'.$dom}) {
! 16156: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
! 16157: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
! 16158: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
! 16159: $changes{'alias'} = 1;
! 16160: }
! 16161: if ($env{'form.wafproxy_alias_saml_'.$key}) {
! 16162: $wafproxy{'saml'}{$key} = 1;
! 16163: }
! 16164: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
! 16165: $changes{'saml'} = 1;
! 16166: }
! 16167: } else {
! 16168: $wafproxy{'alias'}{$key} = '';
! 16169: $wafproxy{'saml'}{$key} = '';
! 16170: if ($curralias{$key}) {
! 16171: $changes{'alias'} = 1;
! 16172: }
! 16173: if ($currsaml{$key}) {
! 16174: $changes{'saml'} = 1;
! 16175: }
! 16176: }
! 16177: if ($wafproxy{'alias'}{$key} eq '') {
! 16178: if ($curralias{$key}) {
! 16179: $expirecache{$key} = 1;
! 16180: }
! 16181: delete($wafproxy{'alias'}{$key});
! 16182: }
! 16183: if ($wafproxy{'saml'}{$key} eq '') {
! 16184: if ($currsaml{$key}) {
! 16185: $expiresaml{$key} = 1;
! 16186: }
! 16187: delete($wafproxy{'saml'}{$key});
! 16188: }
! 16189: }
! 16190: unless (keys(%{$wafproxy{'alias'}})) {
! 16191: delete($wafproxy{'alias'});
! 16192: }
! 16193: unless (keys(%{$wafproxy{'saml'}})) {
! 16194: delete($wafproxy{'saml'});
! 16195: }
! 16196: # Localization for values in %warn occurs in &mt() calls separately.
! 16197: my %warn = (
! 16198: trusted => 'trusted IP range(s)',
! 16199: vpnint => 'internal IP range(s) for VPN sessions(s)',
! 16200: vpnext => 'IP range(s) for backend WAF connections',
! 16201: );
! 16202: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
! 16203: my $possible = $env{'form.wafproxy_'.$item};
! 16204: $possible =~ s/^\s+|\s+$//g;
! 16205: if ($possible ne '') {
! 16206: if ($item eq 'remoteip') {
! 16207: if ($possible =~ /^[mhn]$/) {
! 16208: $wafproxy{$item} = $possible;
! 16209: }
! 16210: } elsif ($item eq 'ipheader') {
! 16211: if ($wafproxy{'remoteip'} eq 'h') {
! 16212: $wafproxy{$item} = $possible;
! 16213: }
! 16214: } elsif ($item eq 'sslopt') {
! 16215: if ($possible =~ /^0|1$/) {
! 16216: $wafproxy{$item} = $possible;
! 16217: }
! 16218: } else {
! 16219: my (@ok,$count);
! 16220: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
! 16221: unless ($env{'form.wafproxy_vpnaccess'}) {
! 16222: $possible = '';
! 16223: }
! 16224: } elsif ($item eq 'trusted') {
! 16225: unless ($wafproxy{'remoteip'} eq 'h') {
! 16226: $possible = '';
! 16227: }
! 16228: }
! 16229: unless ($possible eq '') {
! 16230: $possible =~ s/[\r\n]+/\s/g;
! 16231: $possible =~ s/\s*-\s*/-/g;
! 16232: $possible =~ s/\s+/,/g;
! 16233: $possible =~ s/,+/,/g;
! 16234: }
! 16235: $count = 0;
! 16236: if ($possible ne '') {
! 16237: foreach my $poss (split(/\,/,$possible)) {
! 16238: $count ++;
! 16239: $poss = &validate_ip_pattern($poss);
! 16240: if ($poss ne '') {
! 16241: push(@ok,$poss);
! 16242: }
! 16243: }
! 16244: my $diff = $count - scalar(@ok);
! 16245: if ($diff) {
! 16246: push(@warnings,'<li>'.
! 16247: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
! 16248: $diff,$warn{$item}).
! 16249: '</li>');
! 16250: }
! 16251: if (@ok) {
! 16252: my @cidr_list;
! 16253: foreach my $item (@ok) {
! 16254: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
! 16255: }
! 16256: $wafproxy{$item} = join(',',@cidr_list);
! 16257: }
! 16258: }
! 16259: }
! 16260: if ($wafproxy{$item} ne $currvalue{$item}) {
! 16261: $changes{$item} = 1;
! 16262: }
! 16263: } elsif ($currvalue{$item}) {
! 16264: $changes{$item} = 1;
! 16265: }
! 16266: }
! 16267: } else {
! 16268: if (keys(%curralias)) {
! 16269: $changes{'alias'} = 1;
! 16270: }
! 16271: if (keys(%currsaml)) {
! 16272: $changes{'saml'} = 1;
! 16273: }
! 16274: if (keys(%currvalue)) {
! 16275: foreach my $key (keys(%currvalue)) {
! 16276: $changes{$key} = 1;
! 16277: }
! 16278: }
! 16279: }
! 16280: if (keys(%changes)) {
! 16281: my %defaultshash = (
! 16282: wafproxy => \%wafproxy,
! 16283: );
! 16284: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
! 16285: $dom);
! 16286: if ($putresult eq 'ok') {
! 16287: my $cachetime = 24*60*60;
! 16288: my (%domdefaults,$updatedomdefs);
! 16289: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
! 16290: if ($changes{$item}) {
! 16291: unless ($updatedomdefs) {
! 16292: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
! 16293: $updatedomdefs = 1;
! 16294: }
! 16295: if ($wafproxy{$item}) {
! 16296: $domdefaults{'waf_'.$item} = $wafproxy{$item};
! 16297: } elsif (exists($domdefaults{'waf_'.$item})) {
! 16298: delete($domdefaults{'waf_'.$item});
! 16299: }
! 16300: }
! 16301: }
! 16302: if ($updatedomdefs) {
! 16303: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
! 16304: if (ref($lastactref) eq 'HASH') {
! 16305: $lastactref->{'domdefaults'} = 1;
! 16306: }
! 16307: }
! 16308: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
! 16309: my %updates = %expirecache;
! 16310: foreach my $key (keys(%expirecache)) {
! 16311: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
! 16312: }
! 16313: if (ref($wafproxy{'alias'}) eq 'HASH') {
! 16314: my $cachetime = 24*60*60;
! 16315: foreach my $key (keys(%{$wafproxy{'alias'}})) {
! 16316: $updates{$key} = 1;
! 16317: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
! 16318: $cachetime);
! 16319: }
! 16320: }
! 16321: if (ref($lastactref) eq 'HASH') {
! 16322: $lastactref->{'proxyalias'} = \%updates;
! 16323: }
! 16324: }
! 16325: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
! 16326: my %samlupdates = %expiresaml;
! 16327: foreach my $key (keys(%expiresaml)) {
! 16328: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
! 16329: }
! 16330: if (ref($wafproxy{'saml'}) eq 'HASH') {
! 16331: my $cachetime = 24*60*60;
! 16332: foreach my $key (keys(%{$wafproxy{'saml'}})) {
! 16333: $samlupdates{$key} = 1;
! 16334: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
! 16335: $cachetime);
! 16336: }
! 16337: }
! 16338: if (ref($lastactref) eq 'HASH') {
! 16339: $lastactref->{'proxysaml'} = \%samlupdates;
! 16340: }
! 16341: }
! 16342: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
! 16343: foreach my $item ('alias','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
! 16344: if ($changes{$item}) {
! 16345: if ($item eq 'alias') {
! 16346: my $numaliased = 0;
! 16347: if (ref($wafproxy{'alias'}) eq 'HASH') {
! 16348: my $shown;
! 16349: if (keys(%{$wafproxy{'alias'}})) {
! 16350: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
! 16351: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
! 16352: &Apache::lonnet::hostname($server),
! 16353: $wafproxy{'alias'}{$server}).'</li>';
! 16354: $numaliased ++;
! 16355: }
! 16356: if ($numaliased) {
! 16357: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
! 16358: '<ul>'.$shown.'</ul>').'</li>';
! 16359: }
! 16360: }
! 16361: }
! 16362: unless ($numaliased) {
! 16363: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
! 16364: }
! 16365: } elsif ($item eq 'saml') {
! 16366: my $shown;
! 16367: if (ref($wafproxy{'saml'}) eq 'HASH') {
! 16368: if (keys(%{$wafproxy{'saml'}})) {
! 16369: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
! 16370: }
! 16371: }
! 16372: if ($shown) {
! 16373: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
! 16374: $shown).'</li>';
! 16375: } else {
! 16376: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
! 16377: }
! 16378: } else {
! 16379: if ($item eq 'remoteip') {
! 16380: my %ip_methods = &remoteip_methods();
! 16381: if ($wafproxy{$item} =~ /^[mh]$/) {
! 16382: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
! 16383: $ip_methods{$wafproxy{$item}}).'</li>';
! 16384: } else {
! 16385: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
! 16386: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
! 16387: '</li>';
! 16388: } else {
! 16389: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
! 16390: }
! 16391: }
! 16392: } elsif ($item eq 'ipheader') {
! 16393: if ($wafproxy{$item}) {
! 16394: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
! 16395: $wafproxy{$item}).'</li>';
! 16396: } else {
! 16397: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
! 16398: }
! 16399: } elsif ($item eq 'trusted') {
! 16400: if ($wafproxy{$item}) {
! 16401: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
! 16402: $wafproxy{$item}).'</li>';
! 16403: } else {
! 16404: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
! 16405: }
! 16406: } elsif ($item eq 'vpnint') {
! 16407: if ($wafproxy{$item}) {
! 16408: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
! 16409: $wafproxy{$item}).'</li>';
! 16410: } else {
! 16411: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
! 16412: }
! 16413: } elsif ($item eq 'vpnext') {
! 16414: if ($wafproxy{$item}) {
! 16415: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
! 16416: $wafproxy{$item}).'</li>';
! 16417: } else {
! 16418: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
! 16419: }
! 16420: } elsif ($item eq 'sslopt') {
! 16421: if ($wafproxy{$item}) {
! 16422: $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>';
! 16423: } else {
! 16424: $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>';
! 16425: }
! 16426: }
! 16427: }
! 16428: }
! 16429: }
! 16430: } else {
! 16431: $output = '<span class="LC_error">'.
! 16432: &mt('An error occurred: [_1]',$putresult).'</span>';
! 16433: }
! 16434: } elsif (keys(%canset)) {
! 16435: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
! 16436: }
! 16437: if (@warnings) {
! 16438: $output .= '<br />'.&mt('Warnings:').'<ul>'.
! 16439: join("\n",@warnings).'</ul>';
! 16440: }
! 16441: return $output;
! 16442: }
! 16443:
! 16444: sub validate_ip_pattern {
! 16445: my ($pattern) = @_;
! 16446: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
! 16447: my ($start,$end) = ($1,$2);
! 16448: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
! 16449: if (($start !~ m{/}) && ($end !~ m{/})) {
! 16450: return $start.'-'.$end;
! 16451: }
! 16452: }
! 16453: } elsif ($pattern ne '') {
! 16454: $pattern = &Net::CIDR::cidrvalidate($pattern);
! 16455: if ($pattern ne '') {
! 16456: return $pattern;
! 16457: }
! 16458: }
! 16459: return;
! 16460: }
! 16461:
1.137 raeburn 16462: sub modify_usersessions {
1.160.6.27 raeburn 16463: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 16464: my @hostingtypes = ('version','excludedomain','includedomain');
16465: my @offloadtypes = ('primary','default');
16466: my %types = (
16467: remote => \@hostingtypes,
16468: hosted => \@hostingtypes,
16469: spares => \@offloadtypes,
16470: );
16471: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 16472: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 16473: my (%by_ip,%by_location,@intdoms);
16474: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
16475: my @locations = sort(keys(%by_location));
1.137 raeburn 16476: my (%defaultshash,%changes);
16477: foreach my $prefix (@prefixes) {
16478: $defaultshash{'usersessions'}{$prefix} = {};
16479: }
1.160.6.27 raeburn 16480: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 16481: my $resulttext;
1.138 raeburn 16482: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 16483: foreach my $prefix (@prefixes) {
1.145 raeburn 16484: next if ($prefix eq 'spares');
16485: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 16486: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16487: if ($type eq 'version') {
16488: my $value = $env{'form.'.$prefix.'_'.$type};
16489: my $okvalue;
16490: if ($value ne '') {
16491: if (grep(/^\Q$value\E$/,@lcversions)) {
16492: $okvalue = $value;
16493: }
16494: }
16495: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16496: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16497: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
16498: if ($inuse == 0) {
16499: $changes{$prefix}{$type} = 1;
16500: } else {
16501: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
16502: $changes{$prefix}{$type} = 1;
16503: }
16504: if ($okvalue ne '') {
16505: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16506: }
16507: }
16508: } else {
16509: if (($inuse == 1) && ($okvalue ne '')) {
16510: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16511: $changes{$prefix}{$type} = 1;
16512: }
16513: }
16514: } else {
16515: if (($inuse == 1) && ($okvalue ne '')) {
16516: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16517: $changes{$prefix}{$type} = 1;
16518: }
16519: }
16520: } else {
16521: if (($inuse == 1) && ($okvalue ne '')) {
16522: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16523: $changes{$prefix}{$type} = 1;
16524: }
16525: }
16526: } else {
16527: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16528: my @okvals;
16529: foreach my $val (@vals) {
1.138 raeburn 16530: if ($val =~ /:/) {
16531: my @items = split(/:/,$val);
16532: foreach my $item (@items) {
16533: if (ref($by_location{$item}) eq 'ARRAY') {
16534: push(@okvals,$item);
16535: }
16536: }
16537: } else {
16538: if (ref($by_location{$val}) eq 'ARRAY') {
16539: push(@okvals,$val);
16540: }
1.137 raeburn 16541: }
16542: }
16543: @okvals = sort(@okvals);
16544: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16545: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16546: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16547: if ($inuse == 0) {
16548: $changes{$prefix}{$type} = 1;
16549: } else {
16550: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16551: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
16552: if (@changed > 0) {
16553: $changes{$prefix}{$type} = 1;
16554: }
16555: }
16556: } else {
16557: if ($inuse == 1) {
16558: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16559: $changes{$prefix}{$type} = 1;
16560: }
16561: }
16562: } else {
16563: if ($inuse == 1) {
16564: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16565: $changes{$prefix}{$type} = 1;
16566: }
16567: }
16568: } else {
16569: if ($inuse == 1) {
16570: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16571: $changes{$prefix}{$type} = 1;
16572: }
16573: }
16574: }
16575: }
16576: }
1.145 raeburn 16577:
16578: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 16579: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 16580: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
16581: my $savespares;
16582:
16583: foreach my $lonhost (sort(keys(%servers))) {
16584: my $serverhomeID =
16585: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 16586: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 16587: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
16588: my %spareschg;
16589: foreach my $type (@{$types{'spares'}}) {
16590: my @okspares;
16591: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
16592: foreach my $server (@checked) {
1.152 raeburn 16593: if (&Apache::lonnet::hostname($server) ne '') {
16594: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
16595: unless (grep(/^\Q$server\E$/,@okspares)) {
16596: push(@okspares,$server);
16597: }
1.145 raeburn 16598: }
16599: }
16600: }
16601: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
16602: my $newspare;
1.152 raeburn 16603: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
16604: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 16605: $newspare = $new;
16606: }
16607: }
1.152 raeburn 16608: my @spares;
16609: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
16610: @spares = sort(@okspares,$newspare);
16611: } else {
16612: @spares = sort(@okspares);
16613: }
16614: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 16615: if (ref($spareid{$lonhost}) eq 'HASH') {
16616: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 16617: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 16618: if (@diffs > 0) {
16619: $spareschg{$type} = 1;
16620: }
16621: }
16622: }
16623: }
16624: if (keys(%spareschg) > 0) {
16625: $changes{'spares'}{$lonhost} = \%spareschg;
16626: }
16627: }
1.160.6.61 raeburn 16628: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.160.6.105 raeburn 16629: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.160.6.61 raeburn 16630: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
16631: my @okoffload;
16632: if (@offloadnow) {
16633: foreach my $server (@offloadnow) {
16634: if (&Apache::lonnet::hostname($server) ne '') {
16635: unless (grep(/^\Q$server\E$/,@okoffload)) {
16636: push(@okoffload,$server);
16637: }
16638: }
16639: }
16640: if (@okoffload) {
16641: foreach my $lonhost (@okoffload) {
16642: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
16643: }
16644: }
16645: }
1.160.6.105 raeburn 16646: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
16647: my @okoffloadoth;
16648: if (@offloadoth) {
16649: foreach my $server (@offloadoth) {
16650: if (&Apache::lonnet::hostname($server) ne '') {
16651: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
16652: push(@okoffloadoth,$server);
16653: }
16654: }
16655: }
16656: if (@okoffloadoth) {
16657: foreach my $lonhost (@okoffloadoth) {
16658: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
16659: }
16660: }
16661: }
1.145 raeburn 16662: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16663: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
16664: if (ref($changes{'spares'}) eq 'HASH') {
16665: if (keys(%{$changes{'spares'}}) > 0) {
16666: $savespares = 1;
16667: }
16668: }
16669: } else {
16670: $savespares = 1;
16671: }
1.160.6.105 raeburn 16672: foreach my $offload ('offloadnow','offloadoth') {
16673: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
16674: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
16675: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
16676: $changes{$offload} = 1;
1.160.6.61 raeburn 16677: last;
16678: }
16679: }
1.160.6.105 raeburn 16680: unless ($changes{$offload}) {
16681: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
16682: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
16683: $changes{$offload} = 1;
16684: last;
16685: }
16686: }
16687: }
16688: } else {
16689: if (($offload eq 'offloadnow') && (@okoffload)) {
16690: $changes{'offloadnow'} = 1;
16691: }
16692: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
16693: $changes{'offloadoth'} = 1;
16694: }
1.160.6.61 raeburn 16695: }
1.160.6.105 raeburn 16696: }
16697: } else {
16698: if (@okoffload) {
1.160.6.61 raeburn 16699: $changes{'offloadnow'} = 1;
16700: }
1.160.6.105 raeburn 16701: if (@okoffloadoth) {
16702: $changes{'offloadoth'} = 1;
16703: }
1.145 raeburn 16704: }
1.147 raeburn 16705: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
16706: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 16707: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16708: $dom);
16709: if ($putresult eq 'ok') {
16710: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16711: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
16712: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
16713: }
16714: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
16715: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
16716: }
1.160.6.61 raeburn 16717: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16718: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
16719: }
1.160.6.105 raeburn 16720: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
16721: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
16722: }
1.137 raeburn 16723: }
16724: my $cachetime = 24*60*60;
16725: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 16726: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 16727: if (ref($lastactref) eq 'HASH') {
16728: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 16729: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 16730: }
1.147 raeburn 16731: if (keys(%changes) > 0) {
16732: my %lt = &usersession_titles();
16733: $resulttext = &mt('Changes made:').'<ul>';
16734: foreach my $prefix (@prefixes) {
16735: if (ref($changes{$prefix}) eq 'HASH') {
16736: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16737: if ($prefix eq 'spares') {
16738: if (ref($changes{$prefix}) eq 'HASH') {
16739: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
16740: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 16741: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 16742: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
16743: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 16744: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
16745: foreach my $type (@{$types{$prefix}}) {
16746: if ($changes{$prefix}{$lonhost}{$type}) {
16747: my $offloadto = &mt('None');
16748: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
16749: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
16750: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
16751: }
1.145 raeburn 16752: }
1.147 raeburn 16753: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 16754: }
1.137 raeburn 16755: }
16756: }
1.147 raeburn 16757: $resulttext .= '</li>';
1.137 raeburn 16758: }
16759: }
1.147 raeburn 16760: } else {
16761: foreach my $type (@{$types{$prefix}}) {
16762: if (defined($changes{$prefix}{$type})) {
16763: my $newvalue;
16764: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16765: if (ref($defaultshash{'usersessions'}{$prefix})) {
16766: if ($type eq 'version') {
16767: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
16768: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16769: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
16770: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
16771: }
1.145 raeburn 16772: }
16773: }
16774: }
1.147 raeburn 16775: if ($newvalue eq '') {
16776: if ($type eq 'version') {
16777: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
16778: } else {
16779: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16780: }
1.145 raeburn 16781: } else {
1.147 raeburn 16782: if ($type eq 'version') {
16783: $newvalue .= ' '.&mt('(or later)');
16784: }
16785: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 16786: }
1.137 raeburn 16787: }
16788: }
16789: }
1.147 raeburn 16790: $resulttext .= '</ul>';
1.137 raeburn 16791: }
16792: }
1.160.6.61 raeburn 16793: if ($changes{'offloadnow'}) {
16794: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16795: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.160.6.105 raeburn 16796: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.160.6.61 raeburn 16797: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
16798: $resulttext .= '<li>'.$lonhost.'</li>';
16799: }
16800: $resulttext .= '</ul>';
16801: } else {
1.160.6.105 raeburn 16802: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
16803: }
16804: } else {
16805: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
16806: }
16807: }
16808: if ($changes{'offloadoth'}) {
16809: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
16810: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
16811: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
16812: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
16813: $resulttext .= '<li>'.$lonhost.'</li>';
16814: }
16815: $resulttext .= '</ul>';
16816: } else {
16817: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.160.6.61 raeburn 16818: }
16819: } else {
1.160.6.105 raeburn 16820: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.160.6.61 raeburn 16821: }
16822: }
1.147 raeburn 16823: $resulttext .= '</ul>';
16824: } else {
16825: $resulttext = $nochgmsg;
1.137 raeburn 16826: }
16827: } else {
16828: $resulttext = '<span class="LC_error">'.
16829: &mt('An error occurred: [_1]',$putresult).'</span>';
16830: }
16831: } else {
1.147 raeburn 16832: $resulttext = $nochgmsg;
1.137 raeburn 16833: }
16834: return $resulttext;
16835: }
16836:
1.150 raeburn 16837: sub modify_loadbalancing {
16838: my ($dom,%domconfig) = @_;
16839: my $primary_id = &Apache::lonnet::domain($dom,'primary');
16840: my $intdom = &Apache::lonnet::internet_dom($primary_id);
16841: my ($othertitle,$usertypes,$types) =
16842: &Apache::loncommon::sorted_inst_types($dom);
16843: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 16844: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 16845: my @sparestypes = ('primary','default');
16846: my %typetitles = &sparestype_titles();
16847: my $resulttext;
1.160.6.94 raeburn 16848: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 16849: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16850: %existing = %{$domconfig{'loadbalancing'}};
16851: }
16852: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 16853: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 16854: my ($saveloadbalancing,%defaultshash,%changes);
16855: my ($alltypes,$othertypes,$titles) =
16856: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
16857: my %ruletitles = &offloadtype_text();
16858: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
16859: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
16860: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
16861: if ($balancer eq '') {
16862: next;
16863: }
16864: if (!exists($servers{$balancer})) {
16865: if (exists($currbalancer{$balancer})) {
16866: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 16867: }
1.160.6.7 raeburn 16868: next;
16869: }
16870: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
16871: push(@{$changes{'delete'}},$balancer);
16872: next;
16873: }
16874: if (!exists($currbalancer{$balancer})) {
16875: push(@{$changes{'add'}},$balancer);
16876: }
16877: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
16878: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
16879: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
16880: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16881: $saveloadbalancing = 1;
16882: }
16883: foreach my $sparetype (@sparestypes) {
16884: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
16885: my @offloadto;
16886: foreach my $target (@targets) {
16887: if (($servers{$target}) && ($target ne $balancer)) {
16888: if ($sparetype eq 'default') {
16889: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
16890: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 16891: }
16892: }
1.160.6.7 raeburn 16893: unless(grep(/^\Q$target\E$/,@offloadto)) {
16894: push(@offloadto,$target);
16895: }
1.150 raeburn 16896: }
16897: }
1.160.6.76 raeburn 16898: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
16899: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
16900: push(@offloadto,$balancer);
16901: }
16902: }
16903: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 16904: }
1.160.6.94 raeburn 16905: if ($env{'form.loadbalancing_cookie_'.$i}) {
16906: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
16907: if (exists($currbalancer{$balancer})) {
16908: unless ($currcookies{$balancer}) {
16909: $changes{'curr'}{$balancer}{'cookie'} = 1;
16910: }
16911: }
16912: } elsif (exists($currbalancer{$balancer})) {
16913: if ($currcookies{$balancer}) {
16914: $changes{'curr'}{$balancer}{'cookie'} = 1;
16915: }
16916: }
1.160.6.7 raeburn 16917: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 16918: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 16919: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
16920: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 16921: if (@targetdiffs > 0) {
1.160.6.7 raeburn 16922: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16923: }
1.160.6.7 raeburn 16924: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16925: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16926: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16927: }
16928: }
16929: }
16930: } else {
1.160.6.7 raeburn 16931: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
16932: foreach my $sparetype (@sparestypes) {
16933: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16934: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16935: $changes{'curr'}{$balancer}{'targets'} = 1;
16936: }
1.150 raeburn 16937: }
16938: }
1.160.6.7 raeburn 16939: }
1.150 raeburn 16940: }
16941: my $ishomedom;
1.160.6.7 raeburn 16942: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
16943: $ishomedom = 1;
1.150 raeburn 16944: }
16945: if (ref($alltypes) eq 'ARRAY') {
16946: foreach my $type (@{$alltypes}) {
16947: my $rule;
1.160.6.7 raeburn 16948: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 16949: (!$ishomedom)) {
1.160.6.7 raeburn 16950: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
16951: }
16952: if ($rule eq 'specific') {
1.160.6.55 raeburn 16953: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
16954: if (exists($servers{$specifiedhost})) {
16955: $rule = $specifiedhost;
16956: }
1.150 raeburn 16957: }
1.160.6.7 raeburn 16958: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
16959: if (ref($currrules{$balancer}) eq 'HASH') {
16960: if ($rule ne $currrules{$balancer}{$type}) {
16961: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16962: }
16963: } elsif ($rule ne '') {
1.160.6.7 raeburn 16964: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16965: }
16966: }
16967: }
1.160.6.7 raeburn 16968: }
16969: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
16970: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
16971: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
16972: $defaultshash{'loadbalancing'} = {};
16973: }
16974: my $putresult = &Apache::lonnet::put_dom('configuration',
16975: \%defaultshash,$dom);
16976: if ($putresult eq 'ok') {
16977: if (keys(%changes) > 0) {
1.160.6.54 raeburn 16978: my %toupdate;
1.160.6.7 raeburn 16979: if (ref($changes{'delete'}) eq 'ARRAY') {
16980: foreach my $balancer (sort(@{$changes{'delete'}})) {
16981: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 16982: $toupdate{$balancer} = 1;
1.150 raeburn 16983: }
1.160.6.7 raeburn 16984: }
16985: if (ref($changes{'add'}) eq 'ARRAY') {
16986: foreach my $balancer (sort(@{$changes{'add'}})) {
16987: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 16988: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 16989: }
16990: }
16991: if (ref($changes{'curr'}) eq 'HASH') {
16992: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 16993: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 16994: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
16995: if ($changes{'curr'}{$balancer}{'targets'}) {
16996: my %offloadstr;
16997: foreach my $sparetype (@sparestypes) {
16998: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16999: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
17000: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
17001: }
17002: }
1.150 raeburn 17003: }
1.160.6.7 raeburn 17004: if (keys(%offloadstr) == 0) {
17005: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 17006: } else {
1.160.6.7 raeburn 17007: my $showoffload;
17008: foreach my $sparetype (@sparestypes) {
17009: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
17010: if (defined($offloadstr{$sparetype})) {
17011: $showoffload .= $offloadstr{$sparetype};
17012: } else {
17013: $showoffload .= &mt('None');
17014: }
17015: $showoffload .= (' 'x3);
17016: }
17017: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 17018: }
17019: }
17020: }
1.160.6.7 raeburn 17021: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
17022: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
17023: foreach my $type (@{$alltypes}) {
17024: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
17025: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
17026: my $balancetext;
17027: if ($rule eq '') {
17028: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 17029: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 17030: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
17031: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 17032: foreach my $sparetype (@sparestypes) {
17033: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17034: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
17035: }
17036: }
1.160.6.55 raeburn 17037: foreach my $item (@{$alltypes}) {
17038: next if ($item =~ /^_LC_ipchange/);
17039: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
17040: if ($hasrule eq 'homeserver') {
17041: map { $toupdate{$_} = 1; } (keys(%libraryservers));
17042: } else {
17043: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
17044: if ($servers{$hasrule}) {
17045: $toupdate{$hasrule} = 1;
17046: }
17047: }
17048: }
17049: }
17050: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
17051: $balancetext = $ruletitles{$rule};
17052: } else {
17053: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
17054: $balancetext = $ruletitles{'particular'}.' '.$receiver;
17055: if ($receiver) {
17056: $toupdate{$receiver};
17057: }
17058: }
17059: } else {
17060: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 17061: }
1.160.6.7 raeburn 17062: } else {
17063: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
17064: }
1.160.6.26 raeburn 17065: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 17066: }
17067: }
17068: }
17069: }
1.160.6.94 raeburn 17070: if ($changes{'curr'}{$balancer}{'cookie'}) {
17071: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
17072: $balancer).'</li>';
17073: }
1.160.6.106 raeburn 17074: }
17075: }
17076: if (keys(%toupdate)) {
17077: my %thismachine;
17078: my $updatedhere;
17079: my $cachetime = 60*60*24;
17080: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
17081: foreach my $lonhost (keys(%toupdate)) {
17082: if ($thismachine{$lonhost}) {
17083: unless ($updatedhere) {
17084: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
17085: $defaultshash{'loadbalancing'},
17086: $cachetime);
17087: $updatedhere = 1;
1.160.6.54 raeburn 17088: }
1.160.6.106 raeburn 17089: } else {
17090: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
17091: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.160.6.54 raeburn 17092: }
1.150 raeburn 17093: }
1.160.6.7 raeburn 17094: }
17095: if ($resulttext ne '') {
17096: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 17097: } else {
17098: $resulttext = $nochgmsg;
17099: }
17100: } else {
1.160.6.7 raeburn 17101: $resulttext = $nochgmsg;
1.150 raeburn 17102: }
17103: } else {
1.160.6.7 raeburn 17104: $resulttext = '<span class="LC_error">'.
17105: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 17106: }
17107: } else {
1.160.6.7 raeburn 17108: $resulttext = $nochgmsg;
1.150 raeburn 17109: }
17110: return $resulttext;
17111: }
17112:
1.48 raeburn 17113: sub recurse_check {
17114: my ($chkcats,$categories,$depth,$name) = @_;
17115: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
17116: my $chg = 0;
17117: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
17118: my $category = $chkcats->[$depth]{$name}[$j];
17119: my $item;
17120: if ($category eq '') {
17121: $chg ++;
17122: } else {
17123: my $deeper = $depth + 1;
17124: $item = &escape($category).':'.&escape($name).':'.$depth;
17125: if ($chg) {
17126: $categories->{$item} -= $chg;
17127: }
17128: &recurse_check($chkcats,$categories,$deeper,$category);
17129: $deeper --;
17130: }
17131: }
17132: }
17133: return;
17134: }
17135:
17136: sub recurse_cat_deletes {
17137: my ($item,$coursecategories,$deletions) = @_;
17138: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
17139: my $subdepth = $depth + 1;
17140: if (ref($coursecategories) eq 'HASH') {
17141: foreach my $subitem (keys(%{$coursecategories})) {
17142: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
17143: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
17144: delete($coursecategories->{$subitem});
17145: $deletions->{$subitem} = 1;
17146: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 17147: }
1.48 raeburn 17148: }
17149: }
17150: return;
17151: }
17152:
1.125 raeburn 17153: sub active_dc_picker {
1.160.6.16 raeburn 17154: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 17155: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 17156: my @domcoord = keys(%domcoords);
17157: if (keys(%currhash)) {
17158: foreach my $dc (keys(%currhash)) {
17159: unless (exists($domcoords{$dc})) {
17160: push(@domcoord,$dc);
17161: }
17162: }
17163: }
17164: @domcoord = sort(@domcoord);
17165: my $numdcs = scalar(@domcoord);
17166: my $rows = 0;
17167: my $table;
1.125 raeburn 17168: if ($numdcs > 1) {
1.160.6.16 raeburn 17169: $table = '<table>';
17170: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 17171: my $rem = $i%($numinrow);
17172: if ($rem == 0) {
17173: if ($i > 0) {
1.160.6.16 raeburn 17174: $table .= '</tr>';
1.125 raeburn 17175: }
1.160.6.16 raeburn 17176: $table .= '<tr>';
17177: $rows ++;
1.125 raeburn 17178: }
1.160.6.16 raeburn 17179: my $check = '';
17180: if ($inputtype eq 'radio') {
17181: if (keys(%currhash) == 0) {
17182: if (!$i) {
17183: $check = ' checked="checked"';
17184: }
17185: } elsif (exists($currhash{$domcoord[$i]})) {
17186: $check = ' checked="checked"';
17187: }
17188: } else {
17189: if (exists($currhash{$domcoord[$i]})) {
17190: $check = ' checked="checked"';
1.125 raeburn 17191: }
17192: }
1.160.6.16 raeburn 17193: if ($i == @domcoord - 1) {
1.125 raeburn 17194: my $colsleft = $numinrow - $rem;
17195: if ($colsleft > 1) {
1.160.6.16 raeburn 17196: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 17197: } else {
1.160.6.16 raeburn 17198: $table .= '<td class="LC_left_item">';
1.125 raeburn 17199: }
17200: } else {
1.160.6.16 raeburn 17201: $table .= '<td class="LC_left_item">';
17202: }
17203: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
17204: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
17205: $table .= '<span class="LC_nobreak"><label>'.
17206: '<input type="'.$inputtype.'" name="'.$name.'"'.
17207: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
17208: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 17209: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 17210: }
1.160.6.33 raeburn 17211: $table .= '</label></span></td>';
1.125 raeburn 17212: }
1.160.6.16 raeburn 17213: $table .= '</tr></table>';
17214: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 17215: my ($dcname,$dcdom) = split(':',$domcoord[0]);
17216: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 17217: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 17218: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 17219: if ($user ne $dcname.':'.$dcdom) {
17220: $table .= ' ('.$dcname.':'.$dcdom.')';
17221: }
1.160.6.16 raeburn 17222: } else {
17223: my $check;
17224: if (exists($currhash{$domcoord[0]})) {
17225: $check = ' checked="checked"';
17226: }
1.160.6.50 raeburn 17227: $table = '<span class="LC_nobreak"><label>'.
17228: '<input type="checkbox" name="'.$name.'" '.
17229: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 17230: if ($user ne $dcname.':'.$dcdom) {
17231: $table .= ' ('.$dcname.':'.$dcdom.')';
17232: }
17233: $table .= '</label></span>';
1.160.6.16 raeburn 17234: $rows ++;
17235: }
1.125 raeburn 17236: }
1.160.6.16 raeburn 17237: return ($numdcs,$table,$rows);
1.125 raeburn 17238: }
17239:
1.137 raeburn 17240: sub usersession_titles {
17241: return &Apache::lonlocal::texthash(
17242: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
17243: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 17244: spares => 'Servers offloaded to, when busy',
1.137 raeburn 17245: version => 'LON-CAPA version requirement',
1.138 raeburn 17246: excludedomain => 'Allow all, but exclude specific domains',
17247: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 17248: primary => 'Primary (checked first)',
1.154 raeburn 17249: default => 'Default',
1.137 raeburn 17250: );
17251: }
17252:
1.152 raeburn 17253: sub id_for_thisdom {
17254: my (%servers) = @_;
17255: my %altids;
17256: foreach my $server (keys(%servers)) {
17257: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
17258: if ($serverhome ne $server) {
17259: $altids{$serverhome} = $server;
17260: }
17261: }
17262: return %altids;
17263: }
17264:
1.150 raeburn 17265: sub count_servers {
17266: my ($currbalancer,%servers) = @_;
17267: my (@spares,$numspares);
17268: foreach my $lonhost (sort(keys(%servers))) {
17269: next if ($currbalancer eq $lonhost);
17270: push(@spares,$lonhost);
17271: }
17272: if ($currbalancer) {
17273: $numspares = scalar(@spares);
17274: } else {
17275: $numspares = scalar(@spares) - 1;
17276: }
17277: return ($numspares,@spares);
17278: }
17279:
17280: sub lonbalance_targets_js {
1.160.6.7 raeburn 17281: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 17282: my $select = &mt('Select');
17283: my ($alltargets,$allishome,$allinsttypes,@alltypes);
17284: if (ref($servers) eq 'HASH') {
17285: $alltargets = join("','",sort(keys(%{$servers})));
17286: my @homedoms;
17287: foreach my $server (sort(keys(%{$servers}))) {
17288: if (&Apache::lonnet::host_domain($server) eq $dom) {
17289: push(@homedoms,'1');
17290: } else {
17291: push(@homedoms,'0');
17292: }
17293: }
17294: $allishome = join("','",@homedoms);
17295: }
17296: if (ref($types) eq 'ARRAY') {
17297: if (@{$types} > 0) {
17298: @alltypes = @{$types};
17299: }
17300: }
17301: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
17302: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 17303: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 17304: if (ref($settings) eq 'HASH') {
17305: %existing = %{$settings};
17306: }
17307: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 17308: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 17309: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 17310: return <<"END";
17311:
17312: <script type="text/javascript">
17313: // <![CDATA[
17314:
1.160.6.7 raeburn 17315: currBalancers = new Array('$balancers');
17316:
17317: function toggleTargets(balnum) {
17318: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17319: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
17320: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
17321: var prevbalancer = prevhostitem.value;
17322: var baltotal = document.getElementById('loadbalancing_total').value;
17323: prevhostitem.value = balancer;
17324: if (prevbalancer != '') {
17325: var prevIdx = currBalancers.indexOf(prevbalancer);
17326: if (prevIdx != -1) {
17327: currBalancers.splice(prevIdx,1);
17328: }
17329: }
1.150 raeburn 17330: if (balancer == '') {
1.160.6.7 raeburn 17331: hideSpares(balnum);
1.150 raeburn 17332: } else {
1.160.6.7 raeburn 17333: var currIdx = currBalancers.indexOf(balancer);
17334: if (currIdx == -1) {
17335: currBalancers.push(balancer);
17336: }
1.150 raeburn 17337: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 17338: var ishomedom = homedoms[lonhostitem.selectedIndex];
17339: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 17340: }
1.160.6.7 raeburn 17341: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 17342: return;
17343: }
17344:
1.160.6.7 raeburn 17345: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 17346: var alltargets = new Array('$alltargets');
17347: var insttypes = new Array('$allinsttypes');
1.151 raeburn 17348: var offloadtypes = new Array('primary','default');
17349:
1.160.6.7 raeburn 17350: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
17351: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 17352:
1.151 raeburn 17353: for (var i=0; i<offloadtypes.length; i++) {
17354: var count = 0;
17355: for (var j=0; j<alltargets.length; j++) {
17356: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 17357: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
17358: item.value = alltargets[j];
17359: item.style.textAlign='left';
17360: item.style.textFace='normal';
17361: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
17362: if (currBalancers.indexOf(alltargets[j]) == -1) {
17363: item.disabled = '';
17364: } else {
17365: item.disabled = 'disabled';
17366: item.checked = false;
17367: }
1.151 raeburn 17368: count ++;
17369: }
1.150 raeburn 17370: }
17371: }
1.151 raeburn 17372: for (var k=0; k<insttypes.length; k++) {
17373: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 17374: if (ishomedom == 1) {
1.160.6.7 raeburn 17375: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17376: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17377: } else {
1.160.6.7 raeburn 17378: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17379: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 17380: }
17381: } else {
1.160.6.7 raeburn 17382: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17383: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17384: }
1.151 raeburn 17385: if ((insttypes[k] != '_LC_external') &&
17386: ((insttypes[k] != '_LC_internetdom') ||
17387: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 17388: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
17389: item.options.length = 0;
17390: item.options[0] = new Option("","",true,true);
17391: var idx = 0;
1.151 raeburn 17392: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 17393: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
17394: idx ++;
17395: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 17396: }
17397: }
17398: }
17399: }
17400: return;
17401: }
17402:
1.160.6.7 raeburn 17403: function hideSpares(balnum) {
1.150 raeburn 17404: var alltargets = new Array('$alltargets');
17405: var insttypes = new Array('$allinsttypes');
17406: var offloadtypes = new Array('primary','default');
17407:
1.160.6.7 raeburn 17408: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
17409: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 17410:
17411: var total = alltargets.length - 1;
17412: for (var i=0; i<offloadtypes; i++) {
17413: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 17414: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
17415: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
17416: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 17417: }
1.150 raeburn 17418: }
17419: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 17420: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17421: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 17422: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 17423: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
17424: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 17425: }
17426: }
17427: return;
17428: }
17429:
1.160.6.7 raeburn 17430: function checkOffloads(item,balnum,type) {
1.150 raeburn 17431: var alltargets = new Array('$alltargets');
17432: var offloadtypes = new Array('primary','default');
17433: if (item.checked) {
17434: var total = alltargets.length - 1;
17435: var other;
17436: if (type == offloadtypes[0]) {
1.151 raeburn 17437: other = offloadtypes[1];
1.150 raeburn 17438: } else {
1.151 raeburn 17439: other = offloadtypes[0];
1.150 raeburn 17440: }
17441: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 17442: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 17443: if (server == item.value) {
1.160.6.7 raeburn 17444: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
17445: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 17446: }
17447: }
17448: }
17449: }
17450: return;
17451: }
17452:
1.160.6.7 raeburn 17453: function singleServerToggle(balnum,type) {
17454: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 17455: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 17456: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
17457: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17458:
17459: } else {
1.160.6.7 raeburn 17460: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
17461: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 17462: }
17463: return;
17464: }
17465:
1.160.6.7 raeburn 17466: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 17467: if (type == '_LC_external') {
1.160.6.26 raeburn 17468: return;
1.150 raeburn 17469: }
1.160.6.7 raeburn 17470: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 17471: for (var i=0; i<typesRules.length; i++) {
17472: if (formname.elements[typesRules[i]].checked) {
17473: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 17474: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
17475: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17476: } else {
1.160.6.7 raeburn 17477: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
17478: }
17479: }
17480: }
17481: return;
17482: }
17483:
17484: function balancerDeleteChange(balnum) {
17485: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17486: var baltotal = document.getElementById('loadbalancing_total').value;
17487: var addtarget;
17488: var removetarget;
17489: var action = 'delete';
17490: if (document.getElementById('loadbalancing_delete_'+balnum)) {
17491: var lonhost = hostitem.value;
17492: var currIdx = currBalancers.indexOf(lonhost);
17493: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
17494: if (currIdx != -1) {
17495: currBalancers.splice(currIdx,1);
17496: }
17497: addtarget = lonhost;
17498: } else {
17499: if (currIdx == -1) {
17500: currBalancers.push(lonhost);
17501: }
17502: removetarget = lonhost;
17503: action = 'undelete';
17504: }
17505: balancerChange(balnum,baltotal,action,addtarget,removetarget);
17506: }
17507: return;
17508: }
17509:
17510: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
17511: if (baltotal > 1) {
17512: var offloadtypes = new Array('primary','default');
17513: var alltargets = new Array('$alltargets');
17514: var insttypes = new Array('$allinsttypes');
17515: for (var i=0; i<baltotal; i++) {
17516: if (i != balnum) {
17517: for (var j=0; j<offloadtypes.length; j++) {
17518: var total = alltargets.length - 1;
17519: for (var k=0; k<total; k++) {
17520: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
17521: var server = serveritem.value;
17522: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17523: if (server == addtarget) {
17524: serveritem.disabled = '';
17525: }
17526: }
17527: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17528: if (server == removetarget) {
17529: serveritem.disabled = 'disabled';
17530: serveritem.checked = false;
17531: }
17532: }
17533: }
17534: }
17535: for (var j=0; j<insttypes.length; j++) {
17536: if (insttypes[j] != '_LC_external') {
17537: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
17538: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
17539: var currSel = singleserver.selectedIndex;
17540: var currVal = singleserver.options[currSel].value;
17541: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17542: var numoptions = singleserver.options.length;
17543: var needsnew = 1;
17544: for (var k=0; k<numoptions; k++) {
17545: if (singleserver.options[k] == addtarget) {
17546: needsnew = 0;
17547: break;
17548: }
17549: }
17550: if (needsnew == 1) {
17551: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
17552: }
17553: }
17554: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17555: singleserver.options.length = 0;
17556: if ((currVal) && (currVal != removetarget)) {
17557: singleserver.options[0] = new Option("","",false,false);
17558: } else {
17559: singleserver.options[0] = new Option("","",true,true);
17560: }
17561: var idx = 0;
17562: for (var m=0; m<alltargets.length; m++) {
17563: if (currBalancers.indexOf(alltargets[m]) == -1) {
17564: idx ++;
17565: if (currVal == alltargets[m]) {
17566: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
17567: } else {
17568: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
17569: }
17570: }
17571: }
17572: }
17573: }
17574: }
17575: }
1.150 raeburn 17576: }
17577: }
17578: }
17579: return;
17580: }
17581:
1.152 raeburn 17582: // ]]>
17583: </script>
17584:
17585: END
17586: }
17587:
17588: sub new_spares_js {
17589: my @sparestypes = ('primary','default');
17590: my $types = join("','",@sparestypes);
17591: my $select = &mt('Select');
17592: return <<"END";
17593:
17594: <script type="text/javascript">
17595: // <![CDATA[
17596:
17597: function updateNewSpares(formname,lonhost) {
17598: var types = new Array('$types');
17599: var include = new Array();
17600: var exclude = new Array();
17601: for (var i=0; i<types.length; i++) {
17602: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
17603: for (var j=0; j<spareboxes.length; j++) {
17604: if (formname.elements[spareboxes[j]].checked) {
17605: exclude.push(formname.elements[spareboxes[j]].value);
17606: } else {
17607: include.push(formname.elements[spareboxes[j]].value);
17608: }
17609: }
17610: }
17611: for (var i=0; i<types.length; i++) {
17612: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
17613: var selIdx = newSpare.selectedIndex;
17614: var currnew = newSpare.options[selIdx].value;
17615: var okSpares = new Array();
17616: for (var j=0; j<newSpare.options.length; j++) {
17617: var possible = newSpare.options[j].value;
17618: if (possible != '') {
17619: if (exclude.indexOf(possible) == -1) {
17620: okSpares.push(possible);
17621: } else {
17622: if (currnew == possible) {
17623: selIdx = 0;
17624: }
17625: }
17626: }
17627: }
17628: for (var k=0; k<include.length; k++) {
17629: if (okSpares.indexOf(include[k]) == -1) {
17630: okSpares.push(include[k]);
17631: }
17632: }
17633: okSpares.sort();
17634: newSpare.options.length = 0;
17635: if (selIdx == 0) {
17636: newSpare.options[0] = new Option("$select","",true,true);
17637: } else {
17638: newSpare.options[0] = new Option("$select","",false,false);
17639: }
17640: for (var m=0; m<okSpares.length; m++) {
17641: var idx = m+1;
17642: var selThis = 0;
17643: if (selIdx != 0) {
17644: if (okSpares[m] == currnew) {
17645: selThis = 1;
17646: }
17647: }
17648: if (selThis == 1) {
17649: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
17650: } else {
17651: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
17652: }
17653: }
17654: }
17655: return;
17656: }
17657:
17658: function checkNewSpares(lonhost,type) {
17659: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
17660: var chosen = newSpare.options[newSpare.selectedIndex].value;
17661: if (chosen != '') {
17662: var othertype;
17663: var othernewSpare;
17664: if (type == 'primary') {
17665: othernewSpare = document.getElementById('newspare_default_'+lonhost);
17666: }
17667: if (type == 'default') {
17668: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
17669: }
17670: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
17671: othernewSpare.selectedIndex = 0;
17672: }
17673: }
17674: return;
17675: }
17676:
17677: // ]]>
17678: </script>
17679:
17680: END
17681:
17682: }
17683:
17684: sub common_domprefs_js {
17685: return <<"END";
17686:
17687: <script type="text/javascript">
17688: // <![CDATA[
17689:
1.150 raeburn 17690: function getIndicesByName(formname,item) {
1.152 raeburn 17691: var group = new Array();
1.150 raeburn 17692: for (var i=0;i<formname.elements.length;i++) {
17693: if (formname.elements[i].name == item) {
1.152 raeburn 17694: group.push(formname.elements[i].id);
1.150 raeburn 17695: }
17696: }
1.152 raeburn 17697: return group;
1.150 raeburn 17698: }
17699:
17700: // ]]>
17701: </script>
17702:
17703: END
1.152 raeburn 17704:
1.150 raeburn 17705: }
17706:
1.160.6.5 raeburn 17707: sub recaptcha_js {
17708: my %lt = &captcha_phrases();
17709: return <<"END";
17710:
17711: <script type="text/javascript">
17712: // <![CDATA[
17713:
17714: function updateCaptcha(caller,context) {
17715: var privitem;
17716: var pubitem;
17717: var privtext;
17718: var pubtext;
1.160.6.69 raeburn 17719: var versionitem;
17720: var versiontext;
1.160.6.5 raeburn 17721: if (document.getElementById(context+'_recaptchapub')) {
17722: pubitem = document.getElementById(context+'_recaptchapub');
17723: } else {
17724: return;
17725: }
17726: if (document.getElementById(context+'_recaptchapriv')) {
17727: privitem = document.getElementById(context+'_recaptchapriv');
17728: } else {
17729: return;
17730: }
17731: if (document.getElementById(context+'_recaptchapubtxt')) {
17732: pubtext = document.getElementById(context+'_recaptchapubtxt');
17733: } else {
17734: return;
17735: }
17736: if (document.getElementById(context+'_recaptchaprivtxt')) {
17737: privtext = document.getElementById(context+'_recaptchaprivtxt');
17738: } else {
17739: return;
17740: }
1.160.6.69 raeburn 17741: if (document.getElementById(context+'_recaptchaversion')) {
17742: versionitem = document.getElementById(context+'_recaptchaversion');
17743: } else {
17744: return;
17745: }
17746: if (document.getElementById(context+'_recaptchavertxt')) {
17747: versiontext = document.getElementById(context+'_recaptchavertxt');
17748: } else {
17749: return;
17750: }
1.160.6.5 raeburn 17751: if (caller.checked) {
17752: if (caller.value == 'recaptcha') {
17753: pubitem.type = 'text';
17754: privitem.type = 'text';
17755: pubitem.size = '40';
17756: privitem.size = '40';
17757: pubtext.innerHTML = "$lt{'pub'}";
17758: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 17759: versionitem.type = 'text';
17760: versionitem.size = '3';
17761: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 17762: } else {
17763: pubitem.type = 'hidden';
17764: privitem.type = 'hidden';
1.160.6.69 raeburn 17765: versionitem.type = 'hidden';
1.160.6.5 raeburn 17766: pubtext.innerHTML = '';
17767: privtext.innerHTML = '';
1.160.6.69 raeburn 17768: versiontext.innerHTML = '';
1.160.6.5 raeburn 17769: }
17770: }
17771: return;
17772: }
17773:
17774: // ]]>
17775: </script>
17776:
17777: END
17778:
17779: }
17780:
1.160.6.40 raeburn 17781: sub toggle_display_js {
1.160.6.16 raeburn 17782: return <<"END";
17783:
17784: <script type="text/javascript">
17785: // <![CDATA[
17786:
1.160.6.40 raeburn 17787: function toggleDisplay(domForm,caller) {
17788: if (document.getElementById(caller)) {
17789: var divitem = document.getElementById(caller);
17790: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 17791: var checkval = 1;
17792: var dispval = 'block';
1.160.6.93 raeburn 17793: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 17794: if (caller == 'emailoptions') {
17795: optionsElement = domForm.cancreate_email;
17796: }
1.160.6.57 raeburn 17797: if (caller == 'studentsubmission') {
17798: optionsElement = domForm.postsubmit;
17799: }
1.160.6.64 raeburn 17800: if (caller == 'cloneinstcode') {
17801: optionsElement = domForm.canclone;
17802: checkval = 'instcode';
17803: }
1.160.6.93 raeburn 17804: if (selfcreateRegExp.test(caller)) {
17805: optionsElement = domForm.elements[caller];
17806: checkval = 'other';
17807: dispval = 'inline'
17808: }
1.160.6.40 raeburn 17809: if (optionsElement.length) {
1.160.6.16 raeburn 17810: var currval;
1.160.6.40 raeburn 17811: for (var i=0; i<optionsElement.length; i++) {
17812: if (optionsElement[i].checked) {
17813: currval = optionsElement[i].value;
1.160.6.16 raeburn 17814: }
17815: }
1.160.6.64 raeburn 17816: if (currval == checkval) {
17817: divitem.style.display = dispval;
1.160.6.16 raeburn 17818: } else {
1.160.6.40 raeburn 17819: divitem.style.display = 'none';
1.160.6.16 raeburn 17820: }
17821: }
17822: }
17823: return;
17824: }
17825:
17826: // ]]>
17827: </script>
17828:
17829: END
17830:
17831: }
17832:
1.160.6.5 raeburn 17833: sub captcha_phrases {
17834: return &Apache::lonlocal::texthash (
17835: priv => 'Private key',
17836: pub => 'Public key',
17837: original => 'original (CAPTCHA)',
17838: recaptcha => 'successor (ReCAPTCHA)',
17839: notused => 'unused',
1.160.6.69 raeburn 17840: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 17841: );
17842: }
17843:
1.160.6.24 raeburn 17844: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 17845: my ($dom,$cachekeys) = @_;
17846: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 17847: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17848: my %thismachine;
17849: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.98 raeburn 17850: my @posscached = ('domainconfig','domdefaults','usersessions',
1.160.6.113! raeburn 17851: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
! 17852: 'ipaccess');
! 17853: my %cache_by_lonhost;
! 17854: if (exists($cachekeys->{'samllanding'})) {
! 17855: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
! 17856: my %landing = %{$cachekeys->{'samllanding'}};
! 17857: my %domservers = &Apache::lonnet::get_servers($dom);
! 17858: if (keys(%domservers)) {
! 17859: foreach my $server (keys(%domservers)) {
! 17860: my @cached;
! 17861: next if ($thismachine{$server});
! 17862: if ($landing{$server}) {
! 17863: push(@cached,&escape('samllanding').':'.&escape($server));
! 17864: }
! 17865: if (@cached) {
! 17866: $cache_by_lonhost{$server} = \@cached;
! 17867: }
! 17868: }
! 17869: }
! 17870: }
! 17871: }
1.160.6.61 raeburn 17872: if (keys(%servers)) {
1.160.6.24 raeburn 17873: foreach my $server (keys(%servers)) {
17874: next if ($thismachine{$server});
1.160.6.27 raeburn 17875: my @cached;
17876: foreach my $name (@posscached) {
17877: if ($cachekeys->{$name}) {
1.160.6.113! raeburn 17878: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
! 17879: if (ref($cachekeys->{$name}) eq 'HASH') {
! 17880: foreach my $key (keys(%{$cachekeys->{$name}})) {
! 17881: push(@cached,&escape($name).':'.&escape($key));
! 17882: }
! 17883: }
! 17884: } else {
! 17885: push(@cached,&escape($name).':'.&escape($dom));
! 17886: }
1.160.6.27 raeburn 17887: }
17888: }
1.160.6.113! raeburn 17889: if ((exists($cache_by_lonhost{$server})) &&
! 17890: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
! 17891: push(@cached,@{$cache_by_lonhost{$server}});
! 17892: }
1.160.6.27 raeburn 17893: if (@cached) {
17894: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
17895: }
1.160.6.24 raeburn 17896: }
17897: }
17898: return;
17899: }
17900:
1.3 raeburn 17901: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>