Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.101
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.101! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.100 2019/08/27 18:37:01 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.1 raeburn 177:
1.155 raeburn 178: my $registered_cleanup;
179: my $modified_urls;
180:
1.1 raeburn 181: sub handler {
182: my $r=shift;
183: if ($r->header_only) {
184: &Apache::loncommon::content_type($r,'text/html');
185: $r->send_http_header;
186: return OK;
187: }
188:
1.91 raeburn 189: my $context = 'domain';
1.1 raeburn 190: my $dom = $env{'request.role.domain'};
1.5 albertel 191: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 192: if (&Apache::lonnet::allowed('mau',$dom)) {
193: &Apache::loncommon::content_type($r,'text/html');
194: $r->send_http_header;
195: } else {
196: $env{'user.error.msg'}=
197: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
198: return HTTP_NOT_ACCEPTABLE;
199: }
1.155 raeburn 200:
201: $registered_cleanup=0;
202: @{$modified_urls}=();
203:
1.1 raeburn 204: &Apache::lonhtmlcommon::clear_breadcrumbs();
205: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 206: ['phase','actions']);
1.30 raeburn 207: my $phase = 'pickactions';
1.3 raeburn 208: if ( exists($env{'form.phase'}) ) {
209: $phase = $env{'form.phase'};
210: }
1.150 raeburn 211: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 212: my %domconfig =
1.6 raeburn 213: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 214: 'quotas','autoenroll','autoupdate','autocreate',
215: 'directorysrch','usercreation','usermodification',
216: 'contacts','defaults','scantron','coursecategories',
1.160.6.73 raeburn 217: 'serverstatuses','requestcourses','helpsettings',
218: 'coursedefaults','usersessions','loadbalancing',
1.160.6.98 raeburn 219: 'requestauthor','selfenrollment','inststatus','passwords'],$dom);
220: my @prefs_order = ('rolecolors','login','defaults','passwords','quotas','autoenroll',
1.125 raeburn 221: 'autoupdate','autocreate','directorysrch','contacts',
1.160.6.34 raeburn 222: 'usercreation','selfcreation','usermodification','scantron',
1.160.6.5 raeburn 223: 'requestcourses','requestauthor','coursecategories',
1.160.6.73 raeburn 224: 'serverstatuses','helpsettings','coursedefaults',
225: 'selfenrollment','usersessions');
1.160.6.7 raeburn 226: my %existing;
227: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
228: %existing = %{$domconfig{'loadbalancing'}};
229: }
230: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 231: push(@prefs_order,'loadbalancing');
232: }
1.30 raeburn 233: my %prefs = (
234: 'rolecolors' =>
235: { text => 'Default color schemes',
1.67 raeburn 236: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 237: header => [{col1 => 'Student Settings',
238: col2 => '',},
239: {col1 => 'Coordinator Settings',
240: col2 => '',},
241: {col1 => 'Author Settings',
242: col2 => '',},
243: {col1 => 'Administrator Settings',
244: col2 => '',}],
1.160.6.37 raeburn 245: print => \&print_rolecolors,
246: modify => \&modify_rolecolors,
1.30 raeburn 247: },
1.110 raeburn 248: 'login' =>
1.30 raeburn 249: { text => 'Log-in page options',
1.67 raeburn 250: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 251: header => [{col1 => 'Log-in Page Items',
252: col2 => '',},
253: {col1 => 'Log-in Help',
1.160.6.56 raeburn 254: col2 => 'Value'},
255: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 256: col2 => 'Value'}],
1.160.6.37 raeburn 257: print => \&print_login,
258: modify => \&modify_login,
1.30 raeburn 259: },
1.43 raeburn 260: 'defaults' =>
1.160.6.40 raeburn 261: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 262: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 263: header => [{col1 => 'Setting',
1.160.6.40 raeburn 264: col2 => 'Value'},
265: {col1 => 'Institutional user types',
1.160.6.93 raeburn 266: col2 => 'Name displayed'}],
1.160.6.37 raeburn 267: print => \&print_defaults,
268: modify => \&modify_defaults,
1.43 raeburn 269: },
1.160.6.98 raeburn 270: 'passwords' =>
271: { text => 'Passwords (Internal authentication)',
272: help => 'Domain_Configuration_Passwords',
273: header => [{col1 => 'Resetting Forgotten Password',
274: col2 => 'Settings'},
275: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
276: col2 => 'Settings'},
277: {col1 => 'Rules for LON-CAPA Passwords',
278: col2 => 'Settings'},
279: {col1 => 'Course Owner Changing Student Passwords',
280: col2 => 'Settings'}],
281: print => \&print_passwords,
282: modify => \&modify_passwords,
283: },
1.30 raeburn 284: 'quotas' =>
1.160.6.20 raeburn 285: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 286: help => 'Domain_Configuration_Quotas',
1.77 raeburn 287: header => [{col1 => 'User affiliation',
1.72 raeburn 288: col2 => 'Available tools',
1.160.6.28 raeburn 289: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 290: print => \&print_quotas,
291: modify => \&modify_quotas,
1.30 raeburn 292: },
293: 'autoenroll' =>
294: { text => 'Auto-enrollment settings',
1.67 raeburn 295: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 296: header => [{col1 => 'Configuration setting',
297: col2 => 'Value(s)'}],
1.160.6.37 raeburn 298: print => \&print_autoenroll,
299: modify => \&modify_autoenroll,
1.30 raeburn 300: },
301: 'autoupdate' =>
302: { text => 'Auto-update settings',
1.67 raeburn 303: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 304: header => [{col1 => 'Setting',
305: col2 => 'Value',},
1.131 raeburn 306: {col1 => 'Setting',
307: col2 => 'Affiliation'},
1.43 raeburn 308: {col1 => 'User population',
1.160.6.35 raeburn 309: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 310: print => \&print_autoupdate,
311: modify => \&modify_autoupdate,
1.30 raeburn 312: },
1.125 raeburn 313: 'autocreate' =>
314: { text => 'Auto-course creation settings',
315: help => 'Domain_Configuration_Auto_Creation',
316: header => [{col1 => 'Configuration Setting',
317: col2 => 'Value',}],
1.160.6.37 raeburn 318: print => \&print_autocreate,
319: modify => \&modify_autocreate,
1.125 raeburn 320: },
1.30 raeburn 321: 'directorysrch' =>
1.160.6.72 raeburn 322: { text => 'Directory searches',
1.67 raeburn 323: help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72 raeburn 324: header => [{col1 => 'Institutional Directory Setting',
325: col2 => 'Value',},
326: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 327: col2 => 'Value',}],
1.160.6.37 raeburn 328: print => \&print_directorysrch,
329: modify => \&modify_directorysrch,
1.30 raeburn 330: },
331: 'contacts' =>
1.160.6.78 raeburn 332: { text => 'E-mail addresses and helpform',
1.67 raeburn 333: help => 'Domain_Configuration_Contact_Info',
1.160.6.78 raeburn 334: header => [{col1 => 'Default e-mail addresses',
335: col2 => 'Value',},
336: {col1 => 'Recipient(s) for notifications',
337: col2 => 'Value',},
338: {col1 => 'Ask helpdesk form settings',
339: col2 => 'Value',},],
1.160.6.37 raeburn 340: print => \&print_contacts,
341: modify => \&modify_contacts,
1.30 raeburn 342: },
343: 'usercreation' =>
344: { text => 'User creation',
1.67 raeburn 345: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 346: header => [{col1 => 'Format rule type',
347: col2 => 'Format rules in force'},
1.34 raeburn 348: {col1 => 'User account creation',
349: col2 => 'Usernames which may be created',},
1.30 raeburn 350: {col1 => 'Context',
1.43 raeburn 351: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 352: print => \&print_usercreation,
353: modify => \&modify_usercreation,
1.30 raeburn 354: },
1.160.6.34 raeburn 355: 'selfcreation' =>
356: { text => 'Users self-creating accounts',
357: help => 'Domain_Configuration_Self_Creation',
358: header => [{col1 => 'Self-creation with institutional username',
359: col2 => 'Enabled?'},
360: {col1 => 'Institutional user type (login/SSO self-creation)',
361: col2 => 'Information user can enter'},
1.160.6.93 raeburn 362: {col1 => 'Self-creation with e-mail verification',
1.160.6.34 raeburn 363: col2 => 'Settings'}],
1.160.6.37 raeburn 364: print => \&print_selfcreation,
365: modify => \&modify_selfcreation,
1.160.6.34 raeburn 366: },
1.69 raeburn 367: 'usermodification' =>
1.33 raeburn 368: { text => 'User modification',
1.67 raeburn 369: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 370: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 371: col2 => 'User information updatable in author context'},
1.33 raeburn 372: {col1 => 'Target user has role',
1.160.6.35 raeburn 373: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 374: print => \&print_usermodification,
375: modify => \&modify_usermodification,
1.33 raeburn 376: },
1.69 raeburn 377: 'scantron' =>
1.160.6.97 raeburn 378: { text => 'Bubblesheet format',
1.67 raeburn 379: help => 'Domain_Configuration_Scantron_Format',
1.160.6.97 raeburn 380: header => [ {col1 => 'Bubblesheet format file',
381: col2 => ''},
382: {col1 => 'Bubblesheet data upload formats',
383: col2 => 'Settings'}],
1.160.6.37 raeburn 384: print => \&print_scantron,
385: modify => \&modify_scantron,
1.46 raeburn 386: },
1.86 raeburn 387: 'requestcourses' =>
388: {text => 'Request creation of courses',
389: help => 'Domain_Configuration_Request_Courses',
390: header => [{col1 => 'User affiliation',
1.102 raeburn 391: col2 => 'Availability/Processing of requests',},
392: {col1 => 'Setting',
1.160.6.30 raeburn 393: col2 => 'Value'},
394: {col1 => 'Available textbooks',
1.160.6.39 raeburn 395: col2 => ''},
1.160.6.46 raeburn 396: {col1 => 'Available templates',
397: col2 => ''},
1.160.6.39 raeburn 398: {col1 => 'Validation (not official courses)',
399: col2 => 'Value'},],
1.160.6.37 raeburn 400: print => \&print_quotas,
401: modify => \&modify_quotas,
1.86 raeburn 402: },
1.160.6.5 raeburn 403: 'requestauthor' =>
1.160.6.34 raeburn 404: {text => 'Request Authoring Space',
1.160.6.5 raeburn 405: help => 'Domain_Configuration_Request_Author',
406: header => [{col1 => 'User affiliation',
407: col2 => 'Availability/Processing of requests',},
408: {col1 => 'Setting',
409: col2 => 'Value'}],
1.160.6.37 raeburn 410: print => \&print_quotas,
411: modify => \&modify_quotas,
1.160.6.5 raeburn 412: },
1.69 raeburn 413: 'coursecategories' =>
1.120 raeburn 414: { text => 'Cataloging of courses/communities',
1.67 raeburn 415: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 416: header => [{col1 => 'Catalog type/availability',
417: col2 => '',},
418: {col1 => 'Category settings for standard catalog',
1.57 raeburn 419: col2 => '',},
420: {col1 => 'Categories',
421: col2 => '',
422: }],
1.160.6.37 raeburn 423: print => \&print_coursecategories,
424: modify => \&modify_coursecategories,
1.69 raeburn 425: },
426: 'serverstatuses' =>
1.77 raeburn 427: {text => 'Access to server status pages',
1.69 raeburn 428: help => 'Domain_Configuration_Server_Status',
429: header => [{col1 => 'Status Page',
430: col2 => 'Other named users',
431: col3 => 'Specific IPs',
432: }],
1.160.6.37 raeburn 433: print => \&print_serverstatuses,
434: modify => \&modify_serverstatuses,
1.69 raeburn 435: },
1.160.6.73 raeburn 436: 'helpsettings' =>
437: {text => 'Support settings',
438: help => 'Domain_Configuration_Help_Settings',
439: header => [{col1 => 'Help Page Settings (logged-in users)',
440: col2 => 'Value'},
441: {col1 => 'Helpdesk Roles',
442: col2 => 'Settings'},],
443: print => \&print_helpsettings,
444: modify => \&modify_helpsettings,
445: },
1.160.6.39 raeburn 446: 'coursedefaults' =>
1.160.6.16 raeburn 447: {text => 'Course/Community defaults',
448: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 449: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
450: col2 => 'Value',},
451: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 452: col2 => 'Value',},],
1.160.6.37 raeburn 453: print => \&print_coursedefaults,
454: modify => \&modify_coursedefaults,
455: },
1.160.6.39 raeburn 456: 'selfenrollment' =>
1.160.6.37 raeburn 457: {text => 'Self-enrollment in Course/Community',
458: help => 'Domain_Configuration_Selfenrollment',
459: header => [{col1 => 'Configuration Rights',
460: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
461: {col1 => 'Defaults',
462: col2 => 'Value'},
463: {col1 => 'Self-enrollment validation (optional)',
464: col2 => 'Value'},],
465: print => \&print_selfenrollment,
466: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 467: },
1.141 raeburn 468: 'usersessions' =>
1.145 raeburn 469: {text => 'User session hosting/offloading',
1.137 raeburn 470: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 471: header => [{col1 => 'Domain server',
472: col2 => 'Servers to offload sessions to when busy'},
473: {col1 => 'Hosting of users from other domains',
1.137 raeburn 474: col2 => 'Rules'},
475: {col1 => "Hosting domain's own users elsewhere",
476: col2 => 'Rules'}],
1.160.6.37 raeburn 477: print => \&print_usersessions,
478: modify => \&modify_usersessions,
1.137 raeburn 479: },
1.160.6.78 raeburn 480: 'loadbalancing' =>
1.160.6.7 raeburn 481: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 482: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 483: header => [{col1 => 'Balancers',
1.150 raeburn 484: col2 => 'Default destinations',
1.160.6.13 raeburn 485: col3 => 'User affiliation',
1.150 raeburn 486: col4 => 'Overrides'},
487: ],
1.160.6.37 raeburn 488: print => \&print_loadbalancing,
489: modify => \&modify_loadbalancing,
1.150 raeburn 490: },
1.3 raeburn 491: );
1.110 raeburn 492: if (keys(%servers) > 1) {
493: $prefs{'login'} = { text => 'Log-in page options',
494: help => 'Domain_Configuration_Login_Page',
495: header => [{col1 => 'Log-in Service',
496: col2 => 'Server Setting',},
497: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 498: col2 => ''},
499: {col1 => 'Log-in Help',
1.160.6.56 raeburn 500: col2 => 'Value'},
501: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 502: col2 => 'Value'}],
1.160.6.37 raeburn 503: print => \&print_login,
504: modify => \&modify_login,
1.110 raeburn 505: };
506: }
1.160.6.13 raeburn 507:
1.6 raeburn 508: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 509: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 510: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 511: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 512: text=>"Settings to display/modify"});
1.9 raeburn 513: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 514:
1.3 raeburn 515: if ($phase eq 'process') {
1.160.6.27 raeburn 516: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
517: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 518: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 519: $r->rflush();
1.160.6.27 raeburn 520: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 521: }
1.30 raeburn 522: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 523: my $js = &recaptcha_js().
1.160.6.40 raeburn 524: &toggle_display_js();
1.160.6.7 raeburn 525: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 526: my ($othertitle,$usertypes,$types) =
527: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 528: $js .= &lonbalance_targets_js($dom,$types,\%servers,
529: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 530: &new_spares_js().
531: &common_domprefs_js().
532: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 533: }
1.160.6.30 raeburn 534: if (grep(/^requestcourses$/,@actions)) {
535: my $javascript_validations;
536: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
537: $js .= <<END;
538: <script type="text/javascript">
539: $javascript_validations
540: </script>
541: $coursebrowserjs
542: END
543: }
1.160.6.93 raeburn 544: if (grep(/^selfcreation$/,@actions)) {
545: $js .= &selfcreate_javascript();
546: }
1.160.6.78 raeburn 547: if (grep(/^contacts$/,@actions)) {
548: $js .= &contacts_javascript();
549: }
1.160.6.97 raeburn 550: if (grep(/^scantron$/,@actions)) {
551: $js .= &scantron_javascript();
552: }
1.150 raeburn 553: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 554: } else {
1.160.6.11 raeburn 555: # check if domconfig user exists for the domain.
556: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 557: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 558: &config_check($dom,$confname,$servadm);
559: unless ($configuserok eq 'ok') {
560: &Apache::lonconfigsettings::print_header($r,$phase,$context);
561: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
562: $confname).
563: '<br />'
564: );
565: if ($switchserver) {
566: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
567: '<br />'.
568: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
569: '<br />'.
570: &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).
571: '<br />'.
572: &mt('To do that now, use the following link: [_1]',$switchserver)
573: );
574: } else {
575: $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.').
576: '<br />'.
577: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
578: );
579: }
580: $r->print(&Apache::loncommon::end_page());
581: return OK;
582: }
1.21 raeburn 583: if (keys(%domconfig) == 0) {
584: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 585: my @ids=&Apache::lonnet::current_machine_ids();
586: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 587: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 588: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 589: my $custom_img_count = 0;
590: foreach my $img (@loginimages) {
591: if ($designhash{$dom.'.login.'.$img} ne '') {
592: $custom_img_count ++;
593: }
594: }
595: foreach my $role (@roles) {
596: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
597: $custom_img_count ++;
598: }
599: }
600: if ($custom_img_count > 0) {
1.94 raeburn 601: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 602: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 603: $r->print(
604: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
605: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
606: &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 />'.
607: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
608: if ($switch_server) {
1.30 raeburn 609: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 610: }
1.91 raeburn 611: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 612: return OK;
613: }
614: }
615: }
1.91 raeburn 616: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 617: }
618: return OK;
619: }
620:
621: sub process_changes {
1.160.6.24 raeburn 622: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 623: my %domconfig;
624: if (ref($values) eq 'HASH') {
625: %domconfig = %{$values};
626: }
1.3 raeburn 627: my $output;
628: if ($action eq 'login') {
1.160.6.24 raeburn 629: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 630: } elsif ($action eq 'rolecolors') {
1.9 raeburn 631: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 632: $lastactref,%domconfig);
1.3 raeburn 633: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 634: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 635: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 636: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 637: } elsif ($action eq 'autoupdate') {
638: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 639: } elsif ($action eq 'autocreate') {
640: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 641: } elsif ($action eq 'directorysrch') {
1.160.6.81 raeburn 642: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 643: } elsif ($action eq 'usercreation') {
1.28 raeburn 644: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 645: } elsif ($action eq 'selfcreation') {
1.160.6.93 raeburn 646: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 647: } elsif ($action eq 'usermodification') {
648: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 649: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 650: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 651: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 652: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 653: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 654: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 655: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 656: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 657: } elsif ($action eq 'serverstatuses') {
658: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 659: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 660: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 661: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 662: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 663: } elsif ($action eq 'helpsettings') {
1.160.6.77 raeburn 664: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16 raeburn 665: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 666: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 667: } elsif ($action eq 'selfenrollment') {
668: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 669: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 670: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 671: } elsif ($action eq 'loadbalancing') {
672: $output = &modify_loadbalancing($dom,%domconfig);
1.160.6.98 raeburn 673: } elsif ($action eq 'passwords') {
674: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.3 raeburn 675: }
676: return $output;
677: }
678:
679: sub print_config_box {
1.9 raeburn 680: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 681: my $rowtotal = 0;
1.49 raeburn 682: my $output;
683: if ($action eq 'coursecategories') {
684: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 685: } elsif ($action eq 'defaults') {
686: $output = &defaults_javascript($settings);
1.160.6.98 raeburn 687: } elsif ($action eq 'passwords') {
688: $output = &passwords_javascript();
1.160.6.73 raeburn 689: } elsif ($action eq 'helpsettings') {
690: my (%privs,%levelscurrent);
691: my %full=();
692: my %levels=(
693: course => {},
694: domain => {},
695: system => {},
696: );
697: my $context = 'domain';
698: my $crstype = 'Course';
699: my $formname = 'display';
700: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
701: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
702: $output =
703: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
704: \@templateroles);
1.91 raeburn 705: }
1.160.6.40 raeburn 706: $output .=
1.30 raeburn 707: '<table class="LC_nested_outer">
1.3 raeburn 708: <tr>
1.66 raeburn 709: <th align="left" valign="middle"><span class="LC_nobreak">'.
710: &mt($item->{text}).' '.
711: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
712: '</tr>';
1.30 raeburn 713: $rowtotal ++;
1.110 raeburn 714: my $numheaders = 1;
715: if (ref($item->{'header'}) eq 'ARRAY') {
716: $numheaders = scalar(@{$item->{'header'}});
717: }
718: if ($numheaders > 1) {
1.64 raeburn 719: my $colspan = '';
1.145 raeburn 720: my $rightcolspan = '';
1.160.6.42 raeburn 721: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 722: ($action eq 'directorysrch') ||
1.160.6.56 raeburn 723: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 724: $colspan = ' colspan="2"';
725: }
1.145 raeburn 726: if ($action eq 'usersessions') {
727: $rightcolspan = ' colspan="3"';
728: }
1.30 raeburn 729: $output .= '
1.3 raeburn 730: <tr>
731: <td>
732: <table class="LC_nested">
733: <tr class="LC_info_row">
1.59 bisitz 734: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 735: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 736: </tr>';
1.69 raeburn 737: $rowtotal ++;
1.160.6.37 raeburn 738: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 739: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 740: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.78 raeburn 741: ($action eq 'helpsettings') || ($action eq 'contacts')) {
1.160.6.37 raeburn 742: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.160.6.98 raeburn 743: } elsif ($action eq 'passwords') {
744: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 745: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 746: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.160.6.97 raeburn 747: } elsif ($action eq 'scantron') {
748: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 749: } elsif ($action eq 'login') {
1.160.6.56 raeburn 750: if ($numheaders == 4) {
1.160.6.5 raeburn 751: $colspan = ' colspan="2"';
752: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
753: } else {
754: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
755: }
1.160.6.37 raeburn 756: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 757: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 758: } elsif ($action eq 'rolecolors') {
1.30 raeburn 759: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 760: }
1.30 raeburn 761: $output .= '
1.6 raeburn 762: </table>
763: </td>
764: </tr>
765: <tr>
766: <td>
767: <table class="LC_nested">
768: <tr class="LC_info_row">
1.160.6.37 raeburn 769: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 770: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 771: </tr>';
772: $rowtotal ++;
1.160.6.37 raeburn 773: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
774: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 775: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.98 raeburn 776: ($action eq 'contacts') || ($action eq 'passwords')) {
1.160.6.42 raeburn 777: if ($action eq 'coursecategories') {
778: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
779: $colspan = ' colspan="2"';
1.160.6.98 raeburn 780: } elsif ($action eq 'passwords') {
781: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.160.6.42 raeburn 782: } else {
783: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
784: }
785: $output .= '
1.63 raeburn 786: </table>
787: </td>
788: </tr>
789: <tr>
790: <td>
791: <table class="LC_nested">
792: <tr class="LC_info_row">
793: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 794: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 795: </tr>'."\n";
796: if ($action eq 'coursecategories') {
797: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.160.6.98 raeburn 798: } elsif ($action eq 'passwords') {
799: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal).'
800: </tr>
801: </table>
802: </td>
803: </tr>
804: <tr>
805: <td>
806: <table class="LC_nested">
807: <tr class="LC_info_row">
808: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
809: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n".
810: $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal).'
811: </table>
812: </td>
813: </tr>
814: <tr>';
1.160.6.42 raeburn 815: } else {
816: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
817: }
1.63 raeburn 818: $rowtotal ++;
1.160.6.57 raeburn 819: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 820: ($action eq 'defaults') || ($action eq 'directorysrch') ||
821: ($action eq 'helpsettings')) {
1.160.6.37 raeburn 822: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.160.6.97 raeburn 823: } elsif ($action eq 'scantron') {
824: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 825: } elsif ($action eq 'login') {
1.160.6.56 raeburn 826: if ($numheaders == 4) {
1.160.6.5 raeburn 827: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
828: </table>
829: </td>
830: </tr>
831: <tr>
832: <td>
833: <table class="LC_nested">
834: <tr class="LC_info_row">
835: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 836: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 837: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
838: $rowtotal ++;
839: } else {
840: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
841: }
1.160.6.56 raeburn 842: $output .= '
843: </table>
844: </td>
845: </tr>
846: <tr>
847: <td>
848: <table class="LC_nested">
849: <tr class="LC_info_row">';
850: if ($numheaders == 4) {
851: $output .= '
852: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
853: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
854: </tr>';
855: } else {
856: $output .= '
857: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
858: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
859: </tr>';
860: }
861: $rowtotal ++;
862: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 863: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 864: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
865: $rowtotal ++;
866: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 867: </table>
868: </td>
869: </tr>
870: <tr>
871: <td>
872: <table class="LC_nested">
873: <tr class="LC_info_row">
874: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
875: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 876: &textbookcourses_javascript($settings).
877: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
878: </table>
879: </td>
880: </tr>
881: <tr>
882: <td>
883: <table class="LC_nested">
884: <tr class="LC_info_row">
885: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
886: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
887: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 888: </table>
889: </td>
890: </tr>
891: <tr>
892: <td>
893: <table class="LC_nested">
894: <tr class="LC_info_row">
1.160.6.46 raeburn 895: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
896: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 897: </tr>'.
898: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 899: } elsif ($action eq 'requestauthor') {
900: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 901: $rowtotal ++;
1.122 jms 902: } elsif ($action eq 'rolecolors') {
1.30 raeburn 903: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 904: </table>
905: </td>
906: </tr>
907: <tr>
908: <td>
909: <table class="LC_nested">
910: <tr class="LC_info_row">
1.69 raeburn 911: <td class="LC_left_item"'.$colspan.' valign="top">'.
912: &mt($item->{'header'}->[2]->{'col1'}).'</td>
913: <td class="LC_right_item" valign="top">'.
914: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 915: </tr>'.
1.30 raeburn 916: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 917: </table>
918: </td>
919: </tr>
920: <tr>
921: <td>
922: <table class="LC_nested">
923: <tr class="LC_info_row">
1.59 bisitz 924: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
925: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 926: </tr>'.
1.30 raeburn 927: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
928: $rowtotal += 2;
1.6 raeburn 929: }
1.3 raeburn 930: } else {
1.30 raeburn 931: $output .= '
1.3 raeburn 932: <tr>
933: <td>
934: <table class="LC_nested">
1.30 raeburn 935: <tr class="LC_info_row">';
1.160.6.72 raeburn 936: if ($action eq 'login') {
1.30 raeburn 937: $output .= '
1.59 bisitz 938: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 939: } elsif ($action eq 'serverstatuses') {
940: $output .= '
941: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
942: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
943:
1.6 raeburn 944: } else {
1.30 raeburn 945: $output .= '
1.69 raeburn 946: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
947: }
1.72 raeburn 948: if (defined($item->{'header'}->[0]->{'col3'})) {
949: $output .= '<td class="LC_left_item" valign="top">'.
950: &mt($item->{'header'}->[0]->{'col2'});
951: if ($action eq 'serverstatuses') {
952: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
953: }
1.69 raeburn 954: } else {
955: $output .= '<td class="LC_right_item" valign="top">'.
956: &mt($item->{'header'}->[0]->{'col2'});
957: }
958: $output .= '</td>';
959: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 960: if (defined($item->{'header'}->[0]->{'col4'})) {
961: $output .= '<td class="LC_left_item" valign="top">'.
962: &mt($item->{'header'}->[0]->{'col3'});
963: } else {
964: $output .= '<td class="LC_right_item" valign="top">'.
965: &mt($item->{'header'}->[0]->{'col3'});
966: }
1.69 raeburn 967: if ($action eq 'serverstatuses') {
968: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
969: }
970: $output .= '</td>';
1.6 raeburn 971: }
1.150 raeburn 972: if ($item->{'header'}->[0]->{'col4'}) {
973: $output .= '<td class="LC_right_item" valign="top">'.
974: &mt($item->{'header'}->[0]->{'col4'});
975: }
1.69 raeburn 976: $output .= '</tr>';
1.48 raeburn 977: $rowtotal ++;
1.160.6.5 raeburn 978: if ($action eq 'quotas') {
1.86 raeburn 979: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 980: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.78 raeburn 981: ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.160.6.37 raeburn 982: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 983: }
1.3 raeburn 984: }
1.30 raeburn 985: $output .= '
1.3 raeburn 986: </table>
987: </td>
988: </tr>
1.30 raeburn 989: </table><br />';
990: return ($output,$rowtotal);
1.1 raeburn 991: }
992:
1.3 raeburn 993: sub print_login {
1.160.6.5 raeburn 994: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 995: my ($css_class,$datatable);
1.6 raeburn 996: my %choices = &login_choices();
1.110 raeburn 997:
1.160.6.5 raeburn 998: if ($caller eq 'service') {
1.149 raeburn 999: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1000: my $choice = $choices{'disallowlogin'};
1001: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1002: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 1003: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1004: '<th>'.$choices{'server'}.'</th>'.
1005: '<th>'.$choices{'serverpath'}.'</th>'.
1006: '<th>'.$choices{'custompath'}.'</th>'.
1007: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1008: my %disallowed;
1009: if (ref($settings) eq 'HASH') {
1010: if (ref($settings->{'loginvia'}) eq 'HASH') {
1011: %disallowed = %{$settings->{'loginvia'}};
1012: }
1013: }
1014: foreach my $lonhost (sort(keys(%servers))) {
1015: my $direct = 'selected="selected"';
1.128 raeburn 1016: if (ref($disallowed{$lonhost}) eq 'HASH') {
1017: if ($disallowed{$lonhost}{'server'} ne '') {
1018: $direct = '';
1019: }
1.110 raeburn 1020: }
1.115 raeburn 1021: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1022: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1023: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1024: '</option>';
1.160.6.13 raeburn 1025: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1026: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1027: my $selected = '';
1.128 raeburn 1028: if (ref($disallowed{$lonhost}) eq 'HASH') {
1029: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1030: $selected = 'selected="selected"';
1031: }
1.110 raeburn 1032: }
1033: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1034: $servers{$hostid}.'</option>';
1035: }
1.128 raeburn 1036: $datatable .= '</select></td>'.
1037: '<td><select name="'.$lonhost.'_serverpath">';
1038: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1039: my $pathname = $path;
1040: if ($path eq 'custom') {
1041: $pathname = &mt('Custom Path').' ->';
1042: }
1043: my $selected = '';
1044: if (ref($disallowed{$lonhost}) eq 'HASH') {
1045: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1046: $selected = 'selected="selected"';
1047: }
1048: } elsif ($path eq '') {
1049: $selected = 'selected="selected"';
1050: }
1051: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1052: }
1053: $datatable .= '</select></td>';
1054: my ($custom,$exempt);
1055: if (ref($disallowed{$lonhost}) eq 'HASH') {
1056: $custom = $disallowed{$lonhost}{'custompath'};
1057: $exempt = $disallowed{$lonhost}{'exempt'};
1058: }
1059: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1060: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1061: '</tr>';
1.110 raeburn 1062: }
1063: $datatable .= '</table></td></tr>';
1064: return $datatable;
1.160.6.5 raeburn 1065: } elsif ($caller eq 'page') {
1066: my %defaultchecked = (
1067: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1068: 'helpdesk' => 'on',
1.160.6.5 raeburn 1069: 'adminmail' => 'off',
1070: 'newuser' => 'off',
1071: );
1.160.6.14 raeburn 1072: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1073: my (%checkedon,%checkedoff);
1.42 raeburn 1074: foreach my $item (@toggles) {
1.160.6.5 raeburn 1075: if ($defaultchecked{$item} eq 'on') {
1076: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1077: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1078: } elsif ($defaultchecked{$item} eq 'off') {
1079: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1080: $checkedon{$item} = ' ';
1081: }
1.1 raeburn 1082: }
1.160.6.5 raeburn 1083: my @images = ('img','logo','domlogo','login');
1084: my @logintext = ('textcol','bgcol');
1085: my @bgs = ('pgbg','mainbg','sidebg');
1086: my @links = ('link','alink','vlink');
1087: my %designhash = &Apache::loncommon::get_domainconf($dom);
1088: my %defaultdesign = %Apache::loncommon::defaultdesign;
1089: my (%is_custom,%designs);
1090: my %defaults = (
1091: font => $defaultdesign{'login.font'},
1092: );
1.6 raeburn 1093: foreach my $item (@images) {
1.160.6.5 raeburn 1094: $defaults{$item} = $defaultdesign{'login.'.$item};
1095: $defaults{'showlogo'}{$item} = 1;
1096: }
1097: foreach my $item (@bgs) {
1098: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1099: }
1.41 raeburn 1100: foreach my $item (@logintext) {
1.160.6.5 raeburn 1101: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1102: }
1.160.6.5 raeburn 1103: foreach my $item (@links) {
1104: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1105: }
1.160.6.5 raeburn 1106: if (ref($settings) eq 'HASH') {
1107: foreach my $item (@toggles) {
1108: if ($settings->{$item} eq '1') {
1109: $checkedon{$item} = ' checked="checked" ';
1110: $checkedoff{$item} = ' ';
1111: } elsif ($settings->{$item} eq '0') {
1112: $checkedoff{$item} = ' checked="checked" ';
1113: $checkedon{$item} = ' ';
1114: }
1.6 raeburn 1115: }
1.160.6.5 raeburn 1116: foreach my $item (@images) {
1117: if (defined($settings->{$item})) {
1118: $designs{$item} = $settings->{$item};
1119: $is_custom{$item} = 1;
1120: }
1121: if (defined($settings->{'showlogo'}{$item})) {
1122: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1123: }
1124: }
1125: foreach my $item (@logintext) {
1126: if ($settings->{$item} ne '') {
1127: $designs{'logintext'}{$item} = $settings->{$item};
1128: $is_custom{$item} = 1;
1129: }
1130: }
1131: if ($settings->{'font'} ne '') {
1132: $designs{'font'} = $settings->{'font'};
1133: $is_custom{'font'} = 1;
1134: }
1135: foreach my $item (@bgs) {
1136: if ($settings->{$item} ne '') {
1137: $designs{'bgs'}{$item} = $settings->{$item};
1138: $is_custom{$item} = 1;
1139: }
1140: }
1141: foreach my $item (@links) {
1142: if ($settings->{$item} ne '') {
1143: $designs{'links'}{$item} = $settings->{$item};
1144: $is_custom{$item} = 1;
1145: }
1146: }
1147: } else {
1148: if ($designhash{$dom.'.login.font'} ne '') {
1149: $designs{'font'} = $designhash{$dom.'.login.font'};
1150: $is_custom{'font'} = 1;
1151: }
1152: foreach my $item (@images) {
1153: if ($designhash{$dom.'.login.'.$item} ne '') {
1154: $designs{$item} = $designhash{$dom.'.login.'.$item};
1155: $is_custom{$item} = 1;
1156: }
1157: }
1158: foreach my $item (@bgs) {
1159: if ($designhash{$dom.'.login.'.$item} ne '') {
1160: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1161: $is_custom{$item} = 1;
1162: }
1163: }
1164: foreach my $item (@links) {
1165: if ($designhash{$dom.'.login.'.$item} ne '') {
1166: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1167: $is_custom{$item} = 1;
1168: }
1.6 raeburn 1169: }
1170: }
1.160.6.5 raeburn 1171: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1172: logo => 'Institution Logo',
1173: domlogo => 'Domain Logo',
1174: login => 'Login box');
1175: my $itemcount = 1;
1176: foreach my $item (@toggles) {
1177: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1178: $datatable .=
1179: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1180: '</td><td>'.
1181: '<span class="LC_nobreak"><label><input type="radio" name="'.
1182: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1183: '</label> <label><input type="radio" name="'.$item.'"'.
1184: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1185: '</tr>';
1186: $itemcount ++;
1.6 raeburn 1187: }
1.160.6.5 raeburn 1188: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1189: $datatable .= '</tr></table></td></tr>';
1190: } elsif ($caller eq 'help') {
1191: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1192: my $switchserver = &check_switchserver($dom,$confname);
1193: my $itemcount = 1;
1194: $defaulturl = '/adm/loginproblems.html';
1195: $defaulttype = 'default';
1196: %lt = &Apache::lonlocal::texthash (
1197: del => 'Delete?',
1198: rep => 'Replace:',
1199: upl => 'Upload:',
1200: default => 'Default',
1201: custom => 'Custom',
1202: );
1203: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1204: my @currlangs;
1205: if (ref($settings) eq 'HASH') {
1206: if (ref($settings->{'helpurl'}) eq 'HASH') {
1207: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1208: next if ($settings->{'helpurl'}{$key} eq '');
1209: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1210: $type{$key} = 'custom';
1211: unless ($key eq 'nolang') {
1212: push(@currlangs,$key);
1213: }
1214: }
1215: } elsif ($settings->{'helpurl'} ne '') {
1216: $type{'nolang'} = 'custom';
1217: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1218: }
1219: }
1.160.6.5 raeburn 1220: foreach my $lang ('nolang',sort(@currlangs)) {
1221: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1222: $datatable .= '<tr'.$css_class.'>';
1223: if ($url{$lang} eq '') {
1224: $url{$lang} = $defaulturl;
1225: }
1226: if ($type{$lang} eq '') {
1227: $type{$lang} = $defaulttype;
1228: }
1229: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1230: if ($lang eq 'nolang') {
1231: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1232: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1233: } else {
1234: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1235: $langchoices{$lang},
1236: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1237: }
1238: $datatable .= '</span></td>'."\n".
1239: '<td class="LC_left_item">';
1240: if ($type{$lang} eq 'custom') {
1241: $datatable .= '<span class="LC_nobreak"><label>'.
1242: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1243: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1244: } else {
1245: $datatable .= $lt{'upl'};
1246: }
1247: $datatable .='<br />';
1248: if ($switchserver) {
1249: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1250: } else {
1251: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1252: }
1.160.6.5 raeburn 1253: $datatable .= '</td></tr>';
1254: $itemcount ++;
1.6 raeburn 1255: }
1.160.6.5 raeburn 1256: my @addlangs;
1257: foreach my $lang (sort(keys(%langchoices))) {
1258: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1259: push(@addlangs,$lang);
1260: }
1261: if (@addlangs > 0) {
1262: my %toadd;
1263: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1264: $toadd{''} = &mt('Select');
1265: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1266: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1267: &mt('Add log-in help page for a specific language:').' '.
1268: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1269: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1270: if ($switchserver) {
1271: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1272: } else {
1273: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1274: }
1.160.6.5 raeburn 1275: $datatable .= '</td></tr>';
1276: $itemcount ++;
1.6 raeburn 1277: }
1.160.6.5 raeburn 1278: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1279: } elsif ($caller eq 'headtag') {
1280: my %domservers = &Apache::lonnet::get_servers($dom);
1281: my $choice = $choices{'headtag'};
1282: $css_class = ' class="LC_odd_row"';
1283: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1284: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1285: '<th>'.$choices{'current'}.'</th>'.
1286: '<th>'.$choices{'action'}.'</th>'.
1287: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1288: my (%currurls,%currexempt);
1289: if (ref($settings) eq 'HASH') {
1290: if (ref($settings->{'headtag'}) eq 'HASH') {
1291: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1292: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1293: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1294: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1295: }
1296: }
1297: }
1298: }
1299: my %lt = &Apache::lonlocal::texthash(
1300: del => 'Delete?',
1301: rep => 'Replace:',
1302: upl => 'Upload:',
1303: curr => 'View contents',
1304: none => 'None',
1305: );
1306: my $switchserver = &check_switchserver($dom,$confname);
1307: foreach my $lonhost (sort(keys(%domservers))) {
1308: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1309: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1310: if ($currurls{$lonhost}) {
1311: $datatable .= '<td class="LC_right_item"><a href="'.
1312: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1313: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1314: '">'.$lt{'curr'}.'</a></td>'.
1315: '<td><span class="LC_nobreak"><label>'.
1316: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1317: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1318: } else {
1319: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$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="loginheadtag_'.$lonhost.'" />';
1326: }
1.160.6.87 raeburn 1327: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56 raeburn 1328: }
1329: $datatable .= '</table></td></tr>';
1.1 raeburn 1330: }
1.6 raeburn 1331: return $datatable;
1332: }
1333:
1334: sub login_choices {
1335: my %choices =
1336: &Apache::lonlocal::texthash (
1.116 bisitz 1337: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1338: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1339: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1340: disallowlogin => "Login page requests redirected",
1341: hostid => "Server",
1.128 raeburn 1342: server => "Redirect to:",
1343: serverpath => "Path",
1344: custompath => "Custom",
1345: exempt => "Exempt IP(s)",
1.110 raeburn 1346: directlogin => "No redirect",
1347: newuser => "Link to create a user account",
1348: img => "Header",
1349: logo => "Main Logo",
1350: domlogo => "Domain Logo",
1351: login => "Log-in Header",
1352: textcol => "Text color",
1353: bgcol => "Box color",
1354: bgs => "Background colors",
1355: links => "Link colors",
1356: font => "Font color",
1357: pgbg => "Header",
1358: mainbg => "Page",
1359: sidebg => "Login box",
1360: link => "Link",
1361: alink => "Active link",
1362: vlink => "Visited link",
1.160.6.56 raeburn 1363: headtag => "Custom markup",
1364: action => "Action",
1365: current => "Current",
1.6 raeburn 1366: );
1367: return %choices;
1368: }
1369:
1370: sub print_rolecolors {
1.30 raeburn 1371: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1372: my %choices = &color_font_choices();
1373: my @bgs = ('pgbg','tabbg','sidebg');
1374: my @links = ('link','alink','vlink');
1375: my @images = ('img');
1376: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1377: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1378: my %defaultdesign = %Apache::loncommon::defaultdesign;
1379: my (%is_custom,%designs);
1.160.6.22 raeburn 1380: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1381: if (ref($settings) eq 'HASH') {
1382: if (ref($settings->{$role}) eq 'HASH') {
1383: if ($settings->{$role}->{'img'} ne '') {
1384: $designs{'img'} = $settings->{$role}->{'img'};
1385: $is_custom{'img'} = 1;
1386: }
1387: if ($settings->{$role}->{'font'} ne '') {
1388: $designs{'font'} = $settings->{$role}->{'font'};
1389: $is_custom{'font'} = 1;
1390: }
1.97 tempelho 1391: if ($settings->{$role}->{'fontmenu'} ne '') {
1392: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1393: $is_custom{'fontmenu'} = 1;
1394: }
1.6 raeburn 1395: foreach my $item (@bgs) {
1396: if ($settings->{$role}->{$item} ne '') {
1397: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1398: $is_custom{$item} = 1;
1399: }
1400: }
1401: foreach my $item (@links) {
1402: if ($settings->{$role}->{$item} ne '') {
1403: $designs{'links'}{$item} = $settings->{$role}->{$item};
1404: $is_custom{$item} = 1;
1405: }
1406: }
1407: }
1408: } else {
1409: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1410: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1411: $is_custom{'img'} = 1;
1412: }
1.97 tempelho 1413: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1414: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1415: $is_custom{'fontmenu'} = 1;
1416: }
1.6 raeburn 1417: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1418: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1419: $is_custom{'font'} = 1;
1420: }
1421: foreach my $item (@bgs) {
1422: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1423: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1424: $is_custom{$item} = 1;
1425:
1426: }
1427: }
1428: foreach my $item (@links) {
1429: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1430: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1431: $is_custom{$item} = 1;
1432: }
1433: }
1434: }
1435: my $itemcount = 1;
1.30 raeburn 1436: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1437: $datatable .= '</tr></table></td></tr>';
1438: return $datatable;
1439: }
1440:
1.160.6.22 raeburn 1441: sub role_defaults {
1442: my ($role,$bgs,$links,$images,$logintext) = @_;
1443: my %defaults;
1444: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1445: return %defaults;
1446: }
1447: my %defaultdesign = %Apache::loncommon::defaultdesign;
1448: if ($role eq 'login') {
1449: %defaults = (
1450: font => $defaultdesign{$role.'.font'},
1451: );
1452: if (ref($logintext) eq 'ARRAY') {
1453: foreach my $item (@{$logintext}) {
1454: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1455: }
1456: }
1457: foreach my $item (@{$images}) {
1458: $defaults{'showlogo'}{$item} = 1;
1459: }
1460: } else {
1461: %defaults = (
1462: img => $defaultdesign{$role.'.img'},
1463: font => $defaultdesign{$role.'.font'},
1464: fontmenu => $defaultdesign{$role.'.fontmenu'},
1465: );
1466: }
1467: foreach my $item (@{$bgs}) {
1468: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1469: }
1470: foreach my $item (@{$links}) {
1471: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1472: }
1473: foreach my $item (@{$images}) {
1474: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1475: }
1476: return %defaults;
1477: }
1478:
1.6 raeburn 1479: sub display_color_options {
1.9 raeburn 1480: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1481: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1482: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1483: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1484: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1485: '<td>'.$choices->{'font'}.'</td>';
1486: if (!$is_custom->{'font'}) {
1.160.6.87 raeburn 1487: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1488: } else {
1489: $datatable .= '<td> </td>';
1490: }
1.160.6.9 raeburn 1491: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1492:
1.8 raeburn 1493: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1494: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1495: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1496: ' </span></td></tr>';
1.107 raeburn 1497: unless ($role eq 'login') {
1498: $datatable .= '<tr'.$css_class.'>'.
1499: '<td>'.$choices->{'fontmenu'}.'</td>';
1500: if (!$is_custom->{'fontmenu'}) {
1.160.6.87 raeburn 1501: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1502: } else {
1503: $datatable .= '<td> </td>';
1504: }
1.160.6.22 raeburn 1505: $current_color = $designs->{'fontmenu'} ?
1506: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1507: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1508: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1509: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1510: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1511: ' </span></td></tr>';
1.97 tempelho 1512: }
1.9 raeburn 1513: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1514: foreach my $img (@{$images}) {
1.18 albertel 1515: $itemcount ++;
1.6 raeburn 1516: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1517: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1518: '<td>'.$choices->{$img};
1.41 raeburn 1519: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1520: if ($role eq 'login') {
1521: if ($img eq 'login') {
1522: $login_hdr_pick =
1.135 bisitz 1523: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1524: $logincolors =
1525: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1526: $designs,$defaults);
1.70 raeburn 1527: } elsif ($img ne 'domlogo') {
1528: $datatable.= &logo_display_options($img,$defaults,$designs);
1529: }
1530: }
1531: $datatable .= '</td>';
1.6 raeburn 1532: if ($designs->{$img} ne '') {
1533: $imgfile = $designs->{$img};
1.18 albertel 1534: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1535: } else {
1536: $imgfile = $defaults->{$img};
1537: }
1538: if ($imgfile) {
1.9 raeburn 1539: my ($showfile,$fullsize);
1540: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1541: my $urldir = $1;
1542: my $filename = $2;
1543: my @info = &Apache::lonnet::stat_file($designs->{$img});
1544: if (@info) {
1545: my $thumbfile = 'tn-'.$filename;
1546: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1547: if (@thumb) {
1548: $showfile = $urldir.'/'.$thumbfile;
1549: } else {
1550: $showfile = $imgfile;
1551: }
1552: } else {
1553: $showfile = '';
1554: }
1555: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1556: $showfile = $imgfile;
1.6 raeburn 1557: my $imgdir = $1;
1558: my $filename = $2;
1.159 raeburn 1559: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1560: $showfile = "/$imgdir/tn-".$filename;
1561: } else {
1.159 raeburn 1562: my $input = $londocroot.$imgfile;
1563: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1564: if (!-e $output) {
1.9 raeburn 1565: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1566: my ($fullwidth,$fullheight) = &check_dimensions($input);
1567: if ($fullwidth ne '' && $fullheight ne '') {
1568: if ($fullwidth > $width && $fullheight > $height) {
1569: my $size = $width.'x'.$height;
1.160.6.88 raeburn 1570: my @args = ('convert','-sample',$size,$input,$output);
1571: system({$args[0]} @args);
1.159 raeburn 1572: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1573: }
1574: }
1.6 raeburn 1575: }
1576: }
1.16 raeburn 1577: }
1.6 raeburn 1578: if ($showfile) {
1.40 raeburn 1579: if ($showfile =~ m{^/(adm|res)/}) {
1580: if ($showfile =~ m{^/res/}) {
1581: my $local_showfile =
1582: &Apache::lonnet::filelocation('',$showfile);
1583: &Apache::lonnet::repcopy($local_showfile);
1584: }
1585: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1586: }
1587: if ($imgfile) {
1588: if ($imgfile =~ m{^/(adm|res)/}) {
1589: if ($imgfile =~ m{^/res/}) {
1590: my $local_imgfile =
1591: &Apache::lonnet::filelocation('',$imgfile);
1592: &Apache::lonnet::repcopy($local_imgfile);
1593: }
1594: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1595: } else {
1596: $fullsize = $imgfile;
1597: }
1598: }
1.41 raeburn 1599: $datatable .= '<td>';
1600: if ($img eq 'login') {
1.135 bisitz 1601: $datatable .= $login_hdr_pick;
1602: }
1.41 raeburn 1603: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1604: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1605: } else {
1.160.6.22 raeburn 1606: $datatable .= '<td> </td><td class="LC_left_item">'.
1607: &mt('Upload:').'<br />';
1.6 raeburn 1608: }
1609: } else {
1.160.6.22 raeburn 1610: $datatable .= '<td> </td><td class="LC_left_item">'.
1611: &mt('Upload:').'<br />';
1.6 raeburn 1612: }
1.9 raeburn 1613: if ($switchserver) {
1614: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1615: } else {
1.135 bisitz 1616: if ($img ne 'login') { # suppress file selection for Log-in header
1617: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1618: }
1.9 raeburn 1619: }
1620: $datatable .= '</td></tr>';
1.6 raeburn 1621: }
1622: $itemcount ++;
1623: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1624: $datatable .= '<tr'.$css_class.'>'.
1625: '<td>'.$choices->{'bgs'}.'</td>';
1626: my $bgs_def;
1627: foreach my $item (@{$bgs}) {
1628: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1629: $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 1630: }
1631: }
1632: if ($bgs_def) {
1.8 raeburn 1633: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1634: } else {
1635: $datatable .= '<td> </td>';
1636: }
1637: $datatable .= '<td class="LC_right_item">'.
1638: '<table border="0"><tr>';
1.160.6.13 raeburn 1639:
1.6 raeburn 1640: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1641: $datatable .= '<td align="center">'.$choices->{$item};
1642: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1643: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1644: $datatable .= ' ';
1.6 raeburn 1645: }
1.160.6.9 raeburn 1646: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1647: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1648: }
1649: $datatable .= '</tr></table></td></tr>';
1650: $itemcount ++;
1651: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1652: $datatable .= '<tr'.$css_class.'>'.
1653: '<td>'.$choices->{'links'}.'</td>';
1654: my $links_def;
1655: foreach my $item (@{$links}) {
1656: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1657: $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 1658: }
1659: }
1660: if ($links_def) {
1.8 raeburn 1661: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1662: } else {
1663: $datatable .= '<td> </td>';
1664: }
1665: $datatable .= '<td class="LC_right_item">'.
1666: '<table border="0"><tr>';
1667: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1668: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1669: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1670: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1671: $datatable.=' ';
1.6 raeburn 1672: }
1.160.6.9 raeburn 1673: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1674: '" /></td>';
1675: }
1.30 raeburn 1676: $$rowtotal += $itemcount;
1.3 raeburn 1677: return $datatable;
1678: }
1679:
1.70 raeburn 1680: sub logo_display_options {
1681: my ($img,$defaults,$designs) = @_;
1682: my $checkedon;
1683: if (ref($defaults) eq 'HASH') {
1684: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1685: if ($defaults->{'showlogo'}{$img}) {
1686: $checkedon = 'checked="checked" ';
1687: }
1688: }
1689: }
1690: if (ref($designs) eq 'HASH') {
1691: if (ref($designs->{'showlogo'}) eq 'HASH') {
1692: if (defined($designs->{'showlogo'}{$img})) {
1693: if ($designs->{'showlogo'}{$img} == 0) {
1694: $checkedon = '';
1695: } elsif ($designs->{'showlogo'}{$img} == 1) {
1696: $checkedon = 'checked="checked" ';
1697: }
1698: }
1699: }
1700: }
1701: return '<br /><label> <input type="checkbox" name="'.
1702: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1703: &mt('show').'</label>'."\n";
1704: }
1705:
1.41 raeburn 1706: sub login_header_options {
1.135 bisitz 1707: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1708: my $output = '';
1.41 raeburn 1709: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1710: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1711: if (!$is_custom->{'textcol'}) {
1712: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1713: ' ';
1714: }
1715: if (!$is_custom->{'bgcol'}) {
1716: $output .= $choices->{'bgcol'}.': '.
1717: '<span id="css_'.$role.'_font" style="background-color: '.
1718: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1719: }
1720: $output .= '<br />';
1721: }
1722: $output .='<br />';
1723: return $output;
1724: }
1725:
1726: sub login_text_colors {
1.160.6.22 raeburn 1727: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1728: my $color_menu = '<table border="0"><tr>';
1729: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1730: $color_menu .= '<td align="center">'.$choices->{$item};
1731: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1732: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1733: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1734: }
1735: $color_menu .= '</tr></table><br />';
1736: return $color_menu;
1737: }
1738:
1739: sub image_changes {
1740: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1741: my $output;
1.135 bisitz 1742: if ($img eq 'login') {
1.160.6.87 raeburn 1743: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 1744: } elsif (!$is_custom) {
1.70 raeburn 1745: if ($img ne 'domlogo') {
1.160.6.87 raeburn 1746: $output = &mt('Default image:').'<br />';
1.41 raeburn 1747: } else {
1.160.6.87 raeburn 1748: $output = &mt('Default in use:').'<br />';
1.41 raeburn 1749: }
1750: }
1.160.6.87 raeburn 1751: if ($img ne 'login') {
1.135 bisitz 1752: if ($img_import) {
1753: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1754: }
1755: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1756: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1757: if ($is_custom) {
1758: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1759: '<input type="checkbox" name="'.
1760: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1761: '</label> '.&mt('Replace:').'</span><br />';
1762: } else {
1.160.6.22 raeburn 1763: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1764: }
1.41 raeburn 1765: }
1766: return $output;
1767: }
1768:
1.3 raeburn 1769: sub print_quotas {
1.86 raeburn 1770: my ($dom,$settings,$rowtotal,$action) = @_;
1771: my $context;
1772: if ($action eq 'quotas') {
1773: $context = 'tools';
1774: } else {
1775: $context = $action;
1776: }
1.160.6.20 raeburn 1777: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1778: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1779: my $typecount = 0;
1.101 raeburn 1780: my ($css_class,%titles);
1.86 raeburn 1781: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1782: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1783: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1784: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1785: %titles = &courserequest_titles();
1.160.6.5 raeburn 1786: } elsif ($context eq 'requestauthor') {
1787: @usertools = ('author');
1788: @options = ('norequest','approval','automatic');
1789: %titles = &authorrequest_titles();
1.86 raeburn 1790: } else {
1.160.6.4 raeburn 1791: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1792: %titles = &tool_titles();
1.86 raeburn 1793: }
1.26 raeburn 1794: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1795: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1796: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1797: unless (($context eq 'requestcourses') ||
1798: ($context eq 'requestauthor')) {
1.86 raeburn 1799: if (ref($settings) eq 'HASH') {
1800: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1801: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1802: } else {
1803: $currdefquota = $settings->{$type};
1804: }
1.160.6.20 raeburn 1805: if (ref($settings->{authorquota}) eq 'HASH') {
1806: $currauthorquota = $settings->{authorquota}->{$type};
1807: }
1.78 raeburn 1808: }
1.72 raeburn 1809: }
1.3 raeburn 1810: if (defined($usertypes->{$type})) {
1811: $typecount ++;
1812: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1813: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1814: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1815: '<td class="LC_left_item">';
1.101 raeburn 1816: if ($context eq 'requestcourses') {
1817: $datatable .= '<table><tr>';
1818: }
1819: my %cell;
1.72 raeburn 1820: foreach my $item (@usertools) {
1.101 raeburn 1821: if ($context eq 'requestcourses') {
1822: my ($curroption,$currlimit);
1823: if (ref($settings) eq 'HASH') {
1824: if (ref($settings->{$item}) eq 'HASH') {
1825: $curroption = $settings->{$item}->{$type};
1826: if ($curroption =~ /^autolimit=(\d*)$/) {
1827: $currlimit = $1;
1828: }
1829: }
1830: }
1831: if (!$curroption) {
1832: $curroption = 'norequest';
1833: }
1834: $datatable .= '<th>'.$titles{$item}.'</th>';
1835: foreach my $option (@options) {
1836: my $val = $option;
1837: if ($option eq 'norequest') {
1838: $val = 0;
1839: }
1840: if ($option eq 'validate') {
1841: my $canvalidate = 0;
1842: if (ref($validations{$item}) eq 'HASH') {
1843: if ($validations{$item}{$type}) {
1844: $canvalidate = 1;
1845: }
1846: }
1847: next if (!$canvalidate);
1848: }
1849: my $checked = '';
1850: if ($option eq $curroption) {
1851: $checked = ' checked="checked"';
1852: } elsif ($option eq 'autolimit') {
1853: if ($curroption =~ /^autolimit/) {
1854: $checked = ' checked="checked"';
1855: }
1856: }
1857: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1858: '<input type="radio" name="crsreq_'.$item.
1859: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1860: $titles{$option}.'</label>';
1.101 raeburn 1861: if ($option eq 'autolimit') {
1.127 raeburn 1862: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1863: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1864: 'value="'.$currlimit.'" />';
1.101 raeburn 1865: }
1.127 raeburn 1866: $cell{$item} .= '</span> ';
1.103 raeburn 1867: if ($option eq 'autolimit') {
1.127 raeburn 1868: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1869: }
1.101 raeburn 1870: }
1.160.6.5 raeburn 1871: } elsif ($context eq 'requestauthor') {
1872: my $curroption;
1873: if (ref($settings) eq 'HASH') {
1874: $curroption = $settings->{$type};
1875: }
1876: if (!$curroption) {
1877: $curroption = 'norequest';
1878: }
1879: foreach my $option (@options) {
1880: my $val = $option;
1881: if ($option eq 'norequest') {
1882: $val = 0;
1883: }
1884: my $checked = '';
1885: if ($option eq $curroption) {
1886: $checked = ' checked="checked"';
1887: }
1888: $datatable .= '<span class="LC_nobreak"><label>'.
1889: '<input type="radio" name="authorreq_'.$type.
1890: '" value="'.$val.'"'.$checked.' />'.
1891: $titles{$option}.'</label></span> ';
1892: }
1.101 raeburn 1893: } else {
1894: my $checked = 'checked="checked" ';
1895: if (ref($settings) eq 'HASH') {
1896: if (ref($settings->{$item}) eq 'HASH') {
1897: if ($settings->{$item}->{$type} == 0) {
1898: $checked = '';
1899: } elsif ($settings->{$item}->{$type} == 1) {
1900: $checked = 'checked="checked" ';
1901: }
1.78 raeburn 1902: }
1.72 raeburn 1903: }
1.101 raeburn 1904: $datatable .= '<span class="LC_nobreak"><label>'.
1905: '<input type="checkbox" name="'.$context.'_'.$item.
1906: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1907: '</label></span> ';
1.72 raeburn 1908: }
1.101 raeburn 1909: }
1910: if ($context eq 'requestcourses') {
1911: $datatable .= '</tr><tr>';
1912: foreach my $item (@usertools) {
1.106 raeburn 1913: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1914: }
1915: $datatable .= '</tr></table>';
1.72 raeburn 1916: }
1.86 raeburn 1917: $datatable .= '</td>';
1.160.6.5 raeburn 1918: unless (($context eq 'requestcourses') ||
1919: ($context eq 'requestauthor')) {
1.86 raeburn 1920: $datatable .=
1.160.6.20 raeburn 1921: '<td class="LC_right_item">'.
1922: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1923: '<input type="text" name="quota_'.$type.
1.72 raeburn 1924: '" value="'.$currdefquota.
1.160.6.20 raeburn 1925: '" size="5" /></span>'.(' ' x 2).
1926: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1927: '<input type="text" name="authorquota_'.$type.
1928: '" value="'.$currauthorquota.
1929: '" size="5" /></span></td>';
1.86 raeburn 1930: }
1931: $datatable .= '</tr>';
1.3 raeburn 1932: }
1933: }
1934: }
1.160.6.5 raeburn 1935: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1936: $defaultquota = '20';
1.160.6.20 raeburn 1937: $authorquota = '500';
1.86 raeburn 1938: if (ref($settings) eq 'HASH') {
1939: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1940: $defaultquota = $settings->{'defaultquota'}->{'default'};
1941: } elsif (defined($settings->{'default'})) {
1942: $defaultquota = $settings->{'default'};
1943: }
1.160.6.20 raeburn 1944: if (ref($settings->{'authorquota'}) eq 'HASH') {
1945: $authorquota = $settings->{'authorquota'}->{'default'};
1946: }
1.3 raeburn 1947: }
1948: }
1949: $typecount ++;
1950: $css_class = $typecount%2?' class="LC_odd_row"':'';
1951: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1952: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1953: '<td class="LC_left_item">';
1.101 raeburn 1954: if ($context eq 'requestcourses') {
1955: $datatable .= '<table><tr>';
1956: }
1957: my %defcell;
1.72 raeburn 1958: foreach my $item (@usertools) {
1.101 raeburn 1959: if ($context eq 'requestcourses') {
1960: my ($curroption,$currlimit);
1961: if (ref($settings) eq 'HASH') {
1962: if (ref($settings->{$item}) eq 'HASH') {
1963: $curroption = $settings->{$item}->{'default'};
1964: if ($curroption =~ /^autolimit=(\d*)$/) {
1965: $currlimit = $1;
1966: }
1967: }
1968: }
1969: if (!$curroption) {
1970: $curroption = 'norequest';
1971: }
1972: $datatable .= '<th>'.$titles{$item}.'</th>';
1973: foreach my $option (@options) {
1974: my $val = $option;
1975: if ($option eq 'norequest') {
1976: $val = 0;
1977: }
1978: if ($option eq 'validate') {
1979: my $canvalidate = 0;
1980: if (ref($validations{$item}) eq 'HASH') {
1981: if ($validations{$item}{'default'}) {
1982: $canvalidate = 1;
1983: }
1984: }
1985: next if (!$canvalidate);
1986: }
1987: my $checked = '';
1988: if ($option eq $curroption) {
1989: $checked = ' checked="checked"';
1990: } elsif ($option eq 'autolimit') {
1991: if ($curroption =~ /^autolimit/) {
1992: $checked = ' checked="checked"';
1993: }
1994: }
1995: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1996: '<input type="radio" name="crsreq_'.$item.
1997: '_default" value="'.$val.'"'.$checked.' />'.
1998: $titles{$option}.'</label>';
1999: if ($option eq 'autolimit') {
1.127 raeburn 2000: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2001: $item.'_limit_default" size="1" '.
2002: 'value="'.$currlimit.'" />';
2003: }
1.127 raeburn 2004: $defcell{$item} .= '</span> ';
1.104 raeburn 2005: if ($option eq 'autolimit') {
1.127 raeburn 2006: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2007: }
1.101 raeburn 2008: }
1.160.6.5 raeburn 2009: } elsif ($context eq 'requestauthor') {
2010: my $curroption;
2011: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 2012: $curroption = $settings->{'default'};
1.160.6.5 raeburn 2013: }
2014: if (!$curroption) {
2015: $curroption = 'norequest';
2016: }
2017: foreach my $option (@options) {
2018: my $val = $option;
2019: if ($option eq 'norequest') {
2020: $val = 0;
2021: }
2022: my $checked = '';
2023: if ($option eq $curroption) {
2024: $checked = ' checked="checked"';
2025: }
2026: $datatable .= '<span class="LC_nobreak"><label>'.
2027: '<input type="radio" name="authorreq_default"'.
2028: ' value="'.$val.'"'.$checked.' />'.
2029: $titles{$option}.'</label></span> ';
2030: }
1.101 raeburn 2031: } else {
2032: my $checked = 'checked="checked" ';
2033: if (ref($settings) eq 'HASH') {
2034: if (ref($settings->{$item}) eq 'HASH') {
2035: if ($settings->{$item}->{'default'} == 0) {
2036: $checked = '';
2037: } elsif ($settings->{$item}->{'default'} == 1) {
2038: $checked = 'checked="checked" ';
2039: }
1.78 raeburn 2040: }
1.72 raeburn 2041: }
1.101 raeburn 2042: $datatable .= '<span class="LC_nobreak"><label>'.
2043: '<input type="checkbox" name="'.$context.'_'.$item.
2044: '" value="default" '.$checked.'/>'.$titles{$item}.
2045: '</label></span> ';
2046: }
2047: }
2048: if ($context eq 'requestcourses') {
2049: $datatable .= '</tr><tr>';
2050: foreach my $item (@usertools) {
1.106 raeburn 2051: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2052: }
1.101 raeburn 2053: $datatable .= '</tr></table>';
1.72 raeburn 2054: }
1.86 raeburn 2055: $datatable .= '</td>';
1.160.6.5 raeburn 2056: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2057: $datatable .= '<td class="LC_right_item">'.
2058: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2059: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2060: $defaultquota.'" size="5" /></span>'.(' ' x2).
2061: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2062: '<input type="text" name="authorquota" value="'.
2063: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2064: }
2065: $datatable .= '</tr>';
1.72 raeburn 2066: $typecount ++;
2067: $css_class = $typecount%2?' class="LC_odd_row"':'';
2068: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2069: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2070: if ($context eq 'requestcourses') {
1.109 raeburn 2071: $datatable .= &mt('(overrides affiliation, if set)').
2072: '</td>'.
2073: '<td class="LC_left_item">'.
2074: '<table><tr>';
1.101 raeburn 2075: } else {
1.109 raeburn 2076: $datatable .= &mt('(overrides affiliation, if checked)').
2077: '</td>'.
2078: '<td class="LC_left_item" colspan="2">'.
2079: '<br />';
1.101 raeburn 2080: }
2081: my %advcell;
1.72 raeburn 2082: foreach my $item (@usertools) {
1.101 raeburn 2083: if ($context eq 'requestcourses') {
2084: my ($curroption,$currlimit);
2085: if (ref($settings) eq 'HASH') {
2086: if (ref($settings->{$item}) eq 'HASH') {
2087: $curroption = $settings->{$item}->{'_LC_adv'};
2088: if ($curroption =~ /^autolimit=(\d*)$/) {
2089: $currlimit = $1;
2090: }
2091: }
2092: }
2093: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2094: my $checked = '';
2095: if ($curroption eq '') {
2096: $checked = ' checked="checked"';
2097: }
2098: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2099: '<input type="radio" name="crsreq_'.$item.
2100: '__LC_adv" value=""'.$checked.' />'.
2101: &mt('No override set').'</label></span> ';
1.101 raeburn 2102: foreach my $option (@options) {
2103: my $val = $option;
2104: if ($option eq 'norequest') {
2105: $val = 0;
2106: }
2107: if ($option eq 'validate') {
2108: my $canvalidate = 0;
2109: if (ref($validations{$item}) eq 'HASH') {
2110: if ($validations{$item}{'_LC_adv'}) {
2111: $canvalidate = 1;
2112: }
2113: }
2114: next if (!$canvalidate);
2115: }
2116: my $checked = '';
1.104 raeburn 2117: if ($val eq $curroption) {
1.101 raeburn 2118: $checked = ' checked="checked"';
2119: } elsif ($option eq 'autolimit') {
2120: if ($curroption =~ /^autolimit/) {
2121: $checked = ' checked="checked"';
2122: }
2123: }
2124: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2125: '<input type="radio" name="crsreq_'.$item.
2126: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2127: $titles{$option}.'</label>';
2128: if ($option eq 'autolimit') {
1.127 raeburn 2129: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2130: $item.'_limit__LC_adv" size="1" '.
2131: 'value="'.$currlimit.'" />';
2132: }
1.127 raeburn 2133: $advcell{$item} .= '</span> ';
1.104 raeburn 2134: if ($option eq 'autolimit') {
1.127 raeburn 2135: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2136: }
1.101 raeburn 2137: }
1.160.6.5 raeburn 2138: } elsif ($context eq 'requestauthor') {
2139: my $curroption;
2140: if (ref($settings) eq 'HASH') {
2141: $curroption = $settings->{'_LC_adv'};
2142: }
2143: my $checked = '';
2144: if ($curroption eq '') {
2145: $checked = ' checked="checked"';
2146: }
2147: $datatable .= '<span class="LC_nobreak"><label>'.
2148: '<input type="radio" name="authorreq__LC_adv"'.
2149: ' value=""'.$checked.' />'.
2150: &mt('No override set').'</label></span> ';
2151: foreach my $option (@options) {
2152: my $val = $option;
2153: if ($option eq 'norequest') {
2154: $val = 0;
2155: }
2156: my $checked = '';
2157: if ($val eq $curroption) {
2158: $checked = ' checked="checked"';
2159: }
2160: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2161: '<input type="radio" name="authorreq__LC_adv"'.
2162: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2163: $titles{$option}.'</label></span> ';
2164: }
1.101 raeburn 2165: } else {
2166: my $checked = 'checked="checked" ';
2167: if (ref($settings) eq 'HASH') {
2168: if (ref($settings->{$item}) eq 'HASH') {
2169: if ($settings->{$item}->{'_LC_adv'} == 0) {
2170: $checked = '';
2171: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2172: $checked = 'checked="checked" ';
2173: }
1.79 raeburn 2174: }
1.72 raeburn 2175: }
1.101 raeburn 2176: $datatable .= '<span class="LC_nobreak"><label>'.
2177: '<input type="checkbox" name="'.$context.'_'.$item.
2178: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2179: '</label></span> ';
2180: }
2181: }
2182: if ($context eq 'requestcourses') {
2183: $datatable .= '</tr><tr>';
2184: foreach my $item (@usertools) {
1.106 raeburn 2185: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2186: }
1.101 raeburn 2187: $datatable .= '</tr></table>';
1.72 raeburn 2188: }
1.98 raeburn 2189: $datatable .= '</td></tr>';
1.30 raeburn 2190: $$rowtotal += $typecount;
1.3 raeburn 2191: return $datatable;
2192: }
2193:
1.160.6.5 raeburn 2194: sub print_requestmail {
1.160.6.93 raeburn 2195: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25 raeburn 2196: my ($now,$datatable,%currapp);
1.102 raeburn 2197: $now = time;
2198: if (ref($settings) eq 'HASH') {
2199: if (ref($settings->{'notify'}) eq 'HASH') {
2200: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2201: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2202: }
2203: }
2204: }
1.160.6.16 raeburn 2205: my $numinrow = 2;
1.160.6.34 raeburn 2206: my $css_class;
1.160.6.93 raeburn 2207: if ($$rowtotal%2) {
2208: $css_class = 'LC_odd_row';
2209: }
2210: if ($customcss) {
2211: $css_class .= " $customcss";
2212: }
2213: $css_class =~ s/^\s+//;
2214: if ($css_class) {
2215: $css_class = ' class="'.$css_class.'"';
2216: }
2217: if ($rowstyle) {
2218: $css_class .= ' style="'.$rowstyle.'"';
2219: }
1.160.6.5 raeburn 2220: my $text;
2221: if ($action eq 'requestcourses') {
2222: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2223: } elsif ($action eq 'requestauthor') {
2224: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2225: } else {
1.160.6.34 raeburn 2226: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2227: }
1.160.6.34 raeburn 2228: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2229: ' <td>'.$text.'</td>'.
1.102 raeburn 2230: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2231: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2232: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2233: if ($numdc > 0) {
2234: $datatable .= $table;
1.102 raeburn 2235: } else {
2236: $datatable .= &mt('There are no active Domain Coordinators');
2237: }
2238: $datatable .='</td></tr>';
2239: return $datatable;
2240: }
2241:
1.160.6.30 raeburn 2242: sub print_studentcode {
2243: my ($settings,$rowtotal) = @_;
2244: my $rownum = 0;
2245: my ($output,%current);
2246: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2247: if (ref($settings) eq 'HASH') {
2248: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2249: foreach my $type (@crstypes) {
2250: $current{$type} = $settings->{'uniquecode'}{$type};
2251: }
1.160.6.30 raeburn 2252: }
2253: }
2254: $output .= '<tr>'.
2255: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2256: '<td class="LC_left_item">';
2257: foreach my $type (@crstypes) {
2258: my $check = ' ';
2259: if ($current{$type}) {
2260: $check = ' checked="checked" ';
2261: }
2262: $output .= '<span class="LC_nobreak"><label>'.
2263: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2264: &mt($type).'</label></span>'.(' 'x2).' ';
2265: }
2266: $output .= '</td></tr>';
2267: $$rowtotal ++;
2268: return $output;
2269: }
2270:
2271: sub print_textbookcourses {
1.160.6.46 raeburn 2272: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2273: my $rownum = 0;
2274: my $css_class;
2275: my $itemcount = 1;
2276: my $maxnum = 0;
2277: my $bookshash;
2278: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2279: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2280: }
2281: my %ordered;
2282: if (ref($bookshash) eq 'HASH') {
2283: foreach my $item (keys(%{$bookshash})) {
2284: if (ref($bookshash->{$item}) eq 'HASH') {
2285: my $num = $bookshash->{$item}{'order'};
2286: $ordered{$num} = $item;
2287: }
2288: }
2289: }
2290: my $confname = $dom.'-domainconfig';
2291: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2292: my $maxnum = scalar(keys(%ordered));
2293: my $datatable;
1.160.6.30 raeburn 2294: if (keys(%ordered)) {
2295: my @items = sort { $a <=> $b } keys(%ordered);
2296: for (my $i=0; $i<@items; $i++) {
2297: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2298: my $key = $ordered{$items[$i]};
2299: my %coursehash=&Apache::lonnet::coursedescription($key);
2300: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2301: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2302: if (ref($bookshash->{$key}) eq 'HASH') {
2303: $subject = $bookshash->{$key}->{'subject'};
2304: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2305: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2306: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2307: $author = $bookshash->{$key}->{'author'};
2308: $image = $bookshash->{$key}->{'image'};
2309: if ($image ne '') {
2310: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2311: my $imagethumb = "$path/tn-".$imagefile;
2312: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2313: }
1.160.6.30 raeburn 2314: }
2315: }
1.160.6.46 raeburn 2316: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2317: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2318: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2319: for (my $k=0; $k<=$maxnum; $k++) {
2320: my $vpos = $k+1;
2321: my $selstr;
2322: if ($k == $i) {
2323: $selstr = ' selected="selected" ';
2324: }
2325: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2326: }
2327: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2328: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2329: &mt('Delete?').'</label></span></td>'.
2330: '<td colspan="2">'.
1.160.6.46 raeburn 2331: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2332: (' 'x2).
1.160.6.46 raeburn 2333: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2334: if ($type eq 'textbooks') {
2335: $datatable .= (' 'x2).
1.160.6.47 raeburn 2336: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2337: (' 'x2).
1.160.6.46 raeburn 2338: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2339: (' 'x2).
2340: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2341: if ($image) {
2342: $datatable .= '<span class="LC_nobreak">'.
2343: $imgsrc.
2344: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2345: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2346: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2347: }
2348: if ($switchserver) {
2349: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2350: } else {
2351: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2352: }
1.160.6.30 raeburn 2353: }
1.160.6.46 raeburn 2354: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2355: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2356: $coursetitle.'</span></td></tr>'."\n";
2357: $itemcount ++;
2358: }
2359: }
2360: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2361: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2362: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2363: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2364: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2365: for (my $k=0; $k<$maxnum+1; $k++) {
2366: my $vpos = $k+1;
2367: my $selstr;
2368: if ($k == $maxnum) {
2369: $selstr = ' selected="selected" ';
2370: }
2371: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2372: }
2373: $datatable .= '</select> '."\n".
1.160.6.87 raeburn 2374: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2375: '<td colspan="2">'.
1.160.6.46 raeburn 2376: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2377: (' 'x2).
1.160.6.46 raeburn 2378: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2379: (' 'x2);
2380: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2381: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2382: (' 'x2).
2383: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2384: (' 'x2).
2385: '<span class="LC_nobreak">'.&mt('Image:').' ';
2386: if ($switchserver) {
2387: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2388: } else {
2389: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2390: }
1.160.6.87 raeburn 2391: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2392: }
1.160.6.87 raeburn 2393: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2394: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2395: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2396: &Apache::loncommon::selectcourse_link
1.160.6.87 raeburn 2397: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2398: '</span></td>'."\n".
2399: '</tr>'."\n";
2400: $itemcount ++;
2401: return $datatable;
2402: }
2403:
2404: sub textbookcourses_javascript {
1.160.6.46 raeburn 2405: my ($settings) = @_;
2406: return unless(ref($settings) eq 'HASH');
2407: my (%ordered,%total,%jstext);
2408: foreach my $type ('textbooks','templates') {
2409: $total{$type} = 0;
2410: if (ref($settings->{$type}) eq 'HASH') {
2411: foreach my $item (keys(%{$settings->{$type}})) {
2412: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2413: my $num = $settings->{$type}->{$item}{'order'};
2414: $ordered{$type}{$num} = $item;
2415: }
2416: }
2417: $total{$type} = scalar(keys(%{$settings->{$type}}));
2418: }
2419: my @jsarray = ();
2420: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2421: push(@jsarray,$ordered{$type}{$item});
2422: }
2423: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2424: }
2425: return <<"ENDSCRIPT";
2426: <script type="text/javascript">
2427: // <![CDATA[
1.160.6.46 raeburn 2428: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2429: var changedVal;
1.160.6.46 raeburn 2430: $jstext{'textbooks'};
2431: $jstext{'templates'};
2432: var newpos;
2433: var maxh;
2434: if (caller == 'textbooks') {
2435: newpos = 'textbooks_addbook_pos';
2436: maxh = 1 + $total{'textbooks'};
2437: } else {
2438: newpos = 'templates_addbook_pos';
2439: maxh = 1 + $total{'templates'};
2440: }
1.160.6.30 raeburn 2441: var current = new Array;
2442: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2443: if (item == newpos) {
2444: changedVal = newitemVal;
2445: } else {
2446: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2447: current[newitemVal] = newpos;
2448: }
1.160.6.46 raeburn 2449: if (caller == 'textbooks') {
2450: for (var i=0; i<textbooks.length; i++) {
2451: var elementName = 'textbooks_'+textbooks[i];
2452: if (elementName != item) {
2453: if (form.elements[elementName]) {
2454: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2455: current[currVal] = elementName;
2456: }
2457: }
2458: }
2459: }
2460: if (caller == 'templates') {
2461: for (var i=0; i<templates.length; i++) {
2462: var elementName = 'templates_'+templates[i];
2463: if (elementName != item) {
2464: if (form.elements[elementName]) {
2465: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2466: current[currVal] = elementName;
2467: }
1.160.6.30 raeburn 2468: }
2469: }
2470: }
2471: var oldVal;
2472: for (var j=0; j<maxh; j++) {
2473: if (current[j] == undefined) {
2474: oldVal = j;
2475: }
2476: }
2477: if (oldVal < changedVal) {
2478: for (var k=oldVal+1; k<=changedVal ; k++) {
2479: var elementName = current[k];
2480: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2481: }
2482: } else {
2483: for (var k=changedVal; k<oldVal; k++) {
2484: var elementName = current[k];
2485: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2486: }
2487: }
2488: return;
2489: }
2490:
2491: // ]]>
2492: </script>
2493:
2494: ENDSCRIPT
2495: }
2496:
1.3 raeburn 2497: sub print_autoenroll {
1.30 raeburn 2498: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2499: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68 raeburn 2500: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2501: if (ref($settings) eq 'HASH') {
2502: if (exists($settings->{'run'})) {
2503: if ($settings->{'run'} eq '0') {
2504: $runoff = ' checked="checked" ';
2505: $runon = ' ';
2506: } else {
2507: $runon = ' checked="checked" ';
2508: $runoff = ' ';
2509: }
2510: } else {
2511: if ($autorun) {
2512: $runon = ' checked="checked" ';
2513: $runoff = ' ';
2514: } else {
2515: $runoff = ' checked="checked" ';
2516: $runon = ' ';
2517: }
2518: }
1.129 raeburn 2519: if (exists($settings->{'co-owners'})) {
2520: if ($settings->{'co-owners'} eq '0') {
2521: $coownersoff = ' checked="checked" ';
2522: $coownerson = ' ';
2523: } else {
2524: $coownerson = ' checked="checked" ';
2525: $coownersoff = ' ';
2526: }
2527: } else {
2528: $coownersoff = ' checked="checked" ';
2529: $coownerson = ' ';
2530: }
1.3 raeburn 2531: if (exists($settings->{'sender_domain'})) {
2532: $defdom = $settings->{'sender_domain'};
2533: }
1.160.6.68 raeburn 2534: if (exists($settings->{'autofailsafe'})) {
2535: $failsafe = $settings->{'autofailsafe'};
2536: }
1.14 raeburn 2537: } else {
2538: if ($autorun) {
2539: $runon = ' checked="checked" ';
2540: $runoff = ' ';
2541: } else {
2542: $runoff = ' checked="checked" ';
2543: $runon = ' ';
2544: }
1.3 raeburn 2545: }
2546: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2547: my $notif_sender;
2548: if (ref($settings) eq 'HASH') {
2549: $notif_sender = $settings->{'sender_uname'};
2550: }
1.3 raeburn 2551: my $datatable='<tr class="LC_odd_row">'.
2552: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2553: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2554: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2555: $runon.' value="1" />'.&mt('Yes').'</label> '.
2556: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2557: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2558: '</tr><tr>'.
2559: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2560: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2561: &mt('username').': '.
2562: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2563: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2564: ': '.$domform.'</span></td></tr>'.
2565: '<tr class="LC_odd_row">'.
2566: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2567: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2568: '<input type="radio" name="autoassign_coowners"'.
2569: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2570: '<label><input type="radio" name="autoassign_coowners"'.
2571: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 2572: '</tr><tr>'.
2573: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2574: '<td class="LC_right_item"><span class="LC_nobreak">'.
2575: '<input type="text" name="autoenroll_failsafe"'.
1.160.6.87 raeburn 2576: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.160.6.68 raeburn 2577: $$rowtotal += 4;
1.3 raeburn 2578: return $datatable;
2579: }
2580:
2581: sub print_autoupdate {
1.30 raeburn 2582: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2583: my $datatable;
2584: if ($position eq 'top') {
2585: my $updateon = ' ';
2586: my $updateoff = ' checked="checked" ';
2587: my $classlistson = ' ';
2588: my $classlistsoff = ' checked="checked" ';
2589: if (ref($settings) eq 'HASH') {
2590: if ($settings->{'run'} eq '1') {
2591: $updateon = $updateoff;
2592: $updateoff = ' ';
2593: }
2594: if ($settings->{'classlists'} eq '1') {
2595: $classlistson = $classlistsoff;
2596: $classlistsoff = ' ';
2597: }
2598: }
2599: my %title = (
2600: run => 'Auto-update active?',
2601: classlists => 'Update information in classlists?',
2602: );
2603: $datatable = '<tr class="LC_odd_row">'.
2604: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2605: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2606: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2607: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2608: '<label><input type="radio" name="autoupdate_run"'.
2609: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2610: '</tr><tr>'.
2611: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2612: '<td class="LC_right_item"><span class="LC_nobreak">'.
2613: '<label><input type="radio" name="classlists"'.
2614: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2615: '<label><input type="radio" name="classlists"'.
2616: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2617: '</tr>';
1.30 raeburn 2618: $$rowtotal += 2;
1.131 raeburn 2619: } elsif ($position eq 'middle') {
2620: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2621: my $numinrow = 3;
2622: my $locknamesettings;
2623: $datatable .= &insttypes_row($settings,$types,$usertypes,
2624: $dom,$numinrow,$othertitle,
1.160.6.93 raeburn 2625: 'lockablenames',$rowtotal);
1.131 raeburn 2626: $$rowtotal ++;
1.3 raeburn 2627: } else {
1.44 raeburn 2628: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2629: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2630: 'permanentemail','id');
1.33 raeburn 2631: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2632: my $numrows = 0;
1.26 raeburn 2633: if (ref($types) eq 'ARRAY') {
2634: if (@{$types} > 0) {
2635: $datatable =
2636: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2637: \@fields,$types,\$numrows);
1.30 raeburn 2638: $$rowtotal += @{$types};
1.26 raeburn 2639: }
1.3 raeburn 2640: }
2641: $datatable .=
2642: &usertype_update_row($settings,{'default' => $othertitle},
2643: \%fieldtitles,\@fields,['default'],
2644: \$numrows);
1.30 raeburn 2645: $$rowtotal ++;
1.3 raeburn 2646: }
2647: return $datatable;
2648: }
2649:
1.125 raeburn 2650: sub print_autocreate {
2651: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2652: my (%createon,%createoff,%currhash);
1.125 raeburn 2653: my @types = ('xml','req');
2654: if (ref($settings) eq 'HASH') {
2655: foreach my $item (@types) {
2656: $createoff{$item} = ' checked="checked" ';
2657: $createon{$item} = ' ';
2658: if (exists($settings->{$item})) {
2659: if ($settings->{$item}) {
2660: $createon{$item} = ' checked="checked" ';
2661: $createoff{$item} = ' ';
2662: }
2663: }
2664: }
1.160.6.16 raeburn 2665: if ($settings->{'xmldc'} ne '') {
2666: $currhash{$settings->{'xmldc'}} = 1;
2667: }
1.125 raeburn 2668: } else {
2669: foreach my $item (@types) {
2670: $createoff{$item} = ' checked="checked" ';
2671: $createon{$item} = ' ';
2672: }
2673: }
2674: $$rowtotal += 2;
1.160.6.16 raeburn 2675: my $numinrow = 2;
1.125 raeburn 2676: my $datatable='<tr class="LC_odd_row">'.
2677: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2678: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2679: '<input type="radio" name="autocreate_xml"'.
2680: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2681: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2682: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2683: '</td></tr><tr>'.
2684: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2685: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2686: '<input type="radio" name="autocreate_req"'.
2687: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2688: '<label><input type="radio" name="autocreate_req"'.
2689: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2690: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2691: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 2692: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2693: if ($numdc > 1) {
1.160.6.50 raeburn 2694: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2695: '</td><td class="LC_left_item">';
1.125 raeburn 2696: } else {
1.160.6.50 raeburn 2697: $datatable .= &mt('Course creation processed as:').
2698: '</td><td class="LC_right_item">';
1.125 raeburn 2699: }
1.160.6.50 raeburn 2700: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2701: $$rowtotal += $rows;
1.125 raeburn 2702: return $datatable;
2703: }
2704:
1.23 raeburn 2705: sub print_directorysrch {
1.160.6.72 raeburn 2706: my ($position,$dom,$settings,$rowtotal) = @_;
2707: my $datatable;
2708: if ($position eq 'top') {
2709: my $instsrchon = ' ';
2710: my $instsrchoff = ' checked="checked" ';
2711: my ($exacton,$containson,$beginson);
2712: my $instlocalon = ' ';
2713: my $instlocaloff = ' checked="checked" ';
2714: if (ref($settings) eq 'HASH') {
2715: if ($settings->{'available'} eq '1') {
2716: $instsrchon = $instsrchoff;
2717: $instsrchoff = ' ';
2718: }
2719: if ($settings->{'localonly'} eq '1') {
2720: $instlocalon = $instlocaloff;
2721: $instlocaloff = ' ';
2722: }
2723: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2724: foreach my $type (@{$settings->{'searchtypes'}}) {
2725: if ($type eq 'exact') {
2726: $exacton = ' checked="checked" ';
2727: } elsif ($type eq 'contains') {
2728: $containson = ' checked="checked" ';
2729: } elsif ($type eq 'begins') {
2730: $beginson = ' checked="checked" ';
2731: }
2732: }
2733: } else {
2734: if ($settings->{'searchtypes'} eq 'exact') {
2735: $exacton = ' checked="checked" ';
2736: } elsif ($settings->{'searchtypes'} eq 'contains') {
2737: $containson = ' checked="checked" ';
2738: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2739: $exacton = ' checked="checked" ';
2740: $containson = ' checked="checked" ';
2741: }
2742: }
1.23 raeburn 2743: }
1.160.6.72 raeburn 2744: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2745: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2746:
1.160.6.72 raeburn 2747: my $numinrow = 4;
2748: my $cansrchrow = 0;
2749: $datatable='<tr class="LC_odd_row">'.
2750: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2751: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2752: '<input type="radio" name="dirsrch_available"'.
2753: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2754: '<label><input type="radio" name="dirsrch_available"'.
2755: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2756: '</tr><tr>'.
2757: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2758: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2759: '<input type="radio" name="dirsrch_instlocalonly"'.
2760: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2761: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2762: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2763: '</tr>';
2764: $$rowtotal += 2;
2765: if (ref($usertypes) eq 'HASH') {
2766: if (keys(%{$usertypes}) > 0) {
2767: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93 raeburn 2768: $numinrow,$othertitle,'cansearch',
2769: $rowtotal);
1.160.6.72 raeburn 2770: $cansrchrow = 1;
2771: }
1.26 raeburn 2772: }
1.160.6.72 raeburn 2773: if ($cansrchrow) {
2774: $$rowtotal ++;
2775: $datatable .= '<tr>';
2776: } else {
2777: $datatable .= '<tr class="LC_odd_row">';
2778: }
2779: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2780: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2781: foreach my $title (@{$titleorder}) {
2782: if (defined($searchtitles->{$title})) {
2783: my $check = ' ';
2784: if (ref($settings) eq 'HASH') {
2785: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2786: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2787: $check = ' checked="checked" ';
2788: }
1.39 raeburn 2789: }
1.25 raeburn 2790: }
1.160.6.72 raeburn 2791: $datatable .= '<td class="LC_left_item">'.
2792: '<span class="LC_nobreak"><label>'.
2793: '<input type="checkbox" name="searchby" '.
2794: 'value="'.$title.'"'.$check.'/>'.
2795: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2796: }
2797: }
1.160.6.72 raeburn 2798: $datatable .= '</tr></table></td></tr>';
2799: $$rowtotal ++;
2800: if ($cansrchrow) {
2801: $datatable .= '<tr class="LC_odd_row">';
2802: } else {
2803: $datatable .= '<tr>';
2804: }
2805: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2806: '<td class="LC_left_item" colspan="2">'.
2807: '<span class="LC_nobreak"><label>'.
2808: '<input type="checkbox" name="searchtypes" '.
2809: $exacton.' value="exact" />'.&mt('Exact match').
2810: '</label> '.
2811: '<label><input type="checkbox" name="searchtypes" '.
2812: $beginson.' value="begins" />'.&mt('Begins with').
2813: '</label> '.
2814: '<label><input type="checkbox" name="searchtypes" '.
2815: $containson.' value="contains" />'.&mt('Contains').
2816: '</label></span></td></tr>';
2817: $$rowtotal ++;
1.26 raeburn 2818: } else {
1.160.6.72 raeburn 2819: my $domsrchon = ' checked="checked" ';
2820: my $domsrchoff = ' ';
2821: my $domlocalon = ' ';
2822: my $domlocaloff = ' checked="checked" ';
2823: if (ref($settings) eq 'HASH') {
2824: if ($settings->{'lclocalonly'} eq '1') {
2825: $domlocalon = $domlocaloff;
2826: $domlocaloff = ' ';
2827: }
2828: if ($settings->{'lcavailable'} eq '0') {
2829: $domsrchoff = $domsrchon;
2830: $domsrchon = ' ';
2831: }
2832: }
2833: $datatable='<tr class="LC_odd_row">'.
2834: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2835: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2836: '<input type="radio" name="dirsrch_domavailable"'.
2837: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2838: '<label><input type="radio" name="dirsrch_domavailable"'.
2839: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2840: '</tr><tr>'.
2841: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2842: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2843: '<input type="radio" name="dirsrch_domlocalonly"'.
2844: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2845: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2846: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2847: '</tr>';
2848: $$rowtotal += 2;
1.26 raeburn 2849: }
1.25 raeburn 2850: return $datatable;
2851: }
2852:
1.28 raeburn 2853: sub print_contacts {
1.160.6.78 raeburn 2854: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 2855: my $datatable;
2856: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 2857: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
2858: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
2859: if ($position eq 'top') {
2860: if (ref($settings) eq 'HASH') {
2861: foreach my $item (@contacts) {
2862: if (exists($settings->{$item})) {
2863: $to{$item} = $settings->{$item};
2864: }
1.28 raeburn 2865: }
2866: }
1.160.6.78 raeburn 2867: } elsif ($position eq 'middle') {
2868: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91 raeburn 2869: 'updatesmail','idconflictsmail','hostipmail');
1.28 raeburn 2870: foreach my $type (@mailings) {
1.160.6.78 raeburn 2871: $otheremails{$type} = '';
2872: }
2873: } else {
2874: @mailings = ('helpdeskmail','otherdomsmail');
2875: foreach my $type (@mailings) {
2876: $otheremails{$type} = '';
2877: }
2878: $bccemails{'helpdeskmail'} = '';
2879: $bccemails{'otherdomsmail'} = '';
2880: $includestr{'helpdeskmail'} = '';
2881: $includestr{'otherdomsmail'} = '';
2882: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
2883: }
2884: if (ref($settings) eq 'HASH') {
2885: unless ($position eq 'top') {
2886: foreach my $type (@mailings) {
2887: if (exists($settings->{$type})) {
2888: if (ref($settings->{$type}) eq 'HASH') {
2889: foreach my $item (@contacts) {
2890: if ($settings->{$type}{$item}) {
2891: $checked{$type}{$item} = ' checked="checked" ';
2892: }
1.28 raeburn 2893: }
1.160.6.78 raeburn 2894: $otheremails{$type} = $settings->{$type}{'others'};
2895: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2896: $bccemails{$type} = $settings->{$type}{'bcc'};
2897: if ($settings->{$type}{'include'} ne '') {
2898: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2899: $includestr{$type} = &unescape($includestr{$type});
2900: }
2901: }
2902: }
2903: } elsif ($type eq 'lonstatusmail') {
2904: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2905: }
2906: }
2907: }
2908: if ($position eq 'bottom') {
2909: foreach my $type (@mailings) {
2910: $bccemails{$type} = $settings->{$type}{'bcc'};
2911: if ($settings->{$type}{'include'} ne '') {
2912: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2913: $includestr{$type} = &unescape($includestr{$type});
2914: }
2915: }
2916: if (ref($settings->{'helpform'}) eq 'HASH') {
2917: if (ref($fields) eq 'ARRAY') {
2918: foreach my $field (@{$fields}) {
2919: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 2920: }
1.160.6.78 raeburn 2921: }
2922: if (exists($settings->{'helpform'}{'maxsize'})) {
2923: $maxsize = $settings->{'helpform'}{'maxsize'};
2924: } else {
2925: $maxsize = '1.0';
2926: }
2927: } else {
2928: if (ref($fields) eq 'ARRAY') {
2929: foreach my $field (@{$fields}) {
2930: $currfield{$field} = 'yes';
1.134 raeburn 2931: }
1.28 raeburn 2932: }
1.160.6.78 raeburn 2933: $maxsize = '1.0';
1.28 raeburn 2934: }
2935: }
2936: } else {
1.160.6.78 raeburn 2937: if ($position eq 'top') {
2938: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2939: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2940: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2941: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
2942: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2943: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
2944: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2945: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91 raeburn 2946: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78 raeburn 2947: } elsif ($position eq 'bottom') {
2948: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2949: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
2950: if (ref($fields) eq 'ARRAY') {
2951: foreach my $field (@{$fields}) {
2952: $currfield{$field} = 'yes';
2953: }
2954: }
2955: $maxsize = '1.0';
2956: }
1.28 raeburn 2957: }
2958: my ($titles,$short_titles) = &contact_titles();
2959: my $rownum = 0;
2960: my $css_class;
1.160.6.78 raeburn 2961: if ($position eq 'top') {
2962: foreach my $item (@contacts) {
2963: $css_class = $rownum%2?' class="LC_odd_row"':'';
2964: $datatable .= '<tr'.$css_class.'>'.
2965: '<td><span class="LC_nobreak">'.$titles->{$item}.
2966: '</span></td><td class="LC_right_item">'.
2967: '<input type="text" name="'.$item.'" value="'.
2968: $to{$item}.'" /></td></tr>';
2969: $rownum ++;
2970: }
1.160.6.101! raeburn 2971: } elsif ($position eq 'bottom') {
! 2972: $css_class = $rownum%2?' class="LC_odd_row"':'';
! 2973: $datatable .= '<tr'.$css_class.'>'.
! 2974: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
! 2975: &mt('(e-mail, subject, and description always shown)').
! 2976: '</td><td class="LC_left_item">';
! 2977: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
! 2978: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
! 2979: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
! 2980: foreach my $field (@{$fields}) {
! 2981: $datatable .= '<tr><td>'.$fieldtitles->{$field};
! 2982: if (($field eq 'screenshot') || ($field eq 'cc')) {
! 2983: $datatable .= ' '.&mt('(logged-in users)');
! 2984: }
! 2985: $datatable .='</td><td>';
! 2986: my $clickaction;
! 2987: if ($field eq 'screenshot') {
! 2988: $clickaction = ' onclick="screenshotSize(this);"';
! 2989: }
! 2990: if (ref($possoptions->{$field}) eq 'ARRAY') {
! 2991: foreach my $option (@{$possoptions->{$field}}) {
! 2992: my $checked;
! 2993: if ($currfield{$field} eq $option) {
! 2994: $checked = ' checked="checked"';
! 2995: }
! 2996: $datatable .= '<span class="LC_nobreak"><label>'.
! 2997: '<input type="radio" name="helpform_'.$field.'" '.
! 2998: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
! 2999: '</label></span>'.(' 'x2);
! 3000: }
! 3001: }
! 3002: if ($field eq 'screenshot') {
! 3003: my $display;
! 3004: if ($currfield{$field} eq 'no') {
! 3005: $display = ' style="display:none"';
! 3006: }
! 3007: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
! 3008: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
! 3009: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
! 3010: }
! 3011: $datatable .= '</td></tr>';
! 3012: }
! 3013: $datatable .= '</table>';
! 3014: }
! 3015: $datatable .= '</td></tr>'."\n";
! 3016: $rownum ++;
! 3017: }
! 3018: unless ($position eq 'top') {
1.160.6.78 raeburn 3019: foreach my $type (@mailings) {
3020: $css_class = $rownum%2?' class="LC_odd_row"':'';
3021: $datatable .= '<tr'.$css_class.'>'.
3022: '<td><span class="LC_nobreak">'.
3023: $titles->{$type}.': </span></td>'.
3024: '<td class="LC_left_item">';
3025: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3026: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3027: }
3028: $datatable .= '<span class="LC_nobreak">';
3029: foreach my $item (@contacts) {
3030: $datatable .= '<label>'.
3031: '<input type="checkbox" name="'.$type.'"'.
3032: $checked{$type}{$item}.
3033: ' value="'.$item.'" />'.$short_titles->{$item}.
3034: '</label> ';
3035: }
3036: $datatable .= '</span><br />'.&mt('Others').': '.
3037: '<input type="text" name="'.$type.'_others" '.
3038: 'value="'.$otheremails{$type}.'" />';
3039: my %locchecked;
3040: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3041: foreach my $loc ('s','b') {
3042: if ($includeloc{$type} eq $loc) {
3043: $locchecked{$loc} = ' checked="checked"';
3044: last;
3045: }
3046: }
3047: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3048: '<input type="text" name="'.$type.'_bcc" '.
3049: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3050: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3051: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 3052: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 3053: '<span class="LC_nobreak">'.&mt('Location:').' '.
3054: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3055: (' 'x2).
3056: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3057: '</span></fieldset>';
3058: }
3059: $datatable .= '</td></tr>'."\n";
3060: $rownum ++;
3061: }
1.28 raeburn 3062: }
1.160.6.78 raeburn 3063: if ($position eq 'middle') {
3064: my %choices;
3065: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
3066: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3067: &mt('LON-CAPA core group - MSU'),600,500));
3068: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3069: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3070: &mt('LON-CAPA core group - MSU'),600,500));
3071: my @toggles = ('reporterrors','reportupdates');
3072: my %defaultchecked = ('reporterrors' => 'on',
3073: 'reportupdates' => 'on');
3074: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3075: \%choices,$rownum);
3076: $datatable .= $reports;
3077: } elsif ($position eq 'bottom') {
1.160.6.101! raeburn 3078: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
! 3079: my (@posstypes,%usertypeshash);
! 3080: if (ref($types) eq 'ARRAY') {
! 3081: @posstypes = @{$types};
! 3082: }
! 3083: if (@posstypes) {
! 3084: if (ref($usertypes) eq 'HASH') {
! 3085: %usertypeshash = %{$usertypes};
! 3086: }
! 3087: my @overridden;
! 3088: my $numinrow = 4;
! 3089: if (ref($settings) eq 'HASH') {
! 3090: if (ref($settings->{'overrides'}) eq 'HASH') {
! 3091: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
! 3092: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
! 3093: push(@overridden,$key);
! 3094: foreach my $item (@contacts) {
! 3095: if ($settings->{'overrides'}{$key}{$item}) {
! 3096: $checked{'override_'.$key}{$item} = ' checked="checked" ';
! 3097: }
! 3098: }
! 3099: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
! 3100: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
! 3101: $includeloc{'override_'.$key} = '';
! 3102: $includestr{'override_'.$key} = '';
! 3103: if ($settings->{'overrides'}{$key}{'include'} ne '') {
! 3104: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
! 3105: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
! 3106: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
! 3107: }
1.160.6.78 raeburn 3108: }
3109: }
3110: }
1.160.6.101! raeburn 3111: }
! 3112: my $customclass = 'LC_helpdesk_override';
! 3113: my $optionsprefix = 'LC_options_helpdesk_';
! 3114:
! 3115: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
! 3116:
! 3117: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
! 3118: $numinrow,$othertitle,'overrides',
! 3119: \$rownum,$onclicktypes,$customclass);
! 3120: $rownum ++;
! 3121: $usertypeshash{'default'} = $othertitle;
! 3122: foreach my $status (@posstypes) {
! 3123: my $css_class;
! 3124: if ($rownum%2) {
! 3125: $css_class = 'LC_odd_row ';
! 3126: }
! 3127: $css_class .= $customclass;
! 3128: my $rowid = $optionsprefix.$status;
! 3129: my $hidden = 1;
! 3130: my $currstyle = 'display:none';
! 3131: if (grep(/^\Q$status\E$/,@overridden)) {
! 3132: $currstyle = 'display:table-row';
! 3133: $hidden = 0;
! 3134: }
! 3135: my $key = 'override_'.$status;
! 3136: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
! 3137: $includeloc{$key},$includestr{$key},$status,$rowid,
! 3138: $usertypeshash{$status},$css_class,$currstyle,
! 3139: \@contacts,$short_titles);
! 3140: unless ($hidden) {
! 3141: $rownum ++;
1.160.6.78 raeburn 3142: }
3143: }
1.134 raeburn 3144: }
1.28 raeburn 3145: }
1.30 raeburn 3146: $$rowtotal += $rownum;
1.28 raeburn 3147: return $datatable;
3148: }
3149:
1.160.6.101! raeburn 3150: sub overridden_helpdesk {
! 3151: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
! 3152: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
! 3153: my $class = 'LC_left_item';
! 3154: if ($css_class) {
! 3155: $css_class = ' class="'.$css_class.'"';
! 3156: }
! 3157: if ($rowid) {
! 3158: $rowid = ' id="'.$rowid.'"';
! 3159: }
! 3160: if ($rowstyle) {
! 3161: $rowstyle = ' style="'.$rowstyle.'"';
! 3162: }
! 3163: my ($output,$description);
! 3164: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
! 3165: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
! 3166: "<td>$description</td>\n".
! 3167: '<td class="'.$class.'" colspan="2">'.
! 3168: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
! 3169: '<span class="LC_nobreak">';
! 3170: if (ref($contacts) eq 'ARRAY') {
! 3171: foreach my $item (@{$contacts}) {
! 3172: my $check;
! 3173: if (ref($checked) eq 'HASH') {
! 3174: $check = $checked->{$item};
! 3175: }
! 3176: my $title;
! 3177: if (ref($short_titles) eq 'HASH') {
! 3178: $title = $short_titles->{$item};
! 3179: }
! 3180: $output .= '<label>'.
! 3181: '<input type="checkbox" name="override_'.$type.'"'.$check.
! 3182: ' value="'.$item.'" />'.$title.'</label> ';
! 3183: }
! 3184: }
! 3185: $output .= '</span><br />'.&mt('Others').': '.
! 3186: '<input type="text" name="override_'.$type.'_others" '.
! 3187: 'value="'.$otheremails.'" />';
! 3188: my %locchecked;
! 3189: foreach my $loc ('s','b') {
! 3190: if ($includeloc eq $loc) {
! 3191: $locchecked{$loc} = ' checked="checked"';
! 3192: last;
! 3193: }
! 3194: }
! 3195: $output .= '<br />'.&mt('Bcc:').(' 'x6).
! 3196: '<input type="text" name="override_'.$type.'_bcc" '.
! 3197: 'value="'.$bccemails.'" /></fieldset>'.
! 3198: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
! 3199: &mt('Text automatically added to e-mail:').' '.
! 3200: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
! 3201: '<span class="LC_nobreak">'.&mt('Location:').' '.
! 3202: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
! 3203: (' 'x2).
! 3204: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
! 3205: '</span></fieldset>'.
! 3206: '</td></tr>'."\n";
! 3207: return $output;
! 3208: }
! 3209:
1.160.6.78 raeburn 3210: sub contacts_javascript {
3211: return <<"ENDSCRIPT";
3212:
3213: <script type="text/javascript">
3214: // <![CDATA[
3215:
3216: function screenshotSize(field) {
3217: if (document.getElementById('help_screenshotsize')) {
3218: if (field.value == 'no') {
3219: document.getElementById('help_screenshotsize').style.display="none";
3220: } else {
3221: document.getElementById('help_screenshotsize').style.display="";
3222: }
3223: }
3224: return;
3225: }
3226:
1.160.6.101! raeburn 3227: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
! 3228: if (form.elements[checkbox].length != undefined) {
! 3229: var count = 0;
! 3230: if (docount) {
! 3231: for (var i=0; i<form.elements[checkbox].length; i++) {
! 3232: if (form.elements[checkbox][i].checked) {
! 3233: count ++;
! 3234: }
! 3235: }
! 3236: }
! 3237: for (var i=0; i<form.elements[checkbox].length; i++) {
! 3238: var type = form.elements[checkbox][i].value;
! 3239: if (document.getElementById(prefix+type)) {
! 3240: if (form.elements[checkbox][i].checked) {
! 3241: document.getElementById(prefix+type).style.display = 'table-row';
! 3242: if (count % 2 == 1) {
! 3243: document.getElementById(prefix+type).className = target+' LC_odd_row';
! 3244: } else {
! 3245: document.getElementById(prefix+type).className = target;
! 3246: }
! 3247: count ++;
! 3248: } else {
! 3249: document.getElementById(prefix+type).style.display = 'none';
! 3250: }
! 3251: }
! 3252: }
! 3253: }
! 3254: return;
! 3255: }
! 3256:
1.160.6.78 raeburn 3257: // ]]>
3258: </script>
3259:
3260: ENDSCRIPT
3261: }
3262:
1.118 jms 3263: sub print_helpsettings {
1.160.6.73 raeburn 3264: my ($position,$dom,$settings,$rowtotal) = @_;
3265: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 3266: my $formname = 'display';
1.160.6.5 raeburn 3267: my ($datatable,$itemcount);
1.160.6.73 raeburn 3268: if ($position eq 'top') {
3269: $itemcount = 1;
3270: my (%choices,%defaultchecked,@toggles);
3271: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3272: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3273: &mt('LON-CAPA bug tracker'),600,500));
3274: %defaultchecked = ('submitbugs' => 'on');
3275: @toggles = ('submitbugs');
3276: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3277: \%choices,$itemcount);
3278: $$rowtotal ++;
3279: } else {
3280: my $css_class;
3281: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 3282: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 3283: if (ref($settings) eq 'HASH') {
3284: if (ref($settings->{'adhoc'}) eq 'HASH') {
3285: %current = %{$settings->{'adhoc'}};
3286: }
1.160.6.77 raeburn 3287: }
3288: my $count = 0;
3289: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 3290: if ($key=~/^rolesdef\_(\w+)$/) {
3291: my $rolename = $1;
1.160.6.77 raeburn 3292: my (%privs,$order);
1.160.6.73 raeburn 3293: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3294: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 3295: if (ref($current{$rolename}) eq 'HASH') {
3296: $order = $current{$rolename}{'order'};
3297: }
3298: if ($order eq '') {
3299: $order = $count;
3300: }
3301: $ordered{$order} = $rolename;
3302: $count++;
1.160.6.73 raeburn 3303: }
3304: }
1.160.6.77 raeburn 3305: my $maxnum = scalar(keys(%ordered));
3306: my @roles_by_num = ();
3307: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3308: push(@roles_by_num,$item);
3309: }
3310: my $context = 'domprefs';
3311: my $crstype = 'Course';
3312: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 3313: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 3314: my ($numstatustypes,@jsarray);
3315: if (ref($types) eq 'ARRAY') {
3316: if (@{$types} > 0) {
3317: $numstatustypes = scalar(@{$types});
3318: push(@accesstypes,'status');
3319: @jsarray = ('bystatus');
3320: }
3321: }
1.160.6.86 raeburn 3322: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 3323: if (keys(%domhelpdesk)) {
3324: push(@accesstypes,('inc','exc'));
3325: push(@jsarray,('notinc','notexc'));
3326: }
3327: my $hiddenstr = join("','",@jsarray);
3328: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 3329: my $context = 'domprefs';
3330: my $crstype = 'Course';
1.160.6.77 raeburn 3331: my $prefix = 'helproles_';
3332: my $add_class = 'LC_hidden';
3333: foreach my $num (@roles_by_num) {
3334: my $role = $ordered{$num};
3335: my ($desc,$access,@statuses);
3336: if (ref($current{$role}) eq 'HASH') {
3337: $desc = $current{$role}{'desc'};
3338: $access = $current{$role}{'access'};
3339: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3340: @statuses = @{$current{$role}{'insttypes'}};
3341: }
3342: }
3343: if ($desc eq '') {
3344: $desc = $role;
3345: }
3346: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 3347: my %full=();
3348: my %levels= (
3349: course => {},
3350: domain => {},
3351: system => {},
3352: );
3353: my %levelscurrent=(
3354: course => {},
3355: domain => {},
3356: system => {},
3357: );
3358: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3359: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3360: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 3361: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3362: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3363: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3364: for (my $k=0; $k<=$maxnum; $k++) {
3365: my $vpos = $k+1;
3366: my $selstr;
3367: if ($k == $num) {
3368: $selstr = ' selected="selected" ';
3369: }
3370: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3371: }
3372: $datatable .= '</select>'.(' 'x2).
3373: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3374: '</td>'.
3375: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3376: &mt('Name shown to users:').
3377: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3378: '</fieldset>'.
3379: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3380: $othertitle,$usertypes,$types,\%domhelpdesk).
3381: '<fieldset>'.
3382: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 3383: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 3384: \%levelscurrent,$identifier,
3385: 'LC_hidden',$prefix.$num.'_privs').
3386: '</fieldset></td>';
1.160.6.73 raeburn 3387: $itemcount ++;
3388: }
3389: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3390: my $newcust = 'custhelp'.$count;
3391: my (%privs,%levelscurrent);
3392: my %full=();
3393: my %levels= (
3394: course => {},
3395: domain => {},
3396: system => {},
3397: );
3398: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3399: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 3400: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3401: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3402: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3403: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3404: for (my $k=0; $k<$maxnum+1; $k++) {
3405: my $vpos = $k+1;
3406: my $selstr;
3407: if ($k == $maxnum) {
3408: $selstr = ' selected="selected" ';
3409: }
3410: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3411: }
3412: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 3413: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3414: '</label></span></td>'.
1.160.6.77 raeburn 3415: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3416: '<span class="LC_nobreak">'.
3417: &mt('Internal name:').
3418: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3419: '</span>'.(' 'x4).
3420: '<span class="LC_nobreak">'.
3421: &mt('Name shown to users:').
3422: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3423: '</span></fieldset>'.
3424: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3425: $usertypes,$types,\%domhelpdesk).
3426: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 3427: &Apache::lonuserutils::custom_role_header($context,$crstype,
3428: \@templateroles,$newcust).
3429: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3430: \%levelscurrent,$newcust).
1.160.6.87 raeburn 3431: '</fieldset>'.
3432: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
3433: '</td></tr>';
1.160.6.73 raeburn 3434: $count ++;
3435: $$rowtotal += $count;
3436: }
1.160.6.5 raeburn 3437: return $datatable;
1.121 raeburn 3438: }
3439:
1.160.6.77 raeburn 3440: sub adhocbutton {
3441: my ($prefix,$num,$field,$visibility) = @_;
3442: my %lt = &Apache::lonlocal::texthash(
3443: show => 'Show details',
3444: hide => 'Hide details',
3445: );
3446: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3447: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3448: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3449: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3450: }
3451:
3452: sub helpsettings_javascript {
3453: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3454: return unless(ref($roles_by_num) eq 'ARRAY');
3455: my %html_js_lt = &Apache::lonlocal::texthash(
3456: show => 'Show details',
3457: hide => 'Hide details',
3458: );
3459: &html_escape(\%html_js_lt);
3460: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3461: return <<"ENDSCRIPT";
3462: <script type="text/javascript">
3463: // <![CDATA[
3464:
3465: function reorderHelpRoles(form,item) {
3466: var changedVal;
3467: $jstext
3468: var newpos = 'helproles_${total}_pos';
3469: var maxh = 1 + $total;
3470: var current = new Array();
3471: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3472: if (item == newpos) {
3473: changedVal = newitemVal;
3474: } else {
3475: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3476: current[newitemVal] = newpos;
3477: }
3478: for (var i=0; i<helproles.length; i++) {
3479: var elementName = 'helproles_'+helproles[i]+'_pos';
3480: if (elementName != item) {
3481: if (form.elements[elementName]) {
3482: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3483: current[currVal] = elementName;
3484: }
3485: }
3486: }
3487: var oldVal;
3488: for (var j=0; j<maxh; j++) {
3489: if (current[j] == undefined) {
3490: oldVal = j;
3491: }
3492: }
3493: if (oldVal < changedVal) {
3494: for (var k=oldVal+1; k<=changedVal ; k++) {
3495: var elementName = current[k];
3496: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3497: }
3498: } else {
3499: for (var k=changedVal; k<oldVal; k++) {
3500: var elementName = current[k];
3501: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3502: }
3503: }
3504: return;
3505: }
3506:
3507: function helpdeskAccess(num) {
3508: var curraccess = null;
3509: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3510: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3511: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3512: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3513: }
3514: }
3515: }
3516: var shown = Array();
3517: var hidden = Array();
3518: if (curraccess == 'none') {
3519: hidden = Array('$hiddenstr');
3520: } else {
3521: if (curraccess == 'status') {
3522: shown = Array('bystatus');
3523: hidden = Array('notinc','notexc');
3524: } else {
3525: if (curraccess == 'exc') {
3526: shown = Array('notexc');
3527: hidden = Array('notinc','bystatus');
3528: }
3529: if (curraccess == 'inc') {
3530: shown = Array('notinc');
3531: hidden = Array('notexc','bystatus');
3532: }
1.160.6.79 raeburn 3533: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 3534: hidden = Array('notinc','notexc','bystatus');
3535: }
3536: }
3537: }
3538: if (hidden.length > 0) {
3539: for (var i=0; i<hidden.length; i++) {
3540: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3541: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3542: }
3543: }
3544: }
3545: if (shown.length > 0) {
3546: for (var i=0; i<shown.length; i++) {
3547: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3548: if (shown[i] == 'privs') {
3549: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3550: } else {
3551: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3552: }
3553: }
3554: }
3555: }
3556: return;
3557: }
3558:
3559: function toggleHelpdeskItem(num,field) {
3560: if (document.getElementById('helproles_'+num+'_'+field)) {
3561: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
3562: document.getElementById('helproles_'+num+'_'+field).className =
3563: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3564: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3565: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3566: }
3567: } else {
3568: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3569: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3570: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3571: }
3572: }
3573: }
3574: return;
3575: }
3576:
3577: // ]]>
3578: </script>
3579:
3580: ENDSCRIPT
3581: }
3582:
3583: sub helpdeskroles_access {
3584: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3585: $usertypes,$types,$domhelpdesk) = @_;
3586: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3587: my %lt = &Apache::lonlocal::texthash(
3588: 'rou' => 'Role usage',
3589: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 3590: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3591: 'dh' => 'All with domain helpdesk role',
3592: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 3593: 'none' => 'None',
3594: 'status' => 'Determined based on institutional status',
3595: 'inc' => 'Include all, but exclude specific personnel',
3596: 'exc' => 'Exclude all, but include specific personnel',
3597: );
3598: my %usecheck = (
3599: all => ' checked="checked"',
3600: );
3601: my %displaydiv = (
3602: status => 'none',
3603: inc => 'none',
3604: exc => 'none',
3605: priv => 'block',
3606: );
3607: my $output;
3608: if (ref($current) eq 'HASH') {
3609: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3610: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3611: $usecheck{$current->{access}} = $usecheck{'all'};
3612: delete($usecheck{'all'});
3613: if ($current->{access} =~ /^(status|inc|exc)$/) {
3614: my $access = $1;
3615: $displaydiv{$access} = 'inline';
3616: } elsif ($current->{access} eq 'none') {
3617: $displaydiv{'priv'} = 'none';
3618: }
3619: }
3620: }
3621: }
3622: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3623: '<p>'.$lt{'whi'}.'</p>';
3624: foreach my $access (@{$accesstypes}) {
3625: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3626: ' onclick="helpdeskAccess('."'$num'".');" />'.
3627: $lt{$access}.'</label>';
3628: if ($access eq 'status') {
3629: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3630: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3631: $othertitle,$usertypes,$types).
3632: '</div>';
3633: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3634: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3635: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3636: '</div>';
3637: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3638: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3639: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3640: '</div>';
3641: }
3642: $output .= '</p>';
3643: }
3644: $output .= '</fieldset>';
3645: return $output;
3646: }
3647:
1.121 raeburn 3648: sub radiobutton_prefs {
1.160.6.16 raeburn 3649: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 3650: $additional,$align) = @_;
1.121 raeburn 3651: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3652: (ref($choices) eq 'HASH'));
3653:
3654: my (%checkedon,%checkedoff,$datatable,$css_class);
3655:
3656: foreach my $item (@{$toggles}) {
3657: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3658: $checkedon{$item} = ' checked="checked" ';
3659: $checkedoff{$item} = ' ';
1.121 raeburn 3660: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3661: $checkedoff{$item} = ' checked="checked" ';
3662: $checkedon{$item} = ' ';
3663: }
3664: }
3665: if (ref($settings) eq 'HASH') {
1.121 raeburn 3666: foreach my $item (@{$toggles}) {
1.118 jms 3667: if ($settings->{$item} eq '1') {
3668: $checkedon{$item} = ' checked="checked" ';
3669: $checkedoff{$item} = ' ';
3670: } elsif ($settings->{$item} eq '0') {
3671: $checkedoff{$item} = ' checked="checked" ';
3672: $checkedon{$item} = ' ';
3673: }
3674: }
1.121 raeburn 3675: }
1.160.6.16 raeburn 3676: if ($onclick) {
3677: $onclick = ' onclick="'.$onclick.'"';
3678: }
1.121 raeburn 3679: foreach my $item (@{$toggles}) {
1.118 jms 3680: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3681: $datatable .=
1.160.6.16 raeburn 3682: '<tr'.$css_class.'><td valign="top">'.
3683: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 3684: '</span></td>';
3685: if ($align eq 'left') {
3686: $datatable .= '<td class="LC_left_item">';
3687: } else {
3688: $datatable .= '<td class="LC_right_item">';
3689: }
3690: $datatable .=
3691: '<span class="LC_nobreak">'.
1.118 jms 3692: '<label><input type="radio" name="'.
1.160.6.16 raeburn 3693: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3694: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 3695: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3696: '</span>'.$additional.
3697: '</td>'.
1.118 jms 3698: '</tr>';
3699: $itemcount ++;
1.121 raeburn 3700: }
3701: return ($datatable,$itemcount);
3702: }
3703:
3704: sub print_coursedefaults {
1.139 raeburn 3705: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3706: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3707: my $itemcount = 1;
1.160.6.16 raeburn 3708: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 3709: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 3710: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3711: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 3712: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3713: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.90 raeburn 3714: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 3715: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 3716: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 3717: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 3718: );
1.160.6.21 raeburn 3719: my %staticdefaults = (
3720: anonsurvey_threshold => 10,
3721: uploadquota => 500,
1.160.6.57 raeburn 3722: postsubmit => 60,
1.160.6.70 raeburn 3723: mysqltables => 172800,
1.160.6.21 raeburn 3724: );
1.139 raeburn 3725: if ($position eq 'top') {
1.160.6.57 raeburn 3726: %defaultchecked = (
3727: 'uselcmath' => 'on',
3728: 'usejsme' => 'on',
1.160.6.64 raeburn 3729: 'canclone' => 'none',
1.160.6.57 raeburn 3730: );
3731: @toggles = ('uselcmath','usejsme');
1.160.6.90 raeburn 3732: my $deftex = $Apache::lonnet::deftex;
3733: if (ref($settings) eq 'HASH') {
3734: if ($settings->{'texengine'}) {
3735: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
3736: $deftex = $settings->{'texengine'};
3737: }
3738: }
3739: }
3740: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3741: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
3742: '<span class="LC_nobreak">'.$choices{'texengine'}.
3743: '</span></td><td class="LC_right_item">'.
3744: '<select name="texengine">'."\n";
3745: my %texoptions = (
3746: MathJax => 'MathJax',
3747: mimetex => &mt('Convert to Images'),
3748: tth => &mt('TeX to HTML'),
3749: );
3750: foreach my $renderer ('MathJax','mimetex','tth') {
3751: my $selected = '';
3752: if ($renderer eq $deftex) {
3753: $selected = ' selected="selected"';
3754: }
3755: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
3756: }
3757: $mathdisp .= '</select></td></tr>'."\n";
3758: $itemcount ++;
1.139 raeburn 3759: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3760: \%choices,$itemcount);
1.160.6.90 raeburn 3761: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 3762: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3763: $datatable .=
3764: '<tr'.$css_class.'><td valign="top">'.
3765: '<span class="LC_nobreak">'.$choices{'canclone'}.
3766: '</span></td><td class="LC_left_item">';
3767: my $currcanclone = 'none';
3768: my $onclick;
3769: my @cloneoptions = ('none','domain');
3770: my %clonetitles = (
3771: none => 'No additional course requesters',
3772: domain => "Any course requester in course's domain",
3773: instcode => 'Course requests for official courses ...',
3774: );
3775: my (%codedefaults,@code_order,@posscodes);
3776: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3777: \@code_order) eq 'ok') {
3778: if (@code_order > 0) {
3779: push(@cloneoptions,'instcode');
3780: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3781: }
3782: }
3783: if (ref($settings) eq 'HASH') {
3784: if ($settings->{'canclone'}) {
3785: if (ref($settings->{'canclone'}) eq 'HASH') {
3786: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3787: if (@code_order > 0) {
3788: $currcanclone = 'instcode';
3789: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3790: }
3791: }
3792: } elsif ($settings->{'canclone'} eq 'domain') {
3793: $currcanclone = $settings->{'canclone'};
3794: }
3795: }
3796: }
3797: foreach my $option (@cloneoptions) {
3798: my ($checked,$additional);
3799: if ($currcanclone eq $option) {
3800: $checked = ' checked="checked"';
3801: }
3802: if ($option eq 'instcode') {
3803: if (@code_order) {
3804: my $show = 'none';
3805: if ($checked) {
3806: $show = 'block';
3807: }
3808: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3809: &mt('Institutional codes for new and cloned course have identical:').
3810: '<br />';
3811: foreach my $item (@code_order) {
3812: my $codechk;
3813: if ($checked) {
3814: if (grep(/^\Q$item\E$/,@posscodes)) {
3815: $codechk = ' checked="checked"';
3816: }
3817: }
3818: $additional .= '<label>'.
3819: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3820: $item.'</label>';
3821: }
3822: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3823: }
3824: }
3825: $datatable .=
3826: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3827: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3828: '</label> '.$additional.'</span><br />';
3829: }
3830: $datatable .= '</td>'.
3831: '</tr>';
3832: $itemcount ++;
1.139 raeburn 3833: } else {
3834: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 3835: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 3836: my $currusecredits = 0;
1.160.6.57 raeburn 3837: my $postsubmitclient = 1;
1.160.6.30 raeburn 3838: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 3839: if (ref($settings) eq 'HASH') {
3840: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 3841: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3842: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3843: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3844: }
3845: }
1.160.6.16 raeburn 3846: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 3847: foreach my $type (@types) {
3848: next if ($type eq 'community');
3849: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3850: if ($defcredits{$type} ne '') {
3851: $currusecredits = 1;
3852: }
3853: }
3854: }
3855: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3856: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3857: $postsubmitclient = 0;
3858: foreach my $type (@types) {
3859: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3860: }
3861: } else {
3862: foreach my $type (@types) {
3863: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3864: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3865: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3866: } else {
3867: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3868: }
3869: } else {
3870: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3871: }
3872: }
3873: }
3874: } else {
3875: foreach my $type (@types) {
3876: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 3877: }
3878: }
1.160.6.70 raeburn 3879: if (ref($settings->{'mysqltables'}) eq 'HASH') {
3880: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
3881: $currmysql{$type} = $settings->{'mysqltables'}{$type};
3882: }
3883: } else {
3884: foreach my $type (@types) {
3885: $currmysql{$type} = $staticdefaults{'mysqltables'};
3886: }
3887: }
1.160.6.58 raeburn 3888: } else {
3889: foreach my $type (@types) {
3890: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3891: }
1.139 raeburn 3892: }
3893: if (!$currdefresponder) {
1.160.6.21 raeburn 3894: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3895: } elsif ($currdefresponder < 1) {
3896: $currdefresponder = 1;
3897: }
1.160.6.21 raeburn 3898: foreach my $type (@types) {
3899: if ($curruploadquota{$type} eq '') {
3900: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3901: }
3902: }
1.139 raeburn 3903: $datatable .=
1.160.6.16 raeburn 3904: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3905: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3906: '</span></td>'.
3907: '<td class="LC_right_item"><span class="LC_nobreak">'.
3908: '<input type="text" name="anonsurvey_threshold"'.
3909: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 3910: '</td></tr>'."\n";
3911: $itemcount ++;
3912: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3913: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3914: $choices{'uploadquota'}.
3915: '</span></td>'.
3916: '<td align="right" class="LC_right_item">'.
3917: '<table><tr>';
1.160.6.21 raeburn 3918: foreach my $type (@types) {
3919: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3920: '<input type="text" name="uploadquota_'.$type.'"'.
3921: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3922: }
3923: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 3924: $itemcount ++;
1.160.6.40 raeburn 3925: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 3926: my $display = 'none';
3927: if ($currusecredits) {
3928: $display = 'block';
3929: }
3930: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 3931: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3932: foreach my $type (@types) {
3933: next if ($type eq 'community');
3934: $additional .= '<td align="center">'.&mt($type).'<br />'.
3935: '<input type="text" name="'.$type.'_credits"'.
3936: ' value="'.$defcredits{$type}.'" size="3" /></td>';
3937: }
3938: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 3939: %defaultchecked = ('coursecredits' => 'off');
3940: @toggles = ('coursecredits');
3941: my $current = {
3942: 'coursecredits' => $currusecredits,
3943: };
3944: (my $table,$itemcount) =
3945: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3946: \%choices,$itemcount,$onclick,$additional,'left');
3947: $datatable .= $table;
3948: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3949: my $display = 'none';
3950: if ($postsubmitclient) {
3951: $display = 'block';
3952: }
3953: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 3954: &mt('Number of seconds submit is disabled').'<br />'.
3955: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3956: '<table><tr>';
1.160.6.57 raeburn 3957: foreach my $type (@types) {
3958: $additional .= '<td align="center">'.&mt($type).'<br />'.
3959: '<input type="text" name="'.$type.'_timeout" value="'.
3960: $deftimeout{$type}.'" size="5" /></td>';
3961: }
3962: $additional .= '</tr></table></div>'."\n";
3963: %defaultchecked = ('postsubmit' => 'on');
3964: @toggles = ('postsubmit');
1.160.6.70 raeburn 3965: $current = {
3966: 'postsubmit' => $postsubmitclient,
3967: };
1.160.6.57 raeburn 3968: ($table,$itemcount) =
3969: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3970: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 3971: $datatable .= $table;
1.160.6.70 raeburn 3972: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3973: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3974: $choices{'mysqltables'}.
3975: '</span></td>'.
3976: '<td align="right" class="LC_right_item">'.
3977: '<table><tr>';
3978: foreach my $type (@types) {
3979: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3980: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 3981: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 3982: }
3983: $datatable .= '</tr></table></td></tr>'."\n";
3984: $itemcount ++;
3985:
1.160.6.37 raeburn 3986: }
3987: $$rowtotal += $itemcount;
3988: return $datatable;
3989: }
3990:
3991: sub print_selfenrollment {
3992: my ($position,$dom,$settings,$rowtotal) = @_;
3993: my ($css_class,$datatable);
3994: my $itemcount = 1;
3995: my @types = ('official','unofficial','community','textbook');
3996: if (($position eq 'top') || ($position eq 'middle')) {
3997: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3998: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
3999: my @rows;
4000: my $key;
4001: if ($position eq 'top') {
4002: $key = 'admin';
4003: if (ref($rowsref) eq 'ARRAY') {
4004: @rows = @{$rowsref};
4005: }
4006: } elsif ($position eq 'middle') {
4007: $key = 'default';
4008: @rows = ('types','registered','approval','limit');
4009: }
4010: foreach my $row (@rows) {
4011: if (defined($titlesref->{$row})) {
4012: $itemcount ++;
4013: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4014: $datatable .= '<tr'.$css_class.'>'.
4015: '<td>'.$titlesref->{$row}.'</td>'.
4016: '<td class="LC_left_item">'.
4017: '<table><tr>';
4018: my (%current,%currentcap);
4019: if (ref($settings) eq 'HASH') {
4020: if (ref($settings->{$key}) eq 'HASH') {
4021: foreach my $type (@types) {
4022: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4023: $current{$type} = $settings->{$key}->{$type}->{$row};
4024: }
4025: if (($row eq 'limit') && ($key eq 'default')) {
4026: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4027: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4028: }
4029: }
4030: }
4031: }
4032: }
4033: my %roles = (
4034: '0' => &Apache::lonnet::plaintext('dc'),
4035: );
4036:
4037: foreach my $type (@types) {
4038: unless (($row eq 'registered') && ($key eq 'default')) {
4039: $datatable .= '<th>'.&mt($type).'</th>';
4040: }
4041: }
4042: unless (($row eq 'registered') && ($key eq 'default')) {
4043: $datatable .= '</tr><tr>';
4044: }
4045: foreach my $type (@types) {
4046: if ($type eq 'community') {
4047: $roles{'1'} = &mt('Community personnel');
4048: } else {
4049: $roles{'1'} = &mt('Course personnel');
4050: }
4051: $datatable .= '<td style="vertical-align: top">';
4052: if ($position eq 'top') {
4053: my %checked;
4054: if ($current{$type} eq '0') {
4055: $checked{'0'} = ' checked="checked"';
4056: } else {
4057: $checked{'1'} = ' checked="checked"';
4058: }
4059: foreach my $role ('1','0') {
4060: $datatable .= '<span class="LC_nobreak"><label>'.
4061: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4062: 'value="'.$role.'"'.$checked{$role}.' />'.
4063: $roles{$role}.'</label></span> ';
4064: }
4065: } else {
4066: if ($row eq 'types') {
4067: my %checked;
4068: if ($current{$type} =~ /^(all|dom)$/) {
4069: $checked{$1} = ' checked="checked"';
4070: } else {
4071: $checked{''} = ' checked="checked"';
4072: }
4073: foreach my $val ('','dom','all') {
4074: $datatable .= '<span class="LC_nobreak"><label>'.
4075: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4076: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4077: }
4078: } elsif ($row eq 'registered') {
4079: my %checked;
4080: if ($current{$type} eq '1') {
4081: $checked{'1'} = ' checked="checked"';
4082: } else {
4083: $checked{'0'} = ' checked="checked"';
4084: }
4085: foreach my $val ('0','1') {
4086: $datatable .= '<span class="LC_nobreak"><label>'.
4087: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4088: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4089: }
4090: } elsif ($row eq 'approval') {
4091: my %checked;
4092: if ($current{$type} =~ /^([12])$/) {
4093: $checked{$1} = ' checked="checked"';
4094: } else {
4095: $checked{'0'} = ' checked="checked"';
4096: }
4097: for my $val (0..2) {
4098: $datatable .= '<span class="LC_nobreak"><label>'.
4099: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4100: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4101: }
4102: } elsif ($row eq 'limit') {
4103: my %checked;
4104: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4105: $checked{$1} = ' checked="checked"';
4106: } else {
4107: $checked{'none'} = ' checked="checked"';
4108: }
4109: my $cap;
4110: if ($currentcap{$type} =~ /^\d+$/) {
4111: $cap = $currentcap{$type};
4112: }
4113: foreach my $val ('none','allstudents','selfenrolled') {
4114: $datatable .= '<span class="LC_nobreak"><label>'.
4115: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4116: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4117: }
4118: $datatable .= '<br />'.
4119: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4120: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4121: '</span>';
4122: }
4123: }
4124: $datatable .= '</td>';
4125: }
4126: $datatable .= '</tr>';
4127: }
4128: $datatable .= '</table></td></tr>';
4129: }
4130: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 4131: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4132: }
4133: $$rowtotal += $itemcount;
4134: return $datatable;
4135: }
4136:
4137: sub print_validation_rows {
4138: my ($caller,$dom,$settings,$rowtotal) = @_;
4139: my ($itemsref,$namesref,$fieldsref);
4140: if ($caller eq 'selfenroll') {
4141: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4142: } elsif ($caller eq 'requestcourses') {
4143: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4144: }
4145: my %currvalidation;
4146: if (ref($settings) eq 'HASH') {
4147: if (ref($settings->{'validation'}) eq 'HASH') {
4148: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 4149: }
1.160.6.39 raeburn 4150: }
4151: my $datatable;
4152: my $itemcount = 0;
4153: foreach my $item (@{$itemsref}) {
4154: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4155: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4156: $namesref->{$item}.
4157: '</span></td>'.
4158: '<td class="LC_left_item">';
4159: if (($item eq 'url') || ($item eq 'button')) {
4160: $datatable .= '<span class="LC_nobreak">'.
4161: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4162: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4163: } elsif ($item eq 'fields') {
4164: my @currfields;
4165: if (ref($currvalidation{$item}) eq 'ARRAY') {
4166: @currfields = @{$currvalidation{$item}};
4167: }
4168: foreach my $field (@{$fieldsref}) {
4169: my $check = '';
4170: if (grep(/^\Q$field\E$/,@currfields)) {
4171: $check = ' checked="checked"';
4172: }
4173: $datatable .= '<span class="LC_nobreak"><label>'.
4174: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4175: ' value="'.$field.'"'.$check.' />'.$field.
4176: '</label></span> ';
4177: }
4178: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 4179: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 4180: $currvalidation{$item}.
1.160.6.37 raeburn 4181: '</textarea>';
1.160.6.39 raeburn 4182: }
4183: $datatable .= '</td></tr>'."\n";
4184: if (ref($rowtotal)) {
1.160.6.37 raeburn 4185: $itemcount ++;
4186: }
1.139 raeburn 4187: }
1.160.6.39 raeburn 4188: if ($caller eq 'requestcourses') {
4189: my %currhash;
1.160.6.51 raeburn 4190: if (ref($settings) eq 'HASH') {
4191: if (ref($settings->{'validation'}) eq 'HASH') {
4192: if ($settings->{'validation'}{'dc'} ne '') {
4193: $currhash{$settings->{'validation'}{'dc'}} = 1;
4194: }
1.160.6.39 raeburn 4195: }
4196: }
4197: my $numinrow = 2;
4198: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4199: 'validationdc',%currhash);
1.160.6.50 raeburn 4200: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 4201: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 4202: if ($numdc > 1) {
1.160.6.50 raeburn 4203: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 4204: } else {
1.160.6.50 raeburn 4205: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 4206: }
1.160.6.50 raeburn 4207: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 4208: $itemcount ++;
4209: }
4210: if (ref($rowtotal)) {
4211: $$rowtotal += $itemcount;
4212: }
1.121 raeburn 4213: return $datatable;
1.118 jms 4214: }
4215:
1.160.6.98 raeburn 4216: sub print_passwords {
4217: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
4218: my ($datatable,$css_class);
4219: my $itemcount = 0;
4220: my %titles = &Apache::lonlocal::texthash (
4221: captcha => '"Forgot Password" CAPTCHA validation',
4222: link => 'Reset link expiration (hours)',
4223: case => 'Case-sensitive usernames/e-mail',
4224: prelink => 'Information required (form 1)',
4225: postlink => 'Information required (form 2)',
4226: emailsrc => 'LON-CAPA e-mail address type(s)',
4227: customtext => 'Domain specific text (HTML)',
4228: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
4229: intauth_check => 'Check bcrypt cost if authenticated',
4230: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
4231: permanent => 'Permanent e-mail address',
4232: critical => 'Critical notification address',
4233: notify => 'Notification address',
4234: min => 'Minimum password length',
4235: max => 'Maximum password length',
4236: chars => 'Required characters',
4237: numsaved => 'Number of previous passwords to save and disallow reuse',
4238: );
4239: if ($position eq 'top') {
4240: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4241: my $shownlinklife = 2;
4242: my $prelink = 'both';
4243: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
4244: if (ref($settings) eq 'HASH') {
4245: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
4246: $shownlinklife = $settings->{resetlink};
4247: }
4248: if (ref($settings->{resetcase}) eq 'ARRAY') {
4249: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
4250: }
4251: if ($settings->{resetprelink} =~ /^(both|either)$/) {
4252: $prelink = $settings->{resetprelink};
4253: }
4254: if (ref($settings->{resetpostlink}) eq 'HASH') {
4255: %postlink = %{$settings->{resetpostlink}};
4256: }
4257: if (ref($settings->{resetemail}) eq 'ARRAY') {
4258: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
4259: }
4260: if ($settings->{resetremove}) {
4261: $nostdtext = 1;
4262: }
4263: if ($settings->{resetcustom}) {
4264: $customurl = $settings->{resetcustom};
4265: }
4266: } else {
4267: if (ref($types) eq 'ARRAY') {
4268: foreach my $item (@{$types}) {
4269: $casesens{$item} = 1;
4270: $postlink{$item} = ['username','email'];
4271: }
4272: }
4273: $casesens{'default'} = 1;
4274: $postlink{'default'} = ['username','email'];
4275: $prelink = 'both';
4276: %emailsrc = (
4277: permanent => 1,
4278: critical => 1,
4279: notify => 1,
4280: );
4281: }
4282: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
4283: $itemcount ++;
4284: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4285: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
4286: '<td class="LC_left_item">'.
4287: '<input type="textbox" value="'.$shownlinklife.'" '.
4288: 'name="passwords_link" size="3" /></td></tr>';
4289: $itemcount ++;
4290: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4291: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
4292: '<td class="LC_left_item">';
4293: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
4294: foreach my $item (@{$types}) {
4295: my $checkedcase;
4296: if ($casesens{$item}) {
4297: $checkedcase = ' checked="checked"';
4298: }
4299: $datatable .= '<span class="LC_nobreak"><label>'.
4300: '<input type="checkbox" name="passwords_case_sensitive" value="'.
4301: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
4302: '<span> ';
4303: }
4304: }
4305: my $checkedcase;
4306: if ($casesens{'default'}) {
4307: $checkedcase = ' checked="checked"';
4308: }
4309: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
4310: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
4311: $othertitle.'</label></span></td>';
4312: $itemcount ++;
4313: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4314: my %checkedpre = (
4315: both => ' checked="checked"',
4316: either => '',
4317: );
4318: if ($prelink eq 'either') {
4319: $checkedpre{either} = ' checked="checked"';
4320: $checkedpre{both} = '';
4321: }
4322: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
4323: '<td class="LC_left_item"><span class="LC_nobreak">'.
4324: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
4325: &mt('Both username and e-mail address').'</label></span> '.
4326: '<span class="LC_nobreak"><label>'.
4327: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
4328: &mt('Either username or e-mail address').'</label></span></td></tr>';
4329: $itemcount ++;
4330: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4331: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
4332: '<td class="LC_left_item">';
4333: my %postlinked;
4334: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
4335: foreach my $item (@{$types}) {
4336: undef(%postlinked);
4337: $datatable .= '<fieldset style="display: inline-block;">'.
4338: '<legend>'.$usertypes->{$item}.'</legend>';
4339: if (ref($postlink{$item}) eq 'ARRAY') {
4340: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
4341: }
4342: foreach my $field ('email','username') {
4343: my $checked;
4344: if ($postlinked{$field}) {
4345: $checked = ' checked="checked"';
4346: }
4347: $datatable .= '<span class="LC_nobreak"><label>'.
4348: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
4349: $field.'"'.$checked.' />'.$field.'</label>'.
4350: '<span> ';
4351: }
4352: $datatable .= '</fieldset>';
4353: }
4354: }
4355: if (ref($postlink{'default'}) eq 'ARRAY') {
4356: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
4357: }
4358: $datatable .= '<fieldset style="display: inline-block;">'.
4359: '<legend>'.$othertitle.'</legend>';
4360: foreach my $field ('email','username') {
4361: my $checked;
4362: if ($postlinked{$field}) {
4363: $checked = ' checked="checked"';
4364: }
4365: $datatable .= '<span class="LC_nobreak"><label>'.
4366: '<input type="checkbox" name="passwords_postlink_default" value="'.
4367: $field.'"'.$checked.' />'.$field.'</label>'.
4368: '<span> ';
4369: }
4370: $datatable .= '</fieldset></td></tr>';
4371: $itemcount ++;
4372: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4373: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
4374: '<td class="LC_left_item">';
4375: foreach my $type ('permanent','critical','notify') {
4376: my $checkedemail;
4377: if ($emailsrc{$type}) {
4378: $checkedemail = ' checked="checked"';
4379: }
4380: $datatable .= '<span class="LC_nobreak"><label>'.
4381: '<input type="checkbox" name="passwords_emailsrc" value="'.
4382: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
4383: '<span> ';
4384: }
4385: $datatable .= '</td></tr>';
4386: $itemcount ++;
4387: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4388: my $switchserver = &check_switchserver($dom,$confname);
4389: my ($showstd,$noshowstd);
4390: if ($nostdtext) {
4391: $noshowstd = ' checked="checked"';
4392: } else {
4393: $showstd = ' checked="checked"';
4394: }
4395: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
4396: '<td class="LC_left_item"><span class="LC_nobreak">'.
4397: &mt('Retain standard text:').
4398: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
4399: &mt('Yes').'</label>'.' '.
4400: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
4401: &mt('No').'</label></span><br />'.
4402: '<span class="LC_fontsize_small">'.
4403: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
4404: &mt('Include custom text:');
4405: if ($customurl) {
4406: my $link = &Apache::loncommon::modal_link($customurl,&mt('Custom text file'),600,500,
4407: undef,undef,undef,undef,'background-color:#ffffff');
4408: $datatable .= '<span class="LC_nobreak"> '.$link.
4409: '<label><input type="checkbox" name="passwords_custom_del"'.
4410: ' value="1" />'.&mt('Delete?').'</label></span>'.
4411: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
4412: }
4413: if ($switchserver) {
4414: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
4415: } else {
4416: $datatable .='<span class="LC_nobreak"> '.
4417: '<input type="file" name="passwords_customfile" /></span>';
4418: }
4419: $datatable .= '</td></tr>';
4420: } elsif ($position eq 'middle') {
4421: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
4422: my @items = ('intauth_cost','intauth_check','intauth_switch');
4423: my %defaults;
4424: if (ref($domconf{'defaults'}) eq 'HASH') {
4425: %defaults = %{$domconf{'defaults'}};
4426: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
4427: $defaults{'intauth_cost'} = 10;
4428: }
4429: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
4430: $defaults{'intauth_check'} = 0;
4431: }
4432: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
4433: $defaults{'intauth_switch'} = 0;
4434: }
4435: } else {
4436: %defaults = (
4437: 'intauth_cost' => 10,
4438: 'intauth_check' => 0,
4439: 'intauth_switch' => 0,
4440: );
4441: }
4442: foreach my $item (@items) {
4443: if ($itemcount%2) {
4444: $css_class = '';
4445: } else {
4446: $css_class = ' class="LC_odd_row" ';
4447: }
4448: $datatable .= '<tr'.$css_class.'>'.
4449: '<td><span class="LC_nobreak">'.$titles{$item}.
4450: '</span></td><td class="LC_left_item" colspan="3">';
4451: if ($item eq 'intauth_switch') {
4452: my @options = (0,1,2);
4453: my %optiondesc = &Apache::lonlocal::texthash (
4454: 0 => 'No',
4455: 1 => 'Yes',
4456: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
4457: );
4458: $datatable .= '<table width="100%">';
4459: foreach my $option (@options) {
4460: my $checked = ' ';
4461: if ($defaults{$item} eq $option) {
4462: $checked = ' checked="checked"';
4463: }
4464: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
4465: '<label><input type="radio" name="'.$item.
4466: '" value="'.$option.'"'.$checked.' />'.
4467: $optiondesc{$option}.'</label></span></td></tr>';
4468: }
4469: $datatable .= '</table>';
4470: } elsif ($item eq 'intauth_check') {
4471: my @options = (0,1,2);
4472: my %optiondesc = &Apache::lonlocal::texthash (
4473: 0 => 'No',
4474: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
4475: 2 => 'Yes, disallow login if stored cost is less than domain default',
4476: );
4477: $datatable .= '<table width="100%">';
4478: foreach my $option (@options) {
4479: my $checked = ' ';
4480: my $onclick;
4481: if ($defaults{$item} eq $option) {
4482: $checked = ' checked="checked"';
4483: }
4484: if ($option == 2) {
4485: $onclick = ' onclick="javascript:warnIntAuth(this);"';
4486: }
4487: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
4488: '<label><input type="radio" name="'.$item.
4489: '" value="'.$option.'"'.$checked.$onclick.' />'.
4490: $optiondesc{$option}.'</label></span></td></tr>';
4491: }
4492: $datatable .= '</table>';
4493: } else {
4494: $datatable .= '<input type="text" name="'.$item.'" value="'.
4495: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
4496: }
4497: $datatable .= '</td></tr>';
4498: $itemcount ++;
4499: }
4500: } elsif ($position eq 'lower') {
4501: my ($min,$max,%chars,$numsaved);
1.160.6.99 raeburn 4502: $min = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 4503: if (ref($settings) eq 'HASH') {
4504: if ($settings->{min}) {
4505: $min = $settings->{min};
4506: }
4507: if ($settings->{max}) {
4508: $max = $settings->{max};
4509: }
4510: if (ref($settings->{chars}) eq 'ARRAY') {
4511: map { $chars{$_} = 1; } (@{$settings->{chars}});
4512: }
4513: if ($settings->{numsaved}) {
4514: $numsaved = $settings->{numsaved};
4515: }
4516: }
4517: my %rulenames = &Apache::lonlocal::texthash(
4518: uc => 'At least one upper case letter',
4519: lc => 'At least one lower case letter',
4520: num => 'At least one number',
4521: spec => 'At least one non-alphanumeric',
4522: );
4523: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4524: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
4525: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 4526: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
4527: 'onblur="javascript:warnIntPass(this);" />'.
4528: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.160.6.98 raeburn 4529: '</span></td></tr>';
4530: $itemcount ++;
4531: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4532: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
4533: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 4534: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
4535: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 4536: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
4537: '</span></td></tr>';
4538: $itemcount ++;
4539: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4540: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
4541: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
4542: '</span></td>';
4543: my $numinrow = 2;
4544: my @possrules = ('uc','lc','num','spec');
4545: $datatable .= '<td class="LC_left_item"><table>';
4546: for (my $i=0; $i<@possrules; $i++) {
4547: my ($rem,$checked);
4548: if ($chars{$possrules[$i]}) {
4549: $checked = ' checked="checked"';
4550: }
4551: $rem = $i%($numinrow);
4552: if ($rem == 0) {
4553: if ($i > 0) {
4554: $datatable .= '</tr>';
4555: }
4556: $datatable .= '<tr>';
4557: }
4558: $datatable .= '<td><span class="LC_nobreak"><label>'.
4559: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
4560: $rulenames{$possrules[$i]}.'</label></span></td>';
4561: }
4562: my $rem = @possrules%($numinrow);
4563: my $colsleft = $numinrow - $rem;
4564: if ($colsleft > 1 ) {
4565: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4566: ' </td>';
4567: } elsif ($colsleft == 1) {
4568: $datatable .= '<td class="LC_left_item"> </td>';
4569: }
4570: $datatable .='</table></td></tr>';
4571: $itemcount ++;
4572: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4573: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
4574: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.100 raeburn 4575: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
1.160.6.99 raeburn 4576: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 4577: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
4578: '</span></td></tr>';
4579: } else {
4580: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4581: my %ownerchg = (
4582: by => {},
4583: for => {},
4584: );
4585: my %ownertitles = &Apache::lonlocal::texthash (
4586: by => 'Course owner status(es) allowed',
4587: for => 'Student status(es) allowed',
4588: );
4589: if (ref($settings) eq 'HASH') {
4590: if (ref($settings->{crsownerchg}) eq 'HASH') {
4591: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
4592: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
4593: }
4594: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
4595: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
4596: }
4597: }
4598: }
4599: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4600: $datatable .= '<tr '.$css_class.'>'.
4601: '<td>'.
4602: &mt('Requirements').'<ul>'.
4603: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
4604: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
4605: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
4606: '<li>'.&mt('User, course, and student share same domain').'</li>'.
4607: '</ul>'.
4608: '</td>'.
4609: '<td class="LC_left_item">';
4610: foreach my $item ('by','for') {
4611: $datatable .= '<fieldset style="display: inline-block;">'.
4612: '<legend>'.$ownertitles{$item}.'</legend>';
4613: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
4614: foreach my $type (@{$types}) {
4615: my $checked;
4616: if ($ownerchg{$item}{$type}) {
4617: $checked = ' checked="checked"';
4618: }
4619: $datatable .= '<span class="LC_nobreak"><label>'.
4620: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
4621: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
4622: '<span> ';
4623: }
4624: }
4625: my $checked;
4626: if ($ownerchg{$item}{'default'}) {
4627: $checked = ' checked="checked"';
4628: }
4629: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
4630: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
4631: $othertitle.'</label></span></fieldset>';
4632: }
4633: $datatable .= '</td></tr>';
4634: }
4635: return $datatable;
4636: }
4637:
1.137 raeburn 4638: sub print_usersessions {
4639: my ($position,$dom,$settings,$rowtotal) = @_;
4640: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 4641: my (%by_ip,%by_location,@intdoms);
4642: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 4643:
4644: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 4645: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 4646: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 4647: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 4648: my $itemcount = 1;
4649: if ($position eq 'top') {
1.152 raeburn 4650: if (keys(%serverhomes) > 1) {
1.145 raeburn 4651: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.61 raeburn 4652: my $curroffloadnow;
4653: if (ref($settings) eq 'HASH') {
4654: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4655: $curroffloadnow = $settings->{'offloadnow'};
4656: }
4657: }
4658: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 4659: } else {
1.140 raeburn 4660: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 4661: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 4662: }
1.137 raeburn 4663: } else {
1.145 raeburn 4664: if (keys(%by_location) == 0) {
4665: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 4666: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 4667: } else {
4668: my %lt = &usersession_titles();
4669: my $numinrow = 5;
4670: my $prefix;
4671: my @types;
4672: if ($position eq 'bottom') {
4673: $prefix = 'remote';
4674: @types = ('version','excludedomain','includedomain');
4675: } else {
4676: $prefix = 'hosted';
4677: @types = ('excludedomain','includedomain');
4678: }
4679: my (%current,%checkedon,%checkedoff);
4680: my @lcversions = &Apache::lonnet::all_loncaparevs();
4681: my @locations = sort(keys(%by_location));
4682: foreach my $type (@types) {
4683: $checkedon{$type} = '';
4684: $checkedoff{$type} = ' checked="checked"';
4685: }
4686: if (ref($settings) eq 'HASH') {
4687: if (ref($settings->{$prefix}) eq 'HASH') {
4688: foreach my $key (keys(%{$settings->{$prefix}})) {
4689: $current{$key} = $settings->{$prefix}{$key};
4690: if ($key eq 'version') {
4691: if ($current{$key} ne '') {
4692: $checkedon{$key} = ' checked="checked"';
4693: $checkedoff{$key} = '';
4694: }
4695: } elsif (ref($current{$key}) eq 'ARRAY') {
4696: $checkedon{$key} = ' checked="checked"';
4697: $checkedoff{$key} = '';
4698: }
1.137 raeburn 4699: }
4700: }
4701: }
1.145 raeburn 4702: foreach my $type (@types) {
4703: next if ($type ne 'version' && !@locations);
4704: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4705: $datatable .= '<tr'.$css_class.'>
4706: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
4707: <span class="LC_nobreak">
4708: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4709: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4710: if ($type eq 'version') {
4711: my $selector = '<select name="'.$prefix.'_version">';
4712: foreach my $version (@lcversions) {
4713: my $selected = '';
4714: if ($current{'version'} eq $version) {
4715: $selected = ' selected="selected"';
4716: }
4717: $selector .= ' <option value="'.$version.'"'.
4718: $selected.'>'.$version.'</option>';
4719: }
4720: $selector .= '</select> ';
4721: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4722: } else {
4723: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4724: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4725: ' />'.(' 'x2).
4726: '<input type="button" value="'.&mt('uncheck all').'" '.
4727: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4728: "\n".
4729: '</div><div><table>';
4730: my $rem;
4731: for (my $i=0; $i<@locations; $i++) {
4732: my ($showloc,$value,$checkedtype);
4733: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
4734: my $ip = $by_location{$locations[$i]}->[0];
4735: if (ref($by_ip{$ip}) eq 'ARRAY') {
4736: $value = join(':',@{$by_ip{$ip}});
4737: $showloc = join(', ',@{$by_ip{$ip}});
4738: if (ref($current{$type}) eq 'ARRAY') {
4739: foreach my $loc (@{$by_ip{$ip}}) {
4740: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4741: $checkedtype = ' checked="checked"';
4742: last;
4743: }
4744: }
1.138 raeburn 4745: }
4746: }
4747: }
1.145 raeburn 4748: $rem = $i%($numinrow);
4749: if ($rem == 0) {
4750: if ($i > 0) {
4751: $datatable .= '</tr>';
4752: }
4753: $datatable .= '<tr>';
4754: }
4755: $datatable .= '<td class="LC_left_item">'.
4756: '<span class="LC_nobreak"><label>'.
4757: '<input type="checkbox" name="'.$prefix.'_'.$type.
4758: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4759: '</label></span></td>';
1.137 raeburn 4760: }
1.145 raeburn 4761: $rem = @locations%($numinrow);
4762: my $colsleft = $numinrow - $rem;
4763: if ($colsleft > 1 ) {
4764: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4765: ' </td>';
4766: } elsif ($colsleft == 1) {
4767: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4768: }
1.145 raeburn 4769: $datatable .= '</tr></table>';
1.137 raeburn 4770: }
1.145 raeburn 4771: $datatable .= '</td></tr>';
4772: $itemcount ++;
1.137 raeburn 4773: }
4774: }
4775: }
4776: $$rowtotal += $itemcount;
4777: return $datatable;
4778: }
4779:
1.138 raeburn 4780: sub build_location_hashes {
4781: my ($intdoms,$by_ip,$by_location) = @_;
4782: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
4783: (ref($by_location) eq 'HASH'));
4784: my %iphost = &Apache::lonnet::get_iphost();
4785: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4786: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4787: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4788: foreach my $id (@{$iphost{$primary_ip}}) {
4789: my $intdom = &Apache::lonnet::internet_dom($id);
4790: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4791: push(@{$intdoms},$intdom);
4792: }
4793: }
4794: }
4795: foreach my $ip (keys(%iphost)) {
4796: if (ref($iphost{$ip}) eq 'ARRAY') {
4797: foreach my $id (@{$iphost{$ip}}) {
4798: my $location = &Apache::lonnet::internet_dom($id);
4799: if ($location) {
4800: next if (grep(/^\Q$location\E$/,@{$intdoms}));
4801: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4802: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4803: push(@{$by_ip->{$ip}},$location);
4804: }
4805: } else {
4806: $by_ip->{$ip} = [$location];
4807: }
4808: }
4809: }
4810: }
4811: }
4812: foreach my $ip (sort(keys(%{$by_ip}))) {
4813: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4814: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4815: my $first = $by_ip->{$ip}->[0];
4816: if (ref($by_location->{$first}) eq 'ARRAY') {
4817: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4818: push(@{$by_location->{$first}},$ip);
4819: }
4820: } else {
4821: $by_location->{$first} = [$ip];
4822: }
4823: }
4824: }
4825: return;
4826: }
4827:
1.145 raeburn 4828: sub current_offloads_to {
4829: my ($dom,$settings,$servers) = @_;
4830: my (%spareid,%otherdomconfigs);
1.152 raeburn 4831: if (ref($servers) eq 'HASH') {
1.145 raeburn 4832: foreach my $lonhost (sort(keys(%{$servers}))) {
4833: my $gotspares;
1.152 raeburn 4834: if (ref($settings) eq 'HASH') {
4835: if (ref($settings->{'spares'}) eq 'HASH') {
4836: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4837: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4838: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4839: $gotspares = 1;
4840: }
1.145 raeburn 4841: }
4842: }
4843: unless ($gotspares) {
4844: my $gotspares;
4845: my $serverhomeID =
4846: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4847: my $serverhomedom =
4848: &Apache::lonnet::host_domain($serverhomeID);
4849: if ($serverhomedom ne $dom) {
4850: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4851: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4852: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4853: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4854: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4855: $gotspares = 1;
4856: }
4857: }
4858: } else {
4859: $otherdomconfigs{$serverhomedom} =
4860: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4861: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4862: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4863: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4864: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4865: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4866: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4867: $gotspares = 1;
4868: }
4869: }
4870: }
4871: }
4872: }
4873: }
4874: }
4875: unless ($gotspares) {
4876: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4877: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4878: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4879: } else {
4880: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4881: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4882: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4883: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4884: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4885: } else {
1.150 raeburn 4886: my %what = (
4887: spareid => 1,
4888: );
4889: my ($result,$returnhash) =
4890: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4891: if ($result eq 'ok') {
4892: if (ref($returnhash) eq 'HASH') {
4893: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4894: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4895: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4896: }
4897: }
1.145 raeburn 4898: }
4899: }
4900: }
4901: }
4902: }
4903: }
4904: return %spareid;
4905: }
4906:
4907: sub spares_row {
1.160.6.61 raeburn 4908: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4909: my $css_class;
4910: my $numinrow = 4;
4911: my $itemcount = 1;
4912: my $datatable;
1.152 raeburn 4913: my %typetitles = &sparestype_titles();
4914: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4915: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4916: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4917: my ($othercontrol,$serverdom);
4918: if ($serverhome ne $server) {
4919: $serverdom = &Apache::lonnet::host_domain($serverhome);
4920: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4921: } else {
4922: $serverdom = &Apache::lonnet::host_domain($server);
4923: if ($serverdom ne $dom) {
4924: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4925: }
4926: }
4927: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61 raeburn 4928: my $checkednow;
4929: if (ref($curroffloadnow) eq 'HASH') {
4930: if ($curroffloadnow->{$server}) {
4931: $checkednow = ' checked="checked"';
4932: }
4933: }
1.145 raeburn 4934: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4935: $datatable .= '<tr'.$css_class.'>
4936: <td rowspan="2">
1.160.6.13 raeburn 4937: <span class="LC_nobreak">'.
4938: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 4939: ,'<b>'.$server.'</b>').'</span><br />'.
4940: '<span class="LC_nobreak">'."\n".
4941: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4942: ' '.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13 raeburn 4943: "\n";
1.145 raeburn 4944: my (%current,%canselect);
1.152 raeburn 4945: my @choices =
4946: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4947: foreach my $type ('primary','default') {
4948: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4949: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4950: my @spares = @{$spareid->{$server}{$type}};
4951: if (@spares > 0) {
1.152 raeburn 4952: if ($othercontrol) {
4953: $current{$type} = join(', ',@spares);
4954: } else {
4955: $current{$type} .= '<table>';
4956: my $numspares = scalar(@spares);
4957: for (my $i=0; $i<@spares; $i++) {
4958: my $rem = $i%($numinrow);
4959: if ($rem == 0) {
4960: if ($i > 0) {
4961: $current{$type} .= '</tr>';
4962: }
4963: $current{$type} .= '<tr>';
1.145 raeburn 4964: }
1.152 raeburn 4965: $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'".');" /> '.
4966: $spareid->{$server}{$type}[$i].
4967: '</label></td>'."\n";
4968: }
4969: my $rem = @spares%($numinrow);
4970: my $colsleft = $numinrow - $rem;
4971: if ($colsleft > 1 ) {
4972: $current{$type} .= '<td colspan="'.$colsleft.
4973: '" class="LC_left_item">'.
4974: ' </td>';
4975: } elsif ($colsleft == 1) {
4976: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4977: }
1.152 raeburn 4978: $current{$type} .= '</tr></table>';
1.150 raeburn 4979: }
1.145 raeburn 4980: }
4981: }
4982: if ($current{$type} eq '') {
4983: $current{$type} = &mt('None specified');
4984: }
1.152 raeburn 4985: if ($othercontrol) {
4986: if ($type eq 'primary') {
4987: $canselect{$type} = $othercontrol;
4988: }
4989: } else {
4990: $canselect{$type} =
4991: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4992: '<select name="newspare_'.$type.'_'.$server.'" '.
4993: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4994: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4995: if (@choices > 0) {
4996: foreach my $lonhost (@choices) {
4997: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4998: }
4999: }
5000: $canselect{$type} .= '</select>'."\n";
5001: }
5002: } else {
5003: $current{$type} = &mt('Could not be determined');
5004: if ($type eq 'primary') {
5005: $canselect{$type} = $othercontrol;
5006: }
1.145 raeburn 5007: }
1.152 raeburn 5008: if ($type eq 'default') {
5009: $datatable .= '<tr'.$css_class.'>';
5010: }
5011: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
5012: '<td>'.$current{$type}.'</td>'."\n".
5013: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 5014: }
5015: $itemcount ++;
5016: }
5017: }
5018: $$rowtotal += $itemcount;
5019: return $datatable;
5020: }
5021:
1.152 raeburn 5022: sub possible_newspares {
5023: my ($server,$currspares,$serverhomes,$altids) = @_;
5024: my $serverhostname = &Apache::lonnet::hostname($server);
5025: my %excluded;
5026: if ($serverhostname ne '') {
5027: %excluded = (
5028: $serverhostname => 1,
5029: );
5030: }
5031: if (ref($currspares) eq 'HASH') {
5032: foreach my $type (keys(%{$currspares})) {
5033: if (ref($currspares->{$type}) eq 'ARRAY') {
5034: if (@{$currspares->{$type}} > 0) {
5035: foreach my $curr (@{$currspares->{$type}}) {
5036: my $hostname = &Apache::lonnet::hostname($curr);
5037: $excluded{$hostname} = 1;
5038: }
5039: }
5040: }
5041: }
5042: }
5043: my @choices;
5044: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
5045: if (keys(%{$serverhomes}) > 1) {
5046: foreach my $name (sort(keys(%{$serverhomes}))) {
5047: unless ($excluded{$name}) {
5048: if (exists($altids->{$serverhomes->{$name}})) {
5049: push(@choices,$altids->{$serverhomes->{$name}});
5050: } else {
5051: push(@choices,$serverhomes->{$name});
1.145 raeburn 5052: }
5053: }
5054: }
5055: }
5056: }
1.152 raeburn 5057: return sort(@choices);
1.145 raeburn 5058: }
5059:
1.150 raeburn 5060: sub print_loadbalancing {
5061: my ($dom,$settings,$rowtotal) = @_;
5062: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5063: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5064: my $numinrow = 1;
5065: my $datatable;
5066: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 5067: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 5068: if (ref($settings) eq 'HASH') {
5069: %existing = %{$settings};
5070: }
5071: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5072: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 5073: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 5074: } else {
5075: return;
5076: }
5077: my ($othertitle,$usertypes,$types) =
5078: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 5079: my $rownum = 8;
1.150 raeburn 5080: if (ref($types) eq 'ARRAY') {
5081: $rownum += scalar(@{$types});
5082: }
1.160.6.7 raeburn 5083: my @css_class = ('LC_odd_row','LC_even_row');
5084: my $balnum = 0;
5085: my $islast;
5086: my (@toshow,$disabledtext);
5087: if (keys(%currbalancer) > 0) {
5088: @toshow = sort(keys(%currbalancer));
5089: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5090: push(@toshow,'');
5091: }
5092: } else {
5093: @toshow = ('');
5094: $disabledtext = &mt('No existing load balancer');
5095: }
5096: foreach my $lonhost (@toshow) {
5097: if ($balnum == scalar(@toshow)-1) {
5098: $islast = 1;
5099: } else {
5100: $islast = 0;
5101: }
5102: my $cssidx = $balnum%2;
5103: my $targets_div_style = 'display: none';
5104: my $disabled_div_style = 'display: block';
5105: my $homedom_div_style = 'display: none';
5106: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
5107: '<td rowspan="'.$rownum.'" valign="top">'.
5108: '<p>';
5109: if ($lonhost eq '') {
5110: $datatable .= '<span class="LC_nobreak">';
5111: if (keys(%currbalancer) > 0) {
5112: $datatable .= &mt('Add balancer:');
5113: } else {
5114: $datatable .= &mt('Enable balancer:');
5115: }
5116: $datatable .= ' '.
5117: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5118: ' id="loadbalancing_lonhost_'.$balnum.'"'.
5119: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
5120: '<option value="" selected="selected">'.&mt('None').
5121: '</option>'."\n";
5122: foreach my $server (sort(keys(%servers))) {
5123: next if ($currbalancer{$server});
5124: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
5125: }
5126: $datatable .=
5127: '</select>'."\n".
5128: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
5129: } else {
5130: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
5131: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
5132: &mt('Stop balancing').'</label>'.
5133: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
5134: $targets_div_style = 'display: block';
5135: $disabled_div_style = 'display: none';
5136: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
5137: $homedom_div_style = 'display: block';
5138: }
5139: }
5140: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
5141: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
5142: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
5143: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
5144: my ($numspares,@spares) = &count_servers($lonhost,%servers);
5145: my @sparestypes = ('primary','default');
5146: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 5147: my %hostherechecked = (
5148: no => ' checked="checked"',
5149: );
1.160.6.94 raeburn 5150: my %balcookiechecked = (
5151: no => ' checked="checked"',
5152: );
1.160.6.7 raeburn 5153: foreach my $sparetype (@sparestypes) {
5154: my $targettable;
5155: for (my $i=0; $i<$numspares; $i++) {
5156: my $checked;
5157: if (ref($currtargets{$lonhost}) eq 'HASH') {
5158: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5159: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5160: $checked = ' checked="checked"';
5161: }
5162: }
5163: }
5164: my ($chkboxval,$disabled);
5165: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5166: $chkboxval = $spares[$i];
5167: }
5168: if (exists($currbalancer{$spares[$i]})) {
5169: $disabled = ' disabled="disabled"';
5170: }
5171: $targettable .=
1.160.6.55 raeburn 5172: '<td><span class="LC_nobreak"><label>'.
5173: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 5174: $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 5175: '</span></label></span></td>';
1.160.6.7 raeburn 5176: my $rem = $i%($numinrow);
5177: if ($rem == 0) {
5178: if (($i > 0) && ($i < $numspares-1)) {
5179: $targettable .= '</tr>';
5180: }
5181: if ($i < $numspares-1) {
5182: $targettable .= '<tr>';
1.150 raeburn 5183: }
5184: }
5185: }
1.160.6.7 raeburn 5186: if ($targettable ne '') {
5187: my $rem = $numspares%($numinrow);
5188: my $colsleft = $numinrow - $rem;
5189: if ($colsleft > 1 ) {
5190: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5191: ' </td>';
5192: } elsif ($colsleft == 1) {
5193: $targettable .= '<td class="LC_left_item"> </td>';
5194: }
5195: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5196: '<table><tr>'.$targettable.'</tr></table><br />';
5197: }
1.160.6.76 raeburn 5198: $hostherechecked{$sparetype} = '';
5199: if (ref($currtargets{$lonhost}) eq 'HASH') {
5200: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5201: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5202: $hostherechecked{$sparetype} = ' checked="checked"';
5203: $hostherechecked{'no'} = '';
5204: }
5205: }
5206: }
5207: }
1.160.6.94 raeburn 5208: if ($currcookies{$lonhost}) {
5209: %balcookiechecked = (
5210: yes => ' checked="checked"',
5211: );
5212: }
1.160.6.76 raeburn 5213: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5214: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5215: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5216: foreach my $sparetype (@sparestypes) {
5217: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5218: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5219: '</i></label><br />';
1.160.6.7 raeburn 5220: }
1.160.6.94 raeburn 5221: $datatable .= &mt('Use balancer cookie').'<br />'.
5222: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
5223: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
5224: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
5225: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
5226: '</div></td></tr>'.
1.160.6.7 raeburn 5227: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5228: $othertitle,$usertypes,$types,\%servers,
5229: \%currbalancer,$lonhost,
5230: $targets_div_style,$homedom_div_style,
5231: $css_class[$cssidx],$balnum,$islast);
5232: $$rowtotal += $rownum;
5233: $balnum ++;
5234: }
5235: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5236: return $datatable;
5237: }
5238:
5239: sub get_loadbalancers_config {
1.160.6.94 raeburn 5240: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 5241: return unless ((ref($servers) eq 'HASH') &&
5242: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 5243: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
5244: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 5245: if (keys(%{$existing}) > 0) {
5246: my $oldlonhost;
5247: foreach my $key (sort(keys(%{$existing}))) {
5248: if ($key eq 'lonhost') {
5249: $oldlonhost = $existing->{'lonhost'};
5250: $currbalancer->{$oldlonhost} = 1;
5251: } elsif ($key eq 'targets') {
5252: if ($oldlonhost) {
5253: $currtargets->{$oldlonhost} = $existing->{'targets'};
5254: }
5255: } elsif ($key eq 'rules') {
5256: if ($oldlonhost) {
5257: $currrules->{$oldlonhost} = $existing->{'rules'};
5258: }
5259: } elsif (ref($existing->{$key}) eq 'HASH') {
5260: $currbalancer->{$key} = 1;
5261: $currtargets->{$key} = $existing->{$key}{'targets'};
5262: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 5263: if ($existing->{$key}{'cookie'}) {
5264: $currcookies->{$key} = 1;
5265: }
1.150 raeburn 5266: }
5267: }
1.160.6.7 raeburn 5268: } else {
5269: my ($balancerref,$targetsref) =
5270: &Apache::lonnet::get_lonbalancer_config($servers);
5271: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5272: foreach my $server (sort(keys(%{$balancerref}))) {
5273: $currbalancer->{$server} = 1;
5274: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 5275: }
5276: }
5277: }
1.160.6.7 raeburn 5278: return;
1.150 raeburn 5279: }
5280:
5281: sub loadbalancing_rules {
5282: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 5283: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5284: $css_class,$balnum,$islast) = @_;
1.150 raeburn 5285: my $output;
1.160.6.7 raeburn 5286: my $num = 0;
5287: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 5288: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5289: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5290: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 5291: $num ++;
1.150 raeburn 5292: my $current;
5293: if (ref($currrules) eq 'HASH') {
5294: $current = $currrules->{$type};
5295: }
1.160.6.55 raeburn 5296: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 5297: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 5298: $current = '';
5299: }
5300: }
5301: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 5302: $servers,$currbalancer,$lonhost,$dom,
5303: $targets_div_style,$homedom_div_style,
5304: $css_class,$balnum,$num,$islast);
1.150 raeburn 5305: }
5306: }
5307: return $output;
5308: }
5309:
5310: sub loadbalancing_titles {
5311: my ($dom,$intdom,$usertypes,$types) = @_;
5312: my %othertypes = (
5313: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5314: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5315: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5316: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 5317: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5318: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 5319: );
1.160.6.26 raeburn 5320: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 5321: my @available;
1.150 raeburn 5322: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 5323: @available = @{$types};
1.150 raeburn 5324: }
1.160.6.89 raeburn 5325: unless (grep(/^default$/,@available)) {
5326: push(@available,'default');
5327: }
5328: unshift(@alltypes,@available);
1.150 raeburn 5329: my %titles;
5330: foreach my $type (@alltypes) {
5331: if ($type =~ /^_LC_/) {
5332: $titles{$type} = $othertypes{$type};
5333: } elsif ($type eq 'default') {
5334: $titles{$type} = &mt('All users from [_1]',$dom);
5335: if (ref($types) eq 'ARRAY') {
5336: if (@{$types} > 0) {
5337: $titles{$type} = &mt('Other users from [_1]',$dom);
5338: }
5339: }
5340: } elsif (ref($usertypes) eq 'HASH') {
5341: $titles{$type} = $usertypes->{$type};
5342: }
5343: }
5344: return (\@alltypes,\%othertypes,\%titles);
5345: }
5346:
5347: sub loadbalance_rule_row {
1.160.6.7 raeburn 5348: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
5349: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 5350: my @rulenames;
1.150 raeburn 5351: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 5352: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 5353: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 5354: } else {
1.160.6.26 raeburn 5355: @rulenames = ('default','homeserver');
5356: if ($type eq '_LC_external') {
5357: push(@rulenames,'externalbalancer');
5358: } else {
5359: push(@rulenames,'specific');
5360: }
5361: push(@rulenames,'none');
1.150 raeburn 5362: }
5363: my $style = $targets_div_style;
1.160.6.55 raeburn 5364: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 5365: $style = $homedom_div_style;
5366: }
1.160.6.7 raeburn 5367: my $space;
5368: if ($islast && $num == 1) {
5369: $space = '<div display="inline-block"> </div>';
5370: }
5371: my $output =
5372: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
5373: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
5374: '<td valaign="top">'.$space.
5375: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 5376: for (my $i=0; $i<@rulenames; $i++) {
5377: my $rule = $rulenames[$i];
5378: my ($checked,$extra);
5379: if ($rulenames[$i] eq 'default') {
5380: $rule = '';
5381: }
5382: if ($rulenames[$i] eq 'specific') {
5383: if (ref($servers) eq 'HASH') {
5384: my $default;
5385: if (($current ne '') && (exists($servers->{$current}))) {
5386: $checked = ' checked="checked"';
5387: }
5388: unless ($checked) {
5389: $default = ' selected="selected"';
5390: }
1.160.6.7 raeburn 5391: $extra =
5392: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
5393: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
5394: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
5395: '<option value=""'.$default.'></option>'."\n";
5396: foreach my $server (sort(keys(%{$servers}))) {
5397: if (ref($currbalancer) eq 'HASH') {
5398: next if (exists($currbalancer->{$server}));
5399: }
1.150 raeburn 5400: my $selected;
1.160.6.7 raeburn 5401: if ($server eq $current) {
1.150 raeburn 5402: $selected = ' selected="selected"';
5403: }
1.160.6.7 raeburn 5404: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 5405: }
5406: $extra .= '</select>';
5407: }
5408: } elsif ($rule eq $current) {
5409: $checked = ' checked="checked"';
5410: }
5411: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 5412: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
5413: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
5414: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 5415: ')"'.$checked.' /> ';
1.160.6.56 raeburn 5416: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 5417: $output .= $ruletitles{'particular'};
5418: } else {
5419: $output .= $ruletitles{$rulenames[$i]};
5420: }
5421: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 5422: }
5423: $output .= '</div></td></tr>'."\n";
5424: return $output;
5425: }
5426:
5427: sub offloadtype_text {
5428: my %ruletitles = &Apache::lonlocal::texthash (
5429: 'default' => 'Offloads to default destinations',
5430: 'homeserver' => "Offloads to user's home server",
5431: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
5432: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 5433: 'none' => 'No offload',
1.160.6.26 raeburn 5434: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
5435: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 5436: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 5437: );
5438: return %ruletitles;
5439: }
5440:
5441: sub sparestype_titles {
5442: my %typestitles = &Apache::lonlocal::texthash (
5443: 'primary' => 'primary',
5444: 'default' => 'default',
5445: );
5446: return %typestitles;
5447: }
5448:
1.28 raeburn 5449: sub contact_titles {
5450: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 5451: 'supportemail' => 'Support E-mail address',
5452: 'adminemail' => 'Default Server Admin E-mail address',
5453: 'errormail' => 'Error reports to be e-mailed to',
5454: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.101! raeburn 5455: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
! 5456: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 5457: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
5458: 'requestsmail' => 'E-mail from course requests requiring approval',
5459: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 5460: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 5461: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.28 raeburn 5462: );
5463: my %short_titles = &Apache::lonlocal::texthash (
5464: adminemail => 'Admin E-mail address',
5465: supportemail => 'Support E-mail',
5466: );
5467: return (\%titles,\%short_titles);
5468: }
5469:
1.160.6.78 raeburn 5470: sub helpform_fields {
5471: my %titles = &Apache::lonlocal::texthash (
5472: 'username' => 'Name',
5473: 'user' => 'Username/domain',
5474: 'phone' => 'Phone',
5475: 'cc' => 'Cc e-mail',
5476: 'course' => 'Course Details',
5477: 'section' => 'Sections',
5478: 'screenshot' => 'File upload',
5479: );
5480: my @fields = ('username','phone','user','course','section','cc','screenshot');
5481: my %possoptions = (
5482: username => ['yes','no','req'],
5483: phone => ['yes','no','req'],
5484: user => ['yes','no'],
5485: cc => ['yes','no'],
5486: course => ['yes','no'],
5487: section => ['yes','no'],
5488: screenshot => ['yes','no'],
5489: );
5490: my %fieldoptions = &Apache::lonlocal::texthash (
5491: 'yes' => 'Optional',
5492: 'req' => 'Required',
5493: 'no' => "Not shown",
5494: );
5495: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
5496: }
5497:
1.72 raeburn 5498: sub tool_titles {
5499: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 5500: aboutme => 'Personal web page',
1.86 raeburn 5501: blog => 'Blog',
1.160.6.4 raeburn 5502: webdav => 'WebDAV',
1.86 raeburn 5503: portfolio => 'Portfolio',
1.88 bisitz 5504: official => 'Official courses (with institutional codes)',
5505: unofficial => 'Unofficial courses',
1.98 raeburn 5506: community => 'Communities',
1.160.6.30 raeburn 5507: textbook => 'Textbook courses',
1.86 raeburn 5508: );
1.72 raeburn 5509: return %titles;
5510: }
5511:
1.101 raeburn 5512: sub courserequest_titles {
5513: my %titles = &Apache::lonlocal::texthash (
5514: official => 'Official',
5515: unofficial => 'Unofficial',
5516: community => 'Communities',
1.160.6.30 raeburn 5517: textbook => 'Textbook',
1.101 raeburn 5518: norequest => 'Not allowed',
1.104 raeburn 5519: approval => 'Approval by Dom. Coord.',
1.101 raeburn 5520: validate => 'With validation',
5521: autolimit => 'Numerical limit',
1.103 raeburn 5522: unlimited => '(blank for unlimited)',
1.101 raeburn 5523: );
5524: return %titles;
5525: }
5526:
1.160.6.5 raeburn 5527: sub authorrequest_titles {
5528: my %titles = &Apache::lonlocal::texthash (
5529: norequest => 'Not allowed',
5530: approval => 'Approval by Dom. Coord.',
5531: automatic => 'Automatic approval',
5532: );
5533: return %titles;
5534: }
5535:
1.101 raeburn 5536: sub courserequest_conditions {
5537: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 5538: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 5539: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 5540: );
5541: return %conditions;
5542: }
5543:
5544:
1.27 raeburn 5545: sub print_usercreation {
1.30 raeburn 5546: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 5547: my $numinrow = 4;
1.28 raeburn 5548: my $datatable;
5549: if ($position eq 'top') {
1.30 raeburn 5550: $$rowtotal ++;
1.34 raeburn 5551: my $rowcount = 0;
1.32 raeburn 5552: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 5553: if (ref($rules) eq 'HASH') {
5554: if (keys(%{$rules}) > 0) {
1.32 raeburn 5555: $datatable .= &user_formats_row('username',$settings,$rules,
5556: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 5557: $$rowtotal ++;
1.32 raeburn 5558: $rowcount ++;
5559: }
5560: }
5561: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
5562: if (ref($idrules) eq 'HASH') {
5563: if (keys(%{$idrules}) > 0) {
5564: $datatable .= &user_formats_row('id',$settings,$idrules,
5565: $idruleorder,$numinrow,$rowcount);
5566: $$rowtotal ++;
5567: $rowcount ++;
1.28 raeburn 5568: }
5569: }
1.39 raeburn 5570: if ($rowcount == 0) {
5571: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
5572: $$rowtotal ++;
5573: $rowcount ++;
5574: }
1.34 raeburn 5575: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 5576: my @creators = ('author','course','requestcrs');
1.37 raeburn 5577: my ($rules,$ruleorder) =
5578: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 5579: my %lt = &usercreation_types();
5580: my %checked;
5581: if (ref($settings) eq 'HASH') {
5582: if (ref($settings->{'cancreate'}) eq 'HASH') {
5583: foreach my $item (@creators) {
5584: $checked{$item} = $settings->{'cancreate'}{$item};
5585: }
5586: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
5587: foreach my $item (@creators) {
5588: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
5589: $checked{$item} = 'none';
5590: }
5591: }
5592: }
5593: }
5594: my $rownum = 0;
5595: foreach my $item (@creators) {
5596: $rownum ++;
1.160.6.34 raeburn 5597: if ($checked{$item} eq '') {
5598: $checked{$item} = 'any';
1.34 raeburn 5599: }
5600: my $css_class;
5601: if ($rownum%2) {
5602: $css_class = '';
5603: } else {
5604: $css_class = ' class="LC_odd_row" ';
5605: }
5606: $datatable .= '<tr'.$css_class.'>'.
5607: '<td><span class="LC_nobreak">'.$lt{$item}.
5608: '</span></td><td align="right">';
1.160.6.34 raeburn 5609: my @options = ('any');
5610: if (ref($rules) eq 'HASH') {
5611: if (keys(%{$rules}) > 0) {
5612: push(@options,('official','unofficial'));
1.37 raeburn 5613: }
5614: }
1.160.6.34 raeburn 5615: push(@options,'none');
1.37 raeburn 5616: foreach my $option (@options) {
1.50 raeburn 5617: my $type = 'radio';
1.34 raeburn 5618: my $check = ' ';
1.160.6.34 raeburn 5619: if ($checked{$item} eq $option) {
5620: $check = ' checked="checked" ';
1.34 raeburn 5621: }
5622: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 5623: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 5624: $item.'" value="'.$option.'"'.$check.'/> '.
5625: $lt{$option}.'</label> </span>';
5626: }
5627: $datatable .= '</td></tr>';
5628: }
1.28 raeburn 5629: } else {
5630: my @contexts = ('author','course','domain');
5631: my @authtypes = ('int','krb4','krb5','loc');
5632: my %checked;
5633: if (ref($settings) eq 'HASH') {
5634: if (ref($settings->{'authtypes'}) eq 'HASH') {
5635: foreach my $item (@contexts) {
5636: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5637: foreach my $auth (@authtypes) {
5638: if ($settings->{'authtypes'}{$item}{$auth}) {
5639: $checked{$item}{$auth} = ' checked="checked" ';
5640: }
5641: }
5642: }
5643: }
1.27 raeburn 5644: }
1.35 raeburn 5645: } else {
5646: foreach my $item (@contexts) {
1.36 raeburn 5647: foreach my $auth (@authtypes) {
1.35 raeburn 5648: $checked{$item}{$auth} = ' checked="checked" ';
5649: }
5650: }
1.27 raeburn 5651: }
1.28 raeburn 5652: my %title = &context_names();
5653: my %authname = &authtype_names();
5654: my $rownum = 0;
5655: my $css_class;
5656: foreach my $item (@contexts) {
5657: if ($rownum%2) {
5658: $css_class = '';
5659: } else {
5660: $css_class = ' class="LC_odd_row" ';
5661: }
1.30 raeburn 5662: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5663: '<td>'.$title{$item}.
5664: '</td><td class="LC_left_item">'.
5665: '<span class="LC_nobreak">';
5666: foreach my $auth (@authtypes) {
5667: $datatable .= '<label>'.
5668: '<input type="checkbox" name="'.$item.'_auth" '.
5669: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5670: $authname{$auth}.'</label> ';
5671: }
5672: $datatable .= '</span></td></tr>';
5673: $rownum ++;
1.27 raeburn 5674: }
1.30 raeburn 5675: $$rowtotal += $rownum;
1.27 raeburn 5676: }
5677: return $datatable;
5678: }
5679:
1.160.6.34 raeburn 5680: sub print_selfcreation {
5681: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 5682: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
5683: $emaildomain,$datatable);
1.160.6.34 raeburn 5684: if (ref($settings) eq 'HASH') {
5685: if (ref($settings->{'cancreate'}) eq 'HASH') {
5686: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 5687: if (ref($createsettings) eq 'HASH') {
5688: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5689: @selfcreate = @{$createsettings->{'selfcreate'}};
5690: } elsif ($createsettings->{'selfcreate'} ne '') {
5691: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5692: @selfcreate = ('email','login','sso');
5693: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5694: @selfcreate = ($createsettings->{'selfcreate'});
5695: }
5696: }
5697: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5698: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 5699: }
1.160.6.93 raeburn 5700: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
5701: $emailoptions = $createsettings->{'emailoptions'};
5702: }
5703: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
5704: $emailverified = $createsettings->{'emailverified'};
5705: }
5706: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
5707: $emaildomain = $createsettings->{'emaildomain'};
5708: }
1.160.6.34 raeburn 5709: }
5710: }
5711: }
5712: my %radiohash;
5713: my $numinrow = 4;
5714: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 5715: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 5716: if ($position eq 'top') {
5717: my %choices = &Apache::lonlocal::texthash (
5718: cancreate_login => 'Institutional Login',
5719: cancreate_sso => 'Institutional Single Sign On',
5720: );
5721: my @toggles = sort(keys(%choices));
5722: my %defaultchecked = (
5723: 'cancreate_login' => 'off',
5724: 'cancreate_sso' => 'off',
5725: );
1.160.6.35 raeburn 5726: my ($onclick,$itemcount);
1.160.6.34 raeburn 5727: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5728: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 5729: $$rowtotal += $itemcount;
1.160.6.34 raeburn 5730:
5731: if (ref($usertypes) eq 'HASH') {
5732: if (keys(%{$usertypes}) > 0) {
5733: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5734: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 5735: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 5736: $$rowtotal ++;
5737: }
5738: }
1.160.6.44 raeburn 5739: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5740: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5741: $fieldtitles{'inststatus'} = &mt('Institutional status');
5742: my $rem;
5743: my $numperrow = 2;
5744: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5745: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 5746: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 5747: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 5748: '<table>'."\n";
1.160.6.44 raeburn 5749: for (my $i=0; $i<@fields; $i++) {
5750: $rem = $i%($numperrow);
5751: if ($rem == 0) {
5752: if ($i > 0) {
5753: $datatable .= '</tr>';
5754: }
5755: $datatable .= '<tr>';
5756: }
5757: my $currval;
1.160.6.51 raeburn 5758: if (ref($createsettings) eq 'HASH') {
5759: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5760: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5761: }
1.160.6.44 raeburn 5762: }
5763: $datatable .= '<td class="LC_left_item">'.
5764: '<span class="LC_nobreak">'.
5765: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5766: 'value="'.$currval.'" size="10" /> '.
5767: $fieldtitles{$fields[$i]}.'</span></td>';
5768: }
5769: my $colsleft = $numperrow - $rem;
5770: if ($colsleft > 1 ) {
5771: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5772: ' </td>';
5773: } elsif ($colsleft == 1) {
5774: $datatable .= '<td class="LC_left_item"> </td>';
5775: }
5776: $datatable .= '</tr></table></td></tr>';
5777: $$rowtotal ++;
1.160.6.34 raeburn 5778: } elsif ($position eq 'middle') {
5779: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 5780: my @posstypes;
1.160.6.34 raeburn 5781: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 5782: @posstypes = @{$types};
5783: }
5784: unless (grep(/^default$/,@posstypes)) {
5785: push(@posstypes,'default');
5786: }
5787: my %usertypeshash;
5788: if (ref($usertypes) eq 'HASH') {
5789: %usertypeshash = %{$usertypes};
5790: }
5791: $usertypeshash{'default'} = $othertitle;
5792: foreach my $status (@posstypes) {
5793: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
5794: $numinrow,$$rowtotal,\%usertypeshash);
5795: $$rowtotal ++;
1.160.6.34 raeburn 5796: }
5797: } else {
1.160.6.40 raeburn 5798: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 5799: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 5800: );
5801: my @toggles = sort(keys(%choices));
5802: my %defaultchecked = (
5803: 'cancreate_email' => 'off',
5804: );
1.160.6.93 raeburn 5805: my $customclass = 'LC_selfcreate_email';
5806: my $classprefix = 'LC_canmodify_emailusername_';
5807: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 5808: my $display = 'none';
1.160.6.93 raeburn 5809: my $rowstyle = 'display:none';
1.160.6.40 raeburn 5810: if (grep(/^\Qemail\E$/,@selfcreate)) {
5811: $display = 'block';
1.160.6.93 raeburn 5812: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 5813: }
1.160.6.93 raeburn 5814: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
5815: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5816: \%choices,$$rowtotal,$onclick);
5817: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
5818: $rowstyle);
5819: $$rowtotal ++;
5820: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
5821: $rowstyle);
5822: $$rowtotal ++;
5823: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 5824: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 5825: my ($emailrules,$emailruleorder) =
5826: &Apache::lonnet::inst_userrules($dom,'email');
5827: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5828: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5829: if (ref($types) eq 'ARRAY') {
5830: @posstypes = @{$types};
5831: }
5832: if (@posstypes) {
5833: unless (grep(/^default$/,@posstypes)) {
5834: push(@posstypes,'default');
1.160.6.89 raeburn 5835: }
5836: if (ref($usertypes) eq 'HASH') {
5837: %usertypeshash = %{$usertypes};
5838: }
1.160.6.93 raeburn 5839: my $currassign;
5840: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
5841: $currassign = {
5842: selfassign => $domdefaults{'inststatusguest'},
5843: };
5844: @ordered = @{$domdefaults{'inststatusguest'}};
5845: } else {
5846: $currassign = { selfassign => [] };
5847: }
5848: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
5849: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
5850: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
5851: $numinrow,$othertitle,'selfassign',
5852: $rowtotal,$onclicktypes,$customclass,
5853: $rowstyle);
5854: $$rowtotal ++;
1.160.6.89 raeburn 5855: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 5856: foreach my $status (@posstypes) {
5857: my $css_class;
5858: if ($$rowtotal%2) {
5859: $css_class = 'LC_odd_row ';
5860: }
5861: $css_class .= $customclass;
5862: my $rowid = $optionsprefix.$status;
5863: my $hidden = 1;
5864: my $currstyle = 'display:none';
5865: if (grep(/^\Q$status\E$/,@ordered)) {
5866: $currstyle = $rowstyle;
5867: $hidden = 0;
5868: }
5869: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
5870: $emailrules,$emailruleorder,$settings,$status,$rowid,
5871: $usertypeshash{$status},$css_class,$currstyle,$intdom);
5872: unless ($hidden) {
5873: $$rowtotal ++;
5874: }
1.160.6.89 raeburn 5875: }
5876: } else {
1.160.6.93 raeburn 5877: my $css_class;
5878: if ($$rowtotal%2) {
5879: $css_class = 'LC_odd_row ';
5880: }
5881: $css_class .= $customclass;
1.160.6.89 raeburn 5882: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 5883: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
5884: $emailrules,$emailruleorder,$settings,'default','',
5885: $othertitle,$css_class,$rowstyle,$intdom);
5886: $$rowtotal ++;
1.160.6.34 raeburn 5887: }
1.160.6.35 raeburn 5888: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5889: $numinrow = 1;
1.160.6.93 raeburn 5890: if (@posstypes) {
5891: foreach my $status (@posstypes) {
5892: my $rowid = $classprefix.$status;
5893: my $datarowstyle = 'display:none';
5894: if (grep(/^\Q$status\E$/,@ordered)) {
5895: $datarowstyle = $rowstyle;
5896: }
5897: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5898: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
5899: $infotitles,$rowid,$customclass,$datarowstyle);
5900: unless ($datarowstyle eq 'display:none') {
5901: $$rowtotal ++;
5902: }
1.160.6.34 raeburn 5903: }
1.160.6.93 raeburn 5904: } else {
5905: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
5906: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
5907: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 5908: }
5909: }
5910: return $datatable;
5911: }
5912:
1.160.6.93 raeburn 5913: sub selfcreate_javascript {
5914: return <<"ENDSCRIPT";
5915:
5916: <script type="text/javascript">
5917: // <![CDATA[
5918:
5919: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
5920: var x = document.getElementsByClassName(target);
5921: var insttypes = 0;
5922: var insttypeRegExp = new RegExp(prefix);
5923: if ((x.length != undefined) && (x.length > 0)) {
5924: if (form.elements[radio].length != undefined) {
5925: for (var i=0; i<form.elements[radio].length; i++) {
5926: if (form.elements[radio][i].checked) {
5927: if (form.elements[radio][i].value == 1) {
5928: for (var j=0; j<x.length; j++) {
5929: if (x[j].id == 'undefined') {
5930: x[j].style.display = 'table-row';
5931: } else if (insttypeRegExp.test(x[j].id)) {
5932: insttypes ++;
5933: } else {
5934: x[j].style.display = 'table-row';
5935: }
5936: }
5937: } else {
5938: for (var j=0; j<x.length; j++) {
5939: x[j].style.display = 'none';
5940: }
1.160.6.40 raeburn 5941: }
1.160.6.93 raeburn 5942: break;
5943: }
5944: }
5945: if (insttypes > 0) {
5946: toggleDataRow(form,checkbox,target,altprefix);
5947: toggleDataRow(form,checkbox,target,prefix,1);
5948: }
5949: }
5950: }
5951: return;
5952: }
5953:
5954: function toggleDataRow(form,checkbox,target,prefix,docount) {
5955: if (form.elements[checkbox].length != undefined) {
5956: var count = 0;
5957: if (docount) {
5958: for (var i=0; i<form.elements[checkbox].length; i++) {
5959: if (form.elements[checkbox][i].checked) {
5960: count ++;
5961: }
5962: }
5963: }
5964: for (var i=0; i<form.elements[checkbox].length; i++) {
5965: var type = form.elements[checkbox][i].value;
5966: if (document.getElementById(prefix+type)) {
5967: if (form.elements[checkbox][i].checked) {
5968: document.getElementById(prefix+type).style.display = 'table-row';
5969: if (count % 2 == 1) {
5970: document.getElementById(prefix+type).className = target+' LC_odd_row';
5971: } else {
5972: document.getElementById(prefix+type).className = target;
5973: }
5974: count ++;
1.160.6.40 raeburn 5975: } else {
1.160.6.93 raeburn 5976: document.getElementById(prefix+type).style.display = 'none';
5977: }
5978: }
5979: }
5980: }
5981: return;
5982: }
5983:
5984: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
5985: var caller = radio+'_'+status;
5986: if (form.elements[caller].length != undefined) {
5987: for (var i=0; i<form.elements[caller].length; i++) {
5988: if (form.elements[caller][i].checked) {
5989: if (document.getElementById(altprefix+'_inst_'+status)) {
5990: var curr = form.elements[caller][i].value;
5991: if (prefix) {
5992: document.getElementById(prefix+'_'+status).style.display = 'none';
5993: }
5994: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
5995: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
5996: if (curr == 'custom') {
5997: if (prefix) {
5998: document.getElementById(prefix+'_'+status).style.display = 'inline';
5999: }
6000: } else if (curr == 'inst') {
6001: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
6002: } else if (curr == 'noninst') {
6003: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 6004: }
1.160.6.93 raeburn 6005: break;
1.160.6.40 raeburn 6006: }
1.160.6.93 raeburn 6007: }
6008: }
6009: }
6010: }
6011:
6012: // ]]>
6013: </script>
6014:
6015: ENDSCRIPT
6016: }
6017:
6018: sub noninst_users {
6019: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
6020: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
6021: my $class = 'LC_left_item';
6022: if ($css_class) {
6023: $css_class = ' class="'.$css_class.'"';
6024: }
6025: if ($rowid) {
6026: $rowid = ' id="'.$rowid.'"';
6027: }
6028: if ($rowstyle) {
6029: $rowstyle = ' style="'.$rowstyle.'"';
6030: }
6031: my ($output,$description);
6032: if ($type eq 'default') {
6033: $description = &mt('Requests for: [_1]',$typetitle);
6034: } else {
6035: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
6036: }
6037: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
6038: "<td>$description</td>\n".
6039: '<td class="'.$class.'" colspan="2">'.
6040: '<table><tr>';
6041: my %headers = &Apache::lonlocal::texthash(
6042: approve => 'Processing',
6043: email => 'E-mail',
6044: username => 'Username',
6045: );
6046: foreach my $item ('approve','email','username') {
6047: $output .= '<th>'.$headers{$item}.'</th>';
6048: }
6049: $output .= '</tr><tr>';
6050: foreach my $item ('approve','email','username') {
6051: $output .= '<td valign="top">';
6052: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
6053: if ($item eq 'approve') {
6054: %choices = &Apache::lonlocal::texthash (
6055: automatic => 'Automatically approved',
6056: approval => 'Queued for approval',
6057: );
6058: @options = ('automatic','approval');
6059: $hashref = $processing;
6060: $defoption = 'automatic';
6061: $name = 'cancreate_emailprocess_'.$type;
6062: } elsif ($item eq 'email') {
6063: %choices = &Apache::lonlocal::texthash (
6064: any => 'Any e-mail',
6065: inst => 'Institutional only',
6066: noninst => 'Non-institutional only',
6067: custom => 'Custom restrictions',
6068: );
6069: @options = ('any','inst','noninst');
6070: my $showcustom;
6071: if (ref($emailrules) eq 'HASH') {
6072: if (keys(%{$emailrules}) > 0) {
6073: push(@options,'custom');
6074: $showcustom = 'cancreate_emailrule';
6075: if (ref($settings) eq 'HASH') {
6076: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
6077: foreach my $rule (@{$settings->{'email_rule'}}) {
6078: if (exists($emailrules->{$rule})) {
6079: $hascustom ++;
6080: }
6081: }
6082: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
6083: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
6084: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
6085: if (exists($emailrules->{$rule})) {
6086: $hascustom ++;
6087: }
6088: }
6089: }
6090: }
6091: }
6092: }
6093: }
6094: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
6095: "'cancreate_emaildomain','$type'".');"';
6096: $hashref = $emailoptions;
6097: $defoption = 'any';
6098: $name = 'cancreate_emailoptions_'.$type;
6099: } elsif ($item eq 'username') {
6100: %choices = &Apache::lonlocal::texthash (
6101: all => 'Same as e-mail',
6102: first => 'Omit @domain',
6103: free => 'Free to choose',
6104: );
6105: @options = ('all','first','free');
6106: $hashref = $emailverified;
6107: $defoption = 'all';
6108: $name = 'cancreate_usernameoptions_'.$type;
6109: }
6110: foreach my $option (@options) {
6111: my $checked;
6112: if (ref($hashref) eq 'HASH') {
6113: if ($type eq '') {
6114: if (!exists($hashref->{'default'})) {
6115: if ($option eq $defoption) {
6116: $checked = ' checked="checked"';
6117: }
6118: } else {
6119: if ($hashref->{'default'} eq $option) {
6120: $checked = ' checked="checked"';
6121: }
1.160.6.40 raeburn 6122: }
6123: } else {
1.160.6.93 raeburn 6124: if (!exists($hashref->{$type})) {
6125: if ($option eq $defoption) {
6126: $checked = ' checked="checked"';
6127: }
6128: } else {
6129: if ($hashref->{$type} eq $option) {
6130: $checked = ' checked="checked"';
6131: }
1.160.6.40 raeburn 6132: }
6133: }
1.160.6.93 raeburn 6134: } elsif (($item eq 'email') && ($hascustom)) {
6135: if ($option eq 'custom') {
6136: $checked = ' checked="checked"';
6137: }
6138: } elsif ($option eq $defoption) {
6139: $checked = ' checked="checked"';
6140: }
6141: $output .= '<span class="LC_nobreak"><label>'.
6142: '<input type="radio" name="'.$name.'"'.
6143: $checked.' value="'.$option.'"'.$onclick.' />'.
6144: $choices{$option}.'</label></span><br />';
6145: if ($item eq 'email') {
6146: if ($option eq 'custom') {
6147: my $id = 'cancreate_emailrule_'.$type;
6148: my $display = 'none';
6149: if ($checked) {
6150: $display = 'inline';
6151: }
6152: my $numinrow = 2;
6153: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
6154: '<legend>'.&mt('Disallow').'</legend><table>'.
6155: &user_formats_row('email',$settings,$emailrules,
6156: $emailruleorder,$numinrow,'',$type);
6157: '</table></fieldset>';
6158: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
6159: my %text = &Apache::lonlocal::texthash (
6160: inst => 'must end:',
6161: noninst => 'cannot end:',
6162: );
6163: my $value;
6164: if (ref($emaildomain) eq 'HASH') {
6165: if (ref($emaildomain->{$type}) eq 'HASH') {
6166: $value = $emaildomain->{$type}->{$option};
6167: }
6168: }
6169: if ($value eq '') {
6170: $value = '@'.$intdom;
6171: }
6172: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
6173: my $display = 'none';
6174: if ($checked) {
6175: $display = 'inline';
6176: }
6177: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
6178: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
6179: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
6180: '</div>';
6181: }
1.160.6.40 raeburn 6182: }
6183: }
1.160.6.93 raeburn 6184: $output .= '</td>'."\n";
1.160.6.40 raeburn 6185: }
1.160.6.93 raeburn 6186: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 6187: return $output;
6188: }
6189:
1.160.6.5 raeburn 6190: sub captcha_choice {
1.160.6.93 raeburn 6191: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 6192: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
6193: $vertext,$currver);
1.160.6.5 raeburn 6194: my %lt = &captcha_phrases();
6195: $keyentry = 'hidden';
1.160.6.98 raeburn 6196: my $colspan=2;
1.160.6.5 raeburn 6197: if ($context eq 'cancreate') {
1.160.6.34 raeburn 6198: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 6199: } elsif ($context eq 'login') {
6200: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98 raeburn 6201: } elsif ($context eq 'passwords') {
6202: $rowname = &mt('"Forgot Password" CAPTCHA validation');
6203: $colspan=1;
1.160.6.5 raeburn 6204: }
6205: if (ref($settings) eq 'HASH') {
6206: if ($settings->{'captcha'}) {
6207: $checked{$settings->{'captcha'}} = ' checked="checked"';
6208: } else {
6209: $checked{'original'} = ' checked="checked"';
6210: }
6211: if ($settings->{'captcha'} eq 'recaptcha') {
6212: $pubtext = $lt{'pub'};
6213: $privtext = $lt{'priv'};
6214: $keyentry = 'text';
1.160.6.69 raeburn 6215: $vertext = $lt{'ver'};
6216: $currver = $settings->{'recaptchaversion'};
6217: if ($currver ne '2') {
6218: $currver = 1;
6219: }
1.160.6.5 raeburn 6220: }
6221: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
6222: $currpub = $settings->{'recaptchakeys'}{'public'};
6223: $currpriv = $settings->{'recaptchakeys'}{'private'};
6224: }
6225: } else {
6226: $checked{'original'} = ' checked="checked"';
6227: }
1.160.6.93 raeburn 6228: my $css_class;
6229: if ($itemcount%2) {
6230: $css_class = 'LC_odd_row';
6231: }
6232: if ($customcss) {
6233: $css_class .= " $customcss";
6234: }
6235: $css_class =~ s/^\s+//;
6236: if ($css_class) {
6237: $css_class = ' class="'.$css_class.'"';
6238: }
6239: if ($rowstyle) {
6240: $css_class .= ' style="'.$rowstyle.'"';
6241: }
1.160.6.5 raeburn 6242: my $output = '<tr'.$css_class.'>'.
1.160.6.98 raeburn 6243: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 6244: '<table><tr><td>'."\n";
6245: foreach my $option ('original','recaptcha','notused') {
6246: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
6247: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
6248: $lt{$option}.'</label></span>';
6249: unless ($option eq 'notused') {
6250: $output .= (' 'x2)."\n";
6251: }
6252: }
6253: #
6254: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
6255: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
6256: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
6257: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
6258: #
6259: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 6260: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 6261: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
6262: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
6263: $currpub.'" size="40" /></span><br />'."\n".
6264: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
6265: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 6266: $currpriv.'" size="40" /></span><br />'.
6267: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
6268: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
6269: $currver.'" size="3" /></span><br />'.
6270: '</td></tr></table>'."\n".
1.160.6.5 raeburn 6271: '</td></tr>';
6272: return $output;
6273: }
6274:
1.32 raeburn 6275: sub user_formats_row {
1.160.6.93 raeburn 6276: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 6277: my $output;
6278: my %text = (
6279: 'username' => 'new usernames',
6280: 'id' => 'IDs',
6281: );
1.160.6.93 raeburn 6282: unless ($type eq 'email') {
6283: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6284: $output = '<tr '.$css_class.'>'.
6285: '<td><span class="LC_nobreak">'.
6286: &mt("Format rules to check for $text{$type}: ").
6287: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 6288: }
1.27 raeburn 6289: my $rem;
6290: if (ref($ruleorder) eq 'ARRAY') {
6291: for (my $i=0; $i<@{$ruleorder}; $i++) {
6292: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
6293: my $rem = $i%($numinrow);
6294: if ($rem == 0) {
6295: if ($i > 0) {
6296: $output .= '</tr>';
6297: }
6298: $output .= '<tr>';
6299: }
6300: my $check = ' ';
1.39 raeburn 6301: if (ref($settings) eq 'HASH') {
6302: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
6303: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
6304: $check = ' checked="checked" ';
6305: }
1.160.6.93 raeburn 6306: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
6307: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
6308: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
6309: $check = ' checked="checked" ';
6310: }
6311: }
1.27 raeburn 6312: }
6313: }
1.160.6.93 raeburn 6314: my $name = $type.'_rule';
6315: if ($type eq 'email') {
6316: $name .= '_'.$status;
6317: }
1.27 raeburn 6318: $output .= '<td class="LC_left_item">'.
6319: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 6320: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 6321: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
6322: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
6323: }
6324: }
6325: $rem = @{$ruleorder}%($numinrow);
6326: }
1.160.6.93 raeburn 6327: my $colsleft;
6328: if ($rem) {
6329: $colsleft = $numinrow - $rem;
6330: }
1.27 raeburn 6331: if ($colsleft > 1 ) {
6332: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6333: ' </td>';
6334: } elsif ($colsleft == 1) {
6335: $output .= '<td class="LC_left_item"> </td>';
6336: }
1.160.6.93 raeburn 6337: $output .= '</tr></table>';
6338: unless ($type eq 'email') {
6339: $output .= '</td></tr>';
6340: }
1.27 raeburn 6341: return $output;
6342: }
6343:
1.34 raeburn 6344: sub usercreation_types {
6345: my %lt = &Apache::lonlocal::texthash (
6346: author => 'When adding a co-author',
6347: course => 'When adding a user to a course',
1.100 raeburn 6348: requestcrs => 'When requesting a course',
1.34 raeburn 6349: any => 'Any',
6350: official => 'Institutional only ',
6351: unofficial => 'Non-institutional only',
6352: none => 'None',
6353: );
6354: return %lt;
1.48 raeburn 6355: }
1.34 raeburn 6356:
1.160.6.34 raeburn 6357: sub selfcreation_types {
6358: my %lt = &Apache::lonlocal::texthash (
6359: selfcreate => 'User creates own account',
6360: any => 'Any',
6361: official => 'Institutional only ',
6362: unofficial => 'Non-institutional only',
6363: email => 'E-mail address',
6364: login => 'Institutional Login',
6365: sso => 'SSO',
6366: );
6367: }
6368:
1.28 raeburn 6369: sub authtype_names {
6370: my %lt = &Apache::lonlocal::texthash(
6371: int => 'Internal',
6372: krb4 => 'Kerberos 4',
6373: krb5 => 'Kerberos 5',
6374: loc => 'Local',
6375: );
6376: return %lt;
6377: }
6378:
6379: sub context_names {
6380: my %context_title = &Apache::lonlocal::texthash(
6381: author => 'Creating users when an Author',
6382: course => 'Creating users when in a course',
6383: domain => 'Creating users when a Domain Coordinator',
6384: );
6385: return %context_title;
6386: }
6387:
1.33 raeburn 6388: sub print_usermodification {
6389: my ($position,$dom,$settings,$rowtotal) = @_;
6390: my $numinrow = 4;
6391: my ($context,$datatable,$rowcount);
6392: if ($position eq 'top') {
6393: $rowcount = 0;
6394: $context = 'author';
6395: foreach my $role ('ca','aa') {
6396: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6397: $numinrow,$rowcount);
6398: $$rowtotal ++;
6399: $rowcount ++;
6400: }
1.160.6.37 raeburn 6401: } elsif ($position eq 'bottom') {
1.33 raeburn 6402: $context = 'course';
6403: $rowcount = 0;
6404: foreach my $role ('st','ep','ta','in','cr') {
6405: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6406: $numinrow,$rowcount);
6407: $$rowtotal ++;
6408: $rowcount ++;
6409: }
6410: }
6411: return $datatable;
6412: }
6413:
1.43 raeburn 6414: sub print_defaults {
1.160.6.40 raeburn 6415: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 6416: my $rownum = 0;
1.160.6.80 raeburn 6417: my ($datatable,$css_class,$titles);
6418: unless ($position eq 'bottom') {
6419: $titles = &defaults_titles($dom);
6420: }
1.160.6.40 raeburn 6421: if ($position eq 'top') {
6422: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
6423: 'datelocale_def','portal_def');
6424: my %defaults;
6425: if (ref($settings) eq 'HASH') {
6426: %defaults = %{$settings};
1.43 raeburn 6427: } else {
1.160.6.40 raeburn 6428: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
6429: foreach my $item (@items) {
6430: $defaults{$item} = $domdefaults{$item};
6431: }
1.43 raeburn 6432: }
1.160.6.40 raeburn 6433: foreach my $item (@items) {
6434: if ($rownum%2) {
6435: $css_class = '';
6436: } else {
6437: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 6438: }
1.160.6.40 raeburn 6439: $datatable .= '<tr'.$css_class.'>'.
6440: '<td><span class="LC_nobreak">'.$titles->{$item}.
6441: '</span></td><td class="LC_right_item" colspan="3">';
6442: if ($item eq 'auth_def') {
6443: my @authtypes = ('internal','krb4','krb5','localauth');
6444: my %shortauth = (
6445: internal => 'int',
6446: krb4 => 'krb4',
6447: krb5 => 'krb5',
6448: localauth => 'loc'
6449: );
6450: my %authnames = &authtype_names();
6451: foreach my $auth (@authtypes) {
6452: my $checked = ' ';
6453: if ($defaults{$item} eq $auth) {
6454: $checked = ' checked="checked" ';
6455: }
6456: $datatable .= '<label><input type="radio" name="'.$item.
6457: '" value="'.$auth.'"'.$checked.'/>'.
6458: $authnames{$shortauth{$auth}}.'</label> ';
6459: }
6460: } elsif ($item eq 'timezone_def') {
6461: my $includeempty = 1;
6462: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
6463: } elsif ($item eq 'datelocale_def') {
1.160.6.98 raeburn 6464: my $includeempty = 1;
6465: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
6466: } elsif ($item eq 'lang_def') {
6467: my $includeempty = 1;
6468: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.80 raeburn 6469: } else {
1.160.6.98 raeburn 6470: my $size;
6471: if ($item eq 'portal_def') {
6472: $size = ' size="25"';
6473: }
1.160.6.80 raeburn 6474: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.98 raeburn 6475: $defaults{$item}.'"'.$size.' />';
1.160.6.80 raeburn 6476: }
6477: $datatable .= '</td></tr>';
6478: $rownum ++;
6479: }
1.160.6.40 raeburn 6480: } else {
1.160.6.80 raeburn 6481: my %defaults;
1.160.6.40 raeburn 6482: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 6483: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 6484: my $maxnum = @{$settings->{'inststatusorder'}};
6485: for (my $i=0; $i<$maxnum; $i++) {
6486: $css_class = $rownum%2?' class="LC_odd_row"':'';
6487: my $item = $settings->{'inststatusorder'}->[$i];
6488: my $title = $settings->{'inststatustypes'}->{$item};
6489: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
6490: $datatable .= '<tr'.$css_class.'>'.
6491: '<td><span class="LC_nobreak">'.
6492: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
6493: for (my $k=0; $k<=$maxnum; $k++) {
6494: my $vpos = $k+1;
6495: my $selstr;
6496: if ($k == $i) {
6497: $selstr = ' selected="selected" ';
6498: }
6499: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6500: }
6501: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
6502: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
6503: &mt('delete').'</span></td>'.
6504: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
6505: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 6506: '</span></td></tr>';
1.160.6.40 raeburn 6507: }
6508: $css_class = $rownum%2?' class="LC_odd_row"':'';
6509: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
6510: $datatable .= '<tr '.$css_class.'>'.
6511: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
6512: for (my $k=0; $k<=$maxnum; $k++) {
6513: my $vpos = $k+1;
6514: my $selstr;
6515: if ($k == $maxnum) {
6516: $selstr = ' selected="selected" ';
6517: }
6518: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6519: }
6520: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 6521: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 6522: ' '.&mt('(new)').
6523: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
6524: &mt('Name displayed:').
6525: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
6526: '</tr>'."\n";
6527: $rownum ++;
1.141 raeburn 6528: }
1.43 raeburn 6529: }
6530: }
6531: $$rowtotal += $rownum;
6532: return $datatable;
6533: }
6534:
1.160.6.5 raeburn 6535: sub get_languages_hash {
6536: my %langchoices;
6537: foreach my $id (&Apache::loncommon::languageids()) {
6538: my $code = &Apache::loncommon::supportedlanguagecode($id);
6539: if ($code ne '') {
6540: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
6541: }
6542: }
6543: return %langchoices;
6544: }
6545:
1.43 raeburn 6546: sub defaults_titles {
1.141 raeburn 6547: my ($dom) = @_;
1.43 raeburn 6548: my %titles = &Apache::lonlocal::texthash (
6549: 'auth_def' => 'Default authentication type',
6550: 'auth_arg_def' => 'Default authentication argument',
6551: 'lang_def' => 'Default language',
1.54 raeburn 6552: 'timezone_def' => 'Default timezone',
1.68 raeburn 6553: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 6554: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 6555: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
6556: 'intauth_check' => 'Check bcrypt cost if authenticated',
6557: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 6558: );
1.141 raeburn 6559: if ($dom) {
6560: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
6561: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
6562: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
6563: $protocol = 'http' if ($protocol ne 'https');
6564: if ($uint_dom) {
6565: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
6566: $uint_dom);
6567: }
6568: }
1.43 raeburn 6569: return (\%titles);
6570: }
6571:
1.160.6.97 raeburn 6572: sub print_scantron {
6573: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
6574: if ($position eq 'top') {
6575: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
6576: } else {
6577: return &print_scantronconfig($dom,$settings,\$rowtotal);
6578: }
6579: }
6580:
6581: sub scantron_javascript {
6582: return <<"ENDSCRIPT";
6583:
6584: <script type="text/javascript">
6585: // <![CDATA[
6586:
6587: function toggleScantron(form) {
6588: var csvfieldset = new Array();
6589: if (document.getElementById('scantroncsv_cols')) {
6590: csvfieldset.push(document.getElementById('scantroncsv_cols'));
6591: }
6592: if (document.getElementById('scantroncsv_options')) {
6593: csvfieldset.push(document.getElementById('scantroncsv_options'));
6594: }
6595: if (csvfieldset.length) {
6596: if (document.getElementById('scantronconfcsv')) {
6597: var scantroncsv = document.getElementById('scantronconfcsv');
6598: if (scantroncsv.checked) {
6599: for (var i=0; i<csvfieldset.length; i++) {
6600: csvfieldset[i].style.display = 'block';
6601: }
6602: } else {
6603: for (var i=0; i<csvfieldset.length; i++) {
6604: csvfieldset[i].style.display = 'none';
6605: }
6606: var csvselects = document.getElementsByClassName('scantronconfig_csv');
6607: if (csvselects.length) {
6608: for (var j=0; j<csvselects.length; j++) {
6609: csvselects[j].selectedIndex = 0;
6610: }
6611: }
6612: }
6613: }
6614: }
6615: return;
6616: }
6617: // ]]>
6618: </script>
6619:
6620: ENDSCRIPT
6621:
6622: }
6623:
1.46 raeburn 6624: sub print_scantronformat {
6625: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
6626: my $itemcount = 1;
1.60 raeburn 6627: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
6628: %confhash);
1.46 raeburn 6629: my $switchserver = &check_switchserver($dom,$confname);
6630: my %lt = &Apache::lonlocal::texthash (
1.95 www 6631: default => 'Default bubblesheet format file error',
6632: custom => 'Custom bubblesheet format file error',
1.46 raeburn 6633: );
6634: my %scantronfiles = (
6635: default => 'default.tab',
6636: custom => 'custom.tab',
6637: );
6638: foreach my $key (keys(%scantronfiles)) {
6639: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
6640: .$scantronfiles{$key};
6641: }
6642: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
6643: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
6644: if (!$switchserver) {
6645: my $servadm = $r->dir_config('lonAdmEMail');
6646: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
6647: if ($configuserok eq 'ok') {
6648: if ($author_ok eq 'ok') {
6649: my %legacyfile = (
1.160.6.97 raeburn 6650: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
6651: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 6652: );
6653: my %md5chk;
6654: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6655: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
6656: chomp($md5chk{$type});
1.46 raeburn 6657: }
6658: if ($md5chk{'default'} ne $md5chk{'custom'}) {
6659: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 6660: ($scantronurls{$type},my $error) =
1.46 raeburn 6661: &legacy_scantronformat($r,$dom,$confname,
6662: $type,$legacyfile{$type},
6663: $scantronurls{$type},
6664: $scantronfiles{$type});
1.60 raeburn 6665: if ($error ne '') {
6666: $error{$type} = $error;
6667: }
6668: }
6669: if (keys(%error) == 0) {
6670: $is_custom = 1;
1.160.6.97 raeburn 6671: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 6672: $scantronurls{'custom'};
1.160.6.97 raeburn 6673: my $putresult =
1.60 raeburn 6674: &Apache::lonnet::put_dom('configuration',
6675: \%confhash,$dom);
6676: if ($putresult ne 'ok') {
1.160.6.97 raeburn 6677: $error{'custom'} =
1.60 raeburn 6678: '<span class="LC_error">'.
6679: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6680: }
1.46 raeburn 6681: }
6682: } else {
1.60 raeburn 6683: ($scantronurls{'default'},my $error) =
1.46 raeburn 6684: &legacy_scantronformat($r,$dom,$confname,
6685: 'default',$legacyfile{'default'},
6686: $scantronurls{'default'},
6687: $scantronfiles{'default'});
1.60 raeburn 6688: if ($error eq '') {
6689: $confhash{'scantron'}{'scantronformat'} = '';
6690: my $putresult =
6691: &Apache::lonnet::put_dom('configuration',
6692: \%confhash,$dom);
6693: if ($putresult ne 'ok') {
6694: $error{'default'} =
6695: '<span class="LC_error">'.
6696: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6697: }
6698: } else {
6699: $error{'default'} = $error;
6700: }
1.46 raeburn 6701: }
6702: }
6703: }
6704: } else {
1.95 www 6705: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 6706: }
6707: }
6708: if (ref($settings) eq 'HASH') {
6709: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
6710: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
6711: if ((!@info) || ($info[0] eq 'no_such_dir')) {
6712: $scantronurl = '';
6713: } else {
6714: $scantronurl = $settings->{'scantronformat'};
6715: }
6716: $is_custom = 1;
6717: } else {
6718: $scantronurl = $scantronurls{'default'};
6719: }
6720: } else {
1.60 raeburn 6721: if ($is_custom) {
6722: $scantronurl = $scantronurls{'custom'};
6723: } else {
6724: $scantronurl = $scantronurls{'default'};
6725: }
1.46 raeburn 6726: }
6727: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6728: $datatable .= '<tr'.$css_class.'>';
6729: if (!$is_custom) {
1.65 raeburn 6730: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
6731: '<span class="LC_nobreak">';
1.46 raeburn 6732: if ($scantronurl) {
1.160.6.21 raeburn 6733: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
6734: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 6735: } else {
6736: $datatable = &mt('File unavailable for display');
6737: }
1.65 raeburn 6738: $datatable .= '</span></td>';
1.60 raeburn 6739: if (keys(%error) == 0) {
6740: $datatable .= '<td valign="bottom">';
6741: if (!$switchserver) {
6742: $datatable .= &mt('Upload:').'<br />';
6743: }
6744: } else {
6745: my $errorstr;
6746: foreach my $key (sort(keys(%error))) {
6747: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6748: }
6749: $datatable .= '<td>'.$errorstr;
6750: }
1.46 raeburn 6751: } else {
6752: if (keys(%error) > 0) {
6753: my $errorstr;
6754: foreach my $key (sort(keys(%error))) {
6755: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6756: }
1.60 raeburn 6757: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 6758: } elsif ($scantronurl) {
1.160.6.26 raeburn 6759: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 6760: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 6761: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 6762: $link.
6763: '<label><input type="checkbox" name="scantronformat_del"'.
6764: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 6765: '<td><span class="LC_nobreak"> '.
6766: &mt('Replace:').'</span><br />';
1.46 raeburn 6767: }
6768: }
6769: if (keys(%error) == 0) {
6770: if ($switchserver) {
6771: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6772: } else {
1.65 raeburn 6773: $datatable .='<span class="LC_nobreak"> '.
6774: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 6775: }
6776: }
6777: $datatable .= '</td></tr>';
6778: $$rowtotal ++;
6779: return $datatable;
6780: }
6781:
6782: sub legacy_scantronformat {
6783: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
6784: my ($url,$error);
6785: my @statinfo = &Apache::lonnet::stat_file($newurl);
6786: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
6787: (my $result,$url) =
6788: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
6789: '','',$newfile);
6790: if ($result ne 'ok') {
1.130 raeburn 6791: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 6792: }
6793: }
6794: return ($url,$error);
6795: }
1.43 raeburn 6796:
1.160.6.97 raeburn 6797: sub print_scantronconfig {
6798: my ($dom,$settings,$rowtotal) = @_;
6799: my $itemcount = 2;
6800: my $is_checked = ' checked="checked"';
6801: my %optionson = (
6802: hdr => ' checked="checked"',
6803: pad => ' checked="checked"',
6804: rem => ' checked="checked"',
6805: );
6806: my %optionsoff = (
6807: hdr => '',
6808: pad => '',
6809: rem => '',
6810: );
6811: my $currcsvsty = 'none';
6812: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
6813: my @fields = &scantroncsv_fields();
6814: my %titles = &scantronconfig_titles();
6815: if (ref($settings) eq 'HASH') {
6816: if (ref($settings->{config}) eq 'HASH') {
6817: if ($settings->{config}->{dat}) {
6818: $checked{'dat'} = $is_checked;
6819: }
6820: if (ref($settings->{config}->{csv}) eq 'HASH') {
6821: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
6822: %csvfields = %{$settings->{config}->{csv}->{fields}};
6823: if (keys(%csvfields) > 0) {
6824: $checked{'csv'} = $is_checked;
6825: $currcsvsty = 'block';
6826: }
6827: }
6828: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
6829: %csvoptions = %{$settings->{config}->{csv}->{options}};
6830: foreach my $option (keys(%optionson)) {
6831: unless ($csvoptions{$option}) {
6832: $optionsoff{$option} = $optionson{$option};
6833: $optionson{$option} = '';
6834: }
6835: }
6836: }
6837: }
6838: } else {
6839: $checked{'dat'} = $is_checked;
6840: }
6841: } else {
6842: $checked{'dat'} = $is_checked;
6843: }
6844: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
6845: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6846: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
6847: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
6848: foreach my $item ('dat','csv') {
6849: my $id;
6850: if ($item eq 'csv') {
6851: $id = 'id="scantronconfcsv" ';
6852: }
6853: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
6854: $titles{$item}.'</label>'.(' 'x3);
6855: if ($item eq 'csv') {
6856: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
6857: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
6858: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
6859: foreach my $col (@fields) {
6860: my $selnone;
6861: if ($csvfields{$col} eq '') {
6862: $selnone = ' selected="selected"';
6863: }
6864: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
6865: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
6866: '<option value=""'.$selnone.'></option>';
6867: for (my $i=0; $i<20; $i++) {
6868: my $shown = $i+1;
6869: my $sel;
6870: unless ($selnone) {
6871: if (exists($csvfields{$col})) {
6872: if ($csvfields{$col} == $i) {
6873: $sel = ' selected="selected"';
6874: }
6875: }
6876: }
6877: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
6878: }
6879: $datatable .= '</select></td></tr>';
6880: }
6881: $datatable .= '</table></fieldset>'.
6882: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
6883: '<legend>'.&mt('CSV Options').'</legend>';
6884: foreach my $option ('hdr','pad','rem') {
6885: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
6886: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
6887: &mt('Yes').'</label>'.(' 'x2)."\n".
6888: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
6889: }
6890: $datatable .= '</fieldset>';
6891: $itemcount ++;
6892: }
6893: }
6894: $datatable .= '</td></tr>';
6895: $$rowtotal ++;
6896: return $datatable;
6897: }
6898:
6899: sub scantronconfig_titles {
6900: return &Apache::lonlocal::texthash(
6901: dat => 'Standard format (.dat)',
6902: csv => 'Comma separated values (.csv)',
6903: hdr => 'Remove first line in file (contains column titles)',
6904: pad => 'Prepend 0s to PaperID',
6905: rem => 'Remove leading spaces (except Question Response columns)',
6906: CODE => 'CODE',
6907: ID => 'Student ID',
6908: PaperID => 'Paper ID',
6909: FirstName => 'First Name',
6910: LastName => 'Last Name',
6911: FirstQuestion => 'First Question Response',
6912: Section => 'Section',
6913: );
6914: }
6915:
6916: sub scantroncsv_fields {
6917: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
6918: }
6919:
1.49 raeburn 6920: sub print_coursecategories {
1.57 raeburn 6921: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
6922: my $datatable;
6923: if ($position eq 'top') {
1.160.6.42 raeburn 6924: my (%checked);
6925: my @catitems = ('unauth','auth');
6926: my @cattypes = ('std','domonly','codesrch','none');
6927: $checked{'unauth'} = 'std';
6928: $checked{'auth'} = 'std';
6929: if (ref($settings) eq 'HASH') {
6930: foreach my $type (@cattypes) {
6931: if ($type eq $settings->{'unauth'}) {
6932: $checked{'unauth'} = $type;
6933: }
6934: if ($type eq $settings->{'auth'}) {
6935: $checked{'auth'} = $type;
6936: }
6937: }
6938: }
6939: my %lt = &Apache::lonlocal::texthash (
6940: unauth => 'Catalog type for unauthenticated users',
6941: auth => 'Catalog type for authenticated users',
6942: none => 'No catalog',
6943: std => 'Standard catalog',
6944: domonly => 'Domain-only catalog',
6945: codesrch => "Code search form",
6946: );
6947: my $itemcount = 0;
6948: foreach my $item (@catitems) {
6949: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6950: $datatable .= '<tr '.$css_class.'>'.
6951: '<td>'.$lt{$item}.'</td>'.
6952: '<td class="LC_right_item"><span class="LC_nobreak">';
6953: foreach my $type (@cattypes) {
6954: my $ischecked;
6955: if ($checked{$item} eq $type) {
6956: $ischecked=' checked="checked"';
6957: }
6958: $datatable .= '<label>'.
6959: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
6960: ' />'.$lt{$type}.'</label> ';
6961: }
1.160.6.87 raeburn 6962: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 6963: $itemcount ++;
6964: }
6965: $$rowtotal += $itemcount;
6966: } elsif ($position eq 'middle') {
1.57 raeburn 6967: my $toggle_cats_crs = ' ';
6968: my $toggle_cats_dom = ' checked="checked" ';
6969: my $can_cat_crs = ' ';
6970: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 6971: my $toggle_catscomm_comm = ' ';
6972: my $toggle_catscomm_dom = ' checked="checked" ';
6973: my $can_catcomm_comm = ' ';
6974: my $can_catcomm_dom = ' checked="checked" ';
6975:
1.57 raeburn 6976: if (ref($settings) eq 'HASH') {
6977: if ($settings->{'togglecats'} eq 'crs') {
6978: $toggle_cats_crs = $toggle_cats_dom;
6979: $toggle_cats_dom = ' ';
6980: }
6981: if ($settings->{'categorize'} eq 'crs') {
6982: $can_cat_crs = $can_cat_dom;
6983: $can_cat_dom = ' ';
6984: }
1.120 raeburn 6985: if ($settings->{'togglecatscomm'} eq 'comm') {
6986: $toggle_catscomm_comm = $toggle_catscomm_dom;
6987: $toggle_catscomm_dom = ' ';
6988: }
6989: if ($settings->{'categorizecomm'} eq 'comm') {
6990: $can_catcomm_comm = $can_catcomm_dom;
6991: $can_catcomm_dom = ' ';
6992: }
1.57 raeburn 6993: }
6994: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 6995: togglecats => 'Show/Hide a course in catalog',
6996: togglecatscomm => 'Show/Hide a community in catalog',
6997: categorize => 'Assign a category to a course',
6998: categorizecomm => 'Assign a category to a community',
1.57 raeburn 6999: );
7000: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 7001: dom => 'Set in Domain',
7002: crs => 'Set in Course',
7003: comm => 'Set in Community',
1.57 raeburn 7004: );
7005: $datatable = '<tr class="LC_odd_row">'.
7006: '<td>'.$title{'togglecats'}.'</td>'.
7007: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7008: '<input type="radio" name="togglecats"'.
7009: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7010: '<label><input type="radio" name="togglecats"'.
7011: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
7012: '</tr><tr>'.
7013: '<td>'.$title{'categorize'}.'</td>'.
7014: '<td class="LC_right_item"><span class="LC_nobreak">'.
7015: '<label><input type="radio" name="categorize"'.
7016: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7017: '<label><input type="radio" name="categorize"'.
7018: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 7019: '</tr><tr class="LC_odd_row">'.
7020: '<td>'.$title{'togglecatscomm'}.'</td>'.
7021: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7022: '<input type="radio" name="togglecatscomm"'.
7023: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7024: '<label><input type="radio" name="togglecatscomm"'.
7025: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
7026: '</tr><tr>'.
7027: '<td>'.$title{'categorizecomm'}.'</td>'.
7028: '<td class="LC_right_item"><span class="LC_nobreak">'.
7029: '<label><input type="radio" name="categorizecomm"'.
7030: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7031: '<label><input type="radio" name="categorizecomm"'.
7032: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 7033: '</tr>';
1.120 raeburn 7034: $$rowtotal += 4;
1.57 raeburn 7035: } else {
7036: my $css_class;
7037: my $itemcount = 1;
7038: my $cathash;
7039: if (ref($settings) eq 'HASH') {
7040: $cathash = $settings->{'cats'};
7041: }
7042: if (ref($cathash) eq 'HASH') {
7043: my (@cats,@trails,%allitems,%idx,@jsarray);
7044: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
7045: \%allitems,\%idx,\@jsarray);
7046: my $maxdepth = scalar(@cats);
7047: my $colattrib = '';
7048: if ($maxdepth > 2) {
7049: $colattrib = ' colspan="2" ';
7050: }
7051: my @path;
7052: if (@cats > 0) {
7053: if (ref($cats[0]) eq 'ARRAY') {
7054: my $numtop = @{$cats[0]};
7055: my $maxnum = $numtop;
1.120 raeburn 7056: my %default_names = (
7057: instcode => &mt('Official courses'),
7058: communities => &mt('Communities'),
7059: );
7060:
7061: if ((!grep(/^instcode$/,@{$cats[0]})) ||
7062: ($cathash->{'instcode::0'} eq '') ||
7063: (!grep(/^communities$/,@{$cats[0]})) ||
7064: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 7065: $maxnum ++;
7066: }
7067: my $lastidx;
7068: for (my $i=0; $i<$numtop; $i++) {
7069: my $parent = $cats[0][$i];
7070: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7071: my $item = &escape($parent).'::0';
7072: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
7073: $lastidx = $idx{$item};
7074: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7075: .'<select name="'.$item.'"'.$chgstr.'>';
7076: for (my $k=0; $k<=$maxnum; $k++) {
7077: my $vpos = $k+1;
7078: my $selstr;
7079: if ($k == $i) {
7080: $selstr = ' selected="selected" ';
7081: }
7082: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7083: }
1.160.6.29 raeburn 7084: $datatable .= '</select></span></td><td>';
1.120 raeburn 7085: if ($parent eq 'instcode' || $parent eq 'communities') {
7086: $datatable .= '<span class="LC_nobreak">'
7087: .$default_names{$parent}.'</span>';
7088: if ($parent eq 'instcode') {
7089: $datatable .= '<br /><span class="LC_nobreak">('
7090: .&mt('with institutional codes')
7091: .')</span></td><td'.$colattrib.'>';
7092: } else {
7093: $datatable .= '<table><tr><td>';
7094: }
7095: $datatable .= '<span class="LC_nobreak">'
7096: .'<label><input type="radio" name="'
7097: .$parent.'" value="1" checked="checked" />'
7098: .&mt('Display').'</label>';
7099: if ($parent eq 'instcode') {
7100: $datatable .= ' ';
7101: } else {
7102: $datatable .= '</span></td></tr><tr><td>'
7103: .'<span class="LC_nobreak">';
7104: }
7105: $datatable .= '<label><input type="radio" name="'
7106: .$parent.'" value="0" />'
7107: .&mt('Do not display').'</label></span>';
7108: if ($parent eq 'communities') {
7109: $datatable .= '</td></tr></table>';
7110: }
7111: $datatable .= '</td>';
1.57 raeburn 7112: } else {
7113: $datatable .= $parent
1.160.6.29 raeburn 7114: .' <span class="LC_nobreak"><label>'
7115: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 7116: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
7117: }
7118: my $depth = 1;
7119: push(@path,$parent);
7120: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
7121: pop(@path);
7122: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
7123: $itemcount ++;
7124: }
1.48 raeburn 7125: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 7126: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
7127: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 7128: for (my $k=0; $k<=$maxnum; $k++) {
7129: my $vpos = $k+1;
7130: my $selstr;
1.57 raeburn 7131: if ($k == $numtop) {
1.48 raeburn 7132: $selstr = ' selected="selected" ';
7133: }
7134: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7135: }
1.59 bisitz 7136: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 7137: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
7138: .'</tr>'."\n";
1.48 raeburn 7139: $itemcount ++;
1.120 raeburn 7140: foreach my $default ('instcode','communities') {
7141: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
7142: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7143: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
7144: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
7145: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
7146: for (my $k=0; $k<=$maxnum; $k++) {
7147: my $vpos = $k+1;
7148: my $selstr;
7149: if ($k == $maxnum) {
7150: $selstr = ' selected="selected" ';
7151: }
7152: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 7153: }
1.120 raeburn 7154: $datatable .= '</select></span></td>'.
7155: '<td><span class="LC_nobreak">'.
7156: $default_names{$default}.'</span>';
7157: if ($default eq 'instcode') {
7158: $datatable .= '<br /><span class="LC_nobreak">('
7159: .&mt('with institutional codes').')</span>';
7160: }
7161: $datatable .= '</td>'
7162: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
7163: .&mt('Display').'</label> '
7164: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
7165: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 7166: }
7167: }
7168: }
1.57 raeburn 7169: } else {
7170: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 7171: }
7172: } else {
1.160.6.87 raeburn 7173: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 7174: .&initialize_categories($itemcount);
1.48 raeburn 7175: }
1.57 raeburn 7176: $$rowtotal += $itemcount;
1.48 raeburn 7177: }
7178: return $datatable;
7179: }
7180:
1.69 raeburn 7181: sub print_serverstatuses {
7182: my ($dom,$settings,$rowtotal) = @_;
7183: my $datatable;
7184: my @pages = &serverstatus_pages();
7185: my (%namedaccess,%machineaccess);
7186: foreach my $type (@pages) {
7187: $namedaccess{$type} = '';
7188: $machineaccess{$type}= '';
7189: }
7190: if (ref($settings) eq 'HASH') {
7191: foreach my $type (@pages) {
7192: if (exists($settings->{$type})) {
7193: if (ref($settings->{$type}) eq 'HASH') {
7194: foreach my $key (keys(%{$settings->{$type}})) {
7195: if ($key eq 'namedusers') {
7196: $namedaccess{$type} = $settings->{$type}->{$key};
7197: } elsif ($key eq 'machines') {
7198: $machineaccess{$type} = $settings->{$type}->{$key};
7199: }
7200: }
7201: }
7202: }
7203: }
7204: }
1.81 raeburn 7205: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7206: my $rownum = 0;
7207: my $css_class;
7208: foreach my $type (@pages) {
7209: $rownum ++;
7210: $css_class = $rownum%2?' class="LC_odd_row"':'';
7211: $datatable .= '<tr'.$css_class.'>'.
7212: '<td><span class="LC_nobreak">'.
7213: $titles->{$type}.'</span></td>'.
7214: '<td class="LC_left_item">'.
7215: '<input type="text" name="'.$type.'_namedusers" '.
7216: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
7217: '<td class="LC_right_item">'.
7218: '<span class="LC_nobreak">'.
7219: '<input type="text" name="'.$type.'_machines" '.
7220: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 7221: '</span></td></tr>'."\n";
1.69 raeburn 7222: }
7223: $$rowtotal += $rownum;
7224: return $datatable;
7225: }
7226:
7227: sub serverstatus_pages {
7228: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 7229: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 7230: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 7231: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 7232: }
7233:
1.160.6.40 raeburn 7234: sub defaults_javascript {
7235: my ($settings) = @_;
1.160.6.98 raeburn 7236: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 7237: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
7238: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
7239: if ($maxnum eq '') {
7240: $maxnum = 0;
7241: }
7242: $maxnum ++;
1.160.6.51 raeburn 7243: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 7244: return <<"ENDSCRIPT";
7245: <script type="text/javascript">
7246: // <![CDATA[
7247: function reorderTypes(form,caller) {
7248: var changedVal;
7249: $jstext
7250: var newpos = 'addinststatus_pos';
7251: var current = new Array;
7252: var maxh = $maxnum;
7253: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7254: var oldVal;
7255: if (caller == newpos) {
7256: changedVal = newitemVal;
7257: } else {
7258: var curritem = 'inststatus_pos_'+caller;
7259: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
7260: current[newitemVal] = newpos;
7261: }
7262: for (var i=0; i<inststatuses.length; i++) {
7263: if (inststatuses[i] != caller) {
7264: var elementName = 'inststatus_pos_'+inststatuses[i];
7265: if (form.elements[elementName]) {
7266: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7267: current[currVal] = elementName;
7268: }
7269: }
7270: }
7271: for (var j=0; j<maxh; j++) {
7272: if (current[j] == undefined) {
7273: oldVal = j;
7274: }
7275: }
7276: if (oldVal < changedVal) {
7277: for (var k=oldVal+1; k<=changedVal ; k++) {
7278: var elementName = current[k];
7279: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7280: }
7281: } else {
7282: for (var k=changedVal; k<oldVal; k++) {
7283: var elementName = current[k];
7284: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7285: }
7286: }
7287: return;
7288: }
7289:
7290: // ]]>
7291: </script>
7292:
7293: ENDSCRIPT
7294: }
7295: }
7296:
1.160.6.98 raeburn 7297: sub passwords_javascript {
1.160.6.99 raeburn 7298: my %intalert = &Apache::lonlocal::texthash (
7299: 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.',
7300: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
7301: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
7302: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
7303: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
7304: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
7305: );
7306: &js_escape(\%intalert);
7307: my $defmin = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 7308: my $intauthjs = <<"ENDSCRIPT";
7309:
7310: function warnIntAuth(field) {
7311: if (field.name == 'intauth_check') {
7312: if (field.value == '2') {
1.160.6.99 raeburn 7313: alert('$intalert{authcheck}');
1.160.6.98 raeburn 7314: }
7315: }
7316: if (field.name == 'intauth_cost') {
7317: field.value.replace(/\s/g,'');
7318: if (field.value != '') {
7319: var regexdigit=/^\\d+\$/;
7320: if (!regexdigit.test(field.value)) {
1.160.6.99 raeburn 7321: alert('$intalert{authcost}');
7322: }
7323: }
7324: }
7325: return;
7326: }
7327:
7328: function warnIntPass(field) {
7329: field.value.replace(/^\s+/,'');
7330: field.value.replace(/\s+\$/,'');
7331: var regexdigit=/^\\d+\$/;
7332: if (field.name == 'passwords_min') {
7333: if (field.value == '') {
7334: alert('$intalert{passmin}');
7335: field.value = '$defmin';
7336: } else {
7337: if (!regexdigit.test(field.value)) {
7338: alert('$intalert{passmin}');
7339: field.value = '$defmin';
7340: }
7341: var minval = parseInt(field.value,10);
7342: if (minval < $defmin) {
7343: alert('$intalert{passmin}');
7344: field.value = '$defmin';
7345: }
7346: }
7347: } else {
7348: if (field.value == '0') {
7349: field.value = '';
7350: }
7351: if (field.value != '') {
7352: if (field.name == 'passwords_expire') {
7353: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
7354: if (!regexpposnum.test(field.value)) {
7355: alert('$intalert{passexp}');
7356: field.value = '';
7357: } else {
7358: var expval = parseFloat(field.value);
7359: if (expval == 0) {
7360: alert('$intalert{passexp}');
7361: field.value = '';
7362: }
7363: }
7364: } else {
7365: if (!regexdigit.test(field.value)) {
7366: if (field.name == 'passwords_max') {
7367: alert('$intalert{passmax}');
7368: } else {
7369: if (field.name == 'passwords_numsaved') {
7370: alert('$intalert{passnum}');
7371: }
7372: }
7373: }
7374: field.value = '';
1.160.6.98 raeburn 7375: }
7376: }
7377: }
7378: return;
7379: }
7380:
7381: ENDSCRIPT
7382: return &Apache::lonhtmlcommon::scripttag($intauthjs);
7383: }
7384:
1.49 raeburn 7385: sub coursecategories_javascript {
7386: my ($settings) = @_;
1.57 raeburn 7387: my ($output,$jstext,$cathash);
1.49 raeburn 7388: if (ref($settings) eq 'HASH') {
1.57 raeburn 7389: $cathash = $settings->{'cats'};
7390: }
7391: if (ref($cathash) eq 'HASH') {
1.49 raeburn 7392: my (@cats,@jsarray,%idx);
1.57 raeburn 7393: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 7394: if (@jsarray > 0) {
7395: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
7396: for (my $i=0; $i<@jsarray; $i++) {
7397: if (ref($jsarray[$i]) eq 'ARRAY') {
7398: my $catstr = join('","',@{$jsarray[$i]});
7399: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
7400: }
7401: }
7402: }
7403: } else {
7404: $jstext = ' var categories = Array(1);'."\n".
7405: ' categories[0] = Array("instcode_pos");'."\n";
7406: }
1.160.6.42 raeburn 7407: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
7408: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 7409: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
7410: &js_escape(\$instcode_reserved);
7411: &js_escape(\$communities_reserved);
7412: &js_escape(\$choose_again);
1.49 raeburn 7413: $output = <<"ENDSCRIPT";
7414: <script type="text/javascript">
1.109 raeburn 7415: // <![CDATA[
1.49 raeburn 7416: function reorderCats(form,parent,item,idx) {
7417: var changedVal;
7418: $jstext
7419: var newpos = 'addcategory_pos';
7420: if (parent == '') {
7421: var has_instcode = 0;
7422: var maxtop = categories[idx].length;
7423: for (var j=0; j<maxtop; j++) {
7424: if (categories[idx][j] == 'instcode::0') {
7425: has_instcode == 1;
7426: }
7427: }
7428: if (has_instcode == 0) {
7429: categories[idx][maxtop] = 'instcode_pos';
7430: }
7431: } else {
7432: newpos += '_'+parent;
7433: }
7434: var maxh = 1 + categories[idx].length;
7435: var current = new Array;
7436: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7437: if (item == newpos) {
7438: changedVal = newitemVal;
7439: } else {
7440: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
7441: current[newitemVal] = newpos;
7442: }
7443: for (var i=0; i<categories[idx].length; i++) {
7444: var elementName = categories[idx][i];
7445: if (elementName != item) {
7446: if (form.elements[elementName]) {
7447: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7448: current[currVal] = elementName;
7449: }
7450: }
7451: }
7452: var oldVal;
7453: for (var j=0; j<maxh; j++) {
7454: if (current[j] == undefined) {
7455: oldVal = j;
7456: }
7457: }
7458: if (oldVal < changedVal) {
7459: for (var k=oldVal+1; k<=changedVal ; k++) {
7460: var elementName = current[k];
7461: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7462: }
7463: } else {
7464: for (var k=changedVal; k<oldVal; k++) {
7465: var elementName = current[k];
7466: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7467: }
7468: }
7469: return;
7470: }
1.120 raeburn 7471:
7472: function categoryCheck(form) {
7473: if (form.elements['addcategory_name'].value == 'instcode') {
7474: alert('$instcode_reserved\\n$choose_again');
7475: return false;
7476: }
7477: if (form.elements['addcategory_name'].value == 'communities') {
7478: alert('$communities_reserved\\n$choose_again');
7479: return false;
7480: }
7481: return true;
7482: }
7483:
1.109 raeburn 7484: // ]]>
1.49 raeburn 7485: </script>
7486:
7487: ENDSCRIPT
7488: return $output;
7489: }
7490:
1.48 raeburn 7491: sub initialize_categories {
7492: my ($itemcount) = @_;
1.120 raeburn 7493: my ($datatable,$css_class,$chgstr);
7494: my %default_names = (
7495: instcode => 'Official courses (with institutional codes)',
7496: communities => 'Communities',
7497: );
7498: my $select0 = ' selected="selected"';
7499: my $select1 = '';
7500: foreach my $default ('instcode','communities') {
7501: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 7502: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 7503: if ($default eq 'communities') {
7504: $select1 = $select0;
7505: $select0 = '';
7506: }
7507: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7508: .'<select name="'.$default.'_pos">'
7509: .'<option value="0"'.$select0.'>1</option>'
7510: .'<option value="1"'.$select1.'>2</option>'
7511: .'<option value="2">3</option></select> '
7512: .$default_names{$default}
7513: .'</span></td><td><span class="LC_nobreak">'
7514: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
7515: .&mt('Display').'</label> <label>'
7516: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 7517: .'</label></span></td></tr>';
1.120 raeburn 7518: $itemcount ++;
7519: }
1.48 raeburn 7520: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 7521: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 7522: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 7523: .'<select name="addcategory_pos"'.$chgstr.'>'
7524: .'<option value="0">1</option>'
7525: .'<option value="1">2</option>'
7526: .'<option value="2" selected="selected">3</option></select> '
1.160.6.87 raeburn 7527: .&mt('Add category').'</span></td><tda<span class="LC_nobreak">>'.&mt('Name:')
7528: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
7529: .'</td></tr>';
1.48 raeburn 7530: return $datatable;
7531: }
7532:
7533: sub build_category_rows {
1.49 raeburn 7534: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
7535: my ($text,$name,$item,$chgstr);
1.48 raeburn 7536: if (ref($cats) eq 'ARRAY') {
7537: my $maxdepth = scalar(@{$cats});
7538: if (ref($cats->[$depth]) eq 'HASH') {
7539: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
7540: my $numchildren = @{$cats->[$depth]{$parent}};
7541: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 7542: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 7543: my ($idxnum,$parent_name,$parent_item);
7544: my $higher = $depth - 1;
7545: if ($higher == 0) {
7546: $parent_name = &escape($parent).'::'.$higher;
7547: } else {
7548: if (ref($path) eq 'ARRAY') {
7549: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7550: }
7551: }
7552: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 7553: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 7554: if ($j < $numchildren) {
1.48 raeburn 7555: $name = $cats->[$depth]{$parent}[$j];
7556: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 7557: $idxnum = $idx->{$item};
7558: } else {
7559: $name = $parent_name;
7560: $item = $parent_item;
1.48 raeburn 7561: }
1.49 raeburn 7562: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
7563: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 7564: for (my $i=0; $i<=$numchildren; $i++) {
7565: my $vpos = $i+1;
7566: my $selstr;
7567: if ($j == $i) {
7568: $selstr = ' selected="selected" ';
7569: }
7570: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
7571: }
7572: $text .= '</select> ';
7573: if ($j < $numchildren) {
7574: my $deeper = $depth+1;
7575: $text .= $name.' '
7576: .'<label><input type="checkbox" name="deletecategory" value="'
7577: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
7578: if(ref($path) eq 'ARRAY') {
7579: push(@{$path},$name);
1.49 raeburn 7580: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 7581: pop(@{$path});
7582: }
7583: } else {
1.160.6.87 raeburn 7584: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 7585: if ($j == $numchildren) {
7586: $text .= $name;
7587: } else {
7588: $text .= $item;
7589: }
7590: $text .= '" value="" />';
7591: }
7592: $text .= '</td></tr>';
7593: }
7594: $text .= '</table></td>';
7595: } else {
7596: my $higher = $depth-1;
7597: if ($higher == 0) {
7598: $name = &escape($parent).'::'.$higher;
7599: } else {
7600: if (ref($path) eq 'ARRAY') {
7601: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7602: }
7603: }
7604: my $colspan;
7605: if ($parent ne 'instcode') {
7606: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 7607: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 7608: }
7609: }
7610: }
7611: }
7612: return $text;
7613: }
7614:
1.33 raeburn 7615: sub modifiable_userdata_row {
1.160.6.93 raeburn 7616: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
7617: $rowid,$customcss,$rowstyle) = @_;
1.160.6.35 raeburn 7618: my ($role,$rolename,$statustype);
7619: $role = $item;
1.160.6.34 raeburn 7620: if ($context eq 'cancreate') {
1.160.6.93 raeburn 7621: if ($item =~ /^(emailusername)_(.+)$/) {
7622: $role = $1;
7623: $statustype = $2;
1.160.6.35 raeburn 7624: if (ref($usertypes) eq 'HASH') {
7625: if ($usertypes->{$statustype}) {
7626: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
7627: } else {
7628: $rolename = &mt('Data provided by user');
7629: }
7630: }
1.160.6.34 raeburn 7631: }
7632: } elsif ($context eq 'selfcreate') {
1.63 raeburn 7633: if (ref($usertypes) eq 'HASH') {
7634: $rolename = $usertypes->{$role};
7635: } else {
7636: $rolename = $role;
7637: }
1.33 raeburn 7638: } else {
1.63 raeburn 7639: if ($role eq 'cr') {
7640: $rolename = &mt('Custom role');
7641: } else {
7642: $rolename = &Apache::lonnet::plaintext($role);
7643: }
1.33 raeburn 7644: }
1.160.6.34 raeburn 7645: my (@fields,%fieldtitles);
7646: if (ref($fieldsref) eq 'ARRAY') {
7647: @fields = @{$fieldsref};
7648: } else {
7649: @fields = ('lastname','firstname','middlename','generation',
7650: 'permanentemail','id');
7651: }
7652: if ((ref($titlesref) eq 'HASH')) {
7653: %fieldtitles = %{$titlesref};
7654: } else {
7655: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7656: }
1.33 raeburn 7657: my $output;
1.160.6.93 raeburn 7658: my $css_class;
7659: if ($rowcount%2) {
7660: $css_class = 'LC_odd_row';
7661: }
7662: if ($customcss) {
7663: $css_class .= " $customcss";
7664: }
7665: $css_class =~ s/^\s+//;
7666: if ($css_class) {
7667: $css_class = ' class="'.$css_class.'"';
7668: }
7669: if ($rowstyle) {
7670: $css_class .= ' style="'.$rowstyle.'"';
7671: }
7672: if ($rowid) {
7673: $rowid = ' id="'.$rowid.'"';
7674: }
7675:
7676: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 7677: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
7678: '<td class="LC_left_item" colspan="2"><table>';
7679: my $rem;
7680: my %checks;
7681: if (ref($settings) eq 'HASH') {
7682: if (ref($settings->{$context}) eq 'HASH') {
7683: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 7684: my $hashref = $settings->{$context}->{$role};
7685: if ($role eq 'emailusername') {
7686: if ($statustype) {
7687: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
7688: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 7689: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 7690: foreach my $field (@fields) {
7691: if ($hashref->{$field}) {
7692: $checks{$field} = $hashref->{$field};
7693: }
7694: }
7695: }
7696: }
7697: }
7698: } else {
7699: if (ref($hashref) eq 'HASH') {
7700: foreach my $field (@fields) {
7701: if ($hashref->{$field}) {
7702: $checks{$field} = ' checked="checked" ';
7703: }
7704: }
1.33 raeburn 7705: }
7706: }
7707: }
7708: }
7709: }
1.160.6.93 raeburn 7710:
7711: my $total = scalar(@fields);
7712: for (my $i=0; $i<$total; $i++) {
7713: $rem = $i%($numinrow);
1.33 raeburn 7714: if ($rem == 0) {
7715: if ($i > 0) {
7716: $output .= '</tr>';
7717: }
7718: $output .= '<tr>';
7719: }
7720: my $check = ' ';
1.160.6.35 raeburn 7721: unless ($role eq 'emailusername') {
7722: if (exists($checks{$fields[$i]})) {
1.160.6.98 raeburn 7723: $check = $checks{$fields[$i]};
1.160.6.35 raeburn 7724: } else {
7725: if ($role eq 'st') {
7726: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 7727: $check = ' checked="checked" ';
1.160.6.35 raeburn 7728: }
1.33 raeburn 7729: }
7730: }
7731: }
7732: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 7733: '<span class="LC_nobreak">';
7734: if ($role eq 'emailusername') {
7735: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
7736: $checks{$fields[$i]} = 'omit';
7737: }
7738: foreach my $option ('required','optional','omit') {
7739: my $checked='';
7740: if ($checks{$fields[$i]} eq $option) {
7741: $checked='checked="checked" ';
7742: }
7743: $output .= '<label>'.
7744: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
7745: &mt($option).'</label>'.(' ' x2);
7746: }
7747: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
7748: } else {
7749: $output .= '<label>'.
7750: '<input type="checkbox" name="canmodify_'.$role.'" '.
7751: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
7752: '</label>';
7753: }
7754: $output .= '</span></td>';
1.33 raeburn 7755: }
1.160.6.93 raeburn 7756: $rem = $total%$numinrow;
7757: my $colsleft;
7758: if ($rem) {
7759: $colsleft = $numinrow - $rem;
7760: }
7761: if ($colsleft > 1) {
1.33 raeburn 7762: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7763: ' </td>';
7764: } elsif ($colsleft == 1) {
7765: $output .= '<td class="LC_left_item"> </td>';
7766: }
7767: $output .= '</tr></table></td></tr>';
7768: return $output;
7769: }
1.28 raeburn 7770:
1.93 raeburn 7771: sub insttypes_row {
1.160.6.93 raeburn 7772: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
7773: $customcss,$rowstyle) = @_;
1.93 raeburn 7774: my %lt = &Apache::lonlocal::texthash (
7775: cansearch => 'Users allowed to search',
7776: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 7777: lockablenames => 'User preference to lock name',
1.160.6.93 raeburn 7778: selfassign => 'Self-reportable affiliations',
1.160.6.101! raeburn 7779: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 7780: );
7781: my $showdom;
7782: if ($context eq 'cansearch') {
7783: $showdom = ' ('.$dom.')';
7784: }
1.160.6.5 raeburn 7785: my $class = 'LC_left_item';
7786: if ($context eq 'statustocreate') {
7787: $class = 'LC_right_item';
7788: }
1.160.6.93 raeburn 7789: my $css_class;
7790: if ($$rowtotal%2) {
7791: $css_class = 'LC_odd_row';
7792: }
7793: if ($customcss) {
7794: $css_class .= ' '.$customcss;
7795: }
7796: $css_class =~ s/^\s+//;
7797: if ($css_class) {
7798: $css_class = ' class="'.$css_class.'"';
7799: }
7800: if ($rowstyle) {
7801: $css_class .= ' style="'.$rowstyle.'"';
7802: }
7803: if ($onclick) {
7804: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 7805: }
7806: my $output = '<tr'.$css_class.'>'.
7807: '<td>'.$lt{$context}.$showdom.
7808: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 7809: my $rem;
7810: if (ref($types) eq 'ARRAY') {
7811: for (my $i=0; $i<@{$types}; $i++) {
7812: if (defined($usertypes->{$types->[$i]})) {
7813: my $rem = $i%($numinrow);
7814: if ($rem == 0) {
7815: if ($i > 0) {
7816: $output .= '</tr>';
7817: }
7818: $output .= '<tr>';
1.23 raeburn 7819: }
1.26 raeburn 7820: my $check = ' ';
1.99 raeburn 7821: if (ref($settings) eq 'HASH') {
7822: if (ref($settings->{$context}) eq 'ARRAY') {
7823: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
7824: $check = ' checked="checked" ';
7825: }
1.160.6.101! raeburn 7826: } elsif (ref($settings->{$context}) eq 'HASH') {
! 7827: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
! 7828: $check = ' checked="checked" ';
! 7829: }
1.99 raeburn 7830: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7831: $check = ' checked="checked" ';
7832: }
1.23 raeburn 7833: }
1.26 raeburn 7834: $output .= '<td class="LC_left_item">'.
7835: '<span class="LC_nobreak"><label>'.
1.93 raeburn 7836: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 7837: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
1.26 raeburn 7838: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 7839: }
7840: }
1.26 raeburn 7841: $rem = @{$types}%($numinrow);
1.23 raeburn 7842: }
7843: my $colsleft = $numinrow - $rem;
1.160.6.101! raeburn 7844: if ($context eq 'overrides') {
! 7845: if ($colsleft > 1) {
! 7846: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
! 7847: } else {
! 7848: $output .= '<td class="LC_left_item">';
! 7849: }
! 7850: $output .= ' ';
1.23 raeburn 7851: } else {
1.160.6.101! raeburn 7852: if ($rem == 0) {
! 7853: $output .= '<tr>';
! 7854: }
! 7855: if ($colsleft > 1) {
! 7856: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
! 7857: } else {
! 7858: $output .= '<td class="LC_left_item">';
! 7859: }
! 7860: my $defcheck = ' ';
! 7861: if (ref($settings) eq 'HASH') {
! 7862: if (ref($settings->{$context}) eq 'ARRAY') {
! 7863: if (grep(/^default$/,@{$settings->{$context}})) {
! 7864: $defcheck = ' checked="checked" ';
! 7865: }
! 7866: } elsif ($context eq 'statustocreate') {
1.99 raeburn 7867: $defcheck = ' checked="checked" ';
7868: }
1.26 raeburn 7869: }
1.160.6.101! raeburn 7870: $output .= '<span class="LC_nobreak"><label>'.
! 7871: '<input type="checkbox" name="'.$context.'" '.
! 7872: 'value="default"'.$defcheck.$onclick.' />'.
! 7873: $othertitle.'</label></span>';
1.23 raeburn 7874: }
1.160.6.101! raeburn 7875: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 7876: return $output;
1.23 raeburn 7877: }
7878:
7879: sub sorted_searchtitles {
7880: my %searchtitles = &Apache::lonlocal::texthash(
7881: 'uname' => 'username',
7882: 'lastname' => 'last name',
7883: 'lastfirst' => 'last name, first name',
7884: );
7885: my @titleorder = ('uname','lastname','lastfirst');
7886: return (\%searchtitles,\@titleorder);
7887: }
7888:
1.25 raeburn 7889: sub sorted_searchtypes {
7890: my %srchtypes_desc = (
7891: exact => 'is exact match',
7892: contains => 'contains ..',
7893: begins => 'begins with ..',
7894: );
7895: my @srchtypeorder = ('exact','begins','contains');
7896: return (\%srchtypes_desc,\@srchtypeorder);
7897: }
7898:
1.3 raeburn 7899: sub usertype_update_row {
7900: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
7901: my $datatable;
7902: my $numinrow = 4;
7903: foreach my $type (@{$types}) {
7904: if (defined($usertypes->{$type})) {
7905: $$rownums ++;
7906: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
7907: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
7908: '</td><td class="LC_left_item"><table>';
7909: for (my $i=0; $i<@{$fields}; $i++) {
7910: my $rem = $i%($numinrow);
7911: if ($rem == 0) {
7912: if ($i > 0) {
7913: $datatable .= '</tr>';
7914: }
7915: $datatable .= '<tr>';
7916: }
7917: my $check = ' ';
1.39 raeburn 7918: if (ref($settings) eq 'HASH') {
7919: if (ref($settings->{'fields'}) eq 'HASH') {
7920: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
7921: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
7922: $check = ' checked="checked" ';
7923: }
1.3 raeburn 7924: }
7925: }
7926: }
7927:
7928: if ($i == @{$fields}-1) {
7929: my $colsleft = $numinrow - $rem;
7930: if ($colsleft > 1) {
7931: $datatable .= '<td colspan="'.$colsleft.'">';
7932: } else {
7933: $datatable .= '<td>';
7934: }
7935: } else {
7936: $datatable .= '<td>';
7937: }
1.8 raeburn 7938: $datatable .= '<span class="LC_nobreak"><label>'.
7939: '<input type="checkbox" name="updateable_'.$type.
7940: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
7941: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 7942: }
7943: $datatable .= '</tr></table></td></tr>';
7944: }
7945: }
7946: return $datatable;
1.1 raeburn 7947: }
7948:
7949: sub modify_login {
1.160.6.24 raeburn 7950: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 7951: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
7952: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
7953: %title = ( coursecatalog => 'Display course catalog',
7954: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 7955: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 7956: newuser => 'Link for visitors to create a user account',
7957: loginheader => 'Log-in box header');
7958: @offon = ('off','on');
1.112 raeburn 7959: if (ref($domconfig{login}) eq 'HASH') {
7960: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
7961: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
7962: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
7963: }
7964: }
7965: }
1.9 raeburn 7966: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
7967: \%domconfig,\%loginhash);
1.160.6.14 raeburn 7968: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7969: foreach my $item (@toggles) {
7970: $loginhash{login}{$item} = $env{'form.'.$item};
7971: }
1.41 raeburn 7972: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 7973: if (ref($colchanges{'login'}) eq 'HASH') {
7974: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
7975: \%loginhash);
7976: }
1.110 raeburn 7977:
1.149 raeburn 7978: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 7979: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 7980: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 7981: if (keys(%servers) > 1) {
7982: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 7983: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
7984: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
7985: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
7986: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
7987: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
7988: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7989: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7990: $changes{'loginvia'}{$lonhost} = 1;
7991: } else {
7992: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
7993: $changes{'loginvia'}{$lonhost} = 1;
7994: }
7995: } else {
7996: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7997: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7998: $changes{'loginvia'}{$lonhost} = 1;
7999: }
8000: }
8001: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
8002: foreach my $item (@loginvia_attribs) {
8003: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
8004: }
8005: } else {
8006: foreach my $item (@loginvia_attribs) {
8007: my $new = $env{'form.'.$lonhost.'_'.$item};
8008: if (($item eq 'serverpath') && ($new eq 'custom')) {
8009: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
8010: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8011: $new = '/';
8012: }
8013: }
8014: if (($item eq 'custompath') &&
8015: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8016: $new = '';
8017: }
8018: if ($new ne $curr_loginvia{$lonhost}{$item}) {
8019: $changes{'loginvia'}{$lonhost} = 1;
8020: }
8021: if ($item eq 'exempt') {
1.160.6.56 raeburn 8022: $new = &check_exempt_addresses($new);
1.128 raeburn 8023: }
8024: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8025: }
8026: }
1.112 raeburn 8027: } else {
1.128 raeburn 8028: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8029: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 8030: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 8031: foreach my $item (@loginvia_attribs) {
8032: my $new = $env{'form.'.$lonhost.'_'.$item};
8033: if (($item eq 'serverpath') && ($new eq 'custom')) {
8034: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8035: $new = '/';
8036: }
8037: }
8038: if (($item eq 'custompath') &&
8039: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8040: $new = '';
8041: }
8042: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8043: }
1.110 raeburn 8044: }
8045: }
8046: }
8047: }
1.119 raeburn 8048:
1.160.6.5 raeburn 8049: my $servadm = $r->dir_config('lonAdmEMail');
8050: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
8051: if (ref($domconfig{'login'}) eq 'HASH') {
8052: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
8053: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
8054: if ($lang eq 'nolang') {
8055: push(@currlangs,$lang);
8056: } elsif (defined($langchoices{$lang})) {
8057: push(@currlangs,$lang);
8058: } else {
8059: next;
8060: }
8061: }
8062: }
8063: }
8064: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
8065: if (@currlangs > 0) {
8066: foreach my $lang (@currlangs) {
8067: if (grep(/^\Q$lang\E$/,@delurls)) {
8068: $changes{'helpurl'}{$lang} = 1;
8069: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
8070: $changes{'helpurl'}{$lang} = 1;
8071: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
8072: push(@newlangs,$lang);
8073: } else {
8074: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8075: }
8076: }
8077: }
8078: unless (grep(/^nolang$/,@currlangs)) {
8079: if ($env{'form.loginhelpurl_nolang.filename'}) {
8080: $changes{'helpurl'}{'nolang'} = 1;
8081: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
8082: push(@newlangs,'nolang');
8083: }
8084: }
8085: if ($env{'form.loginhelpurl_add_lang'}) {
8086: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
8087: ($env{'form.loginhelpurl_add_file.filename'})) {
8088: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
8089: $addedfile = $env{'form.loginhelpurl_add_lang'};
8090: }
8091: }
8092: if ((@newlangs > 0) || ($addedfile)) {
8093: my $error;
8094: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8095: if ($configuserok eq 'ok') {
8096: if ($switchserver) {
8097: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
8098: } elsif ($author_ok eq 'ok') {
8099: my @allnew = @newlangs;
8100: if ($addedfile ne '') {
8101: push(@allnew,$addedfile);
8102: }
8103: foreach my $lang (@allnew) {
8104: my $formelem = 'loginhelpurl_'.$lang;
8105: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
8106: $formelem = 'loginhelpurl_add_file';
8107: }
8108: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8109: "help/$lang",'','',$newfile{$lang});
8110: if ($result eq 'ok') {
8111: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
8112: $changes{'helpurl'}{$lang} = 1;
8113: } else {
8114: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
8115: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
8116: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
8117: (!grep(/^\Q$lang\E$/,@delurls))) {
8118: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8119: }
8120: }
8121: }
8122: } else {
8123: $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);
8124: }
8125: } else {
8126: $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);
8127: }
8128: if ($error) {
8129: &Apache::lonnet::logthis($error);
8130: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8131: }
8132: }
1.160.6.56 raeburn 8133:
8134: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
8135: if (ref($domconfig{'login'}) eq 'HASH') {
8136: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
8137: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
8138: if ($domservers{$lonhost}) {
8139: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8140: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 8141: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 8142: }
8143: }
8144: }
8145: }
8146: }
8147: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
8148: foreach my $lonhost (sort(keys(%domservers))) {
8149: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8150: $changes{'headtag'}{$lonhost} = 1;
8151: } else {
8152: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
8153: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
8154: }
8155: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
8156: push(@newhosts,$lonhost);
8157: } elsif ($currheadtagurls{$lonhost}) {
8158: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
8159: if ($currexempt{$lonhost}) {
8160: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
8161: $changes{'headtag'}{$lonhost} = 1;
8162: }
8163: } elsif ($possexempt{$lonhost}) {
8164: $changes{'headtag'}{$lonhost} = 1;
8165: }
8166: if ($possexempt{$lonhost}) {
8167: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8168: }
8169: }
8170: }
8171: }
8172: if (@newhosts) {
8173: my $error;
8174: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8175: if ($configuserok eq 'ok') {
8176: if ($switchserver) {
8177: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
8178: } elsif ($author_ok eq 'ok') {
8179: foreach my $lonhost (@newhosts) {
8180: my $formelem = 'loginheadtag_'.$lonhost;
8181: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8182: "login/headtag/$lonhost",'','',
8183: $env{'form.loginheadtag_'.$lonhost.'.filename'});
8184: if ($result eq 'ok') {
8185: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
8186: $changes{'headtag'}{$lonhost} = 1;
8187: if ($possexempt{$lonhost}) {
8188: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8189: }
8190: } else {
8191: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
8192: $newheadtagurls{$lonhost},$result);
8193: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
8194: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
8195: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
8196: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
8197: }
8198: }
8199: }
8200: } else {
8201: $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);
8202: }
8203: } else {
8204: $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);
8205: }
8206: if ($error) {
8207: &Apache::lonnet::logthis($error);
8208: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8209: }
8210: }
1.160.6.5 raeburn 8211: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
8212:
8213: my $defaulthelpfile = '/adm/loginproblems.html';
8214: my $defaulttext = &mt('Default in use');
8215:
1.1 raeburn 8216: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
8217: $dom);
8218: if ($putresult eq 'ok') {
1.160.6.14 raeburn 8219: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8220: my %defaultchecked = (
8221: 'coursecatalog' => 'on',
1.160.6.14 raeburn 8222: 'helpdesk' => 'on',
1.42 raeburn 8223: 'adminmail' => 'off',
1.43 raeburn 8224: 'newuser' => 'off',
1.42 raeburn 8225: );
1.55 raeburn 8226: if (ref($domconfig{'login'}) eq 'HASH') {
8227: foreach my $item (@toggles) {
8228: if ($defaultchecked{$item} eq 'on') {
8229: if (($domconfig{'login'}{$item} eq '0') &&
8230: ($env{'form.'.$item} eq '1')) {
8231: $changes{$item} = 1;
8232: } elsif (($domconfig{'login'}{$item} eq '' ||
8233: $domconfig{'login'}{$item} eq '1') &&
8234: ($env{'form.'.$item} eq '0')) {
8235: $changes{$item} = 1;
8236: }
8237: } elsif ($defaultchecked{$item} eq 'off') {
8238: if (($domconfig{'login'}{$item} eq '1') &&
8239: ($env{'form.'.$item} eq '0')) {
8240: $changes{$item} = 1;
8241: } elsif (($domconfig{'login'}{$item} eq '' ||
8242: $domconfig{'login'}{$item} eq '0') &&
8243: ($env{'form.'.$item} eq '1')) {
8244: $changes{$item} = 1;
8245: }
1.42 raeburn 8246: }
8247: }
1.41 raeburn 8248: }
1.6 raeburn 8249: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 8250: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8251: if (ref($lastactref) eq 'HASH') {
8252: $lastactref->{'domainconfig'} = 1;
8253: }
1.1 raeburn 8254: $resulttext = &mt('Changes made:').'<ul>';
8255: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 8256: if ($item eq 'loginvia') {
1.112 raeburn 8257: if (ref($changes{$item}) eq 'HASH') {
8258: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
8259: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 8260: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
8261: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
8262: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
8263: $protocol = 'http' if ($protocol ne 'https');
8264: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
8265:
8266: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
8267: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
8268: } else {
8269: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
8270: }
8271: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
8272: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
8273: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
8274: }
8275: $resulttext .= '</li>';
8276: } else {
8277: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
8278: }
1.112 raeburn 8279: } else {
1.128 raeburn 8280: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 8281: }
8282: }
1.128 raeburn 8283: $resulttext .= '</ul></li>';
1.112 raeburn 8284: }
1.160.6.5 raeburn 8285: } elsif ($item eq 'helpurl') {
8286: if (ref($changes{$item}) eq 'HASH') {
8287: foreach my $lang (sort(keys(%{$changes{$item}}))) {
8288: if (grep(/^\Q$lang\E$/,@delurls)) {
8289: my ($chg,$link);
8290: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
8291: if ($lang eq 'nolang') {
8292: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
8293: } else {
8294: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
8295: }
8296: $resulttext .= '<li>'.$chg.'</li>';
8297: } else {
8298: my $chg;
8299: if ($lang eq 'nolang') {
8300: $chg = &mt('custom log-in help file for no preferred language');
8301: } else {
8302: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
8303: }
8304: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
8305: $loginhash{'login'}{'helpurl'}{$lang}.
8306: '?inhibitmenu=yes',$chg,600,500).
8307: '</li>';
8308: }
8309: }
8310: }
1.160.6.56 raeburn 8311: } elsif ($item eq 'headtag') {
8312: if (ref($changes{$item}) eq 'HASH') {
8313: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
8314: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8315: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
8316: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8317: $resulttext .= '<li><a href="'.
8318: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
8319: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
8320: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
8321: if ($possexempt{$lonhost}) {
8322: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
8323: } else {
8324: $resulttext .= &mt('included for any client IP');
8325: }
8326: $resulttext .= '</li>';
8327: }
8328: }
8329: }
1.160.6.5 raeburn 8330: } elsif ($item eq 'captcha') {
8331: if (ref($loginhash{'login'}) eq 'HASH') {
8332: my $chgtxt;
8333: if ($loginhash{'login'}{$item} eq 'notused') {
8334: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
8335: } else {
8336: my %captchas = &captcha_phrases();
8337: if ($captchas{$loginhash{'login'}{$item}}) {
8338: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
8339: } else {
8340: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
8341: }
8342: }
8343: $resulttext .= '<li>'.$chgtxt.'</li>';
8344: }
8345: } elsif ($item eq 'recaptchakeys') {
8346: if (ref($loginhash{'login'}) eq 'HASH') {
8347: my ($privkey,$pubkey);
8348: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
8349: $pubkey = $loginhash{'login'}{$item}{'public'};
8350: $privkey = $loginhash{'login'}{$item}{'private'};
8351: }
8352: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
8353: if (!$pubkey) {
8354: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
8355: } else {
8356: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8357: }
8358: if (!$privkey) {
8359: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
8360: } else {
1.160.6.53 raeburn 8361: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 8362: }
8363: $chgtxt .= '</ul>';
8364: $resulttext .= '<li>'.$chgtxt.'</li>';
8365: }
1.160.6.69 raeburn 8366: } elsif ($item eq 'recaptchaversion') {
8367: if (ref($loginhash{'login'}) eq 'HASH') {
8368: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
8369: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
8370: '</li>';
8371: }
8372: }
1.41 raeburn 8373: } else {
8374: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
8375: }
1.1 raeburn 8376: }
1.6 raeburn 8377: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 8378: } else {
8379: $resulttext = &mt('No changes made to log-in page settings');
8380: }
8381: } else {
1.11 albertel 8382: $resulttext = '<span class="LC_error">'.
8383: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8384: }
1.6 raeburn 8385: if ($errors) {
1.9 raeburn 8386: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 8387: $errors.'</ul>';
8388: }
8389: return $resulttext;
8390: }
8391:
1.160.6.56 raeburn 8392: sub check_exempt_addresses {
8393: my ($iplist) = @_;
8394: $iplist =~ s/^\s+//;
8395: $iplist =~ s/\s+$//;
8396: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
8397: my (@okips,$new);
8398: foreach my $ip (@poss_ips) {
8399: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
8400: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
8401: push(@okips,$ip);
8402: }
8403: }
8404: }
8405: if (@okips > 0) {
8406: $new = join(',',@okips);
8407: } else {
8408: $new = '';
8409: }
8410: return $new;
8411: }
8412:
1.6 raeburn 8413: sub color_font_choices {
8414: my %choices =
8415: &Apache::lonlocal::texthash (
8416: img => "Header",
8417: bgs => "Background colors",
8418: links => "Link colors",
1.55 raeburn 8419: images => "Images",
1.6 raeburn 8420: font => "Font color",
1.160.6.22 raeburn 8421: fontmenu => "Font menu",
1.76 raeburn 8422: pgbg => "Page",
1.6 raeburn 8423: tabbg => "Header",
8424: sidebg => "Border",
8425: link => "Link",
8426: alink => "Active link",
8427: vlink => "Visited link",
8428: );
8429: return %choices;
8430: }
8431:
8432: sub modify_rolecolors {
1.160.6.24 raeburn 8433: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 8434: my ($resulttext,%rolehash);
8435: $rolehash{'rolecolors'} = {};
1.55 raeburn 8436: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
8437: if ($domconfig{'rolecolors'} eq '') {
8438: $domconfig{'rolecolors'} = {};
8439: }
8440: }
1.9 raeburn 8441: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 8442: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
8443: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
8444: $dom);
8445: if ($putresult eq 'ok') {
8446: if (keys(%changes) > 0) {
1.41 raeburn 8447: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8448: if (ref($lastactref) eq 'HASH') {
8449: $lastactref->{'domainconfig'} = 1;
8450: }
1.6 raeburn 8451: $resulttext = &display_colorchgs($dom,\%changes,$roles,
8452: $rolehash{'rolecolors'});
8453: } else {
8454: $resulttext = &mt('No changes made to default color schemes');
8455: }
8456: } else {
1.11 albertel 8457: $resulttext = '<span class="LC_error">'.
8458: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 8459: }
8460: if ($errors) {
8461: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8462: $errors.'</ul>';
8463: }
8464: return $resulttext;
8465: }
8466:
8467: sub modify_colors {
1.9 raeburn 8468: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 8469: my (%changes,%choices);
1.51 raeburn 8470: my @bgs;
1.6 raeburn 8471: my @links = ('link','alink','vlink');
1.41 raeburn 8472: my @logintext;
1.6 raeburn 8473: my @images;
8474: my $servadm = $r->dir_config('lonAdmEMail');
8475: my $errors;
1.160.6.22 raeburn 8476: my %defaults;
1.6 raeburn 8477: foreach my $role (@{$roles}) {
8478: if ($role eq 'login') {
1.12 raeburn 8479: %choices = &login_choices();
1.41 raeburn 8480: @logintext = ('textcol','bgcol');
1.12 raeburn 8481: } else {
8482: %choices = &color_font_choices();
8483: }
8484: if ($role eq 'login') {
1.41 raeburn 8485: @images = ('img','logo','domlogo','login');
1.51 raeburn 8486: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 8487: } else {
8488: @images = ('img');
1.160.6.22 raeburn 8489: @bgs = ('pgbg','tabbg','sidebg');
8490: }
8491: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
8492: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
8493: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
8494: }
8495: if ($role eq 'login') {
8496: foreach my $item (@logintext) {
1.160.6.39 raeburn 8497: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8498: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8499: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8500: }
8501: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 8502: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8503: }
8504: }
8505: } else {
1.160.6.39 raeburn 8506: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
8507: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
8508: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
8509: }
8510: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 8511: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
8512: }
1.6 raeburn 8513: }
1.160.6.22 raeburn 8514: foreach my $item (@bgs) {
1.160.6.39 raeburn 8515: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8516: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8517: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8518: }
8519: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 8520: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8521: }
8522: }
8523: foreach my $item (@links) {
1.160.6.39 raeburn 8524: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8525: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8526: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8527: }
8528: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 8529: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8530: }
1.6 raeburn 8531: }
1.46 raeburn 8532: my ($configuserok,$author_ok,$switchserver) =
8533: &config_check($dom,$confname,$servadm);
1.9 raeburn 8534: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 8535: if (ref($domconfig->{$role}) ne 'HASH') {
8536: $domconfig->{$role} = {};
8537: }
1.8 raeburn 8538: foreach my $img (@images) {
1.70 raeburn 8539: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
8540: if (defined($env{'form.login_showlogo_'.$img})) {
8541: $confhash->{$role}{'showlogo'}{$img} = 1;
8542: } else {
8543: $confhash->{$role}{'showlogo'}{$img} = 0;
8544: }
8545: }
1.18 albertel 8546: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
8547: && !defined($domconfig->{$role}{$img})
8548: && !$env{'form.'.$role.'_del_'.$img}
8549: && $env{'form.'.$role.'_import_'.$img}) {
8550: # import the old configured image from the .tab setting
8551: # if they haven't provided a new one
8552: $domconfig->{$role}{$img} =
8553: $env{'form.'.$role.'_import_'.$img};
8554: }
1.6 raeburn 8555: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 8556: my $error;
1.6 raeburn 8557: if ($configuserok eq 'ok') {
1.9 raeburn 8558: if ($switchserver) {
1.12 raeburn 8559: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 8560: } else {
8561: if ($author_ok eq 'ok') {
8562: my ($result,$logourl) =
8563: &publishlogo($r,'upload',$role.'_'.$img,
8564: $dom,$confname,$img,$width,$height);
8565: if ($result eq 'ok') {
8566: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 8567: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8568: } else {
1.12 raeburn 8569: $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 8570: }
8571: } else {
1.46 raeburn 8572: $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 8573: }
8574: }
8575: } else {
1.46 raeburn 8576: $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 8577: }
8578: if ($error) {
1.8 raeburn 8579: &Apache::lonnet::logthis($error);
1.11 albertel 8580: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 8581: }
8582: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 8583: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
8584: my $error;
8585: if ($configuserok eq 'ok') {
8586: # is confname an author?
8587: if ($switchserver eq '') {
8588: if ($author_ok eq 'ok') {
8589: my ($result,$logourl) =
8590: &publishlogo($r,'copy',$domconfig->{$role}{$img},
8591: $dom,$confname,$img,$width,$height);
8592: if ($result eq 'ok') {
8593: $confhash->{$role}{$img} = $logourl;
1.18 albertel 8594: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8595: }
8596: }
8597: }
8598: }
1.6 raeburn 8599: }
8600: }
8601: }
8602: if (ref($domconfig) eq 'HASH') {
8603: if (ref($domconfig->{$role}) eq 'HASH') {
8604: foreach my $img (@images) {
8605: if ($domconfig->{$role}{$img} ne '') {
8606: if ($env{'form.'.$role.'_del_'.$img}) {
8607: $confhash->{$role}{$img} = '';
1.12 raeburn 8608: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8609: } else {
1.9 raeburn 8610: if ($confhash->{$role}{$img} eq '') {
8611: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
8612: }
1.6 raeburn 8613: }
8614: } else {
8615: if ($env{'form.'.$role.'_del_'.$img}) {
8616: $confhash->{$role}{$img} = '';
1.12 raeburn 8617: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8618: }
8619: }
1.70 raeburn 8620: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
8621: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
8622: if ($confhash->{$role}{'showlogo'}{$img} ne
8623: $domconfig->{$role}{'showlogo'}{$img}) {
8624: $changes{$role}{'showlogo'}{$img} = 1;
8625: }
8626: } else {
8627: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8628: $changes{$role}{'showlogo'}{$img} = 1;
8629: }
8630: }
8631: }
8632: }
1.6 raeburn 8633: if ($domconfig->{$role}{'font'} ne '') {
8634: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
8635: $changes{$role}{'font'} = 1;
8636: }
8637: } else {
8638: if ($confhash->{$role}{'font'}) {
8639: $changes{$role}{'font'} = 1;
8640: }
8641: }
1.107 raeburn 8642: if ($role ne 'login') {
8643: if ($domconfig->{$role}{'fontmenu'} ne '') {
8644: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
8645: $changes{$role}{'fontmenu'} = 1;
8646: }
8647: } else {
8648: if ($confhash->{$role}{'fontmenu'}) {
8649: $changes{$role}{'fontmenu'} = 1;
8650: }
1.97 tempelho 8651: }
8652: }
1.6 raeburn 8653: foreach my $item (@bgs) {
8654: if ($domconfig->{$role}{$item} ne '') {
8655: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8656: $changes{$role}{'bgs'}{$item} = 1;
8657: }
8658: } else {
8659: if ($confhash->{$role}{$item}) {
8660: $changes{$role}{'bgs'}{$item} = 1;
8661: }
8662: }
8663: }
8664: foreach my $item (@links) {
8665: if ($domconfig->{$role}{$item} ne '') {
8666: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8667: $changes{$role}{'links'}{$item} = 1;
8668: }
8669: } else {
8670: if ($confhash->{$role}{$item}) {
8671: $changes{$role}{'links'}{$item} = 1;
8672: }
8673: }
8674: }
1.41 raeburn 8675: foreach my $item (@logintext) {
8676: if ($domconfig->{$role}{$item} ne '') {
8677: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8678: $changes{$role}{'logintext'}{$item} = 1;
8679: }
8680: } else {
8681: if ($confhash->{$role}{$item}) {
8682: $changes{$role}{'logintext'}{$item} = 1;
8683: }
8684: }
8685: }
1.6 raeburn 8686: } else {
8687: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8688: \@logintext,$confhash,\%changes);
1.6 raeburn 8689: }
8690: } else {
8691: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8692: \@logintext,$confhash,\%changes);
1.6 raeburn 8693: }
8694: }
8695: return ($errors,%changes);
8696: }
8697:
1.46 raeburn 8698: sub config_check {
8699: my ($dom,$confname,$servadm) = @_;
8700: my ($configuserok,$author_ok,$switchserver,%currroles);
8701: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8702: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8703: $confname,$servadm);
8704: if ($configuserok eq 'ok') {
8705: $switchserver = &check_switchserver($dom,$confname);
8706: if ($switchserver eq '') {
8707: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8708: }
8709: }
8710: return ($configuserok,$author_ok,$switchserver);
8711: }
8712:
1.6 raeburn 8713: sub default_change_checker {
1.41 raeburn 8714: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 8715: foreach my $item (@{$links}) {
8716: if ($confhash->{$role}{$item}) {
8717: $changes->{$role}{'links'}{$item} = 1;
8718: }
8719: }
8720: foreach my $item (@{$bgs}) {
8721: if ($confhash->{$role}{$item}) {
8722: $changes->{$role}{'bgs'}{$item} = 1;
8723: }
8724: }
1.41 raeburn 8725: foreach my $item (@{$logintext}) {
8726: if ($confhash->{$role}{$item}) {
8727: $changes->{$role}{'logintext'}{$item} = 1;
8728: }
8729: }
1.6 raeburn 8730: foreach my $img (@{$images}) {
8731: if ($env{'form.'.$role.'_del_'.$img}) {
8732: $confhash->{$role}{$img} = '';
1.12 raeburn 8733: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 8734: }
1.70 raeburn 8735: if ($role eq 'login') {
8736: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8737: $changes->{$role}{'showlogo'}{$img} = 1;
8738: }
8739: }
1.6 raeburn 8740: }
8741: if ($confhash->{$role}{'font'}) {
8742: $changes->{$role}{'font'} = 1;
8743: }
1.48 raeburn 8744: }
1.6 raeburn 8745:
8746: sub display_colorchgs {
8747: my ($dom,$changes,$roles,$confhash) = @_;
8748: my (%choices,$resulttext);
8749: if (!grep(/^login$/,@{$roles})) {
8750: $resulttext = &mt('Changes made:').'<br />';
8751: }
8752: foreach my $role (@{$roles}) {
8753: if ($role eq 'login') {
8754: %choices = &login_choices();
8755: } else {
8756: %choices = &color_font_choices();
8757: }
8758: if (ref($changes->{$role}) eq 'HASH') {
8759: if ($role ne 'login') {
8760: $resulttext .= '<h4>'.&mt($role).'</h4>';
8761: }
8762: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8763: if ($role ne 'login') {
8764: $resulttext .= '<ul>';
8765: }
8766: if (ref($changes->{$role}{$key}) eq 'HASH') {
8767: if ($role ne 'login') {
8768: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
8769: }
8770: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 8771: if (($role eq 'login') && ($key eq 'showlogo')) {
8772: if ($confhash->{$role}{$key}{$item}) {
8773: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
8774: } else {
8775: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
8776: }
8777: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 8778: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
8779: } else {
1.12 raeburn 8780: my $newitem = $confhash->{$role}{$item};
8781: if ($key eq 'images') {
8782: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
8783: }
8784: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 8785: }
8786: }
8787: if ($role ne 'login') {
8788: $resulttext .= '</ul></li>';
8789: }
8790: } else {
8791: if ($confhash->{$role}{$key} eq '') {
8792: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
8793: } else {
8794: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8795: }
8796: }
8797: if ($role ne 'login') {
8798: $resulttext .= '</ul>';
8799: }
8800: }
8801: }
8802: }
1.3 raeburn 8803: return $resulttext;
1.1 raeburn 8804: }
8805:
1.9 raeburn 8806: sub thumb_dimensions {
8807: return ('200','50');
8808: }
8809:
1.16 raeburn 8810: sub check_dimensions {
8811: my ($inputfile) = @_;
8812: my ($fullwidth,$fullheight);
8813: if ($inputfile =~ m|^[/\w.\-]+$|) {
8814: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8815: my $imageinfo = <PIPE>;
8816: if (!close(PIPE)) {
8817: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8818: }
8819: chomp($imageinfo);
8820: my ($fullsize) =
1.21 raeburn 8821: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 8822: if ($fullsize) {
8823: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8824: }
8825: }
8826: }
8827: return ($fullwidth,$fullheight);
8828: }
8829:
1.9 raeburn 8830: sub check_configuser {
8831: my ($uhome,$dom,$confname,$servadm) = @_;
8832: my ($configuserok,%currroles);
8833: if ($uhome eq 'no_host') {
8834: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98 raeburn 8835: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 8836: $configuserok =
8837: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8838: $configpass,'','','','','',undef,$servadm);
8839: } else {
8840: $configuserok = 'ok';
8841: %currroles =
8842: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
8843: }
8844: return ($configuserok,%currroles);
8845: }
8846:
8847: sub check_authorstatus {
8848: my ($dom,$confname,%currroles) = @_;
8849: my $author_ok;
1.40 raeburn 8850: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 8851: my $start = time;
8852: my $end = 0;
8853: $author_ok =
8854: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 8855: 'au',$end,$start,'','','domconfig');
1.9 raeburn 8856: } else {
8857: $author_ok = 'ok';
8858: }
8859: return $author_ok;
8860: }
8861:
8862: sub publishlogo {
1.46 raeburn 8863: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 8864: my ($output,$fname,$logourl);
8865: if ($action eq 'upload') {
8866: $fname=$env{'form.'.$formname.'.filename'};
8867: chop($env{'form.'.$formname});
8868: } else {
8869: ($fname) = ($formname =~ /([^\/]+)$/);
8870: }
1.46 raeburn 8871: if ($savefileas ne '') {
8872: $fname = $savefileas;
8873: }
1.9 raeburn 8874: $fname=&Apache::lonnet::clean_filename($fname);
8875: # See if there is anything left
8876: unless ($fname) { return ('error: no uploaded file'); }
8877: $fname="$subdir/$fname";
1.160.6.5 raeburn 8878: my $docroot=$r->dir_config('lonDocRoot');
8879: my $filepath="$docroot/priv";
8880: my $relpath = "$dom/$confname";
1.9 raeburn 8881: my ($fnamepath,$file,$fetchthumb);
8882: $file=$fname;
8883: if ($fname=~m|/|) {
8884: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
8885: }
1.160.6.26 raeburn 8886: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 8887: my $count;
1.160.6.5 raeburn 8888: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 8889: $filepath.="/$parts[$count]";
8890: if ((-e $filepath)!=1) {
8891: mkdir($filepath,02770);
8892: }
8893: }
8894: # Check for bad extension and disallow upload
8895: if ($file=~/\.(\w+)$/ &&
8896: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8897: $output =
1.160.6.25 raeburn 8898: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 8899: } elsif ($file=~/\.(\w+)$/ &&
8900: !defined(&Apache::loncommon::fileembstyle($1))) {
8901: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8902: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 8903: $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 8904: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 8905: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 8906: } else {
8907: my $source = $filepath.'/'.$file;
8908: my $logfile;
1.160.6.88 raeburn 8909: if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 8910: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 8911: }
8912: print $logfile
8913: "\n================= Publish ".localtime()." ================\n".
8914: $env{'user.name'}.':'.$env{'user.domain'}."\n";
8915: # Save the file
1.160.6.88 raeburn 8916: if (!open(FH,">",$source)) {
1.9 raeburn 8917: &Apache::lonnet::logthis('Failed to create '.$source);
8918: return (&mt('Failed to create file'));
8919: }
8920: if ($action eq 'upload') {
8921: if (!print FH ($env{'form.'.$formname})) {
8922: &Apache::lonnet::logthis('Failed to write to '.$source);
8923: return (&mt('Failed to write file'));
8924: }
8925: } else {
8926: my $original = &Apache::lonnet::filelocation('',$formname);
8927: if(!copy($original,$source)) {
8928: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
8929: return (&mt('Failed to write file'));
8930: }
8931: }
8932: close(FH);
8933: chmod(0660, $source); # Permissions to rw-rw---.
8934:
8935: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
8936: my $copyfile=$targetdir.'/'.$file;
8937:
8938: my @parts=split(/\//,$targetdir);
8939: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
8940: for (my $count=5;$count<=$#parts;$count++) {
8941: $path.="/$parts[$count]";
8942: if (!-e $path) {
8943: print $logfile "\nCreating directory ".$path;
8944: mkdir($path,02770);
8945: }
8946: }
8947: my $versionresult;
8948: if (-e $copyfile) {
8949: $versionresult = &logo_versioning($targetdir,$file,$logfile);
8950: } else {
8951: $versionresult = 'ok';
8952: }
8953: if ($versionresult eq 'ok') {
8954: if (copy($source,$copyfile)) {
8955: print $logfile "\nCopied original source to ".$copyfile."\n";
8956: $output = 'ok';
8957: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 8958: push(@{$modified_urls},[$copyfile,$source]);
8959: my $metaoutput =
8960: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
8961: unless ($registered_cleanup) {
8962: my $handlers = $r->get_handlers('PerlCleanupHandler');
8963: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8964: $registered_cleanup=1;
8965: }
1.9 raeburn 8966: } else {
8967: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
8968: $output = &mt('Failed to copy file to RES space').", $!";
8969: }
8970: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
8971: my $inputfile = $filepath.'/'.$file;
8972: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 8973: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
8974: if ($fullwidth ne '' && $fullheight ne '') {
8975: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
8976: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88 raeburn 8977: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
8978: system({$args[0]} @args);
1.16 raeburn 8979: chmod(0660, $filepath.'/tn-'.$file);
8980: if (-e $outfile) {
8981: my $copyfile=$targetdir.'/tn-'.$file;
8982: if (copy($outfile,$copyfile)) {
8983: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 8984: my $thumb_metaoutput =
8985: &write_metadata($dom,$confname,$formname,
8986: $targetdir,'tn-'.$file,$logfile);
8987: push(@{$modified_urls},[$copyfile,$outfile]);
8988: unless ($registered_cleanup) {
8989: my $handlers = $r->get_handlers('PerlCleanupHandler');
8990: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8991: $registered_cleanup=1;
8992: }
1.16 raeburn 8993: } else {
8994: print $logfile "\nUnable to write ".$copyfile.
8995: ':'.$!."\n";
8996: }
8997: }
1.9 raeburn 8998: }
8999: }
9000: }
9001: } else {
9002: $output = $versionresult;
9003: }
9004: }
9005: return ($output,$logourl);
9006: }
9007:
9008: sub logo_versioning {
9009: my ($targetdir,$file,$logfile) = @_;
9010: my $target = $targetdir.'/'.$file;
9011: my ($maxversion,$fn,$extn,$output);
9012: $maxversion = 0;
9013: if ($file =~ /^(.+)\.(\w+)$/) {
9014: $fn=$1;
9015: $extn=$2;
9016: }
9017: opendir(DIR,$targetdir);
9018: while (my $filename=readdir(DIR)) {
9019: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
9020: $maxversion=($1>$maxversion)?$1:$maxversion;
9021: }
9022: }
9023: $maxversion++;
9024: print $logfile "\nCreating old version ".$maxversion."\n";
9025: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
9026: if (copy($target,$copyfile)) {
9027: print $logfile "Copied old target to ".$copyfile."\n";
9028: $copyfile=$copyfile.'.meta';
9029: if (copy($target.'.meta',$copyfile)) {
9030: print $logfile "Copied old target metadata to ".$copyfile."\n";
9031: $output = 'ok';
9032: } else {
9033: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
9034: $output = &mt('Failed to copy old meta').", $!, ";
9035: }
9036: } else {
9037: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
9038: $output = &mt('Failed to copy old target').", $!, ";
9039: }
9040: return $output;
9041: }
9042:
9043: sub write_metadata {
9044: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
9045: my (%metadatafields,%metadatakeys,$output);
9046: $metadatafields{'title'}=$formname;
9047: $metadatafields{'creationdate'}=time;
9048: $metadatafields{'lastrevisiondate'}=time;
9049: $metadatafields{'copyright'}='public';
9050: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
9051: $env{'user.domain'};
9052: $metadatafields{'authorspace'}=$confname.':'.$dom;
9053: $metadatafields{'domain'}=$dom;
9054: {
9055: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
9056: my $mfh;
1.160.6.88 raeburn 9057: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 9058: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 9059: unless ($_=~/\./) {
9060: my $unikey=$_;
9061: $unikey=~/^([A-Za-z]+)/;
9062: my $tag=$1;
9063: $tag=~tr/A-Z/a-z/;
9064: print $mfh "\n\<$tag";
9065: foreach (split(/\,/,$metadatakeys{$unikey})) {
9066: my $value=$metadatafields{$unikey.'.'.$_};
9067: $value=~s/\"/\'\'/g;
9068: print $mfh ' '.$_.'="'.$value.'"';
9069: }
9070: print $mfh '>'.
9071: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
9072: .'</'.$tag.'>';
9073: }
9074: }
9075: $output = 'ok';
9076: print $logfile "\nWrote metadata";
9077: close($mfh);
9078: } else {
9079: print $logfile "\nFailed to open metadata file";
1.9 raeburn 9080: $output = &mt('Could not write metadata');
9081: }
9082: }
1.155 raeburn 9083: return $output;
9084: }
9085:
9086: sub notifysubscribed {
9087: foreach my $targetsource (@{$modified_urls}){
9088: next unless (ref($targetsource) eq 'ARRAY');
9089: my ($target,$source)=@{$targetsource};
9090: if ($source ne '') {
1.160.6.88 raeburn 9091: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 9092: print $logfh "\nCleanup phase: Notifications\n";
9093: my @subscribed=&subscribed_hosts($target);
9094: foreach my $subhost (@subscribed) {
9095: print $logfh "\nNotifying host ".$subhost.':';
9096: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
9097: print $logfh $reply;
9098: }
9099: my @subscribedmeta=&subscribed_hosts("$target.meta");
9100: foreach my $subhost (@subscribedmeta) {
9101: print $logfh "\nNotifying host for metadata only ".$subhost.':';
9102: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
9103: $subhost);
9104: print $logfh $reply;
9105: }
9106: print $logfh "\n============ Done ============\n";
1.160 raeburn 9107: close($logfh);
1.155 raeburn 9108: }
9109: }
9110: }
9111: return OK;
9112: }
9113:
9114: sub subscribed_hosts {
9115: my ($target) = @_;
9116: my @subscribed;
1.160.6.88 raeburn 9117: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 9118: while (my $subline=<$fh>) {
9119: if ($subline =~ /^($match_lonid):/) {
9120: my $host = $1;
9121: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
9122: unless (grep(/^\Q$host\E$/,@subscribed)) {
9123: push(@subscribed,$host);
9124: }
9125: }
9126: }
9127: }
9128: }
9129: return @subscribed;
1.9 raeburn 9130: }
9131:
9132: sub check_switchserver {
9133: my ($dom,$confname) = @_;
9134: my ($allowed,$switchserver);
9135: my $home = &Apache::lonnet::homeserver($confname,$dom);
9136: if ($home eq 'no_host') {
9137: $home = &Apache::lonnet::domain($dom,'primary');
9138: }
9139: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 9140: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
9141: if (!$allowed) {
1.160.6.11 raeburn 9142: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 9143: }
9144: return $switchserver;
9145: }
9146:
1.1 raeburn 9147: sub modify_quotas {
1.160.6.30 raeburn 9148: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 9149: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 9150: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 9151: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
9152: $validationfieldsref);
1.86 raeburn 9153: if ($action eq 'quotas') {
9154: $context = 'tools';
1.160.6.26 raeburn 9155: } else {
1.86 raeburn 9156: $context = $action;
9157: }
9158: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 9159: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 9160: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 9161: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
9162: %titles = &courserequest_titles();
9163: $toolregexp = join('|',@usertools);
9164: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 9165: $confname = $dom.'-domainconfig';
9166: my $servadm = $r->dir_config('lonAdmEMail');
9167: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 9168: ($validationitemsref,$validationnamesref,$validationfieldsref) =
9169: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 9170: } elsif ($context eq 'requestauthor') {
9171: @usertools = ('author');
9172: %titles = &authorrequest_titles();
1.86 raeburn 9173: } else {
1.160.6.4 raeburn 9174: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 9175: %titles = &tool_titles();
1.86 raeburn 9176: }
1.160.6.27 raeburn 9177: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 9178: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9179: foreach my $key (keys(%env)) {
1.101 raeburn 9180: if ($context eq 'requestcourses') {
9181: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
9182: my $item = $1;
9183: my $type = $2;
9184: if ($type =~ /^limit_(.+)/) {
9185: $limithash{$item}{$1} = $env{$key};
9186: } else {
9187: $confhash{$item}{$type} = $env{$key};
9188: }
9189: }
1.160.6.5 raeburn 9190: } elsif ($context eq 'requestauthor') {
9191: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
9192: $confhash{$1} = $env{$key};
9193: }
1.101 raeburn 9194: } else {
1.86 raeburn 9195: if ($key =~ /^form\.quota_(.+)$/) {
9196: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 9197: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
9198: $confhash{'authorquota'}{$1} = $env{$key};
9199: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 9200: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
9201: }
1.72 raeburn 9202: }
9203: }
1.160.6.5 raeburn 9204: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 9205: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 9206: @approvalnotify = sort(@approvalnotify);
9207: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 9208: my @crstypes = ('official','unofficial','community','textbook');
9209: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
9210: foreach my $type (@hasuniquecode) {
9211: if (grep(/^\Q$type\E$/,@crstypes)) {
9212: $confhash{'uniquecode'}{$type} = 1;
9213: }
9214: }
1.160.6.46 raeburn 9215: my (%newbook,%allpos);
1.160.6.30 raeburn 9216: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 9217: foreach my $type ('textbooks','templates') {
9218: @{$allpos{$type}} = ();
9219: my $invalid;
9220: if ($type eq 'textbooks') {
9221: $invalid = &mt('Invalid LON-CAPA course for textbook');
9222: } else {
9223: $invalid = &mt('Invalid LON-CAPA course for template');
9224: }
9225: if ($env{'form.'.$type.'_addbook'}) {
9226: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
9227: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
9228: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
9229: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
9230: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
9231: } else {
9232: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
9233: my $position = $env{'form.'.$type.'_addbook_pos'};
9234: $position =~ s/\D+//g;
9235: if ($position ne '') {
9236: $allpos{$type}[$position] = $newbook{$type};
9237: }
1.160.6.30 raeburn 9238: }
1.160.6.46 raeburn 9239: } else {
9240: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 9241: }
9242: }
1.160.6.46 raeburn 9243: }
1.160.6.30 raeburn 9244: }
1.102 raeburn 9245: if (ref($domconfig{$action}) eq 'HASH') {
9246: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
9247: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
9248: $changes{'notify'}{'approval'} = 1;
9249: }
9250: } else {
1.144 raeburn 9251: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9252: $changes{'notify'}{'approval'} = 1;
9253: }
9254: }
1.160.6.30 raeburn 9255: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
9256: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9257: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
9258: unless ($confhash{'uniquecode'}{$crstype}) {
9259: $changes{'uniquecode'} = 1;
9260: }
9261: }
9262: unless ($changes{'uniquecode'}) {
9263: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
9264: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
9265: $changes{'uniquecode'} = 1;
9266: }
9267: }
9268: }
9269: } else {
9270: $changes{'uniquecode'} = 1;
9271: }
9272: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
9273: $changes{'uniquecode'} = 1;
9274: }
9275: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 9276: foreach my $type ('textbooks','templates') {
9277: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9278: my %deletions;
9279: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
9280: if (@todelete) {
9281: map { $deletions{$_} = 1; } @todelete;
9282: }
9283: my %imgdeletions;
9284: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
9285: if (@todeleteimages) {
9286: map { $imgdeletions{$_} = 1; } @todeleteimages;
9287: }
9288: my $maxnum = $env{'form.'.$type.'_maxnum'};
9289: for (my $i=0; $i<=$maxnum; $i++) {
9290: my $itemid = $env{'form.'.$type.'_id_'.$i};
9291: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
9292: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
9293: if ($deletions{$key}) {
9294: if ($domconfig{$action}{$type}{$key}{'image'}) {
9295: #FIXME need to obsolete item in RES space
9296: }
9297: next;
9298: } else {
9299: my $newpos = $env{'form.'.$itemid};
9300: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 9301: foreach my $item ('subject','title','publisher','author') {
9302: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9303: ($type eq 'templates'));
1.160.6.46 raeburn 9304: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
9305: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
9306: $changes{$type}{$key} = 1;
9307: }
9308: }
9309: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 9310: }
1.160.6.46 raeburn 9311: if ($imgdeletions{$key}) {
9312: $changes{$type}{$key} = 1;
9313: #FIXME need to obsolete item in RES space
9314: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
9315: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 9316: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
9317: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
9318: } else {
9319: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
9320: $cdom,$cnum,$type,$configuserok,
9321: $switchserver,$author_ok);
9322: if ($imgurl) {
9323: $confhash{$type}{$key}{'image'} = $imgurl;
9324: $changes{$type}{$key} = 1;
9325: }
9326: if ($error) {
9327: &Apache::lonnet::logthis($error);
9328: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9329: }
1.160.6.46 raeburn 9330: }
9331: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
9332: $confhash{$type}{$key}{'image'} =
9333: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 9334: }
9335: }
9336: }
9337: }
9338: }
9339: }
1.102 raeburn 9340: } else {
1.144 raeburn 9341: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9342: $changes{'notify'}{'approval'} = 1;
9343: }
1.160.6.30 raeburn 9344: if (ref($confhash{'uniquecode'} eq 'HASH')) {
9345: $changes{'uniquecode'} = 1;
9346: }
9347: }
9348: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 9349: foreach my $type ('textbooks','templates') {
9350: if ($newbook{$type}) {
9351: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 9352: foreach my $item ('subject','title','publisher','author') {
9353: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9354: ($type eq 'template'));
1.160.6.46 raeburn 9355: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
9356: if ($env{'form.'.$type.'_addbook_'.$item}) {
9357: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
9358: }
9359: }
9360: if ($type eq 'textbooks') {
9361: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
9362: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 9363: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
9364: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
9365: } else {
9366: my ($imageurl,$error) =
9367: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
9368: $configuserok,$switchserver,$author_ok);
9369: if ($imageurl) {
9370: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
9371: }
9372: if ($error) {
9373: &Apache::lonnet::logthis($error);
9374: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9375: }
1.160.6.46 raeburn 9376: }
9377: }
1.160.6.30 raeburn 9378: }
9379: }
1.160.6.46 raeburn 9380: if (@{$allpos{$type}} > 0) {
9381: my $idx = 0;
9382: foreach my $item (@{$allpos{$type}}) {
9383: if ($item ne '') {
9384: $confhash{$type}{$item}{'order'} = $idx;
9385: if (ref($domconfig{$action}) eq 'HASH') {
9386: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9387: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
9388: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
9389: $changes{$type}{$item} = 1;
9390: }
1.160.6.30 raeburn 9391: }
9392: }
9393: }
1.160.6.46 raeburn 9394: $idx ++;
1.160.6.30 raeburn 9395: }
9396: }
9397: }
9398: }
1.160.6.39 raeburn 9399: if (ref($validationitemsref) eq 'ARRAY') {
9400: foreach my $item (@{$validationitemsref}) {
9401: if ($item eq 'fields') {
9402: my @changed;
9403: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
9404: if (@{$confhash{'validation'}{$item}} > 0) {
9405: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
9406: }
1.160.6.65 raeburn 9407: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9408: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9409: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
9410: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
9411: $domconfig{'requestcourses'}{'validation'}{$item});
9412: } else {
9413: @changed = @{$confhash{'validation'}{$item}};
9414: }
1.160.6.39 raeburn 9415: } else {
9416: @changed = @{$confhash{'validation'}{$item}};
9417: }
9418: } else {
9419: @changed = @{$confhash{'validation'}{$item}};
9420: }
9421: if (@changed) {
9422: if ($confhash{'validation'}{$item}) {
9423: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
9424: } else {
9425: $changes{'validation'}{$item} = &mt('None');
9426: }
9427: }
9428: } else {
9429: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
9430: if ($item eq 'markup') {
9431: if ($env{'form.requestcourses_validation_'.$item}) {
9432: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
9433: }
9434: }
1.160.6.65 raeburn 9435: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9436: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9437: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
9438: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9439: }
9440: } else {
9441: if ($confhash{'validation'}{$item} ne '') {
9442: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9443: }
1.160.6.39 raeburn 9444: }
9445: } else {
9446: if ($confhash{'validation'}{$item} ne '') {
9447: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9448: }
9449: }
9450: }
9451: }
9452: }
9453: if ($env{'form.validationdc'}) {
9454: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 9455: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 9456: if (exists($domcoords{$newval})) {
9457: $confhash{'validation'}{'dc'} = $newval;
9458: }
9459: }
9460: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 9461: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9462: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9463: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9464: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
9465: if ($confhash{'validation'}{'dc'} eq '') {
9466: $changes{'validation'}{'dc'} = &mt('None');
9467: } else {
9468: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9469: }
1.160.6.39 raeburn 9470: }
1.160.6.65 raeburn 9471: } elsif ($confhash{'validation'}{'dc'} ne '') {
9472: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 9473: }
9474: } elsif ($confhash{'validation'}{'dc'} ne '') {
9475: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9476: }
9477: } elsif ($confhash{'validation'}{'dc'} ne '') {
9478: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9479: }
1.160.6.65 raeburn 9480: } else {
9481: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9482: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9483: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9484: $changes{'validation'}{'dc'} = &mt('None');
9485: }
9486: }
1.160.6.39 raeburn 9487: }
9488: }
1.102 raeburn 9489: }
9490: } else {
1.86 raeburn 9491: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 9492: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 9493: }
1.72 raeburn 9494: foreach my $item (@usertools) {
9495: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 9496: my $unset;
1.101 raeburn 9497: if ($context eq 'requestcourses') {
1.104 raeburn 9498: $unset = '0';
9499: if ($type eq '_LC_adv') {
9500: $unset = '';
9501: }
1.101 raeburn 9502: if ($confhash{$item}{$type} eq 'autolimit') {
9503: $confhash{$item}{$type} .= '=';
9504: unless ($limithash{$item}{$type} =~ /\D/) {
9505: $confhash{$item}{$type} .= $limithash{$item}{$type};
9506: }
9507: }
1.160.6.5 raeburn 9508: } elsif ($context eq 'requestauthor') {
9509: $unset = '0';
9510: if ($type eq '_LC_adv') {
9511: $unset = '';
9512: }
1.72 raeburn 9513: } else {
1.101 raeburn 9514: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
9515: $confhash{$item}{$type} = 1;
9516: } else {
9517: $confhash{$item}{$type} = 0;
9518: }
1.72 raeburn 9519: }
1.86 raeburn 9520: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 9521: if ($action eq 'requestauthor') {
9522: if ($domconfig{$action}{$type} ne $confhash{$type}) {
9523: $changes{$type} = 1;
9524: }
9525: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 9526: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
9527: $changes{$item}{$type} = 1;
9528: }
9529: } else {
9530: if ($context eq 'requestcourses') {
1.104 raeburn 9531: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 9532: $changes{$item}{$type} = 1;
9533: }
9534: } else {
9535: if (!$confhash{$item}{$type}) {
9536: $changes{$item}{$type} = 1;
9537: }
9538: }
9539: }
9540: } else {
9541: if ($context eq 'requestcourses') {
1.104 raeburn 9542: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 9543: $changes{$item}{$type} = 1;
9544: }
1.160.6.5 raeburn 9545: } elsif ($context eq 'requestauthor') {
9546: if ($confhash{$type} ne $unset) {
9547: $changes{$type} = 1;
9548: }
1.72 raeburn 9549: } else {
9550: if (!$confhash{$item}{$type}) {
9551: $changes{$item}{$type} = 1;
9552: }
9553: }
9554: }
1.1 raeburn 9555: }
9556: }
1.160.6.5 raeburn 9557: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 9558: if (ref($domconfig{'quotas'}) eq 'HASH') {
9559: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9560: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
9561: if (exists($confhash{'defaultquota'}{$key})) {
9562: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
9563: $changes{'defaultquota'}{$key} = 1;
9564: }
9565: } else {
9566: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 9567: }
9568: }
1.86 raeburn 9569: } else {
9570: foreach my $key (keys(%{$domconfig{'quotas'}})) {
9571: if (exists($confhash{'defaultquota'}{$key})) {
9572: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
9573: $changes{'defaultquota'}{$key} = 1;
9574: }
9575: } else {
9576: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 9577: }
1.1 raeburn 9578: }
9579: }
1.160.6.20 raeburn 9580: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9581: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
9582: if (exists($confhash{'authorquota'}{$key})) {
9583: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
9584: $changes{'authorquota'}{$key} = 1;
9585: }
9586: } else {
9587: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
9588: }
9589: }
9590: }
1.1 raeburn 9591: }
1.86 raeburn 9592: if (ref($confhash{'defaultquota'}) eq 'HASH') {
9593: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
9594: if (ref($domconfig{'quotas'}) eq 'HASH') {
9595: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9596: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
9597: $changes{'defaultquota'}{$key} = 1;
9598: }
9599: } else {
9600: if (!exists($domconfig{'quotas'}{$key})) {
9601: $changes{'defaultquota'}{$key} = 1;
9602: }
1.72 raeburn 9603: }
9604: } else {
1.86 raeburn 9605: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 9606: }
1.1 raeburn 9607: }
9608: }
1.160.6.20 raeburn 9609: if (ref($confhash{'authorquota'}) eq 'HASH') {
9610: foreach my $key (keys(%{$confhash{'authorquota'}})) {
9611: if (ref($domconfig{'quotas'}) eq 'HASH') {
9612: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9613: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
9614: $changes{'authorquota'}{$key} = 1;
9615: }
9616: } else {
9617: $changes{'authorquota'}{$key} = 1;
9618: }
9619: } else {
9620: $changes{'authorquota'}{$key} = 1;
9621: }
9622: }
9623: }
1.1 raeburn 9624: }
1.72 raeburn 9625:
1.160.6.5 raeburn 9626: if ($context eq 'requestauthor') {
9627: $domdefaults{'requestauthor'} = \%confhash;
9628: } else {
9629: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 9630: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 9631: $domdefaults{$key} = $confhash{$key};
9632: }
1.160.6.5 raeburn 9633: }
1.72 raeburn 9634: }
1.160.6.5 raeburn 9635:
1.1 raeburn 9636: my %quotahash = (
1.86 raeburn 9637: $action => { %confhash }
1.1 raeburn 9638: );
9639: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
9640: $dom);
9641: if ($putresult eq 'ok') {
9642: if (keys(%changes) > 0) {
1.72 raeburn 9643: my $cachetime = 24*60*60;
9644: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 9645: if (ref($lastactref) eq 'HASH') {
9646: $lastactref->{'domdefaults'} = 1;
9647: }
1.1 raeburn 9648: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 9649: unless (($context eq 'requestcourses') ||
9650: ($context eq 'requestauthor')) {
1.86 raeburn 9651: if (ref($changes{'defaultquota'}) eq 'HASH') {
9652: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
9653: foreach my $type (@{$types},'default') {
9654: if (defined($changes{'defaultquota'}{$type})) {
9655: my $typetitle = $usertypes->{$type};
9656: if ($type eq 'default') {
9657: $typetitle = $othertitle;
9658: }
1.160.6.28 raeburn 9659: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 9660: }
9661: }
1.86 raeburn 9662: $resulttext .= '</ul></li>';
1.72 raeburn 9663: }
1.160.6.20 raeburn 9664: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 9665: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 9666: foreach my $type (@{$types},'default') {
9667: if (defined($changes{'authorquota'}{$type})) {
9668: my $typetitle = $usertypes->{$type};
9669: if ($type eq 'default') {
9670: $typetitle = $othertitle;
9671: }
1.160.6.28 raeburn 9672: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 9673: }
9674: }
9675: $resulttext .= '</ul></li>';
9676: }
1.72 raeburn 9677: }
1.80 raeburn 9678: my %newenv;
1.72 raeburn 9679: foreach my $item (@usertools) {
1.160.6.5 raeburn 9680: my (%haschgs,%inconf);
9681: if ($context eq 'requestauthor') {
9682: %haschgs = %changes;
9683: %inconf = %confhash;
9684: } else {
9685: if (ref($changes{$item}) eq 'HASH') {
9686: %haschgs = %{$changes{$item}};
9687: }
9688: if (ref($confhash{$item}) eq 'HASH') {
9689: %inconf = %{$confhash{$item}};
9690: }
9691: }
9692: if (keys(%haschgs) > 0) {
1.80 raeburn 9693: my $newacc =
9694: &Apache::lonnet::usertools_access($env{'user.name'},
9695: $env{'user.domain'},
1.86 raeburn 9696: $item,'reload',$context);
1.160.6.5 raeburn 9697: if (($context eq 'requestcourses') ||
9698: ($context eq 'requestauthor')) {
1.108 raeburn 9699: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9700: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 9701: }
9702: } else {
9703: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9704: $newenv{'environment.availabletools.'.$item} = $newacc;
9705: }
1.80 raeburn 9706: }
1.160.6.5 raeburn 9707: unless ($context eq 'requestauthor') {
9708: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9709: }
1.72 raeburn 9710: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 9711: if ($haschgs{$type}) {
1.72 raeburn 9712: my $typetitle = $usertypes->{$type};
9713: if ($type eq 'default') {
9714: $typetitle = $othertitle;
9715: } elsif ($type eq '_LC_adv') {
9716: $typetitle = 'LON-CAPA Advanced Users';
9717: }
1.160.6.5 raeburn 9718: if ($inconf{$type}) {
1.101 raeburn 9719: if ($context eq 'requestcourses') {
9720: my $cond;
1.160.6.5 raeburn 9721: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 9722: if ($1 eq '') {
9723: $cond = &mt('(Automatic processing of any request).');
9724: } else {
9725: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9726: }
9727: } else {
1.160.6.5 raeburn 9728: $cond = $conditions{$inconf{$type}};
1.101 raeburn 9729: }
9730: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 9731: } elsif ($context eq 'requestauthor') {
9732: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9733: $titles{$inconf{$type}},$typetitle);
9734:
1.101 raeburn 9735: } else {
9736: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9737: }
1.72 raeburn 9738: } else {
1.104 raeburn 9739: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 9740: if ($inconf{$type} eq '0') {
1.104 raeburn 9741: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9742: } else {
9743: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9744: }
9745: } else {
9746: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9747: }
1.72 raeburn 9748: }
9749: }
1.26 raeburn 9750: }
1.160.6.5 raeburn 9751: unless ($context eq 'requestauthor') {
9752: $resulttext .= '</ul></li>';
9753: }
1.26 raeburn 9754: }
1.1 raeburn 9755: }
1.160.6.5 raeburn 9756: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 9757: if (ref($changes{'notify'}) eq 'HASH') {
9758: if ($changes{'notify'}{'approval'}) {
9759: if (ref($confhash{'notify'}) eq 'HASH') {
9760: if ($confhash{'notify'}{'approval'}) {
9761: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9762: } else {
1.160.6.5 raeburn 9763: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 9764: }
9765: }
9766: }
9767: }
9768: }
1.160.6.30 raeburn 9769: if ($action eq 'requestcourses') {
9770: my @offon = ('off','on');
9771: if ($changes{'uniquecode'}) {
9772: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9773: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
9774: $resulttext .= '<li>'.
9775: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
9776: '</li>';
9777: } else {
9778: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
9779: '</li>';
9780: }
9781: }
1.160.6.46 raeburn 9782: foreach my $type ('textbooks','templates') {
9783: if (ref($changes{$type}) eq 'HASH') {
9784: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
9785: foreach my $key (sort(keys(%{$changes{$type}}))) {
9786: my %coursehash = &Apache::lonnet::coursedescription($key);
9787: my $coursetitle = $coursehash{'description'};
9788: my $position = $confhash{$type}{$key}{'order'} + 1;
9789: $resulttext .= '<li>';
1.160.6.47 raeburn 9790: foreach my $item ('subject','title','publisher','author') {
9791: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9792: ($type eq 'templates'));
1.160.6.46 raeburn 9793: my $name = $item.':';
9794: $name =~ s/^(\w)/\U$1/;
9795: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9796: }
9797: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9798: if ($type eq 'textbooks') {
9799: if ($confhash{$type}{$key}{'image'}) {
9800: $resulttext .= ' '.&mt('Image: [_1]',
9801: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9802: ' alt="Textbook cover" />').'<br />';
9803: }
9804: }
9805: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 9806: }
1.160.6.46 raeburn 9807: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 9808: }
9809: }
1.160.6.39 raeburn 9810: if (ref($changes{'validation'}) eq 'HASH') {
9811: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9812: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9813: foreach my $item (@{$validationitemsref}) {
9814: if (exists($changes{'validation'}{$item})) {
9815: if ($item eq 'markup') {
9816: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9817: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9818: } else {
9819: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9820: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9821: }
9822: }
9823: }
9824: if (exists($changes{'validation'}{'dc'})) {
9825: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9826: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9827: }
9828: }
9829: }
1.160.6.30 raeburn 9830: }
1.1 raeburn 9831: $resulttext .= '</ul>';
1.80 raeburn 9832: if (keys(%newenv)) {
9833: &Apache::lonnet::appenv(\%newenv);
9834: }
1.1 raeburn 9835: } else {
1.86 raeburn 9836: if ($context eq 'requestcourses') {
9837: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 9838: } elsif ($context eq 'requestauthor') {
9839: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 9840: } else {
1.90 weissno 9841: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 9842: }
1.1 raeburn 9843: }
9844: } else {
1.11 albertel 9845: $resulttext = '<span class="LC_error">'.
9846: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9847: }
1.160.6.30 raeburn 9848: if ($errors) {
9849: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
9850: '<ul>'.$errors.'</ul></p>';
9851: }
1.3 raeburn 9852: return $resulttext;
1.1 raeburn 9853: }
9854:
1.160.6.30 raeburn 9855: sub process_textbook_image {
1.160.6.46 raeburn 9856: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 9857: my $filename = $env{'form.'.$caller.'.filename'};
9858: my ($error,$url);
9859: my ($width,$height) = (50,50);
9860: if ($configuserok eq 'ok') {
9861: if ($switchserver) {
9862: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
9863: $switchserver);
9864: } elsif ($author_ok eq 'ok') {
9865: my ($result,$imageurl) =
9866: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88 raeburn 9867: "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 9868: if ($result eq 'ok') {
9869: $url = $imageurl;
9870: } else {
9871: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9872: }
9873: } else {
9874: $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);
9875: }
9876: } else {
9877: $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);
9878: }
9879: return ($url,$error);
9880: }
9881:
1.3 raeburn 9882: sub modify_autoenroll {
1.160.6.24 raeburn 9883: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 9884: my ($resulttext,%changes);
9885: my %currautoenroll;
9886: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
9887: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
9888: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
9889: }
9890: }
9891: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
9892: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 9893: sender => 'Sender for notification messages',
1.160.6.68 raeburn 9894: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
9895: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 9896: my @offon = ('off','on');
1.17 raeburn 9897: my $sender_uname = $env{'form.sender_uname'};
9898: my $sender_domain = $env{'form.sender_domain'};
9899: if ($sender_domain eq '') {
9900: $sender_uname = '';
9901: } elsif ($sender_uname eq '') {
9902: $sender_domain = '';
9903: }
1.129 raeburn 9904: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 9905: my $failsafe = $env{'form.autoenroll_failsafe'};
9906: $failsafe =~ s{^\s+|\s+$}{}g;
9907: if ($failsafe =~ /\D/) {
9908: undef($failsafe);
9909: }
1.1 raeburn 9910: my %autoenrollhash = (
1.129 raeburn 9911: autoenroll => { 'run' => $env{'form.autoenroll_run'},
9912: 'sender_uname' => $sender_uname,
9913: 'sender_domain' => $sender_domain,
9914: 'co-owners' => $coowners,
1.160.6.68 raeburn 9915: 'autofailsafe' => $failsafe,
1.1 raeburn 9916: }
9917: );
1.4 raeburn 9918: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
9919: $dom);
1.1 raeburn 9920: if ($putresult eq 'ok') {
9921: if (exists($currautoenroll{'run'})) {
9922: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
9923: $changes{'run'} = 1;
9924: }
9925: } elsif ($autorun) {
9926: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 9927: $changes{'run'} = 1;
1.1 raeburn 9928: }
9929: }
1.17 raeburn 9930: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 9931: $changes{'sender'} = 1;
9932: }
1.17 raeburn 9933: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 9934: $changes{'sender'} = 1;
9935: }
1.129 raeburn 9936: if ($currautoenroll{'co-owners'} ne '') {
9937: if ($currautoenroll{'co-owners'} ne $coowners) {
9938: $changes{'coowners'} = 1;
9939: }
9940: } elsif ($coowners) {
9941: $changes{'coowners'} = 1;
1.160.6.68 raeburn 9942: }
9943: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
9944: $changes{'autofailsafe'} = 1;
9945: }
1.1 raeburn 9946: if (keys(%changes) > 0) {
9947: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 9948: if ($changes{'run'}) {
1.1 raeburn 9949: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
9950: }
9951: if ($changes{'sender'}) {
1.17 raeburn 9952: if ($sender_uname eq '' || $sender_domain eq '') {
9953: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
9954: } else {
9955: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
9956: }
1.1 raeburn 9957: }
1.129 raeburn 9958: if ($changes{'coowners'}) {
9959: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
9960: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9961: if (ref($lastactref) eq 'HASH') {
9962: $lastactref->{'domainconfig'} = 1;
9963: }
1.129 raeburn 9964: }
1.160.6.68 raeburn 9965: if ($changes{'autofailsafe'}) {
9966: if ($failsafe ne '') {
1.160.6.82 raeburn 9967: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68 raeburn 9968: } else {
1.160.6.82 raeburn 9969: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68 raeburn 9970: }
9971: &Apache::lonnet::get_domain_defaults($dom,1);
9972: if (ref($lastactref) eq 'HASH') {
9973: $lastactref->{'domdefaults'} = 1;
9974: }
9975: }
1.1 raeburn 9976: $resulttext .= '</ul>';
9977: } else {
9978: $resulttext = &mt('No changes made to auto-enrollment settings');
9979: }
9980: } else {
1.11 albertel 9981: $resulttext = '<span class="LC_error">'.
9982: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9983: }
1.3 raeburn 9984: return $resulttext;
1.1 raeburn 9985: }
9986:
9987: sub modify_autoupdate {
1.3 raeburn 9988: my ($dom,%domconfig) = @_;
1.1 raeburn 9989: my ($resulttext,%currautoupdate,%fields,%changes);
9990: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
9991: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
9992: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
9993: }
9994: }
9995: my @offon = ('off','on');
9996: my %title = &Apache::lonlocal::texthash (
9997: run => 'Auto-update:',
9998: classlists => 'Updates to user information in classlists?'
9999: );
1.44 raeburn 10000: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10001: my %fieldtitles = &Apache::lonlocal::texthash (
10002: id => 'Student/Employee ID',
1.20 raeburn 10003: permanentemail => 'E-mail address',
1.1 raeburn 10004: lastname => 'Last Name',
10005: firstname => 'First Name',
10006: middlename => 'Middle Name',
1.132 raeburn 10007: generation => 'Generation',
1.1 raeburn 10008: );
1.142 raeburn 10009: $othertitle = &mt('All users');
1.1 raeburn 10010: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 10011: $othertitle = &mt('Other users');
1.1 raeburn 10012: }
10013: foreach my $key (keys(%env)) {
10014: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 10015: my ($usertype,$item) = ($1,$2);
10016: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
10017: if ($usertype eq 'default') {
10018: push(@{$fields{$1}},$2);
10019: } elsif (ref($types) eq 'ARRAY') {
10020: if (grep(/^\Q$usertype\E$/,@{$types})) {
10021: push(@{$fields{$1}},$2);
10022: }
10023: }
10024: }
1.1 raeburn 10025: }
10026: }
1.131 raeburn 10027: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
10028: @lockablenames = sort(@lockablenames);
10029: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
10030: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10031: if (@changed) {
10032: $changes{'lockablenames'} = 1;
10033: }
10034: } else {
10035: if (@lockablenames) {
10036: $changes{'lockablenames'} = 1;
10037: }
10038: }
1.1 raeburn 10039: my %updatehash = (
10040: autoupdate => { run => $env{'form.autoupdate_run'},
10041: classlists => $env{'form.classlists'},
10042: fields => {%fields},
1.131 raeburn 10043: lockablenames => \@lockablenames,
1.1 raeburn 10044: }
10045: );
10046: foreach my $key (keys(%currautoupdate)) {
10047: if (($key eq 'run') || ($key eq 'classlists')) {
10048: if (exists($updatehash{autoupdate}{$key})) {
10049: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
10050: $changes{$key} = 1;
10051: }
10052: }
10053: } elsif ($key eq 'fields') {
10054: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 10055: foreach my $item (@{$types},'default') {
1.1 raeburn 10056: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
10057: my $change = 0;
10058: foreach my $type (@{$currautoupdate{$key}{$item}}) {
10059: if (!exists($fields{$item})) {
10060: $change = 1;
1.132 raeburn 10061: last;
1.1 raeburn 10062: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 10063: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 10064: $change = 1;
1.132 raeburn 10065: last;
1.1 raeburn 10066: }
10067: }
10068: }
10069: if ($change) {
10070: push(@{$changes{$key}},$item);
10071: }
1.26 raeburn 10072: }
1.1 raeburn 10073: }
10074: }
1.131 raeburn 10075: } elsif ($key eq 'lockablenames') {
10076: if (ref($currautoupdate{$key}) eq 'ARRAY') {
10077: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10078: if (@changed) {
10079: $changes{'lockablenames'} = 1;
10080: }
10081: } else {
10082: if (@lockablenames) {
10083: $changes{'lockablenames'} = 1;
10084: }
10085: }
10086: }
10087: }
10088: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
10089: if (@lockablenames) {
10090: $changes{'lockablenames'} = 1;
1.1 raeburn 10091: }
10092: }
1.26 raeburn 10093: foreach my $item (@{$types},'default') {
10094: if (defined($fields{$item})) {
10095: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 10096: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
10097: my $change = 0;
10098: if (ref($fields{$item}) eq 'ARRAY') {
10099: foreach my $type (@{$fields{$item}}) {
10100: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
10101: $change = 1;
10102: last;
10103: }
10104: }
10105: }
10106: if ($change) {
10107: push(@{$changes{'fields'}},$item);
10108: }
10109: } else {
1.26 raeburn 10110: push(@{$changes{'fields'}},$item);
10111: }
10112: } else {
10113: push(@{$changes{'fields'}},$item);
1.1 raeburn 10114: }
10115: }
10116: }
10117: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
10118: $dom);
10119: if ($putresult eq 'ok') {
10120: if (keys(%changes) > 0) {
10121: $resulttext = &mt('Changes made:').'<ul>';
10122: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 10123: if ($key eq 'lockablenames') {
10124: $resulttext .= '<li>';
10125: if (@lockablenames) {
10126: $usertypes->{'default'} = $othertitle;
10127: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
10128: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
10129: } else {
10130: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
10131: }
10132: $resulttext .= '</li>';
10133: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 10134: foreach my $item (@{$changes{$key}}) {
10135: my @newvalues;
10136: foreach my $type (@{$fields{$item}}) {
10137: push(@newvalues,$fieldtitles{$type});
10138: }
1.3 raeburn 10139: my $newvaluestr;
10140: if (@newvalues > 0) {
10141: $newvaluestr = join(', ',@newvalues);
10142: } else {
10143: $newvaluestr = &mt('none');
1.6 raeburn 10144: }
1.1 raeburn 10145: if ($item eq 'default') {
1.26 raeburn 10146: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 10147: } else {
1.26 raeburn 10148: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 10149: }
10150: }
10151: } else {
10152: my $newvalue;
10153: if ($key eq 'run') {
10154: $newvalue = $offon[$env{'form.autoupdate_run'}];
10155: } else {
10156: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 10157: }
1.1 raeburn 10158: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
10159: }
10160: }
10161: $resulttext .= '</ul>';
10162: } else {
1.3 raeburn 10163: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 10164: }
10165: } else {
1.11 albertel 10166: $resulttext = '<span class="LC_error">'.
10167: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10168: }
1.3 raeburn 10169: return $resulttext;
1.1 raeburn 10170: }
10171:
1.125 raeburn 10172: sub modify_autocreate {
10173: my ($dom,%domconfig) = @_;
10174: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
10175: if (ref($domconfig{'autocreate'}) eq 'HASH') {
10176: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
10177: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
10178: }
10179: }
10180: my %title= ( xml => 'Auto-creation of courses in XML course description files',
10181: req => 'Auto-creation of validated requests for official courses',
10182: xmldc => 'Identity of course creator of courses from XML files',
10183: );
10184: my @types = ('xml','req');
10185: foreach my $item (@types) {
10186: $newvals{$item} = $env{'form.autocreate_'.$item};
10187: $newvals{$item} =~ s/\D//g;
10188: $newvals{$item} = 0 if ($newvals{$item} eq '');
10189: }
10190: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 10191: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 10192: unless (exists($domcoords{$newvals{'xmldc'}})) {
10193: $newvals{'xmldc'} = '';
10194: }
10195: %autocreatehash = (
10196: autocreate => { xml => $newvals{'xml'},
10197: req => $newvals{'req'},
10198: }
10199: );
10200: if ($newvals{'xmldc'} ne '') {
10201: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
10202: }
10203: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
10204: $dom);
10205: if ($putresult eq 'ok') {
10206: my @items = @types;
10207: if ($newvals{'xml'}) {
10208: push(@items,'xmldc');
10209: }
10210: foreach my $item (@items) {
10211: if (exists($currautocreate{$item})) {
10212: if ($currautocreate{$item} ne $newvals{$item}) {
10213: $changes{$item} = 1;
10214: }
10215: } elsif ($newvals{$item}) {
10216: $changes{$item} = 1;
10217: }
10218: }
10219: if (keys(%changes) > 0) {
10220: my @offon = ('off','on');
10221: $resulttext = &mt('Changes made:').'<ul>';
10222: foreach my $item (@types) {
10223: if ($changes{$item}) {
10224: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 10225: $resulttext .= '<li>'.
10226: &mt("$title{$item} set to [_1]$newtxt [_2]",
10227: '<b>','</b>').
10228: '</li>';
1.125 raeburn 10229: }
10230: }
10231: if ($changes{'xmldc'}) {
10232: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
10233: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 10234: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 10235: }
10236: $resulttext .= '</ul>';
10237: } else {
10238: $resulttext = &mt('No changes made to auto-creation settings');
10239: }
10240: } else {
10241: $resulttext = '<span class="LC_error">'.
10242: &mt('An error occurred: [_1]',$putresult).'</span>';
10243: }
10244: return $resulttext;
10245: }
10246:
1.23 raeburn 10247: sub modify_directorysrch {
1.160.6.81 raeburn 10248: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 10249: my ($resulttext,%changes);
10250: my %currdirsrch;
10251: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10252: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
10253: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
10254: }
10255: }
1.160.6.72 raeburn 10256: my %title = ( available => 'Institutional directory search available',
10257: localonly => 'Other domains can search institution',
10258: lcavailable => 'LON-CAPA directory search available',
10259: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 10260: searchby => 'Search types',
10261: searchtypes => 'Search latitude');
10262: my @offon = ('off','on');
1.24 raeburn 10263: my @otherdoms = ('Yes','No');
1.23 raeburn 10264:
1.25 raeburn 10265: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 10266: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
10267: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
10268:
1.44 raeburn 10269: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 10270: if (keys(%{$usertypes}) == 0) {
10271: @cansearch = ('default');
10272: } else {
10273: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
10274: foreach my $type (@{$currdirsrch{'cansearch'}}) {
10275: if (!grep(/^\Q$type\E$/,@cansearch)) {
10276: push(@{$changes{'cansearch'}},$type);
10277: }
1.23 raeburn 10278: }
1.26 raeburn 10279: foreach my $type (@cansearch) {
10280: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
10281: push(@{$changes{'cansearch'}},$type);
10282: }
1.23 raeburn 10283: }
1.26 raeburn 10284: } else {
10285: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 10286: }
10287: }
10288:
10289: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
10290: foreach my $by (@{$currdirsrch{'searchby'}}) {
10291: if (!grep(/^\Q$by\E$/,@searchby)) {
10292: push(@{$changes{'searchby'}},$by);
10293: }
10294: }
10295: foreach my $by (@searchby) {
10296: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
10297: push(@{$changes{'searchby'}},$by);
10298: }
10299: }
10300: } else {
10301: push(@{$changes{'searchby'}},@searchby);
10302: }
1.25 raeburn 10303:
10304: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
10305: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
10306: if (!grep(/^\Q$type\E$/,@searchtypes)) {
10307: push(@{$changes{'searchtypes'}},$type);
10308: }
10309: }
10310: foreach my $type (@searchtypes) {
10311: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
10312: push(@{$changes{'searchtypes'}},$type);
10313: }
10314: }
10315: } else {
10316: if (exists($currdirsrch{'searchtypes'})) {
10317: foreach my $type (@searchtypes) {
10318: if ($type ne $currdirsrch{'searchtypes'}) {
10319: push(@{$changes{'searchtypes'}},$type);
10320: }
10321: }
10322: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
10323: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
10324: }
10325: } else {
10326: push(@{$changes{'searchtypes'}},@searchtypes);
10327: }
10328: }
10329:
1.23 raeburn 10330: my %dirsrch_hash = (
10331: directorysrch => { available => $env{'form.dirsrch_available'},
10332: cansearch => \@cansearch,
1.160.6.72 raeburn 10333: localonly => $env{'form.dirsrch_instlocalonly'},
10334: lclocalonly => $env{'form.dirsrch_domlocalonly'},
10335: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 10336: searchby => \@searchby,
1.25 raeburn 10337: searchtypes => \@searchtypes,
1.23 raeburn 10338: }
10339: );
10340: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
10341: $dom);
10342: if ($putresult eq 'ok') {
10343: if (exists($currdirsrch{'available'})) {
10344: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
10345: $changes{'available'} = 1;
10346: }
10347: } else {
10348: if ($env{'form.dirsrch_available'} eq '1') {
10349: $changes{'available'} = 1;
10350: }
10351: }
1.160.6.72 raeburn 10352: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 10353: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
10354: $changes{'lcavailable'} = 1;
10355: }
1.24 raeburn 10356: } else {
1.160.6.72 raeburn 10357: if ($env{'form.dirsrch_lcavailable'} eq '1') {
10358: $changes{'lcavailable'} = 1;
10359: }
10360: }
10361: if (exists($currdirsrch{'localonly'})) {
10362: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 10363: $changes{'localonly'} = 1;
10364: }
1.160.6.72 raeburn 10365: } else {
10366: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
10367: $changes{'localonly'} = 1;
10368: }
10369: }
10370: if (exists($currdirsrch{'lclocalonly'})) {
10371: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
10372: $changes{'lclocalonly'} = 1;
10373: }
10374: } else {
10375: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
10376: $changes{'lclocalonly'} = 1;
10377: }
1.24 raeburn 10378: }
1.23 raeburn 10379: if (keys(%changes) > 0) {
10380: $resulttext = &mt('Changes made:').'<ul>';
10381: if ($changes{'available'}) {
10382: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
10383: }
1.160.6.72 raeburn 10384: if ($changes{'lcavailable'}) {
10385: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
10386: }
1.24 raeburn 10387: if ($changes{'localonly'}) {
1.160.6.72 raeburn 10388: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
10389: }
10390: if ($changes{'lclocalonly'}) {
10391: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 10392: }
1.23 raeburn 10393: if (ref($changes{'cansearch'}) eq 'ARRAY') {
10394: my $chgtext;
1.26 raeburn 10395: if (ref($usertypes) eq 'HASH') {
10396: if (keys(%{$usertypes}) > 0) {
10397: foreach my $type (@{$types}) {
10398: if (grep(/^\Q$type\E$/,@cansearch)) {
10399: $chgtext .= $usertypes->{$type}.'; ';
10400: }
10401: }
10402: if (grep(/^default$/,@cansearch)) {
10403: $chgtext .= $othertitle;
10404: } else {
10405: $chgtext =~ s/\; $//;
10406: }
1.160.6.13 raeburn 10407: $resulttext .=
10408: '<li>'.
10409: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
10410: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
10411: '</li>';
1.23 raeburn 10412: }
10413: }
10414: }
10415: if (ref($changes{'searchby'}) eq 'ARRAY') {
10416: my ($searchtitles,$titleorder) = &sorted_searchtitles();
10417: my $chgtext;
10418: foreach my $type (@{$titleorder}) {
10419: if (grep(/^\Q$type\E$/,@searchby)) {
10420: if (defined($searchtitles->{$type})) {
10421: $chgtext .= $searchtitles->{$type}.'; ';
10422: }
10423: }
10424: }
10425: $chgtext =~ s/\; $//;
10426: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
10427: }
1.25 raeburn 10428: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
10429: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
10430: my $chgtext;
10431: foreach my $type (@{$srchtypeorder}) {
10432: if (grep(/^\Q$type\E$/,@searchtypes)) {
10433: if (defined($srchtypes_desc->{$type})) {
10434: $chgtext .= $srchtypes_desc->{$type}.'; ';
10435: }
10436: }
10437: }
10438: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 10439: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 10440: }
10441: $resulttext .= '</ul>';
1.160.6.81 raeburn 10442: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
10443: if (ref($lastactref) eq 'HASH') {
10444: $lastactref->{'directorysrch'} = 1;
10445: }
1.23 raeburn 10446: } else {
1.160.6.72 raeburn 10447: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 10448: }
10449: } else {
10450: $resulttext = '<span class="LC_error">'.
1.27 raeburn 10451: &mt('An error occurred: [_1]',$putresult).'</span>';
10452: }
10453: return $resulttext;
10454: }
10455:
1.28 raeburn 10456: sub modify_contacts {
1.160.6.24 raeburn 10457: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 10458: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
10459: if (ref($domconfig{'contacts'}) eq 'HASH') {
10460: foreach my $key (keys(%{$domconfig{'contacts'}})) {
10461: $currsetting{$key} = $domconfig{'contacts'}{$key};
10462: }
10463: }
1.160.6.78 raeburn 10464: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 10465: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 10466: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 10467: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.23 raeburn 10468: my @toggles = ('reporterrors','reportupdates');
1.160.6.78 raeburn 10469: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 10470: foreach my $type (@mailings) {
10471: @{$newsetting{$type}} =
10472: &Apache::loncommon::get_env_multiple('form.'.$type);
10473: foreach my $item (@contacts) {
10474: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
10475: $contacts_hash{contacts}{$type}{$item} = 1;
10476: } else {
10477: $contacts_hash{contacts}{$type}{$item} = 0;
10478: }
1.160.6.78 raeburn 10479: }
1.28 raeburn 10480: $others{$type} = $env{'form.'.$type.'_others'};
10481: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 10482: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10483: $bcc{$type} = $env{'form.'.$type.'_bcc'};
10484: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 10485: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
10486: $includestr{$type} = $env{'form.'.$type.'_includestr'};
10487: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
10488: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
10489: }
1.134 raeburn 10490: }
1.28 raeburn 10491: }
10492: foreach my $item (@contacts) {
10493: $to{$item} = $env{'form.'.$item};
10494: $contacts_hash{'contacts'}{$item} = $to{$item};
10495: }
1.160.6.23 raeburn 10496: foreach my $item (@toggles) {
10497: if ($env{'form.'.$item} =~ /^(0|1)$/) {
10498: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
10499: }
10500: }
1.160.6.78 raeburn 10501: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
10502: foreach my $field (@{$fields}) {
10503: if (ref($possoptions->{$field}) eq 'ARRAY') {
10504: my $value = $env{'form.helpform_'.$field};
10505: $value =~ s/^\s+|\s+$//g;
10506: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101! raeburn 10507: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 10508: if ($field eq 'screenshot') {
10509: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
10510: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101! raeburn 10511: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 10512: }
10513: }
10514: }
10515: }
10516: }
10517: }
1.160.6.101! raeburn 10518: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
! 10519: my (@statuses,%usertypeshash,@overrides);
! 10520: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
! 10521: @statuses = @{$types};
! 10522: if (ref($usertypes) eq 'HASH') {
! 10523: %usertypeshash = %{$usertypes};
! 10524: }
! 10525: }
! 10526: if (@statuses) {
! 10527: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
! 10528: foreach my $type (@possoverrides) {
! 10529: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
! 10530: push(@overrides,$type);
! 10531: }
! 10532: }
! 10533: if (@overrides) {
! 10534: foreach my $type (@overrides) {
! 10535: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
! 10536: foreach my $item (@contacts) {
! 10537: if (grep(/^\Q$item\E$/,@standard)) {
! 10538: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
! 10539: $newsetting{'override_'.$type}{$item} = 1;
! 10540: } else {
! 10541: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
! 10542: $newsetting{'override_'.$type}{$item} = 0;
! 10543: }
! 10544: }
! 10545: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
! 10546: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
! 10547: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
! 10548: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
! 10549: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
! 10550: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
! 10551: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
! 10552: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
! 10553: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
! 10554: }
! 10555: }
! 10556: }
! 10557: }
1.28 raeburn 10558: if (keys(%currsetting) > 0) {
10559: foreach my $item (@contacts) {
10560: if ($to{$item} ne $currsetting{$item}) {
10561: $changes{$item} = 1;
10562: }
10563: }
10564: foreach my $type (@mailings) {
10565: foreach my $item (@contacts) {
10566: if (ref($currsetting{$type}) eq 'HASH') {
10567: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
10568: push(@{$changes{$type}},$item);
10569: }
10570: } else {
10571: push(@{$changes{$type}},@{$newsetting{$type}});
10572: }
10573: }
10574: if ($others{$type} ne $currsetting{$type}{'others'}) {
10575: push(@{$changes{$type}},'others');
10576: }
1.160.6.78 raeburn 10577: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10578: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
10579: push(@{$changes{$type}},'bcc');
10580: }
1.160.6.78 raeburn 10581: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
10582: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
10583: push(@{$changes{$type}},'include');
10584: }
10585: }
10586: }
10587: if (ref($fields) eq 'ARRAY') {
10588: if (ref($currsetting{'helpform'}) eq 'HASH') {
10589: foreach my $field (@{$fields}) {
10590: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
10591: push(@{$changes{'helpform'}},$field);
10592: }
10593: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10594: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
10595: push(@{$changes{'helpform'}},'maxsize');
10596: }
10597: }
10598: }
10599: } else {
10600: foreach my $field (@{$fields}) {
10601: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10602: push(@{$changes{'helpform'}},$field);
10603: }
10604: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10605: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10606: push(@{$changes{'helpform'}},'maxsize');
10607: }
10608: }
10609: }
1.134 raeburn 10610: }
1.28 raeburn 10611: }
1.160.6.101! raeburn 10612: if (@statuses) {
! 10613: if (ref($currsetting{'overrides'}) eq 'HASH') {
! 10614: foreach my $key (keys(%{$currsetting{'overrides'}})) {
! 10615: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
! 10616: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
! 10617: foreach my $item (@contacts,'bcc','others','include') {
! 10618: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
! 10619: push(@{$changes{'overrides'}},$key);
! 10620: last;
! 10621: }
! 10622: }
! 10623: } else {
! 10624: push(@{$changes{'overrides'}},$key);
! 10625: }
! 10626: }
! 10627: }
! 10628: foreach my $key (@overrides) {
! 10629: unless (exists($currsetting{'overrides'}{$key})) {
! 10630: push(@{$changes{'overrides'}},$key);
! 10631: }
! 10632: }
! 10633: } else {
! 10634: foreach my $key (@overrides) {
! 10635: push(@{$changes{'overrides'}},$key);
! 10636: }
! 10637: }
! 10638: }
1.28 raeburn 10639: } else {
10640: my %default;
10641: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
10642: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
10643: $default{'errormail'} = 'adminemail';
10644: $default{'packagesmail'} = 'adminemail';
10645: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 10646: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 10647: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 10648: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 10649: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 10650: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 10651: foreach my $item (@contacts) {
10652: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 10653: $changes{$item} = 1;
1.160.6.23 raeburn 10654: }
1.28 raeburn 10655: }
10656: foreach my $type (@mailings) {
10657: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
10658: push(@{$changes{$type}},@{$newsetting{$type}});
10659: }
10660: if ($others{$type} ne '') {
10661: push(@{$changes{$type}},'others');
1.134 raeburn 10662: }
1.160.6.78 raeburn 10663: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10664: if ($bcc{$type} ne '') {
10665: push(@{$changes{$type}},'bcc');
10666: }
1.160.6.78 raeburn 10667: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
10668: push(@{$changes{$type}},'include');
10669: }
10670: }
10671: }
10672: if (ref($fields) eq 'ARRAY') {
10673: foreach my $field (@{$fields}) {
10674: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10675: push(@{$changes{'helpform'}},$field);
10676: }
10677: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10678: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10679: push(@{$changes{'helpform'}},'maxsize');
10680: }
10681: }
1.134 raeburn 10682: }
1.28 raeburn 10683: }
10684: }
1.160.6.23 raeburn 10685: foreach my $item (@toggles) {
10686: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
10687: $changes{$item} = 1;
10688: } elsif ((!$env{'form.'.$item}) &&
10689: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
10690: $changes{$item} = 1;
10691: }
10692: }
1.28 raeburn 10693: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
10694: $dom);
10695: if ($putresult eq 'ok') {
10696: if (keys(%changes) > 0) {
1.160.6.24 raeburn 10697: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10698: if (ref($lastactref) eq 'HASH') {
10699: $lastactref->{'domainconfig'} = 1;
10700: }
1.28 raeburn 10701: my ($titles,$short_titles) = &contact_titles();
10702: $resulttext = &mt('Changes made:').'<ul>';
10703: foreach my $item (@contacts) {
10704: if ($changes{$item}) {
10705: $resulttext .= '<li>'.$titles->{$item}.
10706: &mt(' set to: ').
10707: '<span class="LC_cusr_emph">'.
10708: $to{$item}.'</span></li>';
10709: }
10710: }
10711: foreach my $type (@mailings) {
10712: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 10713: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
10714: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
10715: } else {
10716: $resulttext .= '<li>'.$titles->{$type}.': ';
10717: }
1.28 raeburn 10718: my @text;
10719: foreach my $item (@{$newsetting{$type}}) {
10720: push(@text,$short_titles->{$item});
10721: }
10722: if ($others{$type} ne '') {
10723: push(@text,$others{$type});
10724: }
1.160.6.78 raeburn 10725: if (@text) {
10726: $resulttext .= '<span class="LC_cusr_emph">'.
10727: join(', ',@text).'</span>';
10728: }
10729: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10730: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 10731: my $bcctext;
10732: if (@text) {
10733: $bcctext = ' '.&mt('with Bcc to');
10734: } else {
10735: $bcctext = '(Bcc)';
10736: }
10737: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
10738: } elsif (!@text) {
10739: $resulttext .= &mt('No one');
1.134 raeburn 10740: }
1.160.6.78 raeburn 10741: if ($includestr{$type} ne '') {
10742: if ($includeloc{$type} eq 'b') {
10743: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
10744: } elsif ($includeloc{$type} eq 's') {
10745: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
10746: }
10747: }
10748: } elsif (!@text) {
10749: $resulttext .= &mt('No recipients');
1.134 raeburn 10750: }
10751: $resulttext .= '</li>';
1.28 raeburn 10752: }
10753: }
1.160.6.101! raeburn 10754: if (ref($changes{'overrides'}) eq 'ARRAY') {
! 10755: my @deletions;
! 10756: foreach my $type (@{$changes{'overrides'}}) {
! 10757: if ($usertypeshash{$type}) {
! 10758: if (grep(/^\Q$type\E/,@overrides)) {
! 10759: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
! 10760: $usertypeshash{$type}).'<ul><li>';
! 10761: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
! 10762: my @text;
! 10763: foreach my $item (@contacts) {
! 10764: if ($newsetting{'override_'.$type}{$item}) {
! 10765: push(@text,$short_titles->{$item});
! 10766: }
! 10767: }
! 10768: if ($newsetting{'override_'.$type}{'others'} ne '') {
! 10769: push(@text,$newsetting{'override_'.$type}{'others'});
! 10770: }
! 10771:
! 10772: if (@text) {
! 10773: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
! 10774: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
! 10775: }
! 10776: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
! 10777: my $bcctext;
! 10778: if (@text) {
! 10779: $bcctext = ' '.&mt('with Bcc to');
! 10780: } else {
! 10781: $bcctext = '(Bcc)';
! 10782: }
! 10783: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
! 10784: } elsif (!@text) {
! 10785: $resulttext .= &mt('Helpdesk e-mail sent to no one');
! 10786: }
! 10787: $resulttext .= '</li>';
! 10788: if ($newsetting{'override_'.$type}{'include'} ne '') {
! 10789: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
! 10790: if ($loc eq 'b') {
! 10791: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
! 10792: } elsif ($loc eq 's') {
! 10793: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
! 10794: }
! 10795: }
! 10796: }
! 10797: $resulttext .= '</li></ul></li>';
! 10798: } else {
! 10799: push(@deletions,$usertypeshash{$type});
! 10800: }
! 10801: }
! 10802: }
! 10803: if (@deletions) {
! 10804: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
! 10805: join(', ',@deletions)).'</li>';
! 10806: }
! 10807: }
1.160.6.23 raeburn 10808: my @offon = ('off','on');
10809: if ($changes{'reporterrors'}) {
10810: $resulttext .= '<li>'.
10811: &mt('E-mail error reports to [_1] set to "'.
10812: $offon[$env{'form.reporterrors'}].'".',
10813: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10814: &mt('LON-CAPA core group - MSU'),600,500)).
10815: '</li>';
10816: }
10817: if ($changes{'reportupdates'}) {
10818: $resulttext .= '<li>'.
10819: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
10820: $offon[$env{'form.reportupdates'}].'".',
10821: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10822: &mt('LON-CAPA core group - MSU'),600,500)).
10823: '</li>';
10824: }
1.160.6.78 raeburn 10825: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
10826: my (@optional,@required,@unused,$maxsizechg);
10827: foreach my $field (@{$changes{'helpform'}}) {
10828: if ($field eq 'maxsize') {
10829: $maxsizechg = 1;
10830: next;
10831: }
10832: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
10833: push(@optional,$field);
10834: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
10835: push(@unused,$field);
10836: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
10837: push(@required,$field);
10838: }
10839: }
10840: if (@optional) {
10841: $resulttext .= '<li>'.
10842: &mt('Help form fields changed to "Optional": [_1].',
10843: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
10844: '</li>';
10845: }
10846: if (@required) {
10847: $resulttext .= '<li>'.
10848: &mt('Help form fields changed to "Required": [_1].',
10849: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
10850: '</li>';
10851: }
10852: if (@unused) {
10853: $resulttext .= '<li>'.
10854: &mt('Help form fields changed to "Not shown": [_1].',
10855: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
10856: '</li>';
10857: }
10858: if ($maxsizechg) {
10859: $resulttext .= '<li>'.
10860: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
10861: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
10862: '</li>';
10863: }
10864: }
1.28 raeburn 10865: $resulttext .= '</ul>';
10866: } else {
1.160.6.78 raeburn 10867: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 10868: }
10869: } else {
10870: $resulttext = '<span class="LC_error">'.
10871: &mt('An error occurred: [_1].',$putresult).'</span>';
10872: }
10873: return $resulttext;
10874: }
10875:
1.160.6.98 raeburn 10876: sub modify_passwords {
10877: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
10878: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
10879: $updatedefaults,$updateconf);
10880: my $customfn = 'resetpw.html';
10881: if (ref($domconfig{'passwords'}) eq 'HASH') {
10882: %current = %{$domconfig{'passwords'}};
10883: }
10884: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10885: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10886: if (ref($types) eq 'ARRAY') {
10887: @oktypes = @{$types};
10888: }
10889: push(@oktypes,'default');
10890:
10891: my %titles = &Apache::lonlocal::texthash (
10892: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
10893: intauth_check => 'Check bcrypt cost if authenticated',
10894: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
10895: permanent => 'Permanent e-mail address',
10896: critical => 'Critical notification address',
10897: notify => 'Notification address',
10898: min => 'Minimum password length',
10899: max => 'Maximum password length',
10900: chars => 'Required characters',
10901: numsaved => 'Number of previous passwords to save',
10902: reset => 'Resetting Forgotten Password',
10903: intauth => 'Encryption of Stored Passwords (Internal Auth)',
10904: rules => 'Rules for LON-CAPA Passwords',
10905: crsownerchg => 'Course Owner Changing Student Passwords',
10906: username => 'Username',
10907: email => 'E-mail address',
10908: );
10909:
10910: #
10911: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
10912: #
10913: my (%curr_defaults,%save_defaults);
10914: if (ref($domconfig{'defaults'}) eq 'HASH') {
10915: foreach my $key (keys(%{$domconfig{'defaults'}})) {
10916: if ($key =~ /^intauth_(cost|check|switch)$/) {
10917: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
10918: } else {
10919: $save_defaults{$key} = $domconfig{'defaults'}{$key};
10920: }
10921: }
10922: }
10923: my %staticdefaults = (
10924: 'resetlink' => 2,
10925: 'resetcase' => \@oktypes,
10926: 'resetprelink' => 'both',
10927: 'resetemail' => ['critical','notify','permanent'],
10928: 'intauth_cost' => 10,
10929: 'intauth_check' => 0,
10930: 'intauth_switch' => 0,
10931: );
1.160.6.99 raeburn 10932: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 10933: foreach my $type (@oktypes) {
10934: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
10935: }
10936: my $linklife = $env{'form.passwords_link'};
10937: $linklife =~ s/^\s+|\s+$//g;
10938: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
10939: $newvalues{'resetlink'} = $linklife;
10940: if ($current{'resetlink'}) {
10941: if ($current{'resetlink'} ne $linklife) {
10942: $changes{'reset'} = 1;
10943: }
10944: } elsif (!exists($domconfig{passwords})) {
10945: if ($staticdefaults{'resetlink'} ne $linklife) {
10946: $changes{'reset'} = 1;
10947: }
10948: }
10949: } elsif ($current{'resetlink'}) {
10950: $changes{'reset'} = 1;
10951: }
10952: my @casesens;
10953: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
10954: foreach my $case (sort(@posscase)) {
10955: if (grep(/^\Q$case\E$/,@oktypes)) {
10956: push(@casesens,$case);
10957: }
10958: }
10959: $newvalues{'resetcase'} = \@casesens;
10960: if (ref($current{'resetcase'}) eq 'ARRAY') {
10961: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
10962: if (@diffs > 0) {
10963: $changes{'reset'} = 1;
10964: }
10965: } elsif (!exists($domconfig{passwords})) {
10966: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
10967: if (@diffs > 0) {
10968: $changes{'reset'} = 1;
10969: }
10970: }
10971: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
10972: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
10973: if (exists($current{'resetprelink'})) {
10974: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
10975: $changes{'reset'} = 1;
10976: }
10977: } elsif (!exists($domconfig{passwords})) {
10978: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
10979: $changes{'reset'} = 1;
10980: }
10981: }
10982: } elsif ($current{'resetprelink'}) {
10983: $changes{'reset'} = 1;
10984: }
10985: foreach my $type (@oktypes) {
10986: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
10987: my @postlink;
10988: foreach my $item (sort(@possplink)) {
10989: if ($item =~ /^(email|username)$/) {
10990: push(@postlink,$item);
10991: }
10992: }
10993: $newvalues{'resetpostlink'}{$type} = \@postlink;
10994: unless ($changes{'reset'}) {
10995: if (ref($current{'resetpostlink'}) eq 'HASH') {
10996: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
10997: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
10998: if (@diffs > 0) {
10999: $changes{'reset'} = 1;
11000: }
11001: } else {
11002: $changes{'reset'} = 1;
11003: }
11004: } elsif (!exists($domconfig{passwords})) {
11005: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
11006: if (@diffs > 0) {
11007: $changes{'reset'} = 1;
11008: }
11009: }
11010: }
11011: }
11012: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
11013: my @resetemail;
11014: foreach my $item (sort(@possemailsrc)) {
11015: if ($item =~ /^(permanent|critical|notify)$/) {
11016: push(@resetemail,$item);
11017: }
11018: }
11019: $newvalues{'resetemail'} = \@resetemail;
11020: unless ($changes{'reset'}) {
11021: if (ref($current{'resetemail'}) eq 'ARRAY') {
11022: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
11023: if (@diffs > 0) {
11024: $changes{'reset'} = 1;
11025: }
11026: } elsif (!exists($domconfig{passwords})) {
11027: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
11028: if (@diffs > 0) {
11029: $changes{'reset'} = 1;
11030: }
11031: }
11032: }
11033: if ($env{'form.passwords_stdtext'} == 0) {
11034: $newvalues{'resetremove'} = 1;
11035: unless ($current{'resetremove'}) {
11036: $changes{'reset'} = 1;
11037: }
11038: } elsif ($current{'resetremove'}) {
11039: $changes{'reset'} = 1;
11040: }
11041: if ($env{'form.passwords_customfile.filename'} ne '') {
11042: my $servadm = $r->dir_config('lonAdmEMail');
11043: my $servadm = $r->dir_config('lonAdmEMail');
11044: my ($configuserok,$author_ok,$switchserver) =
11045: &config_check($dom,$confname,$servadm);
11046: my $error;
11047: if ($configuserok eq 'ok') {
11048: if ($switchserver) {
11049: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
11050: } else {
11051: if ($author_ok eq 'ok') {
11052: my ($result,$customurl) =
11053: &publishlogo($r,'upload','passwords_customfile',$dom,
11054: $confname,'customtext/resetpw','','',$customfn);
11055: if ($result eq 'ok') {
11056: $newvalues{'resetcustom'} = $customurl;
11057: $changes{'reset'} = 1;
11058: } else {
11059: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
11060: }
11061: } else {
11062: $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);
11063: }
11064: }
11065: } else {
11066: $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);
11067: }
11068: if ($error) {
11069: &Apache::lonnet::logthis($error);
11070: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11071: }
11072: } elsif ($current{'resetcustom'}) {
11073: if ($env{'form.passwords_custom_del'}) {
11074: $changes{'reset'} = 1;
11075: } else {
11076: $newvalues{'resetcustom'} = $current{'resetcustom'};
11077: }
11078: }
11079: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
11080: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
11081: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
11082: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
11083: $changes{'intauth'} = 1;
11084: }
11085: } else {
11086: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
11087: }
11088: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
11089: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
11090: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
11091: $changes{'intauth'} = 1;
11092: }
11093: } else {
11094: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
11095: }
11096: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
11097: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
11098: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
11099: $changes{'intauth'} = 1;
11100: }
11101: } else {
11102: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
11103: }
11104: foreach my $item ('cost','check','switch') {
11105: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
11106: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
11107: $updatedefaults = 1;
11108: }
11109: }
11110: foreach my $rule ('min','max','numsaved') {
11111: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.160.6.99 raeburn 11112: my $ruleok;
11113: if ($rule eq 'min') {
11114: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
11115: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
11116: $ruleok = 1;
11117: }
11118: }
11119: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
11120: ($env{'form.passwords_'.$rule} ne '0')) {
11121: $ruleok = 1;
11122: }
11123: if ($ruleok) {
1.160.6.98 raeburn 11124: $newvalues{$rule} = $env{'form.passwords_'.$rule};
11125: if (exists($current{$rule})) {
11126: if ($newvalues{$rule} ne $current{$rule}) {
11127: $changes{'rules'} = 1;
11128: }
11129: } elsif ($rule eq 'min') {
11130: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
11131: $changes{'rules'} = 1;
11132: }
11133: }
11134: } elsif (exists($current{$rule})) {
11135: $changes{'rules'} = 1;
11136: }
11137: }
11138: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
11139: my @chars;
11140: foreach my $item (sort(@posschars)) {
11141: if ($item =~ /^(uc|lc|num|spec)$/) {
11142: push(@chars,$item);
11143: }
11144: }
11145: $newvalues{'chars'} = \@chars;
11146: unless ($changes{'rules'}) {
11147: if (ref($current{'chars'}) eq 'ARRAY') {
11148: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
11149: if (@diffs > 0) {
11150: $changes{'rules'} = 1;
11151: }
11152: } else {
11153: if (@chars > 0) {
11154: $changes{'rules'} = 1;
11155: }
11156: }
11157: }
11158: my %crsownerchg = (
11159: by => [],
11160: for => [],
11161: );
11162: foreach my $item ('by','for') {
11163: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
11164: foreach my $type (sort(@posstypes)) {
11165: if (grep(/^\Q$type\E$/,@oktypes)) {
11166: push(@{$crsownerchg{$item}},$type);
11167: }
11168: }
11169: }
11170: $newvalues{'crsownerchg'} = \%crsownerchg;
11171: if (ref($current{'crsownerchg'}) eq 'HASH') {
11172: foreach my $item ('by','for') {
11173: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
11174: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
11175: if (@diffs > 0) {
11176: $changes{'crsownerchg'} = 1;
11177: last;
11178: }
11179: }
11180: }
11181: } elsif (!exists($domconfig{passwords})) {
11182: foreach my $item ('by','for') {
11183: if (@{$crsownerchg{$item}} > 0) {
11184: $changes{'crsownerchg'} = 1;
11185: last;
11186: }
11187: }
11188: }
11189:
11190: my %confighash = (
11191: defaults => \%save_defaults,
11192: passwords => \%newvalues,
11193: );
11194: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
11195:
11196: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
11197: if ($putresult eq 'ok') {
11198: if (keys(%changes) > 0) {
11199: $resulttext = &mt('Changes made: ').'<ul>';
11200: foreach my $key ('reset','intauth','rules','crsownerchg') {
11201: if ($changes{$key}) {
11202: unless ($key eq 'intauth') {
11203: $updateconf = 1;
11204: }
11205: $resulttext .= '<li>'.$titles{$key}.':<ul>';
11206: if ($key eq 'reset') {
11207: if ($confighash{'passwords'}{'captcha'} eq 'original') {
11208: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
11209: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
11210: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
11211: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />'.
11212: &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchapub'}).'</br>'.
11213: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchapriv'}).'</li>';
11214: } else {
11215: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
11216: }
11217: if ($confighash{'passwords'}{'resetlink'}) {
11218: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
11219: } else {
11220: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
11221: &mt('Will default to 2 hours').'</li>';
11222: }
11223: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
11224: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
11225: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
11226: } else {
11227: my $casesens;
11228: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
11229: if ($type eq 'default') {
11230: $casesens .= $othertitle.', ';
11231: } elsif ($usertypes->{$type} ne '') {
11232: $casesens .= $usertypes->{$type}.', ';
11233: }
11234: }
11235: $casesens =~ s/\Q, \E$//;
11236: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
11237: }
11238: } else {
11239: $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>';
11240: }
11241: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
11242: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
11243: } else {
11244: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
11245: }
11246: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
11247: my $output;
11248: if (ref($types) eq 'ARRAY') {
11249: foreach my $type (@{$types}) {
11250: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
11251: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
11252: $output .= $usertypes->{$type}.' -- '.&mt('none');
11253: } else {
11254: $output .= $usertypes->{$type}.' -- '.
11255: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
11256: }
11257: }
11258: }
11259: }
11260: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
11261: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
11262: $output .= $othertitle.' -- '.&mt('none');
11263: } else {
11264: $output .= $othertitle.' -- '.
11265: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
11266: }
11267: }
11268: if ($output) {
11269: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
11270: } else {
11271: $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>';
11272: }
11273: } else {
11274: $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>';
11275: }
11276: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
11277: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
11278: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
11279: } else {
11280: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
11281: }
11282: } else {
11283: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA usedfor verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
11284: }
11285: if ($confighash{'passwords'}{'resetremove'}) {
11286: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
11287: } else {
11288: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
11289: }
11290: if ($confighash{'passwords'}{'resetcustom'}) {
11291: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
11292: $titles{custom},600,500);
11293: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes [_1]',$customlink).'</li>';
11294: } else {
11295: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
11296: }
11297: } elsif ($key eq 'intauth') {
11298: foreach my $item ('cost','switch','check') {
11299: my $value = $save_defaults{$key.'_'.$item};
11300: if ($item eq 'switch') {
11301: my %optiondesc = &Apache::lonlocal::texthash (
11302: 0 => 'No',
11303: 1 => 'Yes',
11304: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
11305: );
11306: if ($value =~ /^(0|1|2)$/) {
11307: $value = $optiondesc{$value};
11308: } else {
11309: $value = &mt('none -- defaults to No');
11310: }
11311: } elsif ($item eq 'check') {
11312: my %optiondesc = &Apache::lonlocal::texthash (
11313: 0 => 'No',
11314: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
11315: 2 => 'Yes, disallow login if stored cost is less than domain default',
11316: );
11317: if ($value =~ /^(0|1|2)$/) {
11318: $value = $optiondesc{$value};
11319: } else {
11320: $value = &mt('none -- defaults to No');
11321: }
11322: }
11323: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
11324: }
11325: } elsif ($key eq 'rules') {
11326: foreach my $rule ('min','max','numsaved') {
11327: if ($confighash{'passwords'}{$rule} eq '') {
11328: if ($rule eq 'min') {
11329: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99 raeburn 11330: ' '.&mt('Default of [_1] will be used',
11331: $Apache::lonnet::passwdmin).'</li>';
1.160.6.98 raeburn 11332: } else {
11333: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
11334: }
11335: } else {
11336: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
11337: }
11338: }
11339: } elsif ($key eq 'crsownerchg') {
11340: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
11341: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
11342: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
11343: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
11344: } else {
11345: my %crsownerstr;
11346: foreach my $item ('by','for') {
11347: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
11348: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
11349: if ($type eq 'default') {
11350: $crsownerstr{$item} .= $othertitle.', ';
11351: } elsif ($usertypes->{$type} ne '') {
11352: $crsownerstr{$item} .= $usertypes->{$type}.', ';
11353: }
11354: }
11355: $crsownerstr{$item} =~ s/\Q, \E$//;
11356: }
11357: }
11358: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
11359: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
11360: }
11361: } else {
11362: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
11363: }
11364: }
11365: $resulttext .= '</ul></li>';
11366: }
11367: }
11368: $resulttext .= '</ul>';
11369: } else {
11370: $resulttext = &mt('No changes made to password settings');
11371: }
11372: my $cachetime = 24*60*60;
11373: if ($updatedefaults) {
11374: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11375: if (ref($lastactref) eq 'HASH') {
11376: $lastactref->{'domdefaults'} = 1;
11377: }
11378: }
11379: if ($updateconf) {
11380: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
11381: if (ref($lastactref) eq 'HASH') {
11382: $lastactref->{'passwdconf'} = 1;
11383: }
11384: }
11385: } else {
11386: $resulttext = '<span class="LC_error">'.
11387: &mt('An error occurred: [_1]',$putresult).'</span>';
11388: }
11389: if ($errors) {
11390: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
11391: $errors.'</ul></p>';
11392: }
11393: return $resulttext;
11394: }
11395:
1.28 raeburn 11396: sub modify_usercreation {
1.27 raeburn 11397: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 11398: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 11399: my $warningmsg;
1.27 raeburn 11400: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11401: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 11402: if ($key eq 'cancreate') {
11403: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11404: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 11405: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 11406: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 11407: } else {
11408: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 11409: }
1.50 raeburn 11410: }
1.43 raeburn 11411: }
1.160.6.34 raeburn 11412: } elsif ($key eq 'email_rule') {
11413: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11414: } else {
11415: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 11416: }
11417: }
1.34 raeburn 11418: }
1.160.6.34 raeburn 11419: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
11420: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
11421: my @contexts = ('author','course','requestcrs');
11422: foreach my $item(@contexts) {
11423: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 11424: }
1.34 raeburn 11425: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11426: foreach my $item (@contexts) {
1.160.6.34 raeburn 11427: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
11428: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 11429: }
1.27 raeburn 11430: }
1.34 raeburn 11431: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
11432: foreach my $item (@contexts) {
1.43 raeburn 11433: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 11434: if ($cancreate{$item} ne 'any') {
11435: push(@{$changes{'cancreate'}},$item);
11436: }
11437: } else {
11438: if ($cancreate{$item} ne 'none') {
11439: push(@{$changes{'cancreate'}},$item);
11440: }
1.27 raeburn 11441: }
11442: }
11443: } else {
1.43 raeburn 11444: foreach my $item (@contexts) {
1.34 raeburn 11445: push(@{$changes{'cancreate'}},$item);
11446: }
1.27 raeburn 11447: }
1.34 raeburn 11448:
1.27 raeburn 11449: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
11450: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
11451: if (!grep(/^\Q$type\E$/,@username_rule)) {
11452: push(@{$changes{'username_rule'}},$type);
11453: }
11454: }
11455: foreach my $type (@username_rule) {
11456: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
11457: push(@{$changes{'username_rule'}},$type);
11458: }
11459: }
11460: } else {
11461: push(@{$changes{'username_rule'}},@username_rule);
11462: }
11463:
1.32 raeburn 11464: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
11465: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
11466: if (!grep(/^\Q$type\E$/,@id_rule)) {
11467: push(@{$changes{'id_rule'}},$type);
11468: }
11469: }
11470: foreach my $type (@id_rule) {
11471: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
11472: push(@{$changes{'id_rule'}},$type);
11473: }
11474: }
11475: } else {
11476: push(@{$changes{'id_rule'}},@id_rule);
11477: }
11478:
1.43 raeburn 11479: my @authen_contexts = ('author','course','domain');
1.28 raeburn 11480: my @authtypes = ('int','krb4','krb5','loc');
11481: my %authhash;
1.43 raeburn 11482: foreach my $item (@authen_contexts) {
1.28 raeburn 11483: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
11484: foreach my $auth (@authtypes) {
11485: if (grep(/^\Q$auth\E$/,@authallowed)) {
11486: $authhash{$item}{$auth} = 1;
11487: } else {
11488: $authhash{$item}{$auth} = 0;
11489: }
11490: }
11491: }
11492: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 11493: foreach my $item (@authen_contexts) {
1.28 raeburn 11494: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
11495: foreach my $auth (@authtypes) {
11496: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
11497: push(@{$changes{'authtypes'}},$item);
11498: last;
11499: }
11500: }
11501: }
11502: }
11503: } else {
1.43 raeburn 11504: foreach my $item (@authen_contexts) {
1.28 raeburn 11505: push(@{$changes{'authtypes'}},$item);
11506: }
11507: }
11508:
1.160.6.34 raeburn 11509: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
11510: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
11511: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
11512: $save_usercreate{'id_rule'} = \@id_rule;
11513: $save_usercreate{'username_rule'} = \@username_rule,
11514: $save_usercreate{'authtypes'} = \%authhash;
11515:
1.27 raeburn 11516: my %usercreation_hash = (
1.160.6.34 raeburn 11517: usercreation => \%save_usercreate,
11518: );
1.27 raeburn 11519:
11520: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
11521: $dom);
1.50 raeburn 11522:
1.160.6.34 raeburn 11523: if ($putresult eq 'ok') {
11524: if (keys(%changes) > 0) {
11525: $resulttext = &mt('Changes made:').'<ul>';
11526: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11527: my %lt = &usercreation_types();
11528: foreach my $type (@{$changes{'cancreate'}}) {
11529: my $chgtext = $lt{$type}.', ';
11530: if ($cancreate{$type} eq 'none') {
11531: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
11532: } elsif ($cancreate{$type} eq 'any') {
11533: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
11534: } elsif ($cancreate{$type} eq 'official') {
11535: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
11536: } elsif ($cancreate{$type} eq 'unofficial') {
11537: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
11538: }
11539: $resulttext .= '<li>'.$chgtext.'</li>';
11540: }
11541: }
11542: if (ref($changes{'username_rule'}) eq 'ARRAY') {
11543: my ($rules,$ruleorder) =
11544: &Apache::lonnet::inst_userrules($dom,'username');
11545: my $chgtext = '<ul>';
11546: foreach my $type (@username_rule) {
11547: if (ref($rules->{$type}) eq 'HASH') {
11548: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
11549: }
11550: }
11551: $chgtext .= '</ul>';
11552: if (@username_rule > 0) {
11553: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11554: } else {
11555: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
11556: }
11557: }
11558: if (ref($changes{'id_rule'}) eq 'ARRAY') {
11559: my ($idrules,$idruleorder) =
11560: &Apache::lonnet::inst_userrules($dom,'id');
11561: my $chgtext = '<ul>';
11562: foreach my $type (@id_rule) {
11563: if (ref($idrules->{$type}) eq 'HASH') {
11564: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
11565: }
11566: }
11567: $chgtext .= '</ul>';
11568: if (@id_rule > 0) {
11569: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11570: } else {
11571: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
11572: }
11573: }
11574: my %authname = &authtype_names();
11575: my %context_title = &context_names();
11576: if (ref($changes{'authtypes'}) eq 'ARRAY') {
11577: my $chgtext = '<ul>';
11578: foreach my $type (@{$changes{'authtypes'}}) {
11579: my @allowed;
11580: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
11581: foreach my $auth (@authtypes) {
11582: if ($authhash{$type}{$auth}) {
11583: push(@allowed,$authname{$auth});
11584: }
11585: }
11586: if (@allowed > 0) {
11587: $chgtext .= join(', ',@allowed).'</li>';
11588: } else {
11589: $chgtext .= &mt('none').'</li>';
11590: }
11591: }
11592: $chgtext .= '</ul>';
11593: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
11594: $resulttext .= '</li>';
11595: }
11596: $resulttext .= '</ul>';
11597: } else {
11598: $resulttext = &mt('No changes made to user creation settings');
11599: }
11600: } else {
11601: $resulttext = '<span class="LC_error">'.
11602: &mt('An error occurred: [_1]',$putresult).'</span>';
11603: }
11604: if ($warningmsg ne '') {
11605: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11606: }
11607: return $resulttext;
11608: }
11609:
11610: sub modify_selfcreation {
1.160.6.93 raeburn 11611: my ($dom,$lastactref,%domconfig) = @_;
11612: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
11613: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
11614: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11615: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
11616: if (ref($typesref) eq 'ARRAY') {
11617: @types = @{$typesref};
11618: }
11619: if (ref($usertypesref) eq 'HASH') {
11620: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 11621: }
1.160.6.93 raeburn 11622: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 11623: #
11624: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
11625: #
11626: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11627: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
11628: if ($key eq 'cancreate') {
11629: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11630: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
11631: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 11632: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
11633: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
11634: ($item eq 'emailusername') || ($item eq 'shibenv') ||
11635: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
11636: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 11637: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11638: } else {
11639: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11640: }
11641: }
11642: }
11643: } elsif ($key eq 'email_rule') {
11644: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11645: } else {
11646: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11647: }
11648: }
11649: }
11650: #
11651: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
11652: #
11653: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11654: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
11655: if ($key eq 'selfcreate') {
11656: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
11657: } else {
11658: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
11659: }
11660: }
11661: }
1.160.6.93 raeburn 11662: #
11663: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
11664: #
11665: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11666: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
11667: if ($key eq 'inststatusguest') {
11668: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
11669: } else {
11670: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
11671: }
11672: }
11673: }
1.160.6.34 raeburn 11674:
11675: my @contexts = ('selfcreate');
11676: @{$cancreate{'selfcreate'}} = ();
11677: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 11678: if (@types) {
11679: @{$cancreate{'statustocreate'}} = ();
11680: }
1.160.6.40 raeburn 11681: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 11682: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 11683: %{$cancreate{'emailverified'}} = ();
11684: %{$cancreate{'emailoptions'}} = ();
11685: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 11686: my %selfcreatetypes = (
11687: sso => 'users authenticated by institutional single sign on',
11688: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 11689: email => 'users verified by e-mail',
1.50 raeburn 11690: );
1.160.6.34 raeburn 11691: #
11692: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
11693: # is permitted.
11694: #
1.160.6.40 raeburn 11695:
1.160.6.93 raeburn 11696: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 11697:
1.160.6.93 raeburn 11698: my (@statuses,%email_rule);
1.160.6.35 raeburn 11699: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 11700: if ($item eq 'email') {
1.160.6.40 raeburn 11701: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 11702: if (@types) {
11703: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
11704: foreach my $status (@poss_statuses) {
11705: if (grep(/^\Q$status\E$/,(@types,'default'))) {
11706: push(@statuses,$status);
11707: }
11708: }
11709: $save_inststatus{'inststatusguest'} = \@statuses;
11710: } else {
11711: push(@statuses,'default');
11712: }
11713: if (@statuses) {
11714: my %curr_rule;
11715: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
11716: foreach my $type (@statuses) {
11717: $curr_rule{$type} = $curr_usercreation{'email_rule'};
11718: }
11719: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
11720: foreach my $type (@statuses) {
11721: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
11722: }
11723: }
11724: push(@{$cancreate{'selfcreate'}},'email');
11725: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
11726: my %curremaildom;
11727: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
11728: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
11729: }
11730: foreach my $type (@statuses) {
11731: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
11732: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
11733: }
11734: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
11735: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
11736: }
11737: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
11738: #
11739: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
11740: #
11741: my $chosen = $1;
11742: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
11743: my $emaildom;
11744: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
11745: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
11746: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
11747: if (ref($curremaildom{$type}) eq 'HASH') {
11748: if (exists($curremaildom{$type}{$chosen})) {
11749: if ($curremaildom{$type}{$chosen} ne $emaildom) {
11750: push(@{$changes{'cancreate'}},'emaildomain');
11751: }
11752: } elsif ($emaildom ne '') {
11753: push(@{$changes{'cancreate'}},'emaildomain');
11754: }
11755: } elsif ($emaildom ne '') {
11756: push(@{$changes{'cancreate'}},'emaildomain');
11757: }
11758: }
11759: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
11760: } elsif ($chosen eq 'custom') {
11761: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
11762: $email_rule{$type} = [];
11763: if (ref($emailrules) eq 'HASH') {
11764: foreach my $rule (@possemail_rules) {
11765: if (exists($emailrules->{$rule})) {
11766: push(@{$email_rule{$type}},$rule);
11767: }
11768: }
11769: }
11770: if (@{$email_rule{$type}}) {
11771: $cancreate{'emailoptions'}{$type} = 'custom';
11772: if (ref($curr_rule{$type}) eq 'ARRAY') {
11773: if (@{$curr_rule{$type}} > 0) {
11774: foreach my $rule (@{$curr_rule{$type}}) {
11775: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
11776: push(@{$changes{'email_rule'}},$type);
11777: }
11778: }
11779: }
11780: foreach my $type (@{$email_rule{$type}}) {
11781: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
11782: push(@{$changes{'email_rule'}},$type);
11783: }
11784: }
11785: } else {
11786: push(@{$changes{'email_rule'}},$type);
11787: }
11788: }
11789: } else {
11790: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
11791: }
11792: }
11793: }
11794: if (@types) {
11795: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
11796: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
11797: if (@changed) {
11798: push(@{$changes{'inststatus'}},'inststatusguest');
11799: }
11800: } else {
11801: push(@{$changes{'inststatus'}},'inststatusguest');
11802: }
11803: }
11804: } else {
11805: delete($env{'form.cancreate_email'});
11806: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
11807: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
11808: push(@{$changes{'inststatus'}},'inststatusguest');
11809: }
11810: }
11811: }
11812: } else {
11813: $save_inststatus{'inststatusguest'} = [];
11814: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
11815: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
11816: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 11817: }
11818: }
1.160.6.34 raeburn 11819: }
11820: } else {
11821: if ($env{'form.cancreate_'.$item}) {
11822: push(@{$cancreate{'selfcreate'}},$item);
11823: }
11824: }
11825: }
1.160.6.93 raeburn 11826: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 11827: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
11828: #
1.160.6.35 raeburn 11829: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
11830: # 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 11831: #
1.160.6.40 raeburn 11832:
1.160.6.48 raeburn 11833: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 11834: push(@contexts,'emailusername');
1.160.6.93 raeburn 11835: if (@statuses) {
11836: foreach my $type (@statuses) {
1.160.6.35 raeburn 11837: if (ref($infofields) eq 'ARRAY') {
11838: foreach my $field (@{$infofields}) {
11839: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
11840: $cancreate{'emailusername'}{$type}{$field} = $1;
11841: }
11842: }
1.160.6.34 raeburn 11843: }
11844: }
11845: }
11846: #
11847: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 11848: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 11849: #
11850:
11851: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
11852: @approvalnotify = sort(@approvalnotify);
11853: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
11854: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11855: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
11856: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
11857: push(@{$changes{'cancreate'}},'notify');
11858: }
11859: } else {
11860: if ($cancreate{'notify'}{'approval'}) {
11861: push(@{$changes{'cancreate'}},'notify');
11862: }
11863: }
11864: } elsif ($cancreate{'notify'}{'approval'}) {
11865: push(@{$changes{'cancreate'}},'notify');
11866: }
11867:
11868: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
11869: }
11870: #
1.160.6.40 raeburn 11871: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 11872: # institutional log-in.
11873: #
11874: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
11875: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
11876: ($domdefaults{'auth_def'} eq 'localauth'))) {
11877: $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.').' '.
11878: &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.');
11879: }
11880: }
11881: my @fields = ('lastname','firstname','middlename','generation',
11882: 'permanentemail','id');
1.160.6.44 raeburn 11883: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 11884: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11885: #
11886: # Where usernames may created for institutional log-in and/or institutional single sign on:
11887: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
11888: # may self-create accounts
11889: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
11890: # which the user may supply, if institutional data is unavailable.
11891: #
11892: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 11893: if (@types) {
11894: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
11895: push(@contexts,'statustocreate');
11896: foreach my $type (@types) {
1.160.6.34 raeburn 11897: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
11898: foreach my $field (@fields) {
11899: if (grep(/^\Q$field\E$/,@modifiable)) {
11900: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
11901: } else {
11902: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
11903: }
11904: }
11905: }
11906: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 11907: foreach my $type (@types) {
1.160.6.34 raeburn 11908: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
11909: foreach my $field (@fields) {
11910: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
11911: $curr_usermodify{'selfcreate'}{$type}{$field}) {
11912: push(@{$changes{'selfcreate'}},$type);
11913: last;
11914: }
11915: }
11916: }
11917: }
11918: } else {
1.160.6.93 raeburn 11919: foreach my $type (@types) {
1.160.6.34 raeburn 11920: push(@{$changes{'selfcreate'}},$type);
11921: }
11922: }
11923: }
1.160.6.44 raeburn 11924: foreach my $field (@shibfields) {
11925: if ($env{'form.shibenv_'.$field} ne '') {
11926: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
11927: }
11928: }
11929: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11930: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
11931: foreach my $field (@shibfields) {
11932: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
11933: push(@{$changes{'cancreate'}},'shibenv');
11934: }
11935: }
11936: } else {
11937: foreach my $field (@shibfields) {
11938: if ($env{'form.shibenv_'.$field}) {
11939: push(@{$changes{'cancreate'}},'shibenv');
11940: last;
11941: }
11942: }
11943: }
11944: }
1.160.6.34 raeburn 11945: }
11946: foreach my $item (@contexts) {
11947: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
11948: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
11949: if (ref($cancreate{$item}) eq 'ARRAY') {
11950: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
11951: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11952: push(@{$changes{'cancreate'}},$item);
11953: }
11954: }
11955: }
11956: }
11957: if (ref($cancreate{$item}) eq 'ARRAY') {
11958: foreach my $type (@{$cancreate{$item}}) {
11959: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
11960: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11961: push(@{$changes{'cancreate'}},$item);
11962: }
11963: }
11964: }
11965: }
11966: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
11967: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 11968: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
11969: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
11970: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
11971: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 11972: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11973: push(@{$changes{'cancreate'}},$item);
11974: }
11975: }
11976: }
1.160.6.93 raeburn 11977: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
11978: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 11979: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11980: push(@{$changes{'cancreate'}},$item);
11981: }
1.160.6.34 raeburn 11982: }
11983: }
11984: }
1.160.6.93 raeburn 11985: foreach my $type (keys(%{$cancreate{$item}})) {
11986: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11987: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11988: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
11989: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 11990: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11991: push(@{$changes{'cancreate'}},$item);
11992: }
11993: }
11994: } else {
11995: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11996: push(@{$changes{'cancreate'}},$item);
11997: }
11998: }
11999: }
1.160.6.93 raeburn 12000: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
12001: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 12002: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12003: push(@{$changes{'cancreate'}},$item);
12004: }
1.160.6.34 raeburn 12005: }
12006: }
12007: }
12008: }
12009: } elsif ($curr_usercreation{'cancreate'}{$item}) {
12010: if (ref($cancreate{$item}) eq 'ARRAY') {
12011: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
12012: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12013: push(@{$changes{'cancreate'}},$item);
12014: }
12015: }
1.160.6.93 raeburn 12016: }
12017: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
12018: if (ref($cancreate{$item}) eq 'HASH') {
12019: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12020: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 12021: }
12022: }
12023: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 12024: if (ref($cancreate{$item}) eq 'HASH') {
12025: foreach my $type (keys(%{$cancreate{$item}})) {
12026: if (ref($cancreate{$item}{$type}) eq 'HASH') {
12027: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
12028: if ($cancreate{$item}{$type}{$field}) {
12029: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12030: push(@{$changes{'cancreate'}},$item);
12031: }
12032: last;
12033: }
12034: }
12035: }
12036: }
1.160.6.34 raeburn 12037: }
12038: }
12039: }
12040: #
12041: # Populate %save_usercreate hash with updates to self-creation configuration.
12042: #
12043: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
12044: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 12045: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 12046: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
12047: if (ref($cancreate{'notify'}) eq 'HASH') {
12048: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
12049: }
1.160.6.40 raeburn 12050: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
12051: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
12052: }
1.160.6.93 raeburn 12053: if (ref($cancreate{'emailverified'}) eq 'HASH') {
12054: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
12055: }
12056: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
12057: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
12058: }
12059: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
12060: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
12061: }
1.160.6.34 raeburn 12062: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
12063: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
12064: }
1.160.6.44 raeburn 12065: if (ref($cancreate{'shibenv'}) eq 'HASH') {
12066: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
12067: }
1.160.6.34 raeburn 12068: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 12069: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 12070:
12071: my %userconfig_hash = (
12072: usercreation => \%save_usercreate,
12073: usermodification => \%save_usermodify,
1.160.6.93 raeburn 12074: inststatus => \%save_inststatus,
1.160.6.34 raeburn 12075: );
1.160.6.93 raeburn 12076:
1.160.6.34 raeburn 12077: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
12078: $dom);
12079: #
1.160.6.93 raeburn 12080: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 12081: #
1.27 raeburn 12082: if ($putresult eq 'ok') {
12083: if (keys(%changes) > 0) {
12084: $resulttext = &mt('Changes made:').'<ul>';
12085: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 12086: my %lt = &selfcreation_types();
1.34 raeburn 12087: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 12088: my $chgtext = '';
1.45 raeburn 12089: if ($type eq 'selfcreate') {
1.50 raeburn 12090: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 12091: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 12092: } else {
1.160.6.34 raeburn 12093: $chgtext .= &mt('Self-creation of a new account is permitted for:').
12094: '<ul>';
1.50 raeburn 12095: foreach my $case (@{$cancreate{$type}}) {
12096: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
12097: }
12098: $chgtext .= '</ul>';
1.100 raeburn 12099: if (ref($cancreate{$type}) eq 'ARRAY') {
12100: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
12101: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
12102: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 12103: $chgtext .= '<span class="LC_warning">'.
12104: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
12105: '</span><br />';
1.100 raeburn 12106: }
12107: }
12108: }
1.160.6.93 raeburn 12109: if (grep(/^email$/,@{$cancreate{$type}})) {
12110: if (!@statuses) {
12111: $chgtext .= '<span class="LC_warning">'.
12112: &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.").
12113: '</span><br />';
12114:
12115: }
12116: }
1.100 raeburn 12117: }
1.43 raeburn 12118: }
1.160.6.44 raeburn 12119: } elsif ($type eq 'shibenv') {
12120: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 12121: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 12122: } else {
12123: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
12124: '<ul>';
12125: foreach my $field (@shibfields) {
12126: next if ($cancreate{$type}{$field} eq '');
12127: if ($field eq 'inststatus') {
12128: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
12129: } else {
12130: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
12131: }
12132: }
12133: $chgtext .= '</ul>';
1.160.6.93 raeburn 12134: }
1.93 raeburn 12135: } elsif ($type eq 'statustocreate') {
1.96 raeburn 12136: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
12137: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
12138: if (@{$cancreate{'selfcreate'}} > 0) {
12139: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 12140: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 12141: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 12142: $chgtext .= '<br />'.
12143: '<span class="LC_warning">'.
12144: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
12145: '</span>';
12146: }
1.160.6.93 raeburn 12147: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 12148: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 12149: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
12150: } else {
12151: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
12152: }
12153: $chgtext .= '<ul>';
12154: foreach my $case (@{$cancreate{$type}}) {
12155: if ($case eq 'default') {
12156: $chgtext .= '<li>'.$othertitle.'</li>';
12157: } else {
1.160.6.93 raeburn 12158: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 12159: }
12160: }
1.100 raeburn 12161: $chgtext .= '</ul>';
12162: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 12163: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 12164: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
12165: '</span>';
1.100 raeburn 12166: }
12167: }
12168: } else {
12169: if (@{$cancreate{$type}} == 0) {
12170: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
12171: } else {
12172: $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 12173: }
12174: }
1.160.6.93 raeburn 12175: $chgtext .= '<br />';
1.93 raeburn 12176: }
1.160.6.40 raeburn 12177: } elsif ($type eq 'selfcreateprocessing') {
12178: my %choices = &Apache::lonlocal::texthash (
12179: automatic => 'Automatic approval',
12180: approval => 'Queued for approval',
12181: );
1.160.6.93 raeburn 12182: if (@types) {
12183: if (@statuses) {
12184: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
12185: '<ul>';
12186: foreach my $status (@statuses) {
12187: if ($status eq 'default') {
12188: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
12189: } else {
12190: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
12191: }
12192: }
12193: $chgtext .= '</ul>';
12194: }
12195: } else {
12196: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
12197: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
12198: }
12199: } elsif ($type eq 'emailverified') {
12200: my %options = &Apache::lonlocal::texthash (
12201: all => 'Same as e-mail',
12202: first => 'Omit @domain',
12203: free => 'Free to choose',
12204: );
12205: if (@types) {
12206: if (@statuses) {
12207: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
12208: '<ul>';
12209: foreach my $status (@statuses) {
12210: if ($status eq 'default') {
12211: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
12212: } else {
12213: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
12214: }
12215: }
12216: $chgtext .= '</ul>';
12217: }
1.160.6.40 raeburn 12218: } else {
1.160.6.93 raeburn 12219: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
12220: $options{$cancreate{'emailverified'}{'default'}});
12221: }
12222: } elsif ($type eq 'emailoptions') {
12223: my %options = &Apache::lonlocal::texthash (
12224: any => 'Any e-mail',
12225: inst => 'Institutional only',
12226: noninst => 'Non-institutional only',
12227: custom => 'Custom restrictions',
12228: );
12229: if (@types) {
12230: if (@statuses) {
12231: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
12232: '<ul>';
12233: foreach my $status (@statuses) {
12234: if ($type eq 'default') {
12235: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
12236: } else {
12237: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
12238: }
12239: }
12240: $chgtext .= '</ul>';
12241: }
12242: } else {
12243: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
12244: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
12245: } else {
12246: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
12247: $options{$cancreate{'emailoptions'}{'default'}});
12248: }
12249: }
12250: } elsif ($type eq 'emaildomain') {
12251: my $output;
12252: if (@statuses) {
12253: foreach my $type (@statuses) {
12254: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
12255: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
12256: if ($type eq 'default') {
12257: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12258: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
12259: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
12260: } else {
12261: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
12262: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
12263: }
12264: } else {
12265: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12266: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
12267: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
12268: } else {
12269: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
12270: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
12271: }
12272: }
12273: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
12274: if ($type eq 'default') {
12275: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12276: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
12277: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
12278: } else {
12279: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
12280: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
12281: }
12282: } else {
12283: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12284: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
12285: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
12286: } else {
12287: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
12288: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
12289: }
12290: }
12291: }
12292: }
12293: }
12294: }
12295: if ($output ne '') {
12296: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
12297: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 12298: }
1.160.6.5 raeburn 12299: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 12300: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 12301: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
12302: } else {
12303: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 12304: if ($captchas{$savecaptcha{$type}}) {
12305: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 12306: } else {
12307: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
12308: }
12309: }
12310: } elsif ($type eq 'recaptchakeys') {
12311: my ($privkey,$pubkey);
1.160.6.34 raeburn 12312: if (ref($savecaptcha{$type}) eq 'HASH') {
12313: $pubkey = $savecaptcha{$type}{'public'};
12314: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 12315: }
12316: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
12317: if (!$pubkey) {
12318: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
12319: } else {
12320: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12321: }
12322: if (!$privkey) {
12323: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
12324: } else {
12325: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
12326: }
12327: $chgtext .= '</ul>';
1.160.6.69 raeburn 12328: } elsif ($type eq 'recaptchaversion') {
12329: if ($savecaptcha{'captcha'} eq 'recaptcha') {
12330: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
12331: }
1.160.6.34 raeburn 12332: } elsif ($type eq 'emailusername') {
12333: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 12334: if (@statuses) {
12335: foreach my $type (@statuses) {
1.160.6.35 raeburn 12336: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
12337: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 12338: $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 12339: '<ul>';
12340: foreach my $field (@{$infofields}) {
12341: if ($cancreate{'emailusername'}{$type}{$field}) {
12342: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
12343: }
12344: }
1.160.6.50 raeburn 12345: $chgtext .= '</ul>';
12346: } else {
1.160.6.93 raeburn 12347: $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 12348: }
12349: } else {
1.160.6.93 raeburn 12350: $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 12351: }
12352: }
12353: }
12354: }
12355: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 12356: my $numapprove = 0;
1.160.6.34 raeburn 12357: if (ref($changes{'cancreate'}) eq 'ARRAY') {
12358: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
12359: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 12360: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
12361: $numapprove ++;
1.160.6.34 raeburn 12362: }
12363: }
1.43 raeburn 12364: }
1.160.6.93 raeburn 12365: unless ($numapprove) {
12366: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
12367: }
1.34 raeburn 12368: }
1.160.6.34 raeburn 12369: if ($chgtext) {
12370: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 12371: }
12372: }
12373: }
1.160.6.93 raeburn 12374: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 12375: my ($emailrules,$emailruleorder) =
12376: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 12377: foreach my $type (@{$changes{'email_rule'}}) {
12378: if (ref($email_rule{$type}) eq 'ARRAY') {
12379: my $chgtext = '<ul>';
12380: foreach my $rule (@{$email_rule{$type}}) {
12381: if (ref($emailrules->{$rule}) eq 'HASH') {
12382: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
12383: }
12384: }
12385: $chgtext .= '</ul>';
12386: my $typename;
12387: if (@types) {
12388: if ($type eq 'default') {
12389: $typename = $othertitle;
12390: } else {
12391: $typename = $usertypes{$type};
12392: }
12393: $chgtext .= &mt('(Affiliation: [_1])',$typename);
12394: }
12395: if (@{$email_rule{$type}} > 0) {
12396: $resulttext .= '<li>'.
12397: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
12398: $usertypes{$type}).
12399: $chgtext.
12400: '</li>';
12401: } else {
12402: $resulttext .= '<li>'.
12403: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
12404: '</li>'.
12405: &mt('(Affiliation: [_1])',$typename);
12406: }
1.43 raeburn 12407: }
12408: }
1.160.6.93 raeburn 12409: }
12410: if (ref($changes{'inststatus'}) eq 'ARRAY') {
12411: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
12412: if (@{$save_inststatus{'inststatusguest'}} > 0) {
12413: my $chgtext = '<ul>';
12414: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
12415: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
12416: }
12417: $chgtext .= '</ul>';
12418: $resulttext .= '<li>'.
12419: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
12420: $chgtext.
12421: '</li>';
12422: } else {
12423: $resulttext .= '<li>'.
12424: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
12425: '</li>';
12426: }
1.43 raeburn 12427: }
12428: }
1.160.6.34 raeburn 12429: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
12430: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
12431: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12432: foreach my $type (@{$changes{'selfcreate'}}) {
12433: my $typename = $type;
1.160.6.93 raeburn 12434: if (keys(%usertypes) > 0) {
12435: if ($usertypes{$type} ne '') {
12436: $typename = $usertypes{$type};
1.28 raeburn 12437: }
12438: }
1.160.6.34 raeburn 12439: my @modifiable;
12440: $resulttext .= '<li>'.
12441: &mt('Self-creation of account by users with status: [_1]',
12442: '<span class="LC_cusr_emph">'.$typename.'</span>').
12443: ' - '.&mt('modifiable fields (if institutional data blank): ');
12444: foreach my $field (@fields) {
12445: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
12446: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
12447: }
12448: }
12449: if (@modifiable > 0) {
12450: $resulttext .= join(', ',@modifiable);
1.43 raeburn 12451: } else {
1.160.6.34 raeburn 12452: $resulttext .= &mt('none');
1.43 raeburn 12453: }
1.160.6.34 raeburn 12454: $resulttext .= '</li>';
1.28 raeburn 12455: }
1.160.6.34 raeburn 12456: $resulttext .= '</ul></li>';
1.28 raeburn 12457: }
1.27 raeburn 12458: $resulttext .= '</ul>';
1.160.6.93 raeburn 12459: my $cachetime = 24*60*60;
12460: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
12461: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12462: if (ref($lastactref) eq 'HASH') {
12463: $lastactref->{'domdefaults'} = 1;
12464: }
1.27 raeburn 12465: } else {
1.160.6.34 raeburn 12466: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 12467: }
12468: } else {
12469: $resulttext = '<span class="LC_error">'.
1.23 raeburn 12470: &mt('An error occurred: [_1]',$putresult).'</span>';
12471: }
1.43 raeburn 12472: if ($warningmsg ne '') {
12473: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
12474: }
1.23 raeburn 12475: return $resulttext;
12476: }
12477:
1.160.6.5 raeburn 12478: sub process_captcha {
12479: my ($container,$changes,$newsettings,$current) = @_;
12480: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
12481: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
12482: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
12483: $newsettings->{'captcha'} = 'original';
12484: }
12485: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
12486: if ($container eq 'cancreate') {
12487: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12488: push(@{$changes->{'cancreate'}},'captcha');
12489: } elsif (!defined($changes->{'cancreate'})) {
12490: $changes->{'cancreate'} = ['captcha'];
12491: }
12492: } else {
12493: $changes->{'captcha'} = 1;
12494: }
12495: }
1.160.6.69 raeburn 12496: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 12497: if ($newsettings->{'captcha'} eq 'recaptcha') {
12498: $newpub = $env{'form.'.$container.'_recaptchapub'};
12499: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 12500: $newpub =~ s/[^\w\-]//g;
12501: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 12502: $newsettings->{'recaptchakeys'} = {
12503: public => $newpub,
12504: private => $newpriv,
12505: };
1.160.6.69 raeburn 12506: $newversion = $env{'form.'.$container.'_recaptchaversion'};
12507: $newversion =~ s/\D//g;
12508: if ($newversion ne '2') {
12509: $newversion = 1;
12510: }
12511: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 12512: }
12513: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
12514: $currpub = $current->{'recaptchakeys'}{'public'};
12515: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 12516: unless ($newsettings->{'captcha'} eq 'recaptcha') {
12517: $newsettings->{'recaptchakeys'} = {
12518: public => '',
12519: private => '',
12520: }
12521: }
1.160.6.5 raeburn 12522: }
1.160.6.69 raeburn 12523: if ($current->{'captcha'} eq 'recaptcha') {
12524: $currversion = $current->{'recaptchaversion'};
12525: if ($currversion ne '2') {
12526: $currversion = 1;
12527: }
12528: }
12529: if ($currversion ne $newversion) {
12530: if ($container eq 'cancreate') {
12531: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12532: push(@{$changes->{'cancreate'}},'recaptchaversion');
12533: } elsif (!defined($changes->{'cancreate'})) {
12534: $changes->{'cancreate'} = ['recaptchaversion'];
12535: }
12536: } else {
12537: $changes->{'recaptchaversion'} = 1;
12538: }
12539: }
1.160.6.5 raeburn 12540: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
12541: if ($container eq 'cancreate') {
12542: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12543: push(@{$changes->{'cancreate'}},'recaptchakeys');
12544: } elsif (!defined($changes->{'cancreate'})) {
12545: $changes->{'cancreate'} = ['recaptchakeys'];
12546: }
12547: } else {
12548: $changes->{'recaptchakeys'} = 1;
12549: }
12550: }
12551: return;
12552: }
12553:
1.33 raeburn 12554: sub modify_usermodification {
12555: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 12556: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 12557: if (ref($domconfig{'usermodification'}) eq 'HASH') {
12558: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 12559: if ($key eq 'selfcreate') {
12560: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
12561: } else {
12562: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
12563: }
1.33 raeburn 12564: }
12565: }
1.160.6.34 raeburn 12566: my @contexts = ('author','course');
1.33 raeburn 12567: my %context_title = (
12568: author => 'In author context',
12569: course => 'In course context',
12570: );
12571: my @fields = ('lastname','firstname','middlename','generation',
12572: 'permanentemail','id');
12573: my %roles = (
12574: author => ['ca','aa'],
12575: course => ['st','ep','ta','in','cr'],
12576: );
12577: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12578: foreach my $context (@contexts) {
12579: foreach my $role (@{$roles{$context}}) {
12580: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
12581: foreach my $item (@fields) {
12582: if (grep(/^\Q$item\E$/,@modifiable)) {
12583: $modifyhash{$context}{$role}{$item} = 1;
12584: } else {
12585: $modifyhash{$context}{$role}{$item} = 0;
12586: }
12587: }
12588: }
12589: if (ref($curr_usermodification{$context}) eq 'HASH') {
12590: foreach my $role (@{$roles{$context}}) {
12591: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
12592: foreach my $field (@fields) {
12593: if ($modifyhash{$context}{$role}{$field} ne
12594: $curr_usermodification{$context}{$role}{$field}) {
12595: push(@{$changes{$context}},$role);
12596: last;
12597: }
12598: }
12599: }
12600: }
12601: } else {
12602: foreach my $context (@contexts) {
12603: foreach my $role (@{$roles{$context}}) {
12604: push(@{$changes{$context}},$role);
12605: }
12606: }
12607: }
12608: }
12609: my %usermodification_hash = (
12610: usermodification => \%modifyhash,
12611: );
12612: my $putresult = &Apache::lonnet::put_dom('configuration',
12613: \%usermodification_hash,$dom);
12614: if ($putresult eq 'ok') {
12615: if (keys(%changes) > 0) {
12616: $resulttext = &mt('Changes made: ').'<ul>';
12617: foreach my $context (@contexts) {
12618: if (ref($changes{$context}) eq 'ARRAY') {
12619: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
12620: if (ref($changes{$context}) eq 'ARRAY') {
12621: foreach my $role (@{$changes{$context}}) {
12622: my $rolename;
1.160.6.34 raeburn 12623: if ($role eq 'cr') {
12624: $rolename = &mt('Custom');
1.33 raeburn 12625: } else {
1.160.6.34 raeburn 12626: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 12627: }
12628: my @modifiable;
1.160.6.34 raeburn 12629: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 12630: foreach my $field (@fields) {
12631: if ($modifyhash{$context}{$role}{$field}) {
12632: push(@modifiable,$fieldtitles{$field});
12633: }
12634: }
12635: if (@modifiable > 0) {
12636: $resulttext .= join(', ',@modifiable);
12637: } else {
12638: $resulttext .= &mt('none');
12639: }
12640: $resulttext .= '</li>';
12641: }
12642: $resulttext .= '</ul></li>';
12643: }
12644: }
12645: }
12646: $resulttext .= '</ul>';
12647: } else {
12648: $resulttext = &mt('No changes made to user modification settings');
12649: }
12650: } else {
12651: $resulttext = '<span class="LC_error">'.
12652: &mt('An error occurred: [_1]',$putresult).'</span>';
12653: }
12654: return $resulttext;
12655: }
12656:
1.43 raeburn 12657: sub modify_defaults {
1.160.6.27 raeburn 12658: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 12659: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 12660: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 12661: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98 raeburn 12662: 'portal_def');
1.43 raeburn 12663: my @authtypes = ('internal','krb4','krb5','localauth');
12664: foreach my $item (@items) {
12665: $newvalues{$item} = $env{'form.'.$item};
12666: if ($item eq 'auth_def') {
12667: if ($newvalues{$item} ne '') {
12668: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
12669: push(@errors,$item);
12670: }
12671: }
12672: } elsif ($item eq 'lang_def') {
12673: if ($newvalues{$item} ne '') {
12674: if ($newvalues{$item} =~ /^(\w+)/) {
12675: my $langcode = $1;
1.103 raeburn 12676: if ($langcode ne 'x_chef') {
12677: if (code2language($langcode) eq '') {
12678: push(@errors,$item);
12679: }
1.43 raeburn 12680: }
12681: } else {
12682: push(@errors,$item);
12683: }
12684: }
1.54 raeburn 12685: } elsif ($item eq 'timezone_def') {
12686: if ($newvalues{$item} ne '') {
1.62 raeburn 12687: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 12688: push(@errors,$item);
12689: }
12690: }
1.68 raeburn 12691: } elsif ($item eq 'datelocale_def') {
12692: if ($newvalues{$item} ne '') {
12693: my @datelocale_ids = DateTime::Locale->ids();
12694: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
12695: push(@errors,$item);
12696: }
12697: }
1.141 raeburn 12698: } elsif ($item eq 'portal_def') {
12699: if ($newvalues{$item} ne '') {
12700: 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])\/?$/) {
12701: push(@errors,$item);
12702: }
12703: }
1.43 raeburn 12704: }
12705: if (grep(/^\Q$item\E$/,@errors)) {
12706: $newvalues{$item} = $domdefaults{$item};
12707: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
12708: $changes{$item} = 1;
12709: }
1.72 raeburn 12710: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 12711: }
1.160.6.98 raeburn 12712: my %staticdefaults = (
12713: 'intauth_cost' => 10,
12714: 'intauth_check' => 0,
12715: 'intauth_switch' => 0,
12716: );
12717: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
12718: if (exists($domdefaults{$item})) {
12719: $newvalues{$item} = $domdefaults{$item};
12720: } else {
12721: $newvalues{$item} = $staticdefaults{$item};
12722: }
12723: }
1.43 raeburn 12724: my %defaults_hash = (
1.72 raeburn 12725: defaults => \%newvalues,
12726: );
1.43 raeburn 12727: my $title = &defaults_titles();
1.160.6.40 raeburn 12728:
12729: my $currinststatus;
12730: if (ref($domconfig{'inststatus'}) eq 'HASH') {
12731: $currinststatus = $domconfig{'inststatus'};
12732: } else {
12733: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12734: $currinststatus = {
12735: inststatustypes => $usertypes,
12736: inststatusorder => $types,
12737: inststatusguest => [],
12738: };
12739: }
12740: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
12741: my @allpos;
12742: my %alltypes;
1.160.6.93 raeburn 12743: my @inststatusguest;
12744: if (ref($currinststatus) eq 'HASH') {
12745: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
12746: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
12747: unless (grep(/^\Q$type\E$/,@todelete)) {
12748: push(@inststatusguest,$type);
12749: }
12750: }
12751: }
12752: }
12753: my ($currtitles,$currorder);
1.160.6.40 raeburn 12754: if (ref($currinststatus) eq 'HASH') {
12755: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
12756: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
12757: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
12758: if ($currinststatus->{inststatustypes}->{$type} ne '') {
12759: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
12760: }
12761: }
12762: unless (grep(/^\Q$type\E$/,@todelete)) {
12763: my $position = $env{'form.inststatus_pos_'.$type};
12764: $position =~ s/\D+//g;
12765: $allpos[$position] = $type;
12766: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
12767: $alltypes{$type} =~ s/`//g;
12768: }
12769: }
12770: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
12771: $currtitles =~ s/,$//;
12772: }
12773: }
12774: if ($env{'form.addinststatus'}) {
12775: my $newtype = $env{'form.addinststatus'};
12776: $newtype =~ s/\W//g;
12777: unless (exists($alltypes{$newtype})) {
12778: $alltypes{$newtype} = $env{'form.addinststatus_title'};
12779: $alltypes{$newtype} =~ s/`//g;
12780: my $position = $env{'form.addinststatus_pos'};
12781: $position =~ s/\D+//g;
12782: if ($position ne '') {
12783: $allpos[$position] = $newtype;
12784: }
12785: }
12786: }
1.160.6.93 raeburn 12787: my @orderedstatus;
1.160.6.40 raeburn 12788: foreach my $type (@allpos) {
12789: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
12790: push(@orderedstatus,$type);
12791: }
12792: }
12793: foreach my $type (keys(%alltypes)) {
12794: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
12795: delete($alltypes{$type});
12796: }
12797: }
12798: $defaults_hash{'inststatus'} = {
12799: inststatustypes => \%alltypes,
12800: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 12801: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 12802: };
12803: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
12804: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
12805: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
12806: }
12807: }
12808: if ($currorder ne join(',',@orderedstatus)) {
12809: $changes{'inststatus'}{'inststatusorder'} = 1;
12810: }
12811: my $newtitles;
12812: foreach my $item (@orderedstatus) {
12813: $newtitles .= $alltypes{$item}.',';
12814: }
12815: $newtitles =~ s/,$//;
12816: if ($currtitles ne $newtitles) {
12817: $changes{'inststatus'}{'inststatustypes'} = 1;
12818: }
1.43 raeburn 12819: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
12820: $dom);
12821: if ($putresult eq 'ok') {
12822: if (keys(%changes) > 0) {
12823: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 12824: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 12825: 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";
12826: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 12827: if ($item eq 'inststatus') {
12828: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 12829: if (@orderedstatus) {
1.160.6.40 raeburn 12830: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
12831: foreach my $type (@orderedstatus) {
12832: $resulttext .= $alltypes{$type}.', ';
12833: }
12834: $resulttext =~ s/, $//;
12835: $resulttext .= '</li>';
1.160.6.93 raeburn 12836: } else {
12837: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 12838: }
12839: }
12840: } else {
12841: my $value = $env{'form.'.$item};
12842: if ($value eq '') {
12843: $value = &mt('none');
12844: } elsif ($item eq 'auth_def') {
12845: my %authnames = &authtype_names();
12846: my %shortauth = (
12847: internal => 'int',
12848: krb4 => 'krb4',
12849: krb5 => 'krb5',
12850: localauth => 'loc',
12851: );
12852: $value = $authnames{$shortauth{$value}};
12853: }
12854: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
12855: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 12856: }
12857: }
12858: $resulttext .= '</ul>';
12859: $mailmsgtext .= "\n";
12860: my $cachetime = 24*60*60;
1.72 raeburn 12861: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 12862: if (ref($lastactref) eq 'HASH') {
12863: $lastactref->{'domdefaults'} = 1;
12864: }
1.68 raeburn 12865: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 12866: my $notify = 1;
12867: if (ref($domconfig{'contacts'}) eq 'HASH') {
12868: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
12869: $notify = 0;
12870: }
12871: }
12872: if ($notify) {
12873: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
12874: "LON-CAPA Domain Settings Change - $dom",
12875: $mailmsgtext);
12876: }
1.54 raeburn 12877: }
1.43 raeburn 12878: } else {
1.54 raeburn 12879: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 12880: }
12881: } else {
12882: $resulttext = '<span class="LC_error">'.
12883: &mt('An error occurred: [_1]',$putresult).'</span>';
12884: }
12885: if (@errors > 0) {
12886: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
12887: foreach my $item (@errors) {
12888: $resulttext .= ' "'.$title->{$item}.'",';
12889: }
12890: $resulttext =~ s/,$//;
12891: }
12892: return $resulttext;
12893: }
12894:
1.46 raeburn 12895: sub modify_scantron {
1.160.6.24 raeburn 12896: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 12897: my ($resulttext,%confhash,%changes,$errors);
12898: my $custom = 'custom.tab';
12899: my $default = 'default.tab';
12900: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 12901: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 12902: &config_check($dom,$confname,$servadm);
12903: if ($env{'form.scantronformat.filename'} ne '') {
12904: my $error;
12905: if ($configuserok eq 'ok') {
12906: if ($switchserver) {
1.130 raeburn 12907: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 12908: } else {
12909: if ($author_ok eq 'ok') {
12910: my ($result,$scantronurl) =
12911: &publishlogo($r,'upload','scantronformat',$dom,
12912: $confname,'scantron','','',$custom);
12913: if ($result eq 'ok') {
12914: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 12915: $changes{'scantronformat'} = 1;
1.46 raeburn 12916: } else {
12917: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
12918: }
12919: } else {
12920: $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);
12921: }
12922: }
12923: } else {
12924: $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);
12925: }
12926: if ($error) {
12927: &Apache::lonnet::logthis($error);
12928: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12929: }
12930: }
1.48 raeburn 12931: if (ref($domconfig{'scantron'}) eq 'HASH') {
12932: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
12933: if ($env{'form.scantronformat_del'}) {
12934: $confhash{'scantron'}{'scantronformat'} = '';
12935: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 12936: } else {
12937: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
12938: }
12939: }
12940: }
12941: my @options = ('hdr','pad','rem');
12942: my @fields = &scantroncsv_fields();
12943: my %titles = &scantronconfig_titles();
12944: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
12945: my ($newdat,$currdat,%newcol,%currcol);
12946: if (grep(/^dat$/,@formats)) {
12947: $confhash{'scantron'}{config}{dat} = 1;
12948: $newdat = 1;
12949: } else {
12950: $newdat = 0;
12951: }
12952: if (grep(/^csv$/,@formats)) {
12953: my %bynum;
12954: foreach my $field (@fields) {
12955: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
12956: my $posscol = $1;
12957: if (($posscol < 20) && (!$bynum{$posscol})) {
12958: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
12959: $bynum{$posscol} = $field;
12960: $newcol{$field} = $posscol;
12961: }
12962: }
12963: }
12964: if (keys(%newcol)) {
12965: foreach my $option (@options) {
12966: if ($env{'form.scantroncsv_'.$option}) {
12967: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
12968: }
12969: }
12970: }
12971: }
12972: $currdat = 1;
12973: if (ref($domconfig{'scantron'}) eq 'HASH') {
12974: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
12975: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
12976: $currdat = 0;
12977: }
12978: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
12979: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
12980: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
12981: }
12982: }
12983: }
12984: }
12985: if ($currdat != $newdat) {
12986: $changes{'config'} = 1;
12987: } else {
12988: foreach my $field (@fields) {
12989: if ($currcol{$field} ne '') {
12990: if ($currcol{$field} ne $newcol{$field}) {
12991: $changes{'config'} = 1;
12992: last;
12993: }
12994: } elsif ($newcol{$field} ne '') {
12995: $changes{'config'} = 1;
12996: last;
1.46 raeburn 12997: }
12998: }
12999: }
13000: if (keys(%confhash) > 0) {
13001: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
13002: $dom);
13003: if ($putresult eq 'ok') {
13004: if (keys(%changes) > 0) {
1.48 raeburn 13005: if (ref($confhash{'scantron'}) eq 'HASH') {
13006: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 13007: if ($changes{'scantronformat'}) {
13008: if ($confhash{'scantron'}{'scantronformat'} eq '') {
13009: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
13010: } else {
13011: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
13012: }
13013: }
13014: if ($changes{'config'}) {
13015: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
13016: if ($confhash{'scantron'}{'config'}{'dat'}) {
13017: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
13018: }
13019: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
13020: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
13021: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
13022: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
13023: foreach my $field (@fields) {
13024: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
13025: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
13026: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
13027: }
13028: }
13029: $resulttext .= '</ul></li>';
13030: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
13031: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
13032: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
13033: foreach my $option (@options) {
13034: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
13035: $resulttext .= '<li>'.$titles{$option}.'</li>';
13036: }
13037: }
13038: $resulttext .= '</ul></li>';
13039: }
13040: }
13041: }
13042: }
13043: }
13044: } else {
13045: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
13046: }
1.46 raeburn 13047: }
1.48 raeburn 13048: $resulttext .= '</ul>';
13049: } else {
1.130 raeburn 13050: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 13051: }
13052: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 13053: if (ref($lastactref) eq 'HASH') {
13054: $lastactref->{'domainconfig'} = 1;
13055: }
1.46 raeburn 13056: } else {
1.160.6.97 raeburn 13057: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 13058: }
13059: } else {
13060: $resulttext = '<span class="LC_error">'.
13061: &mt('An error occurred: [_1]',$putresult).'</span>';
13062: }
13063: } else {
1.160.6.97 raeburn 13064: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 13065: }
13066: if ($errors) {
13067: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13068: $errors.'</ul>';
13069: }
13070: return $resulttext;
13071: }
13072:
1.48 raeburn 13073: sub modify_coursecategories {
1.160.6.43 raeburn 13074: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 13075: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
13076: $cathash);
1.48 raeburn 13077: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 13078: my @catitems = ('unauth','auth');
13079: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 13080: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 13081: $cathash = $domconfig{'coursecategories'}{'cats'};
13082: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
13083: $changes{'togglecats'} = 1;
13084: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
13085: }
13086: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
13087: $changes{'categorize'} = 1;
13088: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
13089: }
1.120 raeburn 13090: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
13091: $changes{'togglecatscomm'} = 1;
13092: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
13093: }
13094: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
13095: $changes{'categorizecomm'} = 1;
13096: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
13097: }
1.160.6.42 raeburn 13098: foreach my $item (@catitems) {
13099: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
13100: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
13101: $changes{$item} = 1;
13102: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
13103: }
13104: }
13105: }
1.57 raeburn 13106: } else {
13107: $changes{'togglecats'} = 1;
13108: $changes{'categorize'} = 1;
1.124 raeburn 13109: $changes{'togglecatscomm'} = 1;
13110: $changes{'categorizecomm'} = 1;
1.87 raeburn 13111: $domconfig{'coursecategories'} = {
13112: togglecats => $env{'form.togglecats'},
13113: categorize => $env{'form.categorize'},
1.124 raeburn 13114: togglecatscomm => $env{'form.togglecatscomm'},
13115: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 13116: };
1.160.6.42 raeburn 13117: foreach my $item (@catitems) {
13118: if ($env{'form.coursecat_'.$item} ne 'std') {
13119: $changes{$item} = 1;
13120: }
13121: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
13122: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
13123: }
13124: }
1.57 raeburn 13125: }
13126: if (ref($cathash) eq 'HASH') {
13127: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 13128: push (@deletecategory,'instcode::0');
13129: }
1.120 raeburn 13130: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
13131: push(@deletecategory,'communities::0');
13132: }
1.48 raeburn 13133: }
1.57 raeburn 13134: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
13135: if (ref($cathash) eq 'HASH') {
1.48 raeburn 13136: if (@deletecategory > 0) {
13137: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 13138: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 13139: foreach my $item (@deletecategory) {
1.57 raeburn 13140: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
13141: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 13142: $deletions{$item} = 1;
1.57 raeburn 13143: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 13144: }
13145: }
13146: }
1.57 raeburn 13147: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 13148: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 13149: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 13150: $reorderings{$item} = 1;
1.57 raeburn 13151: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 13152: }
13153: if ($env{'form.addcategory_name_'.$item} ne '') {
13154: my $newcat = $env{'form.addcategory_name_'.$item};
13155: my $newdepth = $depth+1;
13156: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 13157: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 13158: $adds{$newitem} = 1;
13159: }
13160: if ($env{'form.subcat_'.$item} ne '') {
13161: my $newcat = $env{'form.subcat_'.$item};
13162: my $newdepth = $depth+1;
13163: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 13164: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 13165: $adds{$newitem} = 1;
13166: }
13167: }
13168: }
13169: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 13170: if (ref($cathash) eq 'HASH') {
1.48 raeburn 13171: my $newitem = 'instcode::0';
1.57 raeburn 13172: if ($cathash->{$newitem} eq '') {
13173: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 13174: $adds{$newitem} = 1;
13175: }
13176: } else {
13177: my $newitem = 'instcode::0';
1.57 raeburn 13178: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 13179: $adds{$newitem} = 1;
13180: }
13181: }
1.120 raeburn 13182: if ($env{'form.communities'} eq '1') {
13183: if (ref($cathash) eq 'HASH') {
13184: my $newitem = 'communities::0';
13185: if ($cathash->{$newitem} eq '') {
13186: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
13187: $adds{$newitem} = 1;
13188: }
13189: } else {
13190: my $newitem = 'communities::0';
13191: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
13192: $adds{$newitem} = 1;
13193: }
13194: }
1.48 raeburn 13195: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 13196: if (($env{'form.addcategory_name'} ne 'instcode') &&
13197: ($env{'form.addcategory_name'} ne 'communities')) {
13198: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
13199: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
13200: $adds{$newitem} = 1;
13201: }
1.48 raeburn 13202: }
1.57 raeburn 13203: my $putresult;
1.48 raeburn 13204: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
13205: if (keys(%deletions) > 0) {
13206: foreach my $key (keys(%deletions)) {
13207: if ($predelallitems{$key} ne '') {
13208: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
13209: }
13210: }
13211: }
13212: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 13213: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 13214: if (ref($chkcats[0]) eq 'ARRAY') {
13215: my $depth = 0;
13216: my $chg = 0;
13217: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
13218: my $name = $chkcats[0][$i];
13219: my $item;
13220: if ($name eq '') {
13221: $chg ++;
13222: } else {
13223: $item = &escape($name).'::0';
13224: if ($chg) {
1.57 raeburn 13225: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 13226: }
13227: $depth ++;
1.57 raeburn 13228: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 13229: $depth --;
13230: }
13231: }
13232: }
1.57 raeburn 13233: }
13234: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
13235: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 13236: if ($putresult eq 'ok') {
1.57 raeburn 13237: my %title = (
1.120 raeburn 13238: togglecats => 'Show/Hide a course in catalog',
13239: categorize => 'Assign a category to a course',
13240: togglecatscomm => 'Show/Hide a community in catalog',
13241: categorizecomm => 'Assign a category to a community',
1.57 raeburn 13242: );
13243: my %level = (
1.120 raeburn 13244: dom => 'set in Domain ("Modify Course/Community")',
13245: crs => 'set in Course ("Course Configuration")',
13246: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 13247: none => 'No catalog',
13248: std => 'Standard catalog',
13249: domonly => 'Domain-only catalog',
13250: codesrch => 'Code search form',
1.57 raeburn 13251: );
1.48 raeburn 13252: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 13253: if ($changes{'togglecats'}) {
13254: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
13255: }
13256: if ($changes{'categorize'}) {
13257: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 13258: }
1.120 raeburn 13259: if ($changes{'togglecatscomm'}) {
13260: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
13261: }
13262: if ($changes{'categorizecomm'}) {
13263: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
13264: }
1.160.6.42 raeburn 13265: if ($changes{'unauth'}) {
13266: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
13267: }
13268: if ($changes{'auth'}) {
13269: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
13270: }
1.57 raeburn 13271: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
13272: my $cathash;
13273: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
13274: $cathash = $domconfig{'coursecategories'}{'cats'};
13275: } else {
13276: $cathash = {};
13277: }
13278: my (@cats,@trails,%allitems);
13279: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
13280: if (keys(%deletions) > 0) {
13281: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
13282: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
13283: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
13284: }
13285: $resulttext .= '</ul></li>';
13286: }
13287: if (keys(%reorderings) > 0) {
13288: my %sort_by_trail;
13289: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
13290: foreach my $key (keys(%reorderings)) {
13291: if ($allitems{$key} ne '') {
13292: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
13293: }
1.48 raeburn 13294: }
1.57 raeburn 13295: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
13296: $resulttext .= '<li>'.$trails[$trail].'</li>';
13297: }
13298: $resulttext .= '</ul></li>';
1.48 raeburn 13299: }
1.57 raeburn 13300: if (keys(%adds) > 0) {
13301: my %sort_by_trail;
13302: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
13303: foreach my $key (keys(%adds)) {
13304: if ($allitems{$key} ne '') {
13305: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
13306: }
13307: }
13308: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
13309: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 13310: }
1.57 raeburn 13311: $resulttext .= '</ul></li>';
1.48 raeburn 13312: }
1.160.6.92 raeburn 13313: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
13314: if (ref($lastactref) eq 'HASH') {
13315: $lastactref->{'cats'} = 1;
13316: }
1.48 raeburn 13317: }
13318: $resulttext .= '</ul>';
1.160.6.43 raeburn 13319: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 13320: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
13321: if ($changes{'auth'}) {
13322: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
13323: }
13324: if ($changes{'unauth'}) {
13325: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
13326: }
13327: my $cachetime = 24*60*60;
13328: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 13329: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 13330: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 13331: }
13332: }
1.48 raeburn 13333: } else {
13334: $resulttext = '<span class="LC_error">'.
1.57 raeburn 13335: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 13336: }
13337: } else {
1.120 raeburn 13338: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 13339: }
13340: return $resulttext;
13341: }
13342:
1.69 raeburn 13343: sub modify_serverstatuses {
13344: my ($dom,%domconfig) = @_;
13345: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
13346: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
13347: %currserverstatus = %{$domconfig{'serverstatuses'}};
13348: }
13349: my @pages = &serverstatus_pages();
13350: foreach my $type (@pages) {
13351: $newserverstatus{$type}{'namedusers'} = '';
13352: $newserverstatus{$type}{'machines'} = '';
13353: if (defined($env{'form.'.$type.'_namedusers'})) {
13354: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
13355: my @okusers;
13356: foreach my $user (@users) {
13357: my ($uname,$udom) = split(/:/,$user);
13358: if (($udom =~ /^$match_domain$/) &&
13359: (&Apache::lonnet::domain($udom)) &&
13360: ($uname =~ /^$match_username$/)) {
13361: if (!grep(/^\Q$user\E/,@okusers)) {
13362: push(@okusers,$user);
13363: }
13364: }
13365: }
13366: if (@okusers > 0) {
13367: @okusers = sort(@okusers);
13368: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
13369: }
13370: }
13371: if (defined($env{'form.'.$type.'_machines'})) {
13372: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
13373: my @okmachines;
13374: foreach my $ip (@machines) {
13375: my @parts = split(/\./,$ip);
13376: next if (@parts < 4);
13377: my $badip = 0;
13378: for (my $i=0; $i<4; $i++) {
13379: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
13380: $badip = 1;
13381: last;
13382: }
13383: }
13384: if (!$badip) {
13385: push(@okmachines,$ip);
13386: }
13387: }
13388: @okmachines = sort(@okmachines);
13389: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
13390: }
13391: }
13392: my %serverstatushash = (
13393: serverstatuses => \%newserverstatus,
13394: );
13395: foreach my $type (@pages) {
1.83 raeburn 13396: foreach my $setting ('namedusers','machines') {
1.84 raeburn 13397: my (@current,@new);
1.83 raeburn 13398: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 13399: if ($currserverstatus{$type}{$setting} ne '') {
13400: @current = split(/,/,$currserverstatus{$type}{$setting});
13401: }
13402: }
13403: if ($newserverstatus{$type}{$setting} ne '') {
13404: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 13405: }
13406: if (@current > 0) {
13407: if (@new > 0) {
13408: foreach my $item (@current) {
13409: if (!grep(/^\Q$item\E$/,@new)) {
13410: $changes{$type}{$setting} = 1;
1.82 raeburn 13411: last;
13412: }
13413: }
1.84 raeburn 13414: foreach my $item (@new) {
13415: if (!grep(/^\Q$item\E$/,@current)) {
13416: $changes{$type}{$setting} = 1;
13417: last;
1.82 raeburn 13418: }
13419: }
13420: } else {
1.83 raeburn 13421: $changes{$type}{$setting} = 1;
1.69 raeburn 13422: }
1.83 raeburn 13423: } elsif (@new > 0) {
13424: $changes{$type}{$setting} = 1;
1.69 raeburn 13425: }
13426: }
13427: }
13428: if (keys(%changes) > 0) {
1.81 raeburn 13429: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 13430: my $putresult = &Apache::lonnet::put_dom('configuration',
13431: \%serverstatushash,$dom);
13432: if ($putresult eq 'ok') {
13433: $resulttext .= &mt('Changes made:').'<ul>';
13434: foreach my $type (@pages) {
1.84 raeburn 13435: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 13436: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 13437: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 13438: if ($newserverstatus{$type}{'namedusers'} eq '') {
13439: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
13440: } else {
13441: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
13442: }
1.84 raeburn 13443: }
13444: if ($changes{$type}{'machines'}) {
1.69 raeburn 13445: if ($newserverstatus{$type}{'machines'} eq '') {
13446: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
13447: } else {
13448: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
13449: }
13450:
13451: }
13452: $resulttext .= '</ul></li>';
13453: }
13454: }
13455: $resulttext .= '</ul>';
13456: } else {
13457: $resulttext = '<span class="LC_error">'.
13458: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
13459:
13460: }
13461: } else {
13462: $resulttext = &mt('No changes made to access to server status pages');
13463: }
13464: return $resulttext;
13465: }
13466:
1.118 jms 13467: sub modify_helpsettings {
1.160.6.77 raeburn 13468: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 13469: my ($resulttext,$errors,%changes,%helphash);
13470: my %defaultchecked = ('submitbugs' => 'on');
13471: my @offon = ('off','on');
1.118 jms 13472: my @toggles = ('submitbugs');
1.160.6.77 raeburn 13473: my %current = ('submitbugs' => '',
13474: 'adhoc' => {},
13475: );
1.118 jms 13476: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 13477: %current = %{$domconfig{'helpsettings'}};
13478: }
1.160.6.77 raeburn 13479: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 13480: foreach my $item (@toggles) {
13481: if ($defaultchecked{$item} eq 'on') {
13482: if ($current{$item} eq '') {
13483: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 13484: $changes{$item} = 1;
13485: }
1.160.6.73 raeburn 13486: } elsif ($current{$item} ne $env{'form.'.$item}) {
13487: $changes{$item} = 1;
13488: }
13489: } elsif ($defaultchecked{$item} eq 'off') {
13490: if ($current{$item} eq '') {
13491: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 13492: $changes{$item} = 1;
13493: }
1.160.6.73 raeburn 13494: } elsif ($current{$item} ne $env{'form.'.$item}) {
13495: $changes{$item} = 1;
13496: }
13497: }
13498: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
13499: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
13500: }
13501: }
1.160.6.77 raeburn 13502: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 13503: my $confname = $dom.'-domainconfig';
13504: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 13505: my (@allpos,%newsettings,%changedprivs,$newrole);
13506: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 13507: my @accesstypes = ('all','dh','da','none','status','inc','exc');
13508: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 13509: my %lt = &Apache::lonlocal::texthash(
13510: s => 'system',
13511: d => 'domain',
13512: order => 'Display order',
13513: access => 'Role usage',
1.160.6.79 raeburn 13514: all => 'All with domain helpdesk or helpdesk assistant role',
13515: dh => 'All with domain helpdesk role',
13516: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 13517: none => 'None',
13518: status => 'Determined based on institutional status',
13519: inc => 'Include all, but exclude specific personnel',
13520: exc => 'Exclude all, but include specific personnel',
13521: );
13522: for (my $num=0; $num<=$maxnum; $num++) {
13523: my ($prefix,$identifier,$rolename,%curr);
13524: if ($num == $maxnum) {
13525: next unless ($env{'form.newcusthelp'} == $maxnum);
13526: $identifier = 'custhelp'.$num;
13527: $prefix = 'helproles_'.$num;
13528: $rolename = $env{'form.custhelpname'.$num};
13529: $rolename=~s/[^A-Za-z0-9]//gs;
13530: next if ($rolename eq '');
13531: next if (exists($existing{'rolesdef_'.$rolename}));
13532: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
13533: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
13534: $newprivs{'c'},$confname,$dom);
13535: if ($result ne 'ok') {
13536: $errors .= '<li><span class="LC_error">'.
13537: &mt('An error occurred storing the new custom role: [_1]',
13538: $result).'</span></li>';
13539: next;
13540: } else {
13541: $changedprivs{$rolename} = \%newprivs;
13542: $newrole = $rolename;
13543: }
13544: } else {
13545: $prefix = 'helproles_'.$num;
13546: $rolename = $env{'form.'.$prefix};
13547: next if ($rolename eq '');
13548: next unless (exists($existing{'rolesdef_'.$rolename}));
13549: $identifier = 'custhelp'.$num;
13550: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
13551: my %currprivs;
13552: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
13553: split(/\_/,$existing{'rolesdef_'.$rolename});
13554: foreach my $level ('c','d','s') {
13555: if ($newprivs{$level} ne $currprivs{$level}) {
13556: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
13557: $newprivs{'c'},$confname,$dom);
13558: if ($result ne 'ok') {
13559: $errors .= '<li><span class="LC_error">'.
13560: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
13561: $rolename,$result).'</span></li>';
13562: } else {
13563: $changedprivs{$rolename} = \%newprivs;
13564: }
13565: last;
13566: }
13567: }
13568: if (ref($current{'adhoc'}) eq 'HASH') {
13569: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
13570: %curr = %{$current{'adhoc'}{$rolename}};
13571: }
13572: }
13573: }
13574: my $newpos = $env{'form.'.$prefix.'_pos'};
13575: $newpos =~ s/\D+//g;
13576: $allpos[$newpos] = $rolename;
13577: my $newdesc = $env{'form.'.$prefix.'_desc'};
13578: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
13579: if ($curr{'desc'}) {
13580: if ($curr{'desc'} ne $newdesc) {
13581: $changes{'customrole'}{$rolename}{'desc'} = 1;
13582: $newsettings{$rolename}{'desc'} = $newdesc;
13583: }
13584: } elsif ($newdesc ne '') {
13585: $changes{'customrole'}{$rolename}{'desc'} = 1;
13586: $newsettings{$rolename}{'desc'} = $newdesc;
13587: }
13588: my $access = $env{'form.'.$prefix.'_access'};
13589: if (grep(/^\Q$access\E$/,@accesstypes)) {
13590: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
13591: if ($access eq 'status') {
13592: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
13593: if (scalar(@statuses) == 0) {
13594: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
13595: } else {
13596: my (@shownstatus,$numtypes);
13597: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
13598: if (ref($types) eq 'ARRAY') {
13599: $numtypes = scalar(@{$types});
13600: foreach my $type (sort(@statuses)) {
13601: if ($type eq 'default') {
13602: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
13603: } elsif (grep(/^\Q$type\E$/,@{$types})) {
13604: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
13605: push(@shownstatus,$usertypes->{$type});
13606: }
1.160.6.73 raeburn 13607: }
13608: }
1.160.6.77 raeburn 13609: if (grep(/^default$/,@statuses)) {
13610: push(@shownstatus,$othertitle);
13611: }
13612: if (scalar(@shownstatus) == 1+$numtypes) {
13613: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
13614: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
13615: } else {
13616: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
13617: if (ref($curr{'status'}) eq 'ARRAY') {
13618: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
13619: if (@diffs) {
13620: $changes{'customrole'}{$rolename}{$access} = 1;
13621: }
13622: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13623: $changes{'customrole'}{$rolename}{$access} = 1;
13624: }
13625: }
13626: }
13627: } elsif (($access eq 'inc') || ($access eq 'exc')) {
13628: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
13629: my @newspecstaff;
13630: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
13631: foreach my $person (sort(@personnel)) {
13632: if ($domhelpdesk{$person}) {
13633: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
13634: }
13635: }
13636: if (ref($curr{$access}) eq 'ARRAY') {
13637: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
13638: if (@diffs) {
13639: $changes{'customrole'}{$rolename}{$access} = 1;
13640: }
13641: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13642: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 13643: }
1.160.6.77 raeburn 13644: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13645: my ($uname,$udom) = split(/:/,$person);
13646: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
13647: }
13648: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 13649: }
1.160.6.77 raeburn 13650: } else {
13651: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
13652: }
13653: unless ($curr{'access'} eq $access) {
13654: $changes{'customrole'}{$rolename}{'access'} = 1;
13655: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 13656: }
13657: }
1.160.6.77 raeburn 13658: if (@allpos > 0) {
13659: my $idx = 0;
13660: foreach my $rolename (@allpos) {
13661: if ($rolename ne '') {
13662: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
13663: if (ref($current{'adhoc'}) eq 'HASH') {
13664: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
13665: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
13666: $changes{'customrole'}{$rolename}{'order'} = 1;
13667: $newsettings{$rolename}{'order'} = $idx+1;
13668: }
13669: }
1.160.6.73 raeburn 13670: }
1.160.6.77 raeburn 13671: $idx ++;
1.122 jms 13672: }
13673: }
1.118 jms 13674: }
1.123 jms 13675: my $putresult;
13676: if (keys(%changes) > 0) {
1.160.6.5 raeburn 13677: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
13678: if ($putresult eq 'ok') {
1.160.6.77 raeburn 13679: if (ref($helphash{'helpsettings'}) eq 'HASH') {
13680: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
13681: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
13682: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
13683: }
13684: }
13685: my $cachetime = 24*60*60;
13686: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13687: if (ref($lastactref) eq 'HASH') {
13688: $lastactref->{'domdefaults'} = 1;
13689: }
13690: } else {
13691: $errors .= '<li><span class="LC_error">'.
13692: &mt('An error occurred storing the settings: [_1]',
13693: $putresult).'</span></li>';
13694: }
13695: }
13696: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
13697: $resulttext = &mt('Changes made:').'<ul>';
13698: my (%shownprivs,@levelorder);
13699: @levelorder = ('c','d','s');
13700: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 13701: foreach my $item (sort(keys(%changes))) {
13702: if ($item eq 'submitbugs') {
13703: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
13704: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
13705: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 13706: } elsif ($item eq 'customrole') {
13707: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 13708: my @keyorder = ('order','desc','access','status','exc','inc');
13709: my %keytext = &Apache::lonlocal::texthash(
13710: order => 'Order',
13711: desc => 'Role description',
13712: access => 'Role usage',
1.160.6.83 raeburn 13713: status => 'Allowed institutional types',
1.160.6.77 raeburn 13714: exc => 'Allowed personnel',
13715: inc => 'Disallowed personnel',
13716: );
1.160.6.73 raeburn 13717: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 13718: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
13719: if ($role eq $newrole) {
13720: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
13721: $role).'<ul>';
13722: } else {
13723: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
13724: $role).'<ul>';
13725: }
13726: foreach my $key (@keyorder) {
13727: if ($changes{'customrole'}{$role}{$key}) {
13728: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
13729: $keytext{$key},$newsettings{$role}{$key}).
13730: '</li>';
13731: }
13732: }
13733: if (ref($changedprivs{$role}) eq 'HASH') {
13734: $shownprivs{$role} = 1;
13735: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
13736: foreach my $level (@levelorder) {
13737: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13738: next if ($item eq '');
13739: my ($priv) = split(/\&/,$item,2);
13740: if (&Apache::lonnet::plaintext($priv)) {
13741: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13742: unless ($level eq 'c') {
13743: $resulttext .= ' ('.$lt{$level}.')';
13744: }
13745: $resulttext .= '</li>';
13746: }
13747: }
13748: }
13749: $resulttext .= '</ul>';
13750: }
13751: $resulttext .= '</ul></li>';
13752: }
1.160.6.73 raeburn 13753: }
13754: }
1.160.6.5 raeburn 13755: }
13756: }
13757: }
1.160.6.77 raeburn 13758: if (keys(%changedprivs)) {
13759: foreach my $role (sort(keys(%changedprivs))) {
13760: unless ($shownprivs{$role}) {
13761: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
13762: $role).'<ul>'.
13763: '<li>'.&mt('Privileges set to :').'<ul>';
13764: foreach my $level (@levelorder) {
13765: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13766: next if ($item eq '');
13767: my ($priv) = split(/\&/,$item,2);
13768: if (&Apache::lonnet::plaintext($priv)) {
13769: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13770: unless ($level eq 'c') {
13771: $resulttext .= ' ('.$lt{$level}.')';
13772: }
13773: $resulttext .= '</li>';
13774: }
13775: }
13776: }
13777: $resulttext .= '</ul></li></ul></li>';
13778: }
13779: }
13780: }
13781: $resulttext .= '</ul>';
13782: } else {
13783: $resulttext = &mt('No changes made to help settings');
1.118 jms 13784: }
13785: if ($errors) {
1.160.6.5 raeburn 13786: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 13787: $errors.'</ul>';
1.118 jms 13788: }
13789: return $resulttext;
13790: }
13791:
1.121 raeburn 13792: sub modify_coursedefaults {
1.160.6.27 raeburn 13793: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 13794: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 13795: my %defaultchecked = (
13796: 'uselcmath' => 'on',
13797: 'usejsme' => 'on'
13798: );
13799: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 13800: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 13801: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
13802: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 13803: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 13804: my %staticdefaults = (
13805: anonsurvey_threshold => 10,
13806: uploadquota => 500,
1.160.6.57 raeburn 13807: postsubmit => 60,
1.160.6.70 raeburn 13808: mysqltables => 172800,
1.160.6.21 raeburn 13809: );
1.160.6.90 raeburn 13810: my %texoptions = (
13811: MathJax => 'MathJax',
13812: mimetex => &mt('Convert to Images'),
13813: tth => &mt('TeX to HTML'),
13814: );
1.121 raeburn 13815: $defaultshash{'coursedefaults'} = {};
13816:
13817: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
13818: if ($domconfig{'coursedefaults'} eq '') {
13819: $domconfig{'coursedefaults'} = {};
13820: }
13821: }
13822:
13823: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
13824: foreach my $item (@toggles) {
13825: if ($defaultchecked{$item} eq 'on') {
13826: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13827: ($env{'form.'.$item} eq '0')) {
13828: $changes{$item} = 1;
1.160.6.16 raeburn 13829: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 13830: $changes{$item} = 1;
13831: }
13832: } elsif ($defaultchecked{$item} eq 'off') {
13833: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13834: ($env{'form.'.$item} eq '1')) {
13835: $changes{$item} = 1;
13836: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
13837: $changes{$item} = 1;
13838: }
13839: }
13840: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
13841: }
1.160.6.21 raeburn 13842: foreach my $item (@numbers) {
13843: my ($currdef,$newdef);
1.160.6.26 raeburn 13844: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 13845: if ($item eq 'anonsurvey_threshold') {
13846: $currdef = $domconfig{'coursedefaults'}{$item};
13847: $newdef =~ s/\D//g;
13848: if ($newdef eq '' || $newdef < 1) {
13849: $newdef = 1;
13850: }
13851: $defaultshash{'coursedefaults'}{$item} = $newdef;
13852: } else {
1.160.6.70 raeburn 13853: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
13854: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
13855: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 13856: }
13857: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 13858: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 13859: }
13860: if ($currdef ne $newdef) {
13861: if ($item eq 'anonsurvey_threshold') {
13862: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
13863: $changes{$item} = 1;
13864: }
1.160.6.70 raeburn 13865: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
13866: my $setting = $1;
13867: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
13868: $changes{$setting} = 1;
1.160.6.21 raeburn 13869: }
13870: }
1.139 raeburn 13871: }
13872: }
1.160.6.90 raeburn 13873: my $texengine;
13874: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
13875: $texengine = $env{'form.texengine'};
13876: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
13877: if ($currdef eq '') {
13878: unless ($texengine eq $Apache::lonnet::deftex) {
13879: $changes{'texengine'} = 1;
13880: }
13881: } elsif ($currdef ne $texengine) {
13882: $changes{'texengine'} = 1;
13883: }
13884: }
13885: if ($texengine ne '') {
13886: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
13887: }
1.160.6.64 raeburn 13888: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
13889: my @currclonecode;
13890: if (ref($currclone) eq 'HASH') {
13891: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
13892: @currclonecode = @{$currclone->{'instcode'}};
13893: }
13894: }
13895: my $newclone;
13896: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
13897: $newclone = $env{'form.canclone'};
13898: }
13899: if ($newclone eq 'instcode') {
13900: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
13901: my (%codedefaults,@code_order,@clonecode);
13902: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
13903: \@code_order);
13904: foreach my $item (@code_order) {
13905: if (grep(/^\Q$item\E$/,@newcodes)) {
13906: push(@clonecode,$item);
13907: }
13908: }
13909: if (@clonecode) {
13910: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
13911: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
13912: if (@diffs) {
13913: $changes{'canclone'} = 1;
13914: }
13915: } else {
13916: $newclone eq '';
13917: }
13918: } elsif ($newclone ne '') {
13919: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
13920: }
13921: if ($newclone ne $currclone) {
13922: $changes{'canclone'} = 1;
13923: }
1.160.6.57 raeburn 13924: my %credits;
13925: foreach my $type (@types) {
13926: unless ($type eq 'community') {
13927: $credits{$type} = $env{'form.'.$type.'_credits'};
13928: $credits{$type} =~ s/[^\d.]+//g;
13929: }
13930: }
13931: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
13932: ($env{'form.coursecredits'} eq '1')) {
13933: $changes{'coursecredits'} = 1;
13934: foreach my $type (keys(%credits)) {
13935: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13936: }
13937: } else {
13938: if ($env{'form.coursecredits'} eq '1') {
13939: foreach my $type (@types) {
13940: unless ($type eq 'community') {
13941: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
13942: $changes{'coursecredits'} = 1;
13943: }
13944: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13945: }
13946: }
13947: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13948: foreach my $type (@types) {
13949: unless ($type eq 'community') {
13950: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
13951: $changes{'coursecredits'} = 1;
13952: last;
13953: }
13954: }
13955: }
13956: }
13957: }
13958: if ($env{'form.postsubmit'} eq '1') {
13959: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
13960: my %currtimeout;
13961: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13962: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
13963: $changes{'postsubmit'} = 1;
13964: }
13965: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13966: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
13967: }
13968: } else {
13969: $changes{'postsubmit'} = 1;
13970: }
13971: foreach my $type (@types) {
13972: my $timeout = $env{'form.'.$type.'_timeout'};
13973: $timeout =~ s/\D//g;
13974: if ($timeout == $staticdefaults{'postsubmit'}) {
13975: $timeout = '';
13976: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
13977: $timeout = '0';
13978: }
13979: unless ($timeout eq '') {
13980: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
13981: }
13982: if (exists($currtimeout{$type})) {
13983: if ($timeout ne $currtimeout{$type}) {
13984: $changes{'postsubmit'} = 1;
13985: }
13986: } elsif ($timeout ne '') {
13987: $changes{'postsubmit'} = 1;
13988: }
13989: }
13990: } else {
13991: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
13992: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13993: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
13994: $changes{'postsubmit'} = 1;
13995: }
13996: } else {
13997: $changes{'postsubmit'} = 1;
13998: }
1.160.6.16 raeburn 13999: }
1.121 raeburn 14000: }
14001: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14002: $dom);
14003: if ($putresult eq 'ok') {
14004: if (keys(%changes) > 0) {
1.160.6.27 raeburn 14005: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 14006: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 14007: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.90 raeburn 14008: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
14009: foreach my $item ('uselcmath','usejsme','texengine') {
1.160.6.57 raeburn 14010: if ($changes{$item}) {
14011: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
14012: }
1.160.6.16 raeburn 14013: }
14014: if ($changes{'coursecredits'}) {
14015: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 14016: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
14017: $domdefaults{$type.'credits'} =
14018: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
14019: }
14020: }
14021: }
14022: if ($changes{'postsubmit'}) {
14023: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
14024: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
14025: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
14026: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
14027: $domdefaults{$type.'postsubtimeout'} =
14028: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
14029: }
14030: }
1.160.6.16 raeburn 14031: }
14032: }
1.160.6.21 raeburn 14033: if ($changes{'uploadquota'}) {
14034: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
14035: foreach my $type (@types) {
14036: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
14037: }
14038: }
14039: }
1.160.6.64 raeburn 14040: if ($changes{'canclone'}) {
14041: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
14042: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
14043: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
14044: if (@clonecodes) {
14045: $domdefaults{'canclone'} = join('+',@clonecodes);
14046: }
14047: }
14048: } else {
14049: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
14050: }
14051: }
1.121 raeburn 14052: my $cachetime = 24*60*60;
14053: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 14054: if (ref($lastactref) eq 'HASH') {
14055: $lastactref->{'domdefaults'} = 1;
14056: }
1.121 raeburn 14057: }
14058: $resulttext = &mt('Changes made:').'<ul>';
14059: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 14060: if ($item eq 'uselcmath') {
1.121 raeburn 14061: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 14062: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 14063: } else {
1.160.6.57 raeburn 14064: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
14065: }
14066: } elsif ($item eq 'usejsme') {
14067: if ($env{'form.'.$item} eq '1') {
14068: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
14069: } else {
14070: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 14071: }
1.160.6.90 raeburn 14072: } elsif ($item eq 'texengine') {
14073: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
14074: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
14075: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
14076: }
1.139 raeburn 14077: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 14078: $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 14079: } elsif ($item eq 'uploadquota') {
14080: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
14081: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
14082: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
14083: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 14084: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
14085:
1.160.6.21 raeburn 14086: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
14087: '</ul>'.
14088: '</li>';
14089: } else {
14090: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
14091: }
1.160.6.70 raeburn 14092: } elsif ($item eq 'mysqltables') {
14093: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
14094: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
14095: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
14096: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
14097: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
14098: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
14099: '</ul>'.
14100: '</li>';
14101: } else {
14102: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
14103: }
1.160.6.57 raeburn 14104: } elsif ($item eq 'postsubmit') {
14105: if ($domdefaults{'postsubmit'} eq 'off') {
14106: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
14107: } else {
14108: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
14109: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
14110: $resulttext .= &mt('durations:').'<ul>';
14111: foreach my $type (@types) {
14112: $resulttext .= '<li>';
14113: my $timeout;
14114: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
14115: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
14116: }
14117: my $display;
14118: if ($timeout eq '0') {
14119: $display = &mt('unlimited');
14120: } elsif ($timeout eq '') {
14121: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
14122: } else {
14123: $display = &mt('[quant,_1,second]',$timeout);
14124: }
14125: if ($type eq 'community') {
14126: $resulttext .= &mt('Communities');
14127: } elsif ($type eq 'official') {
14128: $resulttext .= &mt('Official courses');
14129: } elsif ($type eq 'unofficial') {
14130: $resulttext .= &mt('Unofficial courses');
14131: } elsif ($type eq 'textbook') {
14132: $resulttext .= &mt('Textbook courses');
14133: }
14134: $resulttext .= ' -- '.$display.'</li>';
14135: }
14136: $resulttext .= '</ul>';
14137: }
14138: $resulttext .= '</li>';
14139: }
1.160.6.16 raeburn 14140: } elsif ($item eq 'coursecredits') {
14141: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
14142: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 14143: ($domdefaults{'unofficialcredits'} eq '') &&
14144: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 14145: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
14146: } else {
14147: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
14148: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
14149: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 14150: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 14151: '</ul>'.
14152: '</li>';
14153: }
14154: } else {
14155: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
14156: }
1.160.6.64 raeburn 14157: } elsif ($item eq 'canclone') {
14158: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
14159: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
14160: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
14161: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
14162: }
14163: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
14164: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
14165: } else {
14166: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
14167: }
1.140 raeburn 14168: }
1.121 raeburn 14169: }
14170: $resulttext .= '</ul>';
14171: } else {
14172: $resulttext = &mt('No changes made to course defaults');
14173: }
14174: } else {
14175: $resulttext = '<span class="LC_error">'.
14176: &mt('An error occurred: [_1]',$putresult).'</span>';
14177: }
14178: return $resulttext;
14179: }
14180:
1.160.6.37 raeburn 14181: sub modify_selfenrollment {
14182: my ($dom,$lastactref,%domconfig) = @_;
14183: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
14184: my @types = ('official','unofficial','community','textbook');
14185: my %titles = &tool_titles();
14186: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
14187: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
14188: $ordered{'default'} = ['types','registered','approval','limit'];
14189:
14190: my (%roles,%shown,%toplevel);
14191: $roles{'0'} = &Apache::lonnet::plaintext('dc');
14192:
14193: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
14194: if ($domconfig{'selfenrollment'} eq '') {
14195: $domconfig{'selfenrollment'} = {};
14196: }
14197: }
14198: %toplevel = (
14199: admin => 'Configuration Rights',
14200: default => 'Default settings',
14201: validation => 'Validation of self-enrollment requests',
14202: );
14203: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
14204:
14205: if (ref($ordered{'admin'}) eq 'ARRAY') {
14206: foreach my $item (@{$ordered{'admin'}}) {
14207: foreach my $type (@types) {
14208: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
14209: $selfenrollhash{'admin'}{$type}{$item} = 1;
14210: } else {
14211: $selfenrollhash{'admin'}{$type}{$item} = 0;
14212: }
14213: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
14214: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
14215: if ($selfenrollhash{'admin'}{$type}{$item} ne
14216: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
14217: push(@{$changes{'admin'}{$type}},$item);
14218: }
14219: } else {
14220: if (!$selfenrollhash{'admin'}{$type}{$item}) {
14221: push(@{$changes{'admin'}{$type}},$item);
14222: }
14223: }
14224: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
14225: push(@{$changes{'admin'}{$type}},$item);
14226: }
14227: }
14228: }
14229: }
14230:
14231: foreach my $item (@{$ordered{'default'}}) {
14232: foreach my $type (@types) {
14233: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
14234: if ($item eq 'types') {
14235: unless (($value eq 'all') || ($value eq 'dom')) {
14236: $value = '';
14237: }
14238: } elsif ($item eq 'registered') {
14239: unless ($value eq '1') {
14240: $value = 0;
14241: }
14242: } elsif ($item eq 'approval') {
14243: unless ($value =~ /^[012]$/) {
14244: $value = 0;
14245: }
14246: } else {
14247: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
14248: $value = 'none';
14249: }
14250: }
14251: $selfenrollhash{'default'}{$type}{$item} = $value;
14252: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
14253: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
14254: if ($selfenrollhash{'default'}{$type}{$item} ne
14255: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
14256: push(@{$changes{'default'}{$type}},$item);
14257: }
14258: } else {
14259: push(@{$changes{'default'}{$type}},$item);
14260: }
14261: } else {
14262: push(@{$changes{'default'}{$type}},$item);
14263: }
14264: if ($item eq 'limit') {
14265: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
14266: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
14267: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
14268: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
14269: }
14270: } else {
14271: $selfenrollhash{'default'}{$type}{'cap'} = '';
14272: }
14273: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
14274: if ($selfenrollhash{'default'}{$type}{'cap'} ne
14275: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
14276: push(@{$changes{'default'}{$type}},'cap');
14277: }
14278: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
14279: push(@{$changes{'default'}{$type}},'cap');
14280: }
14281: }
14282: }
14283: }
14284:
14285: foreach my $item (@{$itemsref}) {
14286: if ($item eq 'fields') {
14287: my @changed;
14288: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
14289: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
14290: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
14291: }
14292: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
14293: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
14294: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
14295: $domconfig{'selfenrollment'}{'validation'}{$item});
14296: } else {
14297: @changed = @{$selfenrollhash{'validation'}{$item}};
14298: }
14299: } else {
14300: @changed = @{$selfenrollhash{'validation'}{$item}};
14301: }
14302: if (@changed) {
14303: if ($selfenrollhash{'validation'}{$item}) {
14304: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
14305: } else {
14306: $changes{'validation'}{$item} = &mt('None');
14307: }
14308: }
14309: } else {
14310: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
14311: if ($item eq 'markup') {
14312: if ($env{'form.selfenroll_validation_'.$item}) {
14313: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14314: }
14315: }
14316: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
14317: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
14318: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
14319: }
14320: }
14321: }
14322: }
14323:
14324: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
14325: $dom);
14326: if ($putresult eq 'ok') {
14327: if (keys(%changes) > 0) {
14328: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14329: $resulttext = &mt('Changes made:').'<ul>';
14330: foreach my $key ('admin','default','validation') {
14331: if (ref($changes{$key}) eq 'HASH') {
14332: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
14333: if ($key eq 'validation') {
14334: foreach my $item (@{$itemsref}) {
14335: if (exists($changes{$key}{$item})) {
14336: if ($item eq 'markup') {
14337: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
14338: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
14339: } else {
14340: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
14341: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
14342: }
14343: }
14344: }
14345: } else {
14346: foreach my $type (@types) {
14347: if ($type eq 'community') {
14348: $roles{'1'} = &mt('Community personnel');
14349: } else {
14350: $roles{'1'} = &mt('Course personnel');
14351: }
14352: if (ref($changes{$key}{$type}) eq 'ARRAY') {
14353: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
14354: if ($key eq 'admin') {
14355: my @mgrdc = ();
14356: if (ref($ordered{$key}) eq 'ARRAY') {
14357: foreach my $item (@{$ordered{'admin'}}) {
14358: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
14359: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
14360: push(@mgrdc,$item);
14361: }
14362: }
14363: }
14364: if (@mgrdc) {
14365: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
14366: } else {
14367: delete($domdefaults{$type.'selfenrolladmdc'});
14368: }
14369: }
14370: } else {
14371: if (ref($ordered{$key}) eq 'ARRAY') {
14372: foreach my $item (@{$ordered{$key}}) {
14373: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
14374: $domdefaults{$type.'selfenroll'.$item} =
14375: $selfenrollhash{$key}{$type}{$item};
14376: }
14377: }
14378: }
14379: }
14380: }
14381: $resulttext .= '<li>'.$titles{$type}.'<ul>';
14382: foreach my $item (@{$ordered{$key}}) {
14383: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
14384: $resulttext .= '<li>';
14385: if ($key eq 'admin') {
14386: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
14387: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
14388: } else {
14389: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
14390: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
14391: }
14392: $resulttext .= '</li>';
14393: }
14394: }
14395: $resulttext .= '</ul></li>';
14396: }
14397: }
14398: $resulttext .= '</ul></li>';
14399: }
14400: }
1.160.6.93 raeburn 14401: }
14402: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
14403: my $cachetime = 24*60*60;
14404: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14405: if (ref($lastactref) eq 'HASH') {
14406: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 14407: }
14408: }
14409: $resulttext .= '</ul>';
14410: } else {
14411: $resulttext = &mt('No changes made to self-enrollment settings');
14412: }
14413: } else {
14414: $resulttext = '<span class="LC_error">'.
14415: &mt('An error occurred: [_1]',$putresult).'</span>';
14416: }
14417: return $resulttext;
14418: }
14419:
1.137 raeburn 14420: sub modify_usersessions {
1.160.6.27 raeburn 14421: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 14422: my @hostingtypes = ('version','excludedomain','includedomain');
14423: my @offloadtypes = ('primary','default');
14424: my %types = (
14425: remote => \@hostingtypes,
14426: hosted => \@hostingtypes,
14427: spares => \@offloadtypes,
14428: );
14429: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 14430: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 14431: my (%by_ip,%by_location,@intdoms);
14432: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
14433: my @locations = sort(keys(%by_location));
1.137 raeburn 14434: my (%defaultshash,%changes);
14435: foreach my $prefix (@prefixes) {
14436: $defaultshash{'usersessions'}{$prefix} = {};
14437: }
1.160.6.27 raeburn 14438: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 14439: my $resulttext;
1.138 raeburn 14440: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 14441: foreach my $prefix (@prefixes) {
1.145 raeburn 14442: next if ($prefix eq 'spares');
14443: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 14444: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14445: if ($type eq 'version') {
14446: my $value = $env{'form.'.$prefix.'_'.$type};
14447: my $okvalue;
14448: if ($value ne '') {
14449: if (grep(/^\Q$value\E$/,@lcversions)) {
14450: $okvalue = $value;
14451: }
14452: }
14453: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14454: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
14455: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
14456: if ($inuse == 0) {
14457: $changes{$prefix}{$type} = 1;
14458: } else {
14459: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
14460: $changes{$prefix}{$type} = 1;
14461: }
14462: if ($okvalue ne '') {
14463: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14464: }
14465: }
14466: } else {
14467: if (($inuse == 1) && ($okvalue ne '')) {
14468: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14469: $changes{$prefix}{$type} = 1;
14470: }
14471: }
14472: } else {
14473: if (($inuse == 1) && ($okvalue ne '')) {
14474: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14475: $changes{$prefix}{$type} = 1;
14476: }
14477: }
14478: } else {
14479: if (($inuse == 1) && ($okvalue ne '')) {
14480: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14481: $changes{$prefix}{$type} = 1;
14482: }
14483: }
14484: } else {
14485: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14486: my @okvals;
14487: foreach my $val (@vals) {
1.138 raeburn 14488: if ($val =~ /:/) {
14489: my @items = split(/:/,$val);
14490: foreach my $item (@items) {
14491: if (ref($by_location{$item}) eq 'ARRAY') {
14492: push(@okvals,$item);
14493: }
14494: }
14495: } else {
14496: if (ref($by_location{$val}) eq 'ARRAY') {
14497: push(@okvals,$val);
14498: }
1.137 raeburn 14499: }
14500: }
14501: @okvals = sort(@okvals);
14502: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14503: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
14504: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
14505: if ($inuse == 0) {
14506: $changes{$prefix}{$type} = 1;
14507: } else {
14508: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14509: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
14510: if (@changed > 0) {
14511: $changes{$prefix}{$type} = 1;
14512: }
14513: }
14514: } else {
14515: if ($inuse == 1) {
14516: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14517: $changes{$prefix}{$type} = 1;
14518: }
14519: }
14520: } else {
14521: if ($inuse == 1) {
14522: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14523: $changes{$prefix}{$type} = 1;
14524: }
14525: }
14526: } else {
14527: if ($inuse == 1) {
14528: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14529: $changes{$prefix}{$type} = 1;
14530: }
14531: }
14532: }
14533: }
14534: }
1.145 raeburn 14535:
14536: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 14537: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 14538: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
14539: my $savespares;
14540:
14541: foreach my $lonhost (sort(keys(%servers))) {
14542: my $serverhomeID =
14543: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 14544: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 14545: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
14546: my %spareschg;
14547: foreach my $type (@{$types{'spares'}}) {
14548: my @okspares;
14549: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
14550: foreach my $server (@checked) {
1.152 raeburn 14551: if (&Apache::lonnet::hostname($server) ne '') {
14552: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
14553: unless (grep(/^\Q$server\E$/,@okspares)) {
14554: push(@okspares,$server);
14555: }
1.145 raeburn 14556: }
14557: }
14558: }
14559: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
14560: my $newspare;
1.152 raeburn 14561: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
14562: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 14563: $newspare = $new;
14564: }
14565: }
1.152 raeburn 14566: my @spares;
14567: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
14568: @spares = sort(@okspares,$newspare);
14569: } else {
14570: @spares = sort(@okspares);
14571: }
14572: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 14573: if (ref($spareid{$lonhost}) eq 'HASH') {
14574: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 14575: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 14576: if (@diffs > 0) {
14577: $spareschg{$type} = 1;
14578: }
14579: }
14580: }
14581: }
14582: if (keys(%spareschg) > 0) {
14583: $changes{'spares'}{$lonhost} = \%spareschg;
14584: }
14585: }
1.160.6.61 raeburn 14586: $defaultshash{'usersessions'}{'offloadnow'} = {};
14587: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
14588: my @okoffload;
14589: if (@offloadnow) {
14590: foreach my $server (@offloadnow) {
14591: if (&Apache::lonnet::hostname($server) ne '') {
14592: unless (grep(/^\Q$server\E$/,@okoffload)) {
14593: push(@okoffload,$server);
14594: }
14595: }
14596: }
14597: if (@okoffload) {
14598: foreach my $lonhost (@okoffload) {
14599: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
14600: }
14601: }
14602: }
1.145 raeburn 14603: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14604: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
14605: if (ref($changes{'spares'}) eq 'HASH') {
14606: if (keys(%{$changes{'spares'}}) > 0) {
14607: $savespares = 1;
14608: }
14609: }
14610: } else {
14611: $savespares = 1;
14612: }
1.160.6.61 raeburn 14613: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
14614: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
14615: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
14616: $changes{'offloadnow'} = 1;
14617: last;
14618: }
14619: }
14620: unless ($changes{'offloadnow'}) {
14621: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
14622: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
14623: $changes{'offloadnow'} = 1;
14624: last;
14625: }
14626: }
14627: }
14628: } elsif (@okoffload) {
14629: $changes{'offloadnow'} = 1;
14630: }
14631: } elsif (@okoffload) {
14632: $changes{'offloadnow'} = 1;
1.145 raeburn 14633: }
1.147 raeburn 14634: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
14635: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 14636: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14637: $dom);
14638: if ($putresult eq 'ok') {
14639: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
14640: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
14641: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
14642: }
14643: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
14644: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
14645: }
1.160.6.61 raeburn 14646: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
14647: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
14648: }
1.137 raeburn 14649: }
14650: my $cachetime = 24*60*60;
14651: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 14652: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 14653: if (ref($lastactref) eq 'HASH') {
14654: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 14655: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 14656: }
1.147 raeburn 14657: if (keys(%changes) > 0) {
14658: my %lt = &usersession_titles();
14659: $resulttext = &mt('Changes made:').'<ul>';
14660: foreach my $prefix (@prefixes) {
14661: if (ref($changes{$prefix}) eq 'HASH') {
14662: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
14663: if ($prefix eq 'spares') {
14664: if (ref($changes{$prefix}) eq 'HASH') {
14665: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
14666: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 14667: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 14668: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
14669: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 14670: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
14671: foreach my $type (@{$types{$prefix}}) {
14672: if ($changes{$prefix}{$lonhost}{$type}) {
14673: my $offloadto = &mt('None');
14674: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
14675: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
14676: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
14677: }
1.145 raeburn 14678: }
1.147 raeburn 14679: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 14680: }
1.137 raeburn 14681: }
14682: }
1.147 raeburn 14683: $resulttext .= '</li>';
1.137 raeburn 14684: }
14685: }
1.147 raeburn 14686: } else {
14687: foreach my $type (@{$types{$prefix}}) {
14688: if (defined($changes{$prefix}{$type})) {
14689: my $newvalue;
14690: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
14691: if (ref($defaultshash{'usersessions'}{$prefix})) {
14692: if ($type eq 'version') {
14693: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
14694: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
14695: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
14696: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
14697: }
1.145 raeburn 14698: }
14699: }
14700: }
1.147 raeburn 14701: if ($newvalue eq '') {
14702: if ($type eq 'version') {
14703: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
14704: } else {
14705: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
14706: }
1.145 raeburn 14707: } else {
1.147 raeburn 14708: if ($type eq 'version') {
14709: $newvalue .= ' '.&mt('(or later)');
14710: }
14711: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 14712: }
1.137 raeburn 14713: }
14714: }
14715: }
1.147 raeburn 14716: $resulttext .= '</ul>';
1.137 raeburn 14717: }
14718: }
1.160.6.61 raeburn 14719: if ($changes{'offloadnow'}) {
14720: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
14721: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
14722: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
14723: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
14724: $resulttext .= '<li>'.$lonhost.'</li>';
14725: }
14726: $resulttext .= '</ul>';
14727: } else {
14728: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
14729: }
14730: } else {
14731: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
14732: }
14733: }
1.147 raeburn 14734: $resulttext .= '</ul>';
14735: } else {
14736: $resulttext = $nochgmsg;
1.137 raeburn 14737: }
14738: } else {
14739: $resulttext = '<span class="LC_error">'.
14740: &mt('An error occurred: [_1]',$putresult).'</span>';
14741: }
14742: } else {
1.147 raeburn 14743: $resulttext = $nochgmsg;
1.137 raeburn 14744: }
14745: return $resulttext;
14746: }
14747:
1.150 raeburn 14748: sub modify_loadbalancing {
14749: my ($dom,%domconfig) = @_;
14750: my $primary_id = &Apache::lonnet::domain($dom,'primary');
14751: my $intdom = &Apache::lonnet::internet_dom($primary_id);
14752: my ($othertitle,$usertypes,$types) =
14753: &Apache::loncommon::sorted_inst_types($dom);
14754: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 14755: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 14756: my @sparestypes = ('primary','default');
14757: my %typetitles = &sparestype_titles();
14758: my $resulttext;
1.160.6.94 raeburn 14759: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 14760: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14761: %existing = %{$domconfig{'loadbalancing'}};
14762: }
14763: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 14764: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 14765: my ($saveloadbalancing,%defaultshash,%changes);
14766: my ($alltypes,$othertypes,$titles) =
14767: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
14768: my %ruletitles = &offloadtype_text();
14769: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
14770: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
14771: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
14772: if ($balancer eq '') {
14773: next;
14774: }
14775: if (!exists($servers{$balancer})) {
14776: if (exists($currbalancer{$balancer})) {
14777: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 14778: }
1.160.6.7 raeburn 14779: next;
14780: }
14781: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
14782: push(@{$changes{'delete'}},$balancer);
14783: next;
14784: }
14785: if (!exists($currbalancer{$balancer})) {
14786: push(@{$changes{'add'}},$balancer);
14787: }
14788: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
14789: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
14790: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
14791: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14792: $saveloadbalancing = 1;
14793: }
14794: foreach my $sparetype (@sparestypes) {
14795: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
14796: my @offloadto;
14797: foreach my $target (@targets) {
14798: if (($servers{$target}) && ($target ne $balancer)) {
14799: if ($sparetype eq 'default') {
14800: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
14801: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 14802: }
14803: }
1.160.6.7 raeburn 14804: unless(grep(/^\Q$target\E$/,@offloadto)) {
14805: push(@offloadto,$target);
14806: }
1.150 raeburn 14807: }
14808: }
1.160.6.76 raeburn 14809: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
14810: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
14811: push(@offloadto,$balancer);
14812: }
14813: }
14814: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 14815: }
1.160.6.94 raeburn 14816: if ($env{'form.loadbalancing_cookie_'.$i}) {
14817: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
14818: if (exists($currbalancer{$balancer})) {
14819: unless ($currcookies{$balancer}) {
14820: $changes{'curr'}{$balancer}{'cookie'} = 1;
14821: }
14822: }
14823: } elsif (exists($currbalancer{$balancer})) {
14824: if ($currcookies{$balancer}) {
14825: $changes{'curr'}{$balancer}{'cookie'} = 1;
14826: }
14827: }
1.160.6.7 raeburn 14828: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 14829: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 14830: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
14831: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 14832: if (@targetdiffs > 0) {
1.160.6.7 raeburn 14833: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14834: }
1.160.6.7 raeburn 14835: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14836: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14837: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14838: }
14839: }
14840: }
14841: } else {
1.160.6.7 raeburn 14842: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
14843: foreach my $sparetype (@sparestypes) {
14844: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14845: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14846: $changes{'curr'}{$balancer}{'targets'} = 1;
14847: }
1.150 raeburn 14848: }
14849: }
1.160.6.7 raeburn 14850: }
1.150 raeburn 14851: }
14852: my $ishomedom;
1.160.6.7 raeburn 14853: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
14854: $ishomedom = 1;
1.150 raeburn 14855: }
14856: if (ref($alltypes) eq 'ARRAY') {
14857: foreach my $type (@{$alltypes}) {
14858: my $rule;
1.160.6.7 raeburn 14859: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 14860: (!$ishomedom)) {
1.160.6.7 raeburn 14861: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
14862: }
14863: if ($rule eq 'specific') {
1.160.6.55 raeburn 14864: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
14865: if (exists($servers{$specifiedhost})) {
14866: $rule = $specifiedhost;
14867: }
1.150 raeburn 14868: }
1.160.6.7 raeburn 14869: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
14870: if (ref($currrules{$balancer}) eq 'HASH') {
14871: if ($rule ne $currrules{$balancer}{$type}) {
14872: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14873: }
14874: } elsif ($rule ne '') {
1.160.6.7 raeburn 14875: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14876: }
14877: }
14878: }
1.160.6.7 raeburn 14879: }
14880: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
14881: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
14882: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
14883: $defaultshash{'loadbalancing'} = {};
14884: }
14885: my $putresult = &Apache::lonnet::put_dom('configuration',
14886: \%defaultshash,$dom);
14887: if ($putresult eq 'ok') {
14888: if (keys(%changes) > 0) {
1.160.6.54 raeburn 14889: my %toupdate;
1.160.6.7 raeburn 14890: if (ref($changes{'delete'}) eq 'ARRAY') {
14891: foreach my $balancer (sort(@{$changes{'delete'}})) {
14892: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 14893: $toupdate{$balancer} = 1;
1.150 raeburn 14894: }
1.160.6.7 raeburn 14895: }
14896: if (ref($changes{'add'}) eq 'ARRAY') {
14897: foreach my $balancer (sort(@{$changes{'add'}})) {
14898: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 14899: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 14900: }
14901: }
14902: if (ref($changes{'curr'}) eq 'HASH') {
14903: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 14904: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 14905: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
14906: if ($changes{'curr'}{$balancer}{'targets'}) {
14907: my %offloadstr;
14908: foreach my $sparetype (@sparestypes) {
14909: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14910: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14911: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14912: }
14913: }
1.150 raeburn 14914: }
1.160.6.7 raeburn 14915: if (keys(%offloadstr) == 0) {
14916: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 14917: } else {
1.160.6.7 raeburn 14918: my $showoffload;
14919: foreach my $sparetype (@sparestypes) {
14920: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
14921: if (defined($offloadstr{$sparetype})) {
14922: $showoffload .= $offloadstr{$sparetype};
14923: } else {
14924: $showoffload .= &mt('None');
14925: }
14926: $showoffload .= (' 'x3);
14927: }
14928: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 14929: }
14930: }
14931: }
1.160.6.7 raeburn 14932: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
14933: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
14934: foreach my $type (@{$alltypes}) {
14935: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
14936: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14937: my $balancetext;
14938: if ($rule eq '') {
14939: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 14940: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 14941: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
14942: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 14943: foreach my $sparetype (@sparestypes) {
14944: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14945: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14946: }
14947: }
1.160.6.55 raeburn 14948: foreach my $item (@{$alltypes}) {
14949: next if ($item =~ /^_LC_ipchange/);
14950: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
14951: if ($hasrule eq 'homeserver') {
14952: map { $toupdate{$_} = 1; } (keys(%libraryservers));
14953: } else {
14954: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
14955: if ($servers{$hasrule}) {
14956: $toupdate{$hasrule} = 1;
14957: }
14958: }
14959: }
14960: }
14961: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
14962: $balancetext = $ruletitles{$rule};
14963: } else {
14964: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14965: $balancetext = $ruletitles{'particular'}.' '.$receiver;
14966: if ($receiver) {
14967: $toupdate{$receiver};
14968: }
14969: }
14970: } else {
14971: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 14972: }
1.160.6.7 raeburn 14973: } else {
14974: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
14975: }
1.160.6.26 raeburn 14976: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 14977: }
14978: }
14979: }
14980: }
1.160.6.94 raeburn 14981: if ($changes{'curr'}{$balancer}{'cookie'}) {
14982: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
14983: $balancer).'</li>';
14984: }
1.160.6.54 raeburn 14985: if (keys(%toupdate)) {
14986: my %thismachine;
14987: my $updatedhere;
14988: my $cachetime = 60*60*24;
14989: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
14990: foreach my $lonhost (keys(%toupdate)) {
14991: if ($thismachine{$lonhost}) {
14992: unless ($updatedhere) {
14993: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
14994: $defaultshash{'loadbalancing'},
14995: $cachetime);
14996: $updatedhere = 1;
14997: }
14998: } else {
14999: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
15000: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
15001: }
15002: }
15003: }
1.150 raeburn 15004: }
1.160.6.7 raeburn 15005: }
15006: if ($resulttext ne '') {
15007: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 15008: } else {
15009: $resulttext = $nochgmsg;
15010: }
15011: } else {
1.160.6.7 raeburn 15012: $resulttext = $nochgmsg;
1.150 raeburn 15013: }
15014: } else {
1.160.6.7 raeburn 15015: $resulttext = '<span class="LC_error">'.
15016: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 15017: }
15018: } else {
1.160.6.7 raeburn 15019: $resulttext = $nochgmsg;
1.150 raeburn 15020: }
15021: return $resulttext;
15022: }
15023:
1.48 raeburn 15024: sub recurse_check {
15025: my ($chkcats,$categories,$depth,$name) = @_;
15026: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
15027: my $chg = 0;
15028: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
15029: my $category = $chkcats->[$depth]{$name}[$j];
15030: my $item;
15031: if ($category eq '') {
15032: $chg ++;
15033: } else {
15034: my $deeper = $depth + 1;
15035: $item = &escape($category).':'.&escape($name).':'.$depth;
15036: if ($chg) {
15037: $categories->{$item} -= $chg;
15038: }
15039: &recurse_check($chkcats,$categories,$deeper,$category);
15040: $deeper --;
15041: }
15042: }
15043: }
15044: return;
15045: }
15046:
15047: sub recurse_cat_deletes {
15048: my ($item,$coursecategories,$deletions) = @_;
15049: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15050: my $subdepth = $depth + 1;
15051: if (ref($coursecategories) eq 'HASH') {
15052: foreach my $subitem (keys(%{$coursecategories})) {
15053: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
15054: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
15055: delete($coursecategories->{$subitem});
15056: $deletions->{$subitem} = 1;
15057: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 15058: }
1.48 raeburn 15059: }
15060: }
15061: return;
15062: }
15063:
1.125 raeburn 15064: sub active_dc_picker {
1.160.6.16 raeburn 15065: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 15066: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 15067: my @domcoord = keys(%domcoords);
15068: if (keys(%currhash)) {
15069: foreach my $dc (keys(%currhash)) {
15070: unless (exists($domcoords{$dc})) {
15071: push(@domcoord,$dc);
15072: }
15073: }
15074: }
15075: @domcoord = sort(@domcoord);
15076: my $numdcs = scalar(@domcoord);
15077: my $rows = 0;
15078: my $table;
1.125 raeburn 15079: if ($numdcs > 1) {
1.160.6.16 raeburn 15080: $table = '<table>';
15081: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 15082: my $rem = $i%($numinrow);
15083: if ($rem == 0) {
15084: if ($i > 0) {
1.160.6.16 raeburn 15085: $table .= '</tr>';
1.125 raeburn 15086: }
1.160.6.16 raeburn 15087: $table .= '<tr>';
15088: $rows ++;
1.125 raeburn 15089: }
1.160.6.16 raeburn 15090: my $check = '';
15091: if ($inputtype eq 'radio') {
15092: if (keys(%currhash) == 0) {
15093: if (!$i) {
15094: $check = ' checked="checked"';
15095: }
15096: } elsif (exists($currhash{$domcoord[$i]})) {
15097: $check = ' checked="checked"';
15098: }
15099: } else {
15100: if (exists($currhash{$domcoord[$i]})) {
15101: $check = ' checked="checked"';
1.125 raeburn 15102: }
15103: }
1.160.6.16 raeburn 15104: if ($i == @domcoord - 1) {
1.125 raeburn 15105: my $colsleft = $numinrow - $rem;
15106: if ($colsleft > 1) {
1.160.6.16 raeburn 15107: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 15108: } else {
1.160.6.16 raeburn 15109: $table .= '<td class="LC_left_item">';
1.125 raeburn 15110: }
15111: } else {
1.160.6.16 raeburn 15112: $table .= '<td class="LC_left_item">';
15113: }
15114: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
15115: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
15116: $table .= '<span class="LC_nobreak"><label>'.
15117: '<input type="'.$inputtype.'" name="'.$name.'"'.
15118: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
15119: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 15120: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 15121: }
1.160.6.33 raeburn 15122: $table .= '</label></span></td>';
1.125 raeburn 15123: }
1.160.6.16 raeburn 15124: $table .= '</tr></table>';
15125: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 15126: my ($dcname,$dcdom) = split(':',$domcoord[0]);
15127: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 15128: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 15129: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 15130: if ($user ne $dcname.':'.$dcdom) {
15131: $table .= ' ('.$dcname.':'.$dcdom.')';
15132: }
1.160.6.16 raeburn 15133: } else {
15134: my $check;
15135: if (exists($currhash{$domcoord[0]})) {
15136: $check = ' checked="checked"';
15137: }
1.160.6.50 raeburn 15138: $table = '<span class="LC_nobreak"><label>'.
15139: '<input type="checkbox" name="'.$name.'" '.
15140: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 15141: if ($user ne $dcname.':'.$dcdom) {
15142: $table .= ' ('.$dcname.':'.$dcdom.')';
15143: }
15144: $table .= '</label></span>';
1.160.6.16 raeburn 15145: $rows ++;
15146: }
1.125 raeburn 15147: }
1.160.6.16 raeburn 15148: return ($numdcs,$table,$rows);
1.125 raeburn 15149: }
15150:
1.137 raeburn 15151: sub usersession_titles {
15152: return &Apache::lonlocal::texthash(
15153: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
15154: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 15155: spares => 'Servers offloaded to, when busy',
1.137 raeburn 15156: version => 'LON-CAPA version requirement',
1.138 raeburn 15157: excludedomain => 'Allow all, but exclude specific domains',
15158: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 15159: primary => 'Primary (checked first)',
1.154 raeburn 15160: default => 'Default',
1.137 raeburn 15161: );
15162: }
15163:
1.152 raeburn 15164: sub id_for_thisdom {
15165: my (%servers) = @_;
15166: my %altids;
15167: foreach my $server (keys(%servers)) {
15168: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
15169: if ($serverhome ne $server) {
15170: $altids{$serverhome} = $server;
15171: }
15172: }
15173: return %altids;
15174: }
15175:
1.150 raeburn 15176: sub count_servers {
15177: my ($currbalancer,%servers) = @_;
15178: my (@spares,$numspares);
15179: foreach my $lonhost (sort(keys(%servers))) {
15180: next if ($currbalancer eq $lonhost);
15181: push(@spares,$lonhost);
15182: }
15183: if ($currbalancer) {
15184: $numspares = scalar(@spares);
15185: } else {
15186: $numspares = scalar(@spares) - 1;
15187: }
15188: return ($numspares,@spares);
15189: }
15190:
15191: sub lonbalance_targets_js {
1.160.6.7 raeburn 15192: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 15193: my $select = &mt('Select');
15194: my ($alltargets,$allishome,$allinsttypes,@alltypes);
15195: if (ref($servers) eq 'HASH') {
15196: $alltargets = join("','",sort(keys(%{$servers})));
15197: my @homedoms;
15198: foreach my $server (sort(keys(%{$servers}))) {
15199: if (&Apache::lonnet::host_domain($server) eq $dom) {
15200: push(@homedoms,'1');
15201: } else {
15202: push(@homedoms,'0');
15203: }
15204: }
15205: $allishome = join("','",@homedoms);
15206: }
15207: if (ref($types) eq 'ARRAY') {
15208: if (@{$types} > 0) {
15209: @alltypes = @{$types};
15210: }
15211: }
15212: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
15213: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 15214: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 15215: if (ref($settings) eq 'HASH') {
15216: %existing = %{$settings};
15217: }
15218: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 15219: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 15220: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 15221: return <<"END";
15222:
15223: <script type="text/javascript">
15224: // <![CDATA[
15225:
1.160.6.7 raeburn 15226: currBalancers = new Array('$balancers');
15227:
15228: function toggleTargets(balnum) {
15229: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
15230: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
15231: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
15232: var prevbalancer = prevhostitem.value;
15233: var baltotal = document.getElementById('loadbalancing_total').value;
15234: prevhostitem.value = balancer;
15235: if (prevbalancer != '') {
15236: var prevIdx = currBalancers.indexOf(prevbalancer);
15237: if (prevIdx != -1) {
15238: currBalancers.splice(prevIdx,1);
15239: }
15240: }
1.150 raeburn 15241: if (balancer == '') {
1.160.6.7 raeburn 15242: hideSpares(balnum);
1.150 raeburn 15243: } else {
1.160.6.7 raeburn 15244: var currIdx = currBalancers.indexOf(balancer);
15245: if (currIdx == -1) {
15246: currBalancers.push(balancer);
15247: }
1.150 raeburn 15248: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 15249: var ishomedom = homedoms[lonhostitem.selectedIndex];
15250: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 15251: }
1.160.6.7 raeburn 15252: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 15253: return;
15254: }
15255:
1.160.6.7 raeburn 15256: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 15257: var alltargets = new Array('$alltargets');
15258: var insttypes = new Array('$allinsttypes');
1.151 raeburn 15259: var offloadtypes = new Array('primary','default');
15260:
1.160.6.7 raeburn 15261: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
15262: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 15263:
1.151 raeburn 15264: for (var i=0; i<offloadtypes.length; i++) {
15265: var count = 0;
15266: for (var j=0; j<alltargets.length; j++) {
15267: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 15268: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
15269: item.value = alltargets[j];
15270: item.style.textAlign='left';
15271: item.style.textFace='normal';
15272: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
15273: if (currBalancers.indexOf(alltargets[j]) == -1) {
15274: item.disabled = '';
15275: } else {
15276: item.disabled = 'disabled';
15277: item.checked = false;
15278: }
1.151 raeburn 15279: count ++;
15280: }
1.150 raeburn 15281: }
15282: }
1.151 raeburn 15283: for (var k=0; k<insttypes.length; k++) {
15284: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 15285: if (ishomedom == 1) {
1.160.6.7 raeburn 15286: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
15287: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 15288: } else {
1.160.6.7 raeburn 15289: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
15290: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 15291: }
15292: } else {
1.160.6.7 raeburn 15293: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
15294: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 15295: }
1.151 raeburn 15296: if ((insttypes[k] != '_LC_external') &&
15297: ((insttypes[k] != '_LC_internetdom') ||
15298: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 15299: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
15300: item.options.length = 0;
15301: item.options[0] = new Option("","",true,true);
15302: var idx = 0;
1.151 raeburn 15303: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 15304: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
15305: idx ++;
15306: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 15307: }
15308: }
15309: }
15310: }
15311: return;
15312: }
15313:
1.160.6.7 raeburn 15314: function hideSpares(balnum) {
1.150 raeburn 15315: var alltargets = new Array('$alltargets');
15316: var insttypes = new Array('$allinsttypes');
15317: var offloadtypes = new Array('primary','default');
15318:
1.160.6.7 raeburn 15319: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
15320: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 15321:
15322: var total = alltargets.length - 1;
15323: for (var i=0; i<offloadtypes; i++) {
15324: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 15325: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
15326: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
15327: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 15328: }
1.150 raeburn 15329: }
15330: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 15331: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
15332: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 15333: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 15334: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
15335: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 15336: }
15337: }
15338: return;
15339: }
15340:
1.160.6.7 raeburn 15341: function checkOffloads(item,balnum,type) {
1.150 raeburn 15342: var alltargets = new Array('$alltargets');
15343: var offloadtypes = new Array('primary','default');
15344: if (item.checked) {
15345: var total = alltargets.length - 1;
15346: var other;
15347: if (type == offloadtypes[0]) {
1.151 raeburn 15348: other = offloadtypes[1];
1.150 raeburn 15349: } else {
1.151 raeburn 15350: other = offloadtypes[0];
1.150 raeburn 15351: }
15352: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 15353: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 15354: if (server == item.value) {
1.160.6.7 raeburn 15355: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
15356: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 15357: }
15358: }
15359: }
15360: }
15361: return;
15362: }
15363:
1.160.6.7 raeburn 15364: function singleServerToggle(balnum,type) {
15365: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 15366: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 15367: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
15368: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 15369:
15370: } else {
1.160.6.7 raeburn 15371: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
15372: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 15373: }
15374: return;
15375: }
15376:
1.160.6.7 raeburn 15377: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 15378: if (type == '_LC_external') {
1.160.6.26 raeburn 15379: return;
1.150 raeburn 15380: }
1.160.6.7 raeburn 15381: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 15382: for (var i=0; i<typesRules.length; i++) {
15383: if (formname.elements[typesRules[i]].checked) {
15384: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 15385: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
15386: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 15387: } else {
1.160.6.7 raeburn 15388: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
15389: }
15390: }
15391: }
15392: return;
15393: }
15394:
15395: function balancerDeleteChange(balnum) {
15396: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
15397: var baltotal = document.getElementById('loadbalancing_total').value;
15398: var addtarget;
15399: var removetarget;
15400: var action = 'delete';
15401: if (document.getElementById('loadbalancing_delete_'+balnum)) {
15402: var lonhost = hostitem.value;
15403: var currIdx = currBalancers.indexOf(lonhost);
15404: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
15405: if (currIdx != -1) {
15406: currBalancers.splice(currIdx,1);
15407: }
15408: addtarget = lonhost;
15409: } else {
15410: if (currIdx == -1) {
15411: currBalancers.push(lonhost);
15412: }
15413: removetarget = lonhost;
15414: action = 'undelete';
15415: }
15416: balancerChange(balnum,baltotal,action,addtarget,removetarget);
15417: }
15418: return;
15419: }
15420:
15421: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
15422: if (baltotal > 1) {
15423: var offloadtypes = new Array('primary','default');
15424: var alltargets = new Array('$alltargets');
15425: var insttypes = new Array('$allinsttypes');
15426: for (var i=0; i<baltotal; i++) {
15427: if (i != balnum) {
15428: for (var j=0; j<offloadtypes.length; j++) {
15429: var total = alltargets.length - 1;
15430: for (var k=0; k<total; k++) {
15431: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
15432: var server = serveritem.value;
15433: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
15434: if (server == addtarget) {
15435: serveritem.disabled = '';
15436: }
15437: }
15438: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
15439: if (server == removetarget) {
15440: serveritem.disabled = 'disabled';
15441: serveritem.checked = false;
15442: }
15443: }
15444: }
15445: }
15446: for (var j=0; j<insttypes.length; j++) {
15447: if (insttypes[j] != '_LC_external') {
15448: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
15449: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
15450: var currSel = singleserver.selectedIndex;
15451: var currVal = singleserver.options[currSel].value;
15452: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
15453: var numoptions = singleserver.options.length;
15454: var needsnew = 1;
15455: for (var k=0; k<numoptions; k++) {
15456: if (singleserver.options[k] == addtarget) {
15457: needsnew = 0;
15458: break;
15459: }
15460: }
15461: if (needsnew == 1) {
15462: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
15463: }
15464: }
15465: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
15466: singleserver.options.length = 0;
15467: if ((currVal) && (currVal != removetarget)) {
15468: singleserver.options[0] = new Option("","",false,false);
15469: } else {
15470: singleserver.options[0] = new Option("","",true,true);
15471: }
15472: var idx = 0;
15473: for (var m=0; m<alltargets.length; m++) {
15474: if (currBalancers.indexOf(alltargets[m]) == -1) {
15475: idx ++;
15476: if (currVal == alltargets[m]) {
15477: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
15478: } else {
15479: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
15480: }
15481: }
15482: }
15483: }
15484: }
15485: }
15486: }
1.150 raeburn 15487: }
15488: }
15489: }
15490: return;
15491: }
15492:
1.152 raeburn 15493: // ]]>
15494: </script>
15495:
15496: END
15497: }
15498:
15499: sub new_spares_js {
15500: my @sparestypes = ('primary','default');
15501: my $types = join("','",@sparestypes);
15502: my $select = &mt('Select');
15503: return <<"END";
15504:
15505: <script type="text/javascript">
15506: // <![CDATA[
15507:
15508: function updateNewSpares(formname,lonhost) {
15509: var types = new Array('$types');
15510: var include = new Array();
15511: var exclude = new Array();
15512: for (var i=0; i<types.length; i++) {
15513: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
15514: for (var j=0; j<spareboxes.length; j++) {
15515: if (formname.elements[spareboxes[j]].checked) {
15516: exclude.push(formname.elements[spareboxes[j]].value);
15517: } else {
15518: include.push(formname.elements[spareboxes[j]].value);
15519: }
15520: }
15521: }
15522: for (var i=0; i<types.length; i++) {
15523: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
15524: var selIdx = newSpare.selectedIndex;
15525: var currnew = newSpare.options[selIdx].value;
15526: var okSpares = new Array();
15527: for (var j=0; j<newSpare.options.length; j++) {
15528: var possible = newSpare.options[j].value;
15529: if (possible != '') {
15530: if (exclude.indexOf(possible) == -1) {
15531: okSpares.push(possible);
15532: } else {
15533: if (currnew == possible) {
15534: selIdx = 0;
15535: }
15536: }
15537: }
15538: }
15539: for (var k=0; k<include.length; k++) {
15540: if (okSpares.indexOf(include[k]) == -1) {
15541: okSpares.push(include[k]);
15542: }
15543: }
15544: okSpares.sort();
15545: newSpare.options.length = 0;
15546: if (selIdx == 0) {
15547: newSpare.options[0] = new Option("$select","",true,true);
15548: } else {
15549: newSpare.options[0] = new Option("$select","",false,false);
15550: }
15551: for (var m=0; m<okSpares.length; m++) {
15552: var idx = m+1;
15553: var selThis = 0;
15554: if (selIdx != 0) {
15555: if (okSpares[m] == currnew) {
15556: selThis = 1;
15557: }
15558: }
15559: if (selThis == 1) {
15560: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
15561: } else {
15562: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
15563: }
15564: }
15565: }
15566: return;
15567: }
15568:
15569: function checkNewSpares(lonhost,type) {
15570: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
15571: var chosen = newSpare.options[newSpare.selectedIndex].value;
15572: if (chosen != '') {
15573: var othertype;
15574: var othernewSpare;
15575: if (type == 'primary') {
15576: othernewSpare = document.getElementById('newspare_default_'+lonhost);
15577: }
15578: if (type == 'default') {
15579: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
15580: }
15581: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
15582: othernewSpare.selectedIndex = 0;
15583: }
15584: }
15585: return;
15586: }
15587:
15588: // ]]>
15589: </script>
15590:
15591: END
15592:
15593: }
15594:
15595: sub common_domprefs_js {
15596: return <<"END";
15597:
15598: <script type="text/javascript">
15599: // <![CDATA[
15600:
1.150 raeburn 15601: function getIndicesByName(formname,item) {
1.152 raeburn 15602: var group = new Array();
1.150 raeburn 15603: for (var i=0;i<formname.elements.length;i++) {
15604: if (formname.elements[i].name == item) {
1.152 raeburn 15605: group.push(formname.elements[i].id);
1.150 raeburn 15606: }
15607: }
1.152 raeburn 15608: return group;
1.150 raeburn 15609: }
15610:
15611: // ]]>
15612: </script>
15613:
15614: END
1.152 raeburn 15615:
1.150 raeburn 15616: }
15617:
1.160.6.5 raeburn 15618: sub recaptcha_js {
15619: my %lt = &captcha_phrases();
15620: return <<"END";
15621:
15622: <script type="text/javascript">
15623: // <![CDATA[
15624:
15625: function updateCaptcha(caller,context) {
15626: var privitem;
15627: var pubitem;
15628: var privtext;
15629: var pubtext;
1.160.6.69 raeburn 15630: var versionitem;
15631: var versiontext;
1.160.6.5 raeburn 15632: if (document.getElementById(context+'_recaptchapub')) {
15633: pubitem = document.getElementById(context+'_recaptchapub');
15634: } else {
15635: return;
15636: }
15637: if (document.getElementById(context+'_recaptchapriv')) {
15638: privitem = document.getElementById(context+'_recaptchapriv');
15639: } else {
15640: return;
15641: }
15642: if (document.getElementById(context+'_recaptchapubtxt')) {
15643: pubtext = document.getElementById(context+'_recaptchapubtxt');
15644: } else {
15645: return;
15646: }
15647: if (document.getElementById(context+'_recaptchaprivtxt')) {
15648: privtext = document.getElementById(context+'_recaptchaprivtxt');
15649: } else {
15650: return;
15651: }
1.160.6.69 raeburn 15652: if (document.getElementById(context+'_recaptchaversion')) {
15653: versionitem = document.getElementById(context+'_recaptchaversion');
15654: } else {
15655: return;
15656: }
15657: if (document.getElementById(context+'_recaptchavertxt')) {
15658: versiontext = document.getElementById(context+'_recaptchavertxt');
15659: } else {
15660: return;
15661: }
1.160.6.5 raeburn 15662: if (caller.checked) {
15663: if (caller.value == 'recaptcha') {
15664: pubitem.type = 'text';
15665: privitem.type = 'text';
15666: pubitem.size = '40';
15667: privitem.size = '40';
15668: pubtext.innerHTML = "$lt{'pub'}";
15669: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 15670: versionitem.type = 'text';
15671: versionitem.size = '3';
15672: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 15673: } else {
15674: pubitem.type = 'hidden';
15675: privitem.type = 'hidden';
1.160.6.69 raeburn 15676: versionitem.type = 'hidden';
1.160.6.5 raeburn 15677: pubtext.innerHTML = '';
15678: privtext.innerHTML = '';
1.160.6.69 raeburn 15679: versiontext.innerHTML = '';
1.160.6.5 raeburn 15680: }
15681: }
15682: return;
15683: }
15684:
15685: // ]]>
15686: </script>
15687:
15688: END
15689:
15690: }
15691:
1.160.6.40 raeburn 15692: sub toggle_display_js {
1.160.6.16 raeburn 15693: return <<"END";
15694:
15695: <script type="text/javascript">
15696: // <![CDATA[
15697:
1.160.6.40 raeburn 15698: function toggleDisplay(domForm,caller) {
15699: if (document.getElementById(caller)) {
15700: var divitem = document.getElementById(caller);
15701: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 15702: var checkval = 1;
15703: var dispval = 'block';
1.160.6.93 raeburn 15704: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 15705: if (caller == 'emailoptions') {
15706: optionsElement = domForm.cancreate_email;
15707: }
1.160.6.57 raeburn 15708: if (caller == 'studentsubmission') {
15709: optionsElement = domForm.postsubmit;
15710: }
1.160.6.64 raeburn 15711: if (caller == 'cloneinstcode') {
15712: optionsElement = domForm.canclone;
15713: checkval = 'instcode';
15714: }
1.160.6.93 raeburn 15715: if (selfcreateRegExp.test(caller)) {
15716: optionsElement = domForm.elements[caller];
15717: checkval = 'other';
15718: dispval = 'inline'
15719: }
1.160.6.40 raeburn 15720: if (optionsElement.length) {
1.160.6.16 raeburn 15721: var currval;
1.160.6.40 raeburn 15722: for (var i=0; i<optionsElement.length; i++) {
15723: if (optionsElement[i].checked) {
15724: currval = optionsElement[i].value;
1.160.6.16 raeburn 15725: }
15726: }
1.160.6.64 raeburn 15727: if (currval == checkval) {
15728: divitem.style.display = dispval;
1.160.6.16 raeburn 15729: } else {
1.160.6.40 raeburn 15730: divitem.style.display = 'none';
1.160.6.16 raeburn 15731: }
15732: }
15733: }
15734: return;
15735: }
15736:
15737: // ]]>
15738: </script>
15739:
15740: END
15741:
15742: }
15743:
1.160.6.5 raeburn 15744: sub captcha_phrases {
15745: return &Apache::lonlocal::texthash (
15746: priv => 'Private key',
15747: pub => 'Public key',
15748: original => 'original (CAPTCHA)',
15749: recaptcha => 'successor (ReCAPTCHA)',
15750: notused => 'unused',
1.160.6.69 raeburn 15751: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 15752: );
15753: }
15754:
1.160.6.24 raeburn 15755: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 15756: my ($dom,$cachekeys) = @_;
15757: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 15758: my %servers = &Apache::lonnet::internet_dom_servers($dom);
15759: my %thismachine;
15760: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.98 raeburn 15761: my @posscached = ('domainconfig','domdefaults','usersessions',
15762: 'directorysrch','passwdconf','cats');
1.160.6.61 raeburn 15763: if (keys(%servers)) {
1.160.6.24 raeburn 15764: foreach my $server (keys(%servers)) {
15765: next if ($thismachine{$server});
1.160.6.27 raeburn 15766: my @cached;
15767: foreach my $name (@posscached) {
15768: if ($cachekeys->{$name}) {
15769: push(@cached,&escape($name).':'.&escape($dom));
15770: }
15771: }
15772: if (@cached) {
15773: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
15774: }
1.160.6.24 raeburn 15775: }
15776: }
15777: return;
15778: }
15779:
1.3 raeburn 15780: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>