Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.100
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.100! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.99 2019/08/25 14:35:21 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: }
2971: } else {
2972: foreach my $type (@mailings) {
2973: $css_class = $rownum%2?' class="LC_odd_row"':'';
2974: $datatable .= '<tr'.$css_class.'>'.
2975: '<td><span class="LC_nobreak">'.
2976: $titles->{$type}.': </span></td>'.
2977: '<td class="LC_left_item">';
2978: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2979: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
2980: }
2981: $datatable .= '<span class="LC_nobreak">';
2982: foreach my $item (@contacts) {
2983: $datatable .= '<label>'.
2984: '<input type="checkbox" name="'.$type.'"'.
2985: $checked{$type}{$item}.
2986: ' value="'.$item.'" />'.$short_titles->{$item}.
2987: '</label> ';
2988: }
2989: $datatable .= '</span><br />'.&mt('Others').': '.
2990: '<input type="text" name="'.$type.'_others" '.
2991: 'value="'.$otheremails{$type}.'" />';
2992: my %locchecked;
2993: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2994: foreach my $loc ('s','b') {
2995: if ($includeloc{$type} eq $loc) {
2996: $locchecked{$loc} = ' checked="checked"';
2997: last;
2998: }
2999: }
3000: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3001: '<input type="text" name="'.$type.'_bcc" '.
3002: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3003: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3004: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 3005: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 3006: '<span class="LC_nobreak">'.&mt('Location:').' '.
3007: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3008: (' 'x2).
3009: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3010: '</span></fieldset>';
3011: }
3012: $datatable .= '</td></tr>'."\n";
3013: $rownum ++;
3014: }
1.28 raeburn 3015: }
1.160.6.78 raeburn 3016: if ($position eq 'middle') {
3017: my %choices;
3018: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
3019: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3020: &mt('LON-CAPA core group - MSU'),600,500));
3021: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3022: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3023: &mt('LON-CAPA core group - MSU'),600,500));
3024: my @toggles = ('reporterrors','reportupdates');
3025: my %defaultchecked = ('reporterrors' => 'on',
3026: 'reportupdates' => 'on');
3027: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3028: \%choices,$rownum);
3029: $datatable .= $reports;
3030: } elsif ($position eq 'bottom') {
1.69 raeburn 3031: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 3032: $datatable .= '<tr'.$css_class.'>'.
1.160.6.78 raeburn 3033: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3034: &mt('(e-mail, subject, and description always shown)').
3035: '</td><td class="LC_left_item">';
3036: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3037: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3038: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3039: foreach my $field (@{$fields}) {
3040: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3041: if (($field eq 'screenshot') || ($field eq 'cc')) {
3042: $datatable .= ' '.&mt('(logged-in users)');
3043: }
3044: $datatable .='</td><td>';
3045: my $clickaction;
3046: if ($field eq 'screenshot') {
3047: $clickaction = ' onclick="screenshotSize(this);"';
3048: }
3049: if (ref($possoptions->{$field}) eq 'ARRAY') {
3050: foreach my $option (@{$possoptions->{$field}}) {
3051: my $checked;
3052: if ($currfield{$field} eq $option) {
3053: $checked = ' checked="checked"';
3054: }
3055: $datatable .= '<span class="LC_nobreak"><label>'.
3056: '<input type="radio" name="helpform_'.$field.'" '.
3057: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3058: '</label></span>'.(' 'x2);
3059: }
3060: }
3061: if ($field eq 'screenshot') {
3062: my $display;
3063: if ($currfield{$field} eq 'no') {
3064: $display = ' style="display:none"';
3065: }
1.160.6.87 raeburn 3066: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.160.6.78 raeburn 3067: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3068: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3069: }
3070: $datatable .= '</td></tr>';
3071: }
3072: $datatable .= '</table>';
1.134 raeburn 3073: }
3074: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 3075: $rownum ++;
1.28 raeburn 3076: }
1.30 raeburn 3077: $$rowtotal += $rownum;
1.28 raeburn 3078: return $datatable;
3079: }
3080:
1.160.6.78 raeburn 3081: sub contacts_javascript {
3082: return <<"ENDSCRIPT";
3083:
3084: <script type="text/javascript">
3085: // <![CDATA[
3086:
3087: function screenshotSize(field) {
3088: if (document.getElementById('help_screenshotsize')) {
3089: if (field.value == 'no') {
3090: document.getElementById('help_screenshotsize').style.display="none";
3091: } else {
3092: document.getElementById('help_screenshotsize').style.display="";
3093: }
3094: }
3095: return;
3096: }
3097:
3098: // ]]>
3099: </script>
3100:
3101: ENDSCRIPT
3102: }
3103:
1.118 jms 3104: sub print_helpsettings {
1.160.6.73 raeburn 3105: my ($position,$dom,$settings,$rowtotal) = @_;
3106: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 3107: my $formname = 'display';
1.160.6.5 raeburn 3108: my ($datatable,$itemcount);
1.160.6.73 raeburn 3109: if ($position eq 'top') {
3110: $itemcount = 1;
3111: my (%choices,%defaultchecked,@toggles);
3112: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3113: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3114: &mt('LON-CAPA bug tracker'),600,500));
3115: %defaultchecked = ('submitbugs' => 'on');
3116: @toggles = ('submitbugs');
3117: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3118: \%choices,$itemcount);
3119: $$rowtotal ++;
3120: } else {
3121: my $css_class;
3122: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 3123: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 3124: if (ref($settings) eq 'HASH') {
3125: if (ref($settings->{'adhoc'}) eq 'HASH') {
3126: %current = %{$settings->{'adhoc'}};
3127: }
1.160.6.77 raeburn 3128: }
3129: my $count = 0;
3130: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 3131: if ($key=~/^rolesdef\_(\w+)$/) {
3132: my $rolename = $1;
1.160.6.77 raeburn 3133: my (%privs,$order);
1.160.6.73 raeburn 3134: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3135: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 3136: if (ref($current{$rolename}) eq 'HASH') {
3137: $order = $current{$rolename}{'order'};
3138: }
3139: if ($order eq '') {
3140: $order = $count;
3141: }
3142: $ordered{$order} = $rolename;
3143: $count++;
1.160.6.73 raeburn 3144: }
3145: }
1.160.6.77 raeburn 3146: my $maxnum = scalar(keys(%ordered));
3147: my @roles_by_num = ();
3148: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3149: push(@roles_by_num,$item);
3150: }
3151: my $context = 'domprefs';
3152: my $crstype = 'Course';
3153: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 3154: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 3155: my ($numstatustypes,@jsarray);
3156: if (ref($types) eq 'ARRAY') {
3157: if (@{$types} > 0) {
3158: $numstatustypes = scalar(@{$types});
3159: push(@accesstypes,'status');
3160: @jsarray = ('bystatus');
3161: }
3162: }
1.160.6.86 raeburn 3163: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 3164: if (keys(%domhelpdesk)) {
3165: push(@accesstypes,('inc','exc'));
3166: push(@jsarray,('notinc','notexc'));
3167: }
3168: my $hiddenstr = join("','",@jsarray);
3169: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 3170: my $context = 'domprefs';
3171: my $crstype = 'Course';
1.160.6.77 raeburn 3172: my $prefix = 'helproles_';
3173: my $add_class = 'LC_hidden';
3174: foreach my $num (@roles_by_num) {
3175: my $role = $ordered{$num};
3176: my ($desc,$access,@statuses);
3177: if (ref($current{$role}) eq 'HASH') {
3178: $desc = $current{$role}{'desc'};
3179: $access = $current{$role}{'access'};
3180: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3181: @statuses = @{$current{$role}{'insttypes'}};
3182: }
3183: }
3184: if ($desc eq '') {
3185: $desc = $role;
3186: }
3187: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 3188: my %full=();
3189: my %levels= (
3190: course => {},
3191: domain => {},
3192: system => {},
3193: );
3194: my %levelscurrent=(
3195: course => {},
3196: domain => {},
3197: system => {},
3198: );
3199: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3200: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3201: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 3202: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3203: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3204: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3205: for (my $k=0; $k<=$maxnum; $k++) {
3206: my $vpos = $k+1;
3207: my $selstr;
3208: if ($k == $num) {
3209: $selstr = ' selected="selected" ';
3210: }
3211: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3212: }
3213: $datatable .= '</select>'.(' 'x2).
3214: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3215: '</td>'.
3216: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3217: &mt('Name shown to users:').
3218: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3219: '</fieldset>'.
3220: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3221: $othertitle,$usertypes,$types,\%domhelpdesk).
3222: '<fieldset>'.
3223: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 3224: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 3225: \%levelscurrent,$identifier,
3226: 'LC_hidden',$prefix.$num.'_privs').
3227: '</fieldset></td>';
1.160.6.73 raeburn 3228: $itemcount ++;
3229: }
3230: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3231: my $newcust = 'custhelp'.$count;
3232: my (%privs,%levelscurrent);
3233: my %full=();
3234: my %levels= (
3235: course => {},
3236: domain => {},
3237: system => {},
3238: );
3239: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3240: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 3241: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3242: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3243: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3244: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3245: for (my $k=0; $k<$maxnum+1; $k++) {
3246: my $vpos = $k+1;
3247: my $selstr;
3248: if ($k == $maxnum) {
3249: $selstr = ' selected="selected" ';
3250: }
3251: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3252: }
3253: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 3254: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3255: '</label></span></td>'.
1.160.6.77 raeburn 3256: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3257: '<span class="LC_nobreak">'.
3258: &mt('Internal name:').
3259: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3260: '</span>'.(' 'x4).
3261: '<span class="LC_nobreak">'.
3262: &mt('Name shown to users:').
3263: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3264: '</span></fieldset>'.
3265: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3266: $usertypes,$types,\%domhelpdesk).
3267: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 3268: &Apache::lonuserutils::custom_role_header($context,$crstype,
3269: \@templateroles,$newcust).
3270: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3271: \%levelscurrent,$newcust).
1.160.6.87 raeburn 3272: '</fieldset>'.
3273: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
3274: '</td></tr>';
1.160.6.73 raeburn 3275: $count ++;
3276: $$rowtotal += $count;
3277: }
1.160.6.5 raeburn 3278: return $datatable;
1.121 raeburn 3279: }
3280:
1.160.6.77 raeburn 3281: sub adhocbutton {
3282: my ($prefix,$num,$field,$visibility) = @_;
3283: my %lt = &Apache::lonlocal::texthash(
3284: show => 'Show details',
3285: hide => 'Hide details',
3286: );
3287: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3288: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3289: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3290: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3291: }
3292:
3293: sub helpsettings_javascript {
3294: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3295: return unless(ref($roles_by_num) eq 'ARRAY');
3296: my %html_js_lt = &Apache::lonlocal::texthash(
3297: show => 'Show details',
3298: hide => 'Hide details',
3299: );
3300: &html_escape(\%html_js_lt);
3301: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3302: return <<"ENDSCRIPT";
3303: <script type="text/javascript">
3304: // <![CDATA[
3305:
3306: function reorderHelpRoles(form,item) {
3307: var changedVal;
3308: $jstext
3309: var newpos = 'helproles_${total}_pos';
3310: var maxh = 1 + $total;
3311: var current = new Array();
3312: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3313: if (item == newpos) {
3314: changedVal = newitemVal;
3315: } else {
3316: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3317: current[newitemVal] = newpos;
3318: }
3319: for (var i=0; i<helproles.length; i++) {
3320: var elementName = 'helproles_'+helproles[i]+'_pos';
3321: if (elementName != item) {
3322: if (form.elements[elementName]) {
3323: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3324: current[currVal] = elementName;
3325: }
3326: }
3327: }
3328: var oldVal;
3329: for (var j=0; j<maxh; j++) {
3330: if (current[j] == undefined) {
3331: oldVal = j;
3332: }
3333: }
3334: if (oldVal < changedVal) {
3335: for (var k=oldVal+1; k<=changedVal ; k++) {
3336: var elementName = current[k];
3337: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3338: }
3339: } else {
3340: for (var k=changedVal; k<oldVal; k++) {
3341: var elementName = current[k];
3342: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3343: }
3344: }
3345: return;
3346: }
3347:
3348: function helpdeskAccess(num) {
3349: var curraccess = null;
3350: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3351: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3352: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3353: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3354: }
3355: }
3356: }
3357: var shown = Array();
3358: var hidden = Array();
3359: if (curraccess == 'none') {
3360: hidden = Array('$hiddenstr');
3361: } else {
3362: if (curraccess == 'status') {
3363: shown = Array('bystatus');
3364: hidden = Array('notinc','notexc');
3365: } else {
3366: if (curraccess == 'exc') {
3367: shown = Array('notexc');
3368: hidden = Array('notinc','bystatus');
3369: }
3370: if (curraccess == 'inc') {
3371: shown = Array('notinc');
3372: hidden = Array('notexc','bystatus');
3373: }
1.160.6.79 raeburn 3374: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 3375: hidden = Array('notinc','notexc','bystatus');
3376: }
3377: }
3378: }
3379: if (hidden.length > 0) {
3380: for (var i=0; i<hidden.length; i++) {
3381: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3382: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3383: }
3384: }
3385: }
3386: if (shown.length > 0) {
3387: for (var i=0; i<shown.length; i++) {
3388: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3389: if (shown[i] == 'privs') {
3390: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3391: } else {
3392: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3393: }
3394: }
3395: }
3396: }
3397: return;
3398: }
3399:
3400: function toggleHelpdeskItem(num,field) {
3401: if (document.getElementById('helproles_'+num+'_'+field)) {
3402: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
3403: document.getElementById('helproles_'+num+'_'+field).className =
3404: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3405: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3406: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3407: }
3408: } else {
3409: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3410: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3411: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3412: }
3413: }
3414: }
3415: return;
3416: }
3417:
3418: // ]]>
3419: </script>
3420:
3421: ENDSCRIPT
3422: }
3423:
3424: sub helpdeskroles_access {
3425: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3426: $usertypes,$types,$domhelpdesk) = @_;
3427: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3428: my %lt = &Apache::lonlocal::texthash(
3429: 'rou' => 'Role usage',
3430: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 3431: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3432: 'dh' => 'All with domain helpdesk role',
3433: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 3434: 'none' => 'None',
3435: 'status' => 'Determined based on institutional status',
3436: 'inc' => 'Include all, but exclude specific personnel',
3437: 'exc' => 'Exclude all, but include specific personnel',
3438: );
3439: my %usecheck = (
3440: all => ' checked="checked"',
3441: );
3442: my %displaydiv = (
3443: status => 'none',
3444: inc => 'none',
3445: exc => 'none',
3446: priv => 'block',
3447: );
3448: my $output;
3449: if (ref($current) eq 'HASH') {
3450: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3451: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3452: $usecheck{$current->{access}} = $usecheck{'all'};
3453: delete($usecheck{'all'});
3454: if ($current->{access} =~ /^(status|inc|exc)$/) {
3455: my $access = $1;
3456: $displaydiv{$access} = 'inline';
3457: } elsif ($current->{access} eq 'none') {
3458: $displaydiv{'priv'} = 'none';
3459: }
3460: }
3461: }
3462: }
3463: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3464: '<p>'.$lt{'whi'}.'</p>';
3465: foreach my $access (@{$accesstypes}) {
3466: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3467: ' onclick="helpdeskAccess('."'$num'".');" />'.
3468: $lt{$access}.'</label>';
3469: if ($access eq 'status') {
3470: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3471: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3472: $othertitle,$usertypes,$types).
3473: '</div>';
3474: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3475: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3476: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3477: '</div>';
3478: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3479: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3480: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3481: '</div>';
3482: }
3483: $output .= '</p>';
3484: }
3485: $output .= '</fieldset>';
3486: return $output;
3487: }
3488:
1.121 raeburn 3489: sub radiobutton_prefs {
1.160.6.16 raeburn 3490: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 3491: $additional,$align) = @_;
1.121 raeburn 3492: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3493: (ref($choices) eq 'HASH'));
3494:
3495: my (%checkedon,%checkedoff,$datatable,$css_class);
3496:
3497: foreach my $item (@{$toggles}) {
3498: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3499: $checkedon{$item} = ' checked="checked" ';
3500: $checkedoff{$item} = ' ';
1.121 raeburn 3501: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3502: $checkedoff{$item} = ' checked="checked" ';
3503: $checkedon{$item} = ' ';
3504: }
3505: }
3506: if (ref($settings) eq 'HASH') {
1.121 raeburn 3507: foreach my $item (@{$toggles}) {
1.118 jms 3508: if ($settings->{$item} eq '1') {
3509: $checkedon{$item} = ' checked="checked" ';
3510: $checkedoff{$item} = ' ';
3511: } elsif ($settings->{$item} eq '0') {
3512: $checkedoff{$item} = ' checked="checked" ';
3513: $checkedon{$item} = ' ';
3514: }
3515: }
1.121 raeburn 3516: }
1.160.6.16 raeburn 3517: if ($onclick) {
3518: $onclick = ' onclick="'.$onclick.'"';
3519: }
1.121 raeburn 3520: foreach my $item (@{$toggles}) {
1.118 jms 3521: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3522: $datatable .=
1.160.6.16 raeburn 3523: '<tr'.$css_class.'><td valign="top">'.
3524: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 3525: '</span></td>';
3526: if ($align eq 'left') {
3527: $datatable .= '<td class="LC_left_item">';
3528: } else {
3529: $datatable .= '<td class="LC_right_item">';
3530: }
3531: $datatable .=
3532: '<span class="LC_nobreak">'.
1.118 jms 3533: '<label><input type="radio" name="'.
1.160.6.16 raeburn 3534: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3535: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 3536: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3537: '</span>'.$additional.
3538: '</td>'.
1.118 jms 3539: '</tr>';
3540: $itemcount ++;
1.121 raeburn 3541: }
3542: return ($datatable,$itemcount);
3543: }
3544:
3545: sub print_coursedefaults {
1.139 raeburn 3546: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3547: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3548: my $itemcount = 1;
1.160.6.16 raeburn 3549: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 3550: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 3551: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3552: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 3553: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3554: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.90 raeburn 3555: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 3556: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 3557: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 3558: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 3559: );
1.160.6.21 raeburn 3560: my %staticdefaults = (
3561: anonsurvey_threshold => 10,
3562: uploadquota => 500,
1.160.6.57 raeburn 3563: postsubmit => 60,
1.160.6.70 raeburn 3564: mysqltables => 172800,
1.160.6.21 raeburn 3565: );
1.139 raeburn 3566: if ($position eq 'top') {
1.160.6.57 raeburn 3567: %defaultchecked = (
3568: 'uselcmath' => 'on',
3569: 'usejsme' => 'on',
1.160.6.64 raeburn 3570: 'canclone' => 'none',
1.160.6.57 raeburn 3571: );
3572: @toggles = ('uselcmath','usejsme');
1.160.6.90 raeburn 3573: my $deftex = $Apache::lonnet::deftex;
3574: if (ref($settings) eq 'HASH') {
3575: if ($settings->{'texengine'}) {
3576: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
3577: $deftex = $settings->{'texengine'};
3578: }
3579: }
3580: }
3581: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3582: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
3583: '<span class="LC_nobreak">'.$choices{'texengine'}.
3584: '</span></td><td class="LC_right_item">'.
3585: '<select name="texengine">'."\n";
3586: my %texoptions = (
3587: MathJax => 'MathJax',
3588: mimetex => &mt('Convert to Images'),
3589: tth => &mt('TeX to HTML'),
3590: );
3591: foreach my $renderer ('MathJax','mimetex','tth') {
3592: my $selected = '';
3593: if ($renderer eq $deftex) {
3594: $selected = ' selected="selected"';
3595: }
3596: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
3597: }
3598: $mathdisp .= '</select></td></tr>'."\n";
3599: $itemcount ++;
1.139 raeburn 3600: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3601: \%choices,$itemcount);
1.160.6.90 raeburn 3602: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 3603: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3604: $datatable .=
3605: '<tr'.$css_class.'><td valign="top">'.
3606: '<span class="LC_nobreak">'.$choices{'canclone'}.
3607: '</span></td><td class="LC_left_item">';
3608: my $currcanclone = 'none';
3609: my $onclick;
3610: my @cloneoptions = ('none','domain');
3611: my %clonetitles = (
3612: none => 'No additional course requesters',
3613: domain => "Any course requester in course's domain",
3614: instcode => 'Course requests for official courses ...',
3615: );
3616: my (%codedefaults,@code_order,@posscodes);
3617: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3618: \@code_order) eq 'ok') {
3619: if (@code_order > 0) {
3620: push(@cloneoptions,'instcode');
3621: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3622: }
3623: }
3624: if (ref($settings) eq 'HASH') {
3625: if ($settings->{'canclone'}) {
3626: if (ref($settings->{'canclone'}) eq 'HASH') {
3627: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3628: if (@code_order > 0) {
3629: $currcanclone = 'instcode';
3630: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3631: }
3632: }
3633: } elsif ($settings->{'canclone'} eq 'domain') {
3634: $currcanclone = $settings->{'canclone'};
3635: }
3636: }
3637: }
3638: foreach my $option (@cloneoptions) {
3639: my ($checked,$additional);
3640: if ($currcanclone eq $option) {
3641: $checked = ' checked="checked"';
3642: }
3643: if ($option eq 'instcode') {
3644: if (@code_order) {
3645: my $show = 'none';
3646: if ($checked) {
3647: $show = 'block';
3648: }
3649: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3650: &mt('Institutional codes for new and cloned course have identical:').
3651: '<br />';
3652: foreach my $item (@code_order) {
3653: my $codechk;
3654: if ($checked) {
3655: if (grep(/^\Q$item\E$/,@posscodes)) {
3656: $codechk = ' checked="checked"';
3657: }
3658: }
3659: $additional .= '<label>'.
3660: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3661: $item.'</label>';
3662: }
3663: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3664: }
3665: }
3666: $datatable .=
3667: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3668: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3669: '</label> '.$additional.'</span><br />';
3670: }
3671: $datatable .= '</td>'.
3672: '</tr>';
3673: $itemcount ++;
1.139 raeburn 3674: } else {
3675: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 3676: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 3677: my $currusecredits = 0;
1.160.6.57 raeburn 3678: my $postsubmitclient = 1;
1.160.6.30 raeburn 3679: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 3680: if (ref($settings) eq 'HASH') {
3681: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 3682: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3683: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3684: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3685: }
3686: }
1.160.6.16 raeburn 3687: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 3688: foreach my $type (@types) {
3689: next if ($type eq 'community');
3690: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3691: if ($defcredits{$type} ne '') {
3692: $currusecredits = 1;
3693: }
3694: }
3695: }
3696: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3697: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3698: $postsubmitclient = 0;
3699: foreach my $type (@types) {
3700: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3701: }
3702: } else {
3703: foreach my $type (@types) {
3704: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3705: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3706: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3707: } else {
3708: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3709: }
3710: } else {
3711: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3712: }
3713: }
3714: }
3715: } else {
3716: foreach my $type (@types) {
3717: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 3718: }
3719: }
1.160.6.70 raeburn 3720: if (ref($settings->{'mysqltables'}) eq 'HASH') {
3721: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
3722: $currmysql{$type} = $settings->{'mysqltables'}{$type};
3723: }
3724: } else {
3725: foreach my $type (@types) {
3726: $currmysql{$type} = $staticdefaults{'mysqltables'};
3727: }
3728: }
1.160.6.58 raeburn 3729: } else {
3730: foreach my $type (@types) {
3731: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3732: }
1.139 raeburn 3733: }
3734: if (!$currdefresponder) {
1.160.6.21 raeburn 3735: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3736: } elsif ($currdefresponder < 1) {
3737: $currdefresponder = 1;
3738: }
1.160.6.21 raeburn 3739: foreach my $type (@types) {
3740: if ($curruploadquota{$type} eq '') {
3741: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3742: }
3743: }
1.139 raeburn 3744: $datatable .=
1.160.6.16 raeburn 3745: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3746: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3747: '</span></td>'.
3748: '<td class="LC_right_item"><span class="LC_nobreak">'.
3749: '<input type="text" name="anonsurvey_threshold"'.
3750: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 3751: '</td></tr>'."\n";
3752: $itemcount ++;
3753: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3754: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3755: $choices{'uploadquota'}.
3756: '</span></td>'.
3757: '<td align="right" class="LC_right_item">'.
3758: '<table><tr>';
1.160.6.21 raeburn 3759: foreach my $type (@types) {
3760: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3761: '<input type="text" name="uploadquota_'.$type.'"'.
3762: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3763: }
3764: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 3765: $itemcount ++;
1.160.6.40 raeburn 3766: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 3767: my $display = 'none';
3768: if ($currusecredits) {
3769: $display = 'block';
3770: }
3771: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 3772: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3773: foreach my $type (@types) {
3774: next if ($type eq 'community');
3775: $additional .= '<td align="center">'.&mt($type).'<br />'.
3776: '<input type="text" name="'.$type.'_credits"'.
3777: ' value="'.$defcredits{$type}.'" size="3" /></td>';
3778: }
3779: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 3780: %defaultchecked = ('coursecredits' => 'off');
3781: @toggles = ('coursecredits');
3782: my $current = {
3783: 'coursecredits' => $currusecredits,
3784: };
3785: (my $table,$itemcount) =
3786: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3787: \%choices,$itemcount,$onclick,$additional,'left');
3788: $datatable .= $table;
3789: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3790: my $display = 'none';
3791: if ($postsubmitclient) {
3792: $display = 'block';
3793: }
3794: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 3795: &mt('Number of seconds submit is disabled').'<br />'.
3796: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3797: '<table><tr>';
1.160.6.57 raeburn 3798: foreach my $type (@types) {
3799: $additional .= '<td align="center">'.&mt($type).'<br />'.
3800: '<input type="text" name="'.$type.'_timeout" value="'.
3801: $deftimeout{$type}.'" size="5" /></td>';
3802: }
3803: $additional .= '</tr></table></div>'."\n";
3804: %defaultchecked = ('postsubmit' => 'on');
3805: @toggles = ('postsubmit');
1.160.6.70 raeburn 3806: $current = {
3807: 'postsubmit' => $postsubmitclient,
3808: };
1.160.6.57 raeburn 3809: ($table,$itemcount) =
3810: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3811: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 3812: $datatable .= $table;
1.160.6.70 raeburn 3813: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3814: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3815: $choices{'mysqltables'}.
3816: '</span></td>'.
3817: '<td align="right" class="LC_right_item">'.
3818: '<table><tr>';
3819: foreach my $type (@types) {
3820: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3821: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 3822: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 3823: }
3824: $datatable .= '</tr></table></td></tr>'."\n";
3825: $itemcount ++;
3826:
1.160.6.37 raeburn 3827: }
3828: $$rowtotal += $itemcount;
3829: return $datatable;
3830: }
3831:
3832: sub print_selfenrollment {
3833: my ($position,$dom,$settings,$rowtotal) = @_;
3834: my ($css_class,$datatable);
3835: my $itemcount = 1;
3836: my @types = ('official','unofficial','community','textbook');
3837: if (($position eq 'top') || ($position eq 'middle')) {
3838: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3839: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
3840: my @rows;
3841: my $key;
3842: if ($position eq 'top') {
3843: $key = 'admin';
3844: if (ref($rowsref) eq 'ARRAY') {
3845: @rows = @{$rowsref};
3846: }
3847: } elsif ($position eq 'middle') {
3848: $key = 'default';
3849: @rows = ('types','registered','approval','limit');
3850: }
3851: foreach my $row (@rows) {
3852: if (defined($titlesref->{$row})) {
3853: $itemcount ++;
3854: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3855: $datatable .= '<tr'.$css_class.'>'.
3856: '<td>'.$titlesref->{$row}.'</td>'.
3857: '<td class="LC_left_item">'.
3858: '<table><tr>';
3859: my (%current,%currentcap);
3860: if (ref($settings) eq 'HASH') {
3861: if (ref($settings->{$key}) eq 'HASH') {
3862: foreach my $type (@types) {
3863: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3864: $current{$type} = $settings->{$key}->{$type}->{$row};
3865: }
3866: if (($row eq 'limit') && ($key eq 'default')) {
3867: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3868: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3869: }
3870: }
3871: }
3872: }
3873: }
3874: my %roles = (
3875: '0' => &Apache::lonnet::plaintext('dc'),
3876: );
3877:
3878: foreach my $type (@types) {
3879: unless (($row eq 'registered') && ($key eq 'default')) {
3880: $datatable .= '<th>'.&mt($type).'</th>';
3881: }
3882: }
3883: unless (($row eq 'registered') && ($key eq 'default')) {
3884: $datatable .= '</tr><tr>';
3885: }
3886: foreach my $type (@types) {
3887: if ($type eq 'community') {
3888: $roles{'1'} = &mt('Community personnel');
3889: } else {
3890: $roles{'1'} = &mt('Course personnel');
3891: }
3892: $datatable .= '<td style="vertical-align: top">';
3893: if ($position eq 'top') {
3894: my %checked;
3895: if ($current{$type} eq '0') {
3896: $checked{'0'} = ' checked="checked"';
3897: } else {
3898: $checked{'1'} = ' checked="checked"';
3899: }
3900: foreach my $role ('1','0') {
3901: $datatable .= '<span class="LC_nobreak"><label>'.
3902: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3903: 'value="'.$role.'"'.$checked{$role}.' />'.
3904: $roles{$role}.'</label></span> ';
3905: }
3906: } else {
3907: if ($row eq 'types') {
3908: my %checked;
3909: if ($current{$type} =~ /^(all|dom)$/) {
3910: $checked{$1} = ' checked="checked"';
3911: } else {
3912: $checked{''} = ' checked="checked"';
3913: }
3914: foreach my $val ('','dom','all') {
3915: $datatable .= '<span class="LC_nobreak"><label>'.
3916: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3917: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3918: }
3919: } elsif ($row eq 'registered') {
3920: my %checked;
3921: if ($current{$type} eq '1') {
3922: $checked{'1'} = ' checked="checked"';
3923: } else {
3924: $checked{'0'} = ' checked="checked"';
3925: }
3926: foreach my $val ('0','1') {
3927: $datatable .= '<span class="LC_nobreak"><label>'.
3928: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3929: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3930: }
3931: } elsif ($row eq 'approval') {
3932: my %checked;
3933: if ($current{$type} =~ /^([12])$/) {
3934: $checked{$1} = ' checked="checked"';
3935: } else {
3936: $checked{'0'} = ' checked="checked"';
3937: }
3938: for my $val (0..2) {
3939: $datatable .= '<span class="LC_nobreak"><label>'.
3940: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3941: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3942: }
3943: } elsif ($row eq 'limit') {
3944: my %checked;
3945: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3946: $checked{$1} = ' checked="checked"';
3947: } else {
3948: $checked{'none'} = ' checked="checked"';
3949: }
3950: my $cap;
3951: if ($currentcap{$type} =~ /^\d+$/) {
3952: $cap = $currentcap{$type};
3953: }
3954: foreach my $val ('none','allstudents','selfenrolled') {
3955: $datatable .= '<span class="LC_nobreak"><label>'.
3956: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3957: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3958: }
3959: $datatable .= '<br />'.
3960: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3961: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3962: '</span>';
3963: }
3964: }
3965: $datatable .= '</td>';
3966: }
3967: $datatable .= '</tr>';
3968: }
3969: $datatable .= '</table></td></tr>';
3970: }
3971: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 3972: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3973: }
3974: $$rowtotal += $itemcount;
3975: return $datatable;
3976: }
3977:
3978: sub print_validation_rows {
3979: my ($caller,$dom,$settings,$rowtotal) = @_;
3980: my ($itemsref,$namesref,$fieldsref);
3981: if ($caller eq 'selfenroll') {
3982: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3983: } elsif ($caller eq 'requestcourses') {
3984: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3985: }
3986: my %currvalidation;
3987: if (ref($settings) eq 'HASH') {
3988: if (ref($settings->{'validation'}) eq 'HASH') {
3989: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3990: }
1.160.6.39 raeburn 3991: }
3992: my $datatable;
3993: my $itemcount = 0;
3994: foreach my $item (@{$itemsref}) {
3995: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3996: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3997: $namesref->{$item}.
3998: '</span></td>'.
3999: '<td class="LC_left_item">';
4000: if (($item eq 'url') || ($item eq 'button')) {
4001: $datatable .= '<span class="LC_nobreak">'.
4002: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4003: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4004: } elsif ($item eq 'fields') {
4005: my @currfields;
4006: if (ref($currvalidation{$item}) eq 'ARRAY') {
4007: @currfields = @{$currvalidation{$item}};
4008: }
4009: foreach my $field (@{$fieldsref}) {
4010: my $check = '';
4011: if (grep(/^\Q$field\E$/,@currfields)) {
4012: $check = ' checked="checked"';
4013: }
4014: $datatable .= '<span class="LC_nobreak"><label>'.
4015: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4016: ' value="'.$field.'"'.$check.' />'.$field.
4017: '</label></span> ';
4018: }
4019: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 4020: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 4021: $currvalidation{$item}.
1.160.6.37 raeburn 4022: '</textarea>';
1.160.6.39 raeburn 4023: }
4024: $datatable .= '</td></tr>'."\n";
4025: if (ref($rowtotal)) {
1.160.6.37 raeburn 4026: $itemcount ++;
4027: }
1.139 raeburn 4028: }
1.160.6.39 raeburn 4029: if ($caller eq 'requestcourses') {
4030: my %currhash;
1.160.6.51 raeburn 4031: if (ref($settings) eq 'HASH') {
4032: if (ref($settings->{'validation'}) eq 'HASH') {
4033: if ($settings->{'validation'}{'dc'} ne '') {
4034: $currhash{$settings->{'validation'}{'dc'}} = 1;
4035: }
1.160.6.39 raeburn 4036: }
4037: }
4038: my $numinrow = 2;
4039: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4040: 'validationdc',%currhash);
1.160.6.50 raeburn 4041: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 4042: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 4043: if ($numdc > 1) {
1.160.6.50 raeburn 4044: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 4045: } else {
1.160.6.50 raeburn 4046: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 4047: }
1.160.6.50 raeburn 4048: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 4049: $itemcount ++;
4050: }
4051: if (ref($rowtotal)) {
4052: $$rowtotal += $itemcount;
4053: }
1.121 raeburn 4054: return $datatable;
1.118 jms 4055: }
4056:
1.160.6.98 raeburn 4057: sub print_passwords {
4058: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
4059: my ($datatable,$css_class);
4060: my $itemcount = 0;
4061: my %titles = &Apache::lonlocal::texthash (
4062: captcha => '"Forgot Password" CAPTCHA validation',
4063: link => 'Reset link expiration (hours)',
4064: case => 'Case-sensitive usernames/e-mail',
4065: prelink => 'Information required (form 1)',
4066: postlink => 'Information required (form 2)',
4067: emailsrc => 'LON-CAPA e-mail address type(s)',
4068: customtext => 'Domain specific text (HTML)',
4069: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
4070: intauth_check => 'Check bcrypt cost if authenticated',
4071: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
4072: permanent => 'Permanent e-mail address',
4073: critical => 'Critical notification address',
4074: notify => 'Notification address',
4075: min => 'Minimum password length',
4076: max => 'Maximum password length',
4077: chars => 'Required characters',
4078: numsaved => 'Number of previous passwords to save and disallow reuse',
4079: );
4080: if ($position eq 'top') {
4081: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4082: my $shownlinklife = 2;
4083: my $prelink = 'both';
4084: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
4085: if (ref($settings) eq 'HASH') {
4086: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
4087: $shownlinklife = $settings->{resetlink};
4088: }
4089: if (ref($settings->{resetcase}) eq 'ARRAY') {
4090: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
4091: }
4092: if ($settings->{resetprelink} =~ /^(both|either)$/) {
4093: $prelink = $settings->{resetprelink};
4094: }
4095: if (ref($settings->{resetpostlink}) eq 'HASH') {
4096: %postlink = %{$settings->{resetpostlink}};
4097: }
4098: if (ref($settings->{resetemail}) eq 'ARRAY') {
4099: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
4100: }
4101: if ($settings->{resetremove}) {
4102: $nostdtext = 1;
4103: }
4104: if ($settings->{resetcustom}) {
4105: $customurl = $settings->{resetcustom};
4106: }
4107: } else {
4108: if (ref($types) eq 'ARRAY') {
4109: foreach my $item (@{$types}) {
4110: $casesens{$item} = 1;
4111: $postlink{$item} = ['username','email'];
4112: }
4113: }
4114: $casesens{'default'} = 1;
4115: $postlink{'default'} = ['username','email'];
4116: $prelink = 'both';
4117: %emailsrc = (
4118: permanent => 1,
4119: critical => 1,
4120: notify => 1,
4121: );
4122: }
4123: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
4124: $itemcount ++;
4125: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4126: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
4127: '<td class="LC_left_item">'.
4128: '<input type="textbox" value="'.$shownlinklife.'" '.
4129: 'name="passwords_link" size="3" /></td></tr>';
4130: $itemcount ++;
4131: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4132: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
4133: '<td class="LC_left_item">';
4134: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
4135: foreach my $item (@{$types}) {
4136: my $checkedcase;
4137: if ($casesens{$item}) {
4138: $checkedcase = ' checked="checked"';
4139: }
4140: $datatable .= '<span class="LC_nobreak"><label>'.
4141: '<input type="checkbox" name="passwords_case_sensitive" value="'.
4142: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
4143: '<span> ';
4144: }
4145: }
4146: my $checkedcase;
4147: if ($casesens{'default'}) {
4148: $checkedcase = ' checked="checked"';
4149: }
4150: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
4151: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
4152: $othertitle.'</label></span></td>';
4153: $itemcount ++;
4154: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4155: my %checkedpre = (
4156: both => ' checked="checked"',
4157: either => '',
4158: );
4159: if ($prelink eq 'either') {
4160: $checkedpre{either} = ' checked="checked"';
4161: $checkedpre{both} = '';
4162: }
4163: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
4164: '<td class="LC_left_item"><span class="LC_nobreak">'.
4165: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
4166: &mt('Both username and e-mail address').'</label></span> '.
4167: '<span class="LC_nobreak"><label>'.
4168: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
4169: &mt('Either username or e-mail address').'</label></span></td></tr>';
4170: $itemcount ++;
4171: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4172: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
4173: '<td class="LC_left_item">';
4174: my %postlinked;
4175: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
4176: foreach my $item (@{$types}) {
4177: undef(%postlinked);
4178: $datatable .= '<fieldset style="display: inline-block;">'.
4179: '<legend>'.$usertypes->{$item}.'</legend>';
4180: if (ref($postlink{$item}) eq 'ARRAY') {
4181: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
4182: }
4183: foreach my $field ('email','username') {
4184: my $checked;
4185: if ($postlinked{$field}) {
4186: $checked = ' checked="checked"';
4187: }
4188: $datatable .= '<span class="LC_nobreak"><label>'.
4189: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
4190: $field.'"'.$checked.' />'.$field.'</label>'.
4191: '<span> ';
4192: }
4193: $datatable .= '</fieldset>';
4194: }
4195: }
4196: if (ref($postlink{'default'}) eq 'ARRAY') {
4197: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
4198: }
4199: $datatable .= '<fieldset style="display: inline-block;">'.
4200: '<legend>'.$othertitle.'</legend>';
4201: foreach my $field ('email','username') {
4202: my $checked;
4203: if ($postlinked{$field}) {
4204: $checked = ' checked="checked"';
4205: }
4206: $datatable .= '<span class="LC_nobreak"><label>'.
4207: '<input type="checkbox" name="passwords_postlink_default" value="'.
4208: $field.'"'.$checked.' />'.$field.'</label>'.
4209: '<span> ';
4210: }
4211: $datatable .= '</fieldset></td></tr>';
4212: $itemcount ++;
4213: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4214: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
4215: '<td class="LC_left_item">';
4216: foreach my $type ('permanent','critical','notify') {
4217: my $checkedemail;
4218: if ($emailsrc{$type}) {
4219: $checkedemail = ' checked="checked"';
4220: }
4221: $datatable .= '<span class="LC_nobreak"><label>'.
4222: '<input type="checkbox" name="passwords_emailsrc" value="'.
4223: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
4224: '<span> ';
4225: }
4226: $datatable .= '</td></tr>';
4227: $itemcount ++;
4228: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4229: my $switchserver = &check_switchserver($dom,$confname);
4230: my ($showstd,$noshowstd);
4231: if ($nostdtext) {
4232: $noshowstd = ' checked="checked"';
4233: } else {
4234: $showstd = ' checked="checked"';
4235: }
4236: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
4237: '<td class="LC_left_item"><span class="LC_nobreak">'.
4238: &mt('Retain standard text:').
4239: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
4240: &mt('Yes').'</label>'.' '.
4241: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
4242: &mt('No').'</label></span><br />'.
4243: '<span class="LC_fontsize_small">'.
4244: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
4245: &mt('Include custom text:');
4246: if ($customurl) {
4247: my $link = &Apache::loncommon::modal_link($customurl,&mt('Custom text file'),600,500,
4248: undef,undef,undef,undef,'background-color:#ffffff');
4249: $datatable .= '<span class="LC_nobreak"> '.$link.
4250: '<label><input type="checkbox" name="passwords_custom_del"'.
4251: ' value="1" />'.&mt('Delete?').'</label></span>'.
4252: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
4253: }
4254: if ($switchserver) {
4255: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
4256: } else {
4257: $datatable .='<span class="LC_nobreak"> '.
4258: '<input type="file" name="passwords_customfile" /></span>';
4259: }
4260: $datatable .= '</td></tr>';
4261: } elsif ($position eq 'middle') {
4262: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
4263: my @items = ('intauth_cost','intauth_check','intauth_switch');
4264: my %defaults;
4265: if (ref($domconf{'defaults'}) eq 'HASH') {
4266: %defaults = %{$domconf{'defaults'}};
4267: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
4268: $defaults{'intauth_cost'} = 10;
4269: }
4270: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
4271: $defaults{'intauth_check'} = 0;
4272: }
4273: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
4274: $defaults{'intauth_switch'} = 0;
4275: }
4276: } else {
4277: %defaults = (
4278: 'intauth_cost' => 10,
4279: 'intauth_check' => 0,
4280: 'intauth_switch' => 0,
4281: );
4282: }
4283: foreach my $item (@items) {
4284: if ($itemcount%2) {
4285: $css_class = '';
4286: } else {
4287: $css_class = ' class="LC_odd_row" ';
4288: }
4289: $datatable .= '<tr'.$css_class.'>'.
4290: '<td><span class="LC_nobreak">'.$titles{$item}.
4291: '</span></td><td class="LC_left_item" colspan="3">';
4292: if ($item eq 'intauth_switch') {
4293: my @options = (0,1,2);
4294: my %optiondesc = &Apache::lonlocal::texthash (
4295: 0 => 'No',
4296: 1 => 'Yes',
4297: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
4298: );
4299: $datatable .= '<table width="100%">';
4300: foreach my $option (@options) {
4301: my $checked = ' ';
4302: if ($defaults{$item} eq $option) {
4303: $checked = ' checked="checked"';
4304: }
4305: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
4306: '<label><input type="radio" name="'.$item.
4307: '" value="'.$option.'"'.$checked.' />'.
4308: $optiondesc{$option}.'</label></span></td></tr>';
4309: }
4310: $datatable .= '</table>';
4311: } elsif ($item eq 'intauth_check') {
4312: my @options = (0,1,2);
4313: my %optiondesc = &Apache::lonlocal::texthash (
4314: 0 => 'No',
4315: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
4316: 2 => 'Yes, disallow login if stored cost is less than domain default',
4317: );
4318: $datatable .= '<table width="100%">';
4319: foreach my $option (@options) {
4320: my $checked = ' ';
4321: my $onclick;
4322: if ($defaults{$item} eq $option) {
4323: $checked = ' checked="checked"';
4324: }
4325: if ($option == 2) {
4326: $onclick = ' onclick="javascript:warnIntAuth(this);"';
4327: }
4328: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
4329: '<label><input type="radio" name="'.$item.
4330: '" value="'.$option.'"'.$checked.$onclick.' />'.
4331: $optiondesc{$option}.'</label></span></td></tr>';
4332: }
4333: $datatable .= '</table>';
4334: } else {
4335: $datatable .= '<input type="text" name="'.$item.'" value="'.
4336: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
4337: }
4338: $datatable .= '</td></tr>';
4339: $itemcount ++;
4340: }
4341: } elsif ($position eq 'lower') {
4342: my ($min,$max,%chars,$numsaved);
1.160.6.99 raeburn 4343: $min = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 4344: if (ref($settings) eq 'HASH') {
4345: if ($settings->{min}) {
4346: $min = $settings->{min};
4347: }
4348: if ($settings->{max}) {
4349: $max = $settings->{max};
4350: }
4351: if (ref($settings->{chars}) eq 'ARRAY') {
4352: map { $chars{$_} = 1; } (@{$settings->{chars}});
4353: }
4354: if ($settings->{numsaved}) {
4355: $numsaved = $settings->{numsaved};
4356: }
4357: }
4358: my %rulenames = &Apache::lonlocal::texthash(
4359: uc => 'At least one upper case letter',
4360: lc => 'At least one lower case letter',
4361: num => 'At least one number',
4362: spec => 'At least one non-alphanumeric',
4363: );
4364: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4365: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
4366: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 4367: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
4368: 'onblur="javascript:warnIntPass(this);" />'.
4369: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.160.6.98 raeburn 4370: '</span></td></tr>';
4371: $itemcount ++;
4372: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4373: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
4374: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 4375: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
4376: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 4377: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
4378: '</span></td></tr>';
4379: $itemcount ++;
4380: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4381: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
4382: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
4383: '</span></td>';
4384: my $numinrow = 2;
4385: my @possrules = ('uc','lc','num','spec');
4386: $datatable .= '<td class="LC_left_item"><table>';
4387: for (my $i=0; $i<@possrules; $i++) {
4388: my ($rem,$checked);
4389: if ($chars{$possrules[$i]}) {
4390: $checked = ' checked="checked"';
4391: }
4392: $rem = $i%($numinrow);
4393: if ($rem == 0) {
4394: if ($i > 0) {
4395: $datatable .= '</tr>';
4396: }
4397: $datatable .= '<tr>';
4398: }
4399: $datatable .= '<td><span class="LC_nobreak"><label>'.
4400: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
4401: $rulenames{$possrules[$i]}.'</label></span></td>';
4402: }
4403: my $rem = @possrules%($numinrow);
4404: my $colsleft = $numinrow - $rem;
4405: if ($colsleft > 1 ) {
4406: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4407: ' </td>';
4408: } elsif ($colsleft == 1) {
4409: $datatable .= '<td class="LC_left_item"> </td>';
4410: }
4411: $datatable .='</table></td></tr>';
4412: $itemcount ++;
4413: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4414: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
4415: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.100! raeburn 4416: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
1.160.6.99 raeburn 4417: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 4418: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
4419: '</span></td></tr>';
4420: } else {
4421: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4422: my %ownerchg = (
4423: by => {},
4424: for => {},
4425: );
4426: my %ownertitles = &Apache::lonlocal::texthash (
4427: by => 'Course owner status(es) allowed',
4428: for => 'Student status(es) allowed',
4429: );
4430: if (ref($settings) eq 'HASH') {
4431: if (ref($settings->{crsownerchg}) eq 'HASH') {
4432: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
4433: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
4434: }
4435: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
4436: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
4437: }
4438: }
4439: }
4440: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4441: $datatable .= '<tr '.$css_class.'>'.
4442: '<td>'.
4443: &mt('Requirements').'<ul>'.
4444: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
4445: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
4446: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
4447: '<li>'.&mt('User, course, and student share same domain').'</li>'.
4448: '</ul>'.
4449: '</td>'.
4450: '<td class="LC_left_item">';
4451: foreach my $item ('by','for') {
4452: $datatable .= '<fieldset style="display: inline-block;">'.
4453: '<legend>'.$ownertitles{$item}.'</legend>';
4454: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
4455: foreach my $type (@{$types}) {
4456: my $checked;
4457: if ($ownerchg{$item}{$type}) {
4458: $checked = ' checked="checked"';
4459: }
4460: $datatable .= '<span class="LC_nobreak"><label>'.
4461: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
4462: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
4463: '<span> ';
4464: }
4465: }
4466: my $checked;
4467: if ($ownerchg{$item}{'default'}) {
4468: $checked = ' checked="checked"';
4469: }
4470: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
4471: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
4472: $othertitle.'</label></span></fieldset>';
4473: }
4474: $datatable .= '</td></tr>';
4475: }
4476: return $datatable;
4477: }
4478:
1.137 raeburn 4479: sub print_usersessions {
4480: my ($position,$dom,$settings,$rowtotal) = @_;
4481: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 4482: my (%by_ip,%by_location,@intdoms);
4483: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 4484:
4485: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 4486: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 4487: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 4488: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 4489: my $itemcount = 1;
4490: if ($position eq 'top') {
1.152 raeburn 4491: if (keys(%serverhomes) > 1) {
1.145 raeburn 4492: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.61 raeburn 4493: my $curroffloadnow;
4494: if (ref($settings) eq 'HASH') {
4495: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4496: $curroffloadnow = $settings->{'offloadnow'};
4497: }
4498: }
4499: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 4500: } else {
1.140 raeburn 4501: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 4502: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 4503: }
1.137 raeburn 4504: } else {
1.145 raeburn 4505: if (keys(%by_location) == 0) {
4506: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 4507: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 4508: } else {
4509: my %lt = &usersession_titles();
4510: my $numinrow = 5;
4511: my $prefix;
4512: my @types;
4513: if ($position eq 'bottom') {
4514: $prefix = 'remote';
4515: @types = ('version','excludedomain','includedomain');
4516: } else {
4517: $prefix = 'hosted';
4518: @types = ('excludedomain','includedomain');
4519: }
4520: my (%current,%checkedon,%checkedoff);
4521: my @lcversions = &Apache::lonnet::all_loncaparevs();
4522: my @locations = sort(keys(%by_location));
4523: foreach my $type (@types) {
4524: $checkedon{$type} = '';
4525: $checkedoff{$type} = ' checked="checked"';
4526: }
4527: if (ref($settings) eq 'HASH') {
4528: if (ref($settings->{$prefix}) eq 'HASH') {
4529: foreach my $key (keys(%{$settings->{$prefix}})) {
4530: $current{$key} = $settings->{$prefix}{$key};
4531: if ($key eq 'version') {
4532: if ($current{$key} ne '') {
4533: $checkedon{$key} = ' checked="checked"';
4534: $checkedoff{$key} = '';
4535: }
4536: } elsif (ref($current{$key}) eq 'ARRAY') {
4537: $checkedon{$key} = ' checked="checked"';
4538: $checkedoff{$key} = '';
4539: }
1.137 raeburn 4540: }
4541: }
4542: }
1.145 raeburn 4543: foreach my $type (@types) {
4544: next if ($type ne 'version' && !@locations);
4545: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4546: $datatable .= '<tr'.$css_class.'>
4547: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
4548: <span class="LC_nobreak">
4549: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4550: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4551: if ($type eq 'version') {
4552: my $selector = '<select name="'.$prefix.'_version">';
4553: foreach my $version (@lcversions) {
4554: my $selected = '';
4555: if ($current{'version'} eq $version) {
4556: $selected = ' selected="selected"';
4557: }
4558: $selector .= ' <option value="'.$version.'"'.
4559: $selected.'>'.$version.'</option>';
4560: }
4561: $selector .= '</select> ';
4562: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4563: } else {
4564: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4565: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4566: ' />'.(' 'x2).
4567: '<input type="button" value="'.&mt('uncheck all').'" '.
4568: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4569: "\n".
4570: '</div><div><table>';
4571: my $rem;
4572: for (my $i=0; $i<@locations; $i++) {
4573: my ($showloc,$value,$checkedtype);
4574: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
4575: my $ip = $by_location{$locations[$i]}->[0];
4576: if (ref($by_ip{$ip}) eq 'ARRAY') {
4577: $value = join(':',@{$by_ip{$ip}});
4578: $showloc = join(', ',@{$by_ip{$ip}});
4579: if (ref($current{$type}) eq 'ARRAY') {
4580: foreach my $loc (@{$by_ip{$ip}}) {
4581: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4582: $checkedtype = ' checked="checked"';
4583: last;
4584: }
4585: }
1.138 raeburn 4586: }
4587: }
4588: }
1.145 raeburn 4589: $rem = $i%($numinrow);
4590: if ($rem == 0) {
4591: if ($i > 0) {
4592: $datatable .= '</tr>';
4593: }
4594: $datatable .= '<tr>';
4595: }
4596: $datatable .= '<td class="LC_left_item">'.
4597: '<span class="LC_nobreak"><label>'.
4598: '<input type="checkbox" name="'.$prefix.'_'.$type.
4599: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4600: '</label></span></td>';
1.137 raeburn 4601: }
1.145 raeburn 4602: $rem = @locations%($numinrow);
4603: my $colsleft = $numinrow - $rem;
4604: if ($colsleft > 1 ) {
4605: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4606: ' </td>';
4607: } elsif ($colsleft == 1) {
4608: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4609: }
1.145 raeburn 4610: $datatable .= '</tr></table>';
1.137 raeburn 4611: }
1.145 raeburn 4612: $datatable .= '</td></tr>';
4613: $itemcount ++;
1.137 raeburn 4614: }
4615: }
4616: }
4617: $$rowtotal += $itemcount;
4618: return $datatable;
4619: }
4620:
1.138 raeburn 4621: sub build_location_hashes {
4622: my ($intdoms,$by_ip,$by_location) = @_;
4623: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
4624: (ref($by_location) eq 'HASH'));
4625: my %iphost = &Apache::lonnet::get_iphost();
4626: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4627: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4628: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4629: foreach my $id (@{$iphost{$primary_ip}}) {
4630: my $intdom = &Apache::lonnet::internet_dom($id);
4631: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4632: push(@{$intdoms},$intdom);
4633: }
4634: }
4635: }
4636: foreach my $ip (keys(%iphost)) {
4637: if (ref($iphost{$ip}) eq 'ARRAY') {
4638: foreach my $id (@{$iphost{$ip}}) {
4639: my $location = &Apache::lonnet::internet_dom($id);
4640: if ($location) {
4641: next if (grep(/^\Q$location\E$/,@{$intdoms}));
4642: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4643: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4644: push(@{$by_ip->{$ip}},$location);
4645: }
4646: } else {
4647: $by_ip->{$ip} = [$location];
4648: }
4649: }
4650: }
4651: }
4652: }
4653: foreach my $ip (sort(keys(%{$by_ip}))) {
4654: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4655: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4656: my $first = $by_ip->{$ip}->[0];
4657: if (ref($by_location->{$first}) eq 'ARRAY') {
4658: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4659: push(@{$by_location->{$first}},$ip);
4660: }
4661: } else {
4662: $by_location->{$first} = [$ip];
4663: }
4664: }
4665: }
4666: return;
4667: }
4668:
1.145 raeburn 4669: sub current_offloads_to {
4670: my ($dom,$settings,$servers) = @_;
4671: my (%spareid,%otherdomconfigs);
1.152 raeburn 4672: if (ref($servers) eq 'HASH') {
1.145 raeburn 4673: foreach my $lonhost (sort(keys(%{$servers}))) {
4674: my $gotspares;
1.152 raeburn 4675: if (ref($settings) eq 'HASH') {
4676: if (ref($settings->{'spares'}) eq 'HASH') {
4677: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4678: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4679: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4680: $gotspares = 1;
4681: }
1.145 raeburn 4682: }
4683: }
4684: unless ($gotspares) {
4685: my $gotspares;
4686: my $serverhomeID =
4687: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4688: my $serverhomedom =
4689: &Apache::lonnet::host_domain($serverhomeID);
4690: if ($serverhomedom ne $dom) {
4691: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4692: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4693: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4694: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4695: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4696: $gotspares = 1;
4697: }
4698: }
4699: } else {
4700: $otherdomconfigs{$serverhomedom} =
4701: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4702: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4703: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4704: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4705: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4706: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4707: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4708: $gotspares = 1;
4709: }
4710: }
4711: }
4712: }
4713: }
4714: }
4715: }
4716: unless ($gotspares) {
4717: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4718: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4719: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4720: } else {
4721: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4722: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4723: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4724: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4725: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4726: } else {
1.150 raeburn 4727: my %what = (
4728: spareid => 1,
4729: );
4730: my ($result,$returnhash) =
4731: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4732: if ($result eq 'ok') {
4733: if (ref($returnhash) eq 'HASH') {
4734: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4735: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4736: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4737: }
4738: }
1.145 raeburn 4739: }
4740: }
4741: }
4742: }
4743: }
4744: }
4745: return %spareid;
4746: }
4747:
4748: sub spares_row {
1.160.6.61 raeburn 4749: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4750: my $css_class;
4751: my $numinrow = 4;
4752: my $itemcount = 1;
4753: my $datatable;
1.152 raeburn 4754: my %typetitles = &sparestype_titles();
4755: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4756: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4757: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4758: my ($othercontrol,$serverdom);
4759: if ($serverhome ne $server) {
4760: $serverdom = &Apache::lonnet::host_domain($serverhome);
4761: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4762: } else {
4763: $serverdom = &Apache::lonnet::host_domain($server);
4764: if ($serverdom ne $dom) {
4765: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4766: }
4767: }
4768: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61 raeburn 4769: my $checkednow;
4770: if (ref($curroffloadnow) eq 'HASH') {
4771: if ($curroffloadnow->{$server}) {
4772: $checkednow = ' checked="checked"';
4773: }
4774: }
1.145 raeburn 4775: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4776: $datatable .= '<tr'.$css_class.'>
4777: <td rowspan="2">
1.160.6.13 raeburn 4778: <span class="LC_nobreak">'.
4779: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 4780: ,'<b>'.$server.'</b>').'</span><br />'.
4781: '<span class="LC_nobreak">'."\n".
4782: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4783: ' '.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13 raeburn 4784: "\n";
1.145 raeburn 4785: my (%current,%canselect);
1.152 raeburn 4786: my @choices =
4787: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4788: foreach my $type ('primary','default') {
4789: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4790: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4791: my @spares = @{$spareid->{$server}{$type}};
4792: if (@spares > 0) {
1.152 raeburn 4793: if ($othercontrol) {
4794: $current{$type} = join(', ',@spares);
4795: } else {
4796: $current{$type} .= '<table>';
4797: my $numspares = scalar(@spares);
4798: for (my $i=0; $i<@spares; $i++) {
4799: my $rem = $i%($numinrow);
4800: if ($rem == 0) {
4801: if ($i > 0) {
4802: $current{$type} .= '</tr>';
4803: }
4804: $current{$type} .= '<tr>';
1.145 raeburn 4805: }
1.152 raeburn 4806: $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'".');" /> '.
4807: $spareid->{$server}{$type}[$i].
4808: '</label></td>'."\n";
4809: }
4810: my $rem = @spares%($numinrow);
4811: my $colsleft = $numinrow - $rem;
4812: if ($colsleft > 1 ) {
4813: $current{$type} .= '<td colspan="'.$colsleft.
4814: '" class="LC_left_item">'.
4815: ' </td>';
4816: } elsif ($colsleft == 1) {
4817: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4818: }
1.152 raeburn 4819: $current{$type} .= '</tr></table>';
1.150 raeburn 4820: }
1.145 raeburn 4821: }
4822: }
4823: if ($current{$type} eq '') {
4824: $current{$type} = &mt('None specified');
4825: }
1.152 raeburn 4826: if ($othercontrol) {
4827: if ($type eq 'primary') {
4828: $canselect{$type} = $othercontrol;
4829: }
4830: } else {
4831: $canselect{$type} =
4832: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4833: '<select name="newspare_'.$type.'_'.$server.'" '.
4834: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4835: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4836: if (@choices > 0) {
4837: foreach my $lonhost (@choices) {
4838: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4839: }
4840: }
4841: $canselect{$type} .= '</select>'."\n";
4842: }
4843: } else {
4844: $current{$type} = &mt('Could not be determined');
4845: if ($type eq 'primary') {
4846: $canselect{$type} = $othercontrol;
4847: }
1.145 raeburn 4848: }
1.152 raeburn 4849: if ($type eq 'default') {
4850: $datatable .= '<tr'.$css_class.'>';
4851: }
4852: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4853: '<td>'.$current{$type}.'</td>'."\n".
4854: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 4855: }
4856: $itemcount ++;
4857: }
4858: }
4859: $$rowtotal += $itemcount;
4860: return $datatable;
4861: }
4862:
1.152 raeburn 4863: sub possible_newspares {
4864: my ($server,$currspares,$serverhomes,$altids) = @_;
4865: my $serverhostname = &Apache::lonnet::hostname($server);
4866: my %excluded;
4867: if ($serverhostname ne '') {
4868: %excluded = (
4869: $serverhostname => 1,
4870: );
4871: }
4872: if (ref($currspares) eq 'HASH') {
4873: foreach my $type (keys(%{$currspares})) {
4874: if (ref($currspares->{$type}) eq 'ARRAY') {
4875: if (@{$currspares->{$type}} > 0) {
4876: foreach my $curr (@{$currspares->{$type}}) {
4877: my $hostname = &Apache::lonnet::hostname($curr);
4878: $excluded{$hostname} = 1;
4879: }
4880: }
4881: }
4882: }
4883: }
4884: my @choices;
4885: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4886: if (keys(%{$serverhomes}) > 1) {
4887: foreach my $name (sort(keys(%{$serverhomes}))) {
4888: unless ($excluded{$name}) {
4889: if (exists($altids->{$serverhomes->{$name}})) {
4890: push(@choices,$altids->{$serverhomes->{$name}});
4891: } else {
4892: push(@choices,$serverhomes->{$name});
1.145 raeburn 4893: }
4894: }
4895: }
4896: }
4897: }
1.152 raeburn 4898: return sort(@choices);
1.145 raeburn 4899: }
4900:
1.150 raeburn 4901: sub print_loadbalancing {
4902: my ($dom,$settings,$rowtotal) = @_;
4903: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4904: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4905: my $numinrow = 1;
4906: my $datatable;
4907: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 4908: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 4909: if (ref($settings) eq 'HASH') {
4910: %existing = %{$settings};
4911: }
4912: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
4913: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 4914: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 4915: } else {
4916: return;
4917: }
4918: my ($othertitle,$usertypes,$types) =
4919: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 4920: my $rownum = 8;
1.150 raeburn 4921: if (ref($types) eq 'ARRAY') {
4922: $rownum += scalar(@{$types});
4923: }
1.160.6.7 raeburn 4924: my @css_class = ('LC_odd_row','LC_even_row');
4925: my $balnum = 0;
4926: my $islast;
4927: my (@toshow,$disabledtext);
4928: if (keys(%currbalancer) > 0) {
4929: @toshow = sort(keys(%currbalancer));
4930: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
4931: push(@toshow,'');
4932: }
4933: } else {
4934: @toshow = ('');
4935: $disabledtext = &mt('No existing load balancer');
4936: }
4937: foreach my $lonhost (@toshow) {
4938: if ($balnum == scalar(@toshow)-1) {
4939: $islast = 1;
4940: } else {
4941: $islast = 0;
4942: }
4943: my $cssidx = $balnum%2;
4944: my $targets_div_style = 'display: none';
4945: my $disabled_div_style = 'display: block';
4946: my $homedom_div_style = 'display: none';
4947: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
4948: '<td rowspan="'.$rownum.'" valign="top">'.
4949: '<p>';
4950: if ($lonhost eq '') {
4951: $datatable .= '<span class="LC_nobreak">';
4952: if (keys(%currbalancer) > 0) {
4953: $datatable .= &mt('Add balancer:');
4954: } else {
4955: $datatable .= &mt('Enable balancer:');
4956: }
4957: $datatable .= ' '.
4958: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
4959: ' id="loadbalancing_lonhost_'.$balnum.'"'.
4960: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
4961: '<option value="" selected="selected">'.&mt('None').
4962: '</option>'."\n";
4963: foreach my $server (sort(keys(%servers))) {
4964: next if ($currbalancer{$server});
4965: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4966: }
4967: $datatable .=
4968: '</select>'."\n".
4969: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4970: } else {
4971: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4972: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4973: &mt('Stop balancing').'</label>'.
4974: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4975: $targets_div_style = 'display: block';
4976: $disabled_div_style = 'display: none';
4977: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
4978: $homedom_div_style = 'display: block';
4979: }
4980: }
4981: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
4982: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
4983: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
4984: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
4985: my ($numspares,@spares) = &count_servers($lonhost,%servers);
4986: my @sparestypes = ('primary','default');
4987: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 4988: my %hostherechecked = (
4989: no => ' checked="checked"',
4990: );
1.160.6.94 raeburn 4991: my %balcookiechecked = (
4992: no => ' checked="checked"',
4993: );
1.160.6.7 raeburn 4994: foreach my $sparetype (@sparestypes) {
4995: my $targettable;
4996: for (my $i=0; $i<$numspares; $i++) {
4997: my $checked;
4998: if (ref($currtargets{$lonhost}) eq 'HASH') {
4999: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5000: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5001: $checked = ' checked="checked"';
5002: }
5003: }
5004: }
5005: my ($chkboxval,$disabled);
5006: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5007: $chkboxval = $spares[$i];
5008: }
5009: if (exists($currbalancer{$spares[$i]})) {
5010: $disabled = ' disabled="disabled"';
5011: }
5012: $targettable .=
1.160.6.55 raeburn 5013: '<td><span class="LC_nobreak"><label>'.
5014: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 5015: $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 5016: '</span></label></span></td>';
1.160.6.7 raeburn 5017: my $rem = $i%($numinrow);
5018: if ($rem == 0) {
5019: if (($i > 0) && ($i < $numspares-1)) {
5020: $targettable .= '</tr>';
5021: }
5022: if ($i < $numspares-1) {
5023: $targettable .= '<tr>';
1.150 raeburn 5024: }
5025: }
5026: }
1.160.6.7 raeburn 5027: if ($targettable ne '') {
5028: my $rem = $numspares%($numinrow);
5029: my $colsleft = $numinrow - $rem;
5030: if ($colsleft > 1 ) {
5031: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5032: ' </td>';
5033: } elsif ($colsleft == 1) {
5034: $targettable .= '<td class="LC_left_item"> </td>';
5035: }
5036: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5037: '<table><tr>'.$targettable.'</tr></table><br />';
5038: }
1.160.6.76 raeburn 5039: $hostherechecked{$sparetype} = '';
5040: if (ref($currtargets{$lonhost}) eq 'HASH') {
5041: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5042: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5043: $hostherechecked{$sparetype} = ' checked="checked"';
5044: $hostherechecked{'no'} = '';
5045: }
5046: }
5047: }
5048: }
1.160.6.94 raeburn 5049: if ($currcookies{$lonhost}) {
5050: %balcookiechecked = (
5051: yes => ' checked="checked"',
5052: );
5053: }
1.160.6.76 raeburn 5054: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5055: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5056: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5057: foreach my $sparetype (@sparestypes) {
5058: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5059: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5060: '</i></label><br />';
1.160.6.7 raeburn 5061: }
1.160.6.94 raeburn 5062: $datatable .= &mt('Use balancer cookie').'<br />'.
5063: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
5064: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
5065: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
5066: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
5067: '</div></td></tr>'.
1.160.6.7 raeburn 5068: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5069: $othertitle,$usertypes,$types,\%servers,
5070: \%currbalancer,$lonhost,
5071: $targets_div_style,$homedom_div_style,
5072: $css_class[$cssidx],$balnum,$islast);
5073: $$rowtotal += $rownum;
5074: $balnum ++;
5075: }
5076: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5077: return $datatable;
5078: }
5079:
5080: sub get_loadbalancers_config {
1.160.6.94 raeburn 5081: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 5082: return unless ((ref($servers) eq 'HASH') &&
5083: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 5084: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
5085: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 5086: if (keys(%{$existing}) > 0) {
5087: my $oldlonhost;
5088: foreach my $key (sort(keys(%{$existing}))) {
5089: if ($key eq 'lonhost') {
5090: $oldlonhost = $existing->{'lonhost'};
5091: $currbalancer->{$oldlonhost} = 1;
5092: } elsif ($key eq 'targets') {
5093: if ($oldlonhost) {
5094: $currtargets->{$oldlonhost} = $existing->{'targets'};
5095: }
5096: } elsif ($key eq 'rules') {
5097: if ($oldlonhost) {
5098: $currrules->{$oldlonhost} = $existing->{'rules'};
5099: }
5100: } elsif (ref($existing->{$key}) eq 'HASH') {
5101: $currbalancer->{$key} = 1;
5102: $currtargets->{$key} = $existing->{$key}{'targets'};
5103: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 5104: if ($existing->{$key}{'cookie'}) {
5105: $currcookies->{$key} = 1;
5106: }
1.150 raeburn 5107: }
5108: }
1.160.6.7 raeburn 5109: } else {
5110: my ($balancerref,$targetsref) =
5111: &Apache::lonnet::get_lonbalancer_config($servers);
5112: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5113: foreach my $server (sort(keys(%{$balancerref}))) {
5114: $currbalancer->{$server} = 1;
5115: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 5116: }
5117: }
5118: }
1.160.6.7 raeburn 5119: return;
1.150 raeburn 5120: }
5121:
5122: sub loadbalancing_rules {
5123: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 5124: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5125: $css_class,$balnum,$islast) = @_;
1.150 raeburn 5126: my $output;
1.160.6.7 raeburn 5127: my $num = 0;
5128: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 5129: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5130: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5131: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 5132: $num ++;
1.150 raeburn 5133: my $current;
5134: if (ref($currrules) eq 'HASH') {
5135: $current = $currrules->{$type};
5136: }
1.160.6.55 raeburn 5137: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 5138: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 5139: $current = '';
5140: }
5141: }
5142: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 5143: $servers,$currbalancer,$lonhost,$dom,
5144: $targets_div_style,$homedom_div_style,
5145: $css_class,$balnum,$num,$islast);
1.150 raeburn 5146: }
5147: }
5148: return $output;
5149: }
5150:
5151: sub loadbalancing_titles {
5152: my ($dom,$intdom,$usertypes,$types) = @_;
5153: my %othertypes = (
5154: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5155: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5156: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5157: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 5158: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5159: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 5160: );
1.160.6.26 raeburn 5161: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 5162: my @available;
1.150 raeburn 5163: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 5164: @available = @{$types};
1.150 raeburn 5165: }
1.160.6.89 raeburn 5166: unless (grep(/^default$/,@available)) {
5167: push(@available,'default');
5168: }
5169: unshift(@alltypes,@available);
1.150 raeburn 5170: my %titles;
5171: foreach my $type (@alltypes) {
5172: if ($type =~ /^_LC_/) {
5173: $titles{$type} = $othertypes{$type};
5174: } elsif ($type eq 'default') {
5175: $titles{$type} = &mt('All users from [_1]',$dom);
5176: if (ref($types) eq 'ARRAY') {
5177: if (@{$types} > 0) {
5178: $titles{$type} = &mt('Other users from [_1]',$dom);
5179: }
5180: }
5181: } elsif (ref($usertypes) eq 'HASH') {
5182: $titles{$type} = $usertypes->{$type};
5183: }
5184: }
5185: return (\@alltypes,\%othertypes,\%titles);
5186: }
5187:
5188: sub loadbalance_rule_row {
1.160.6.7 raeburn 5189: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
5190: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 5191: my @rulenames;
1.150 raeburn 5192: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 5193: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 5194: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 5195: } else {
1.160.6.26 raeburn 5196: @rulenames = ('default','homeserver');
5197: if ($type eq '_LC_external') {
5198: push(@rulenames,'externalbalancer');
5199: } else {
5200: push(@rulenames,'specific');
5201: }
5202: push(@rulenames,'none');
1.150 raeburn 5203: }
5204: my $style = $targets_div_style;
1.160.6.55 raeburn 5205: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 5206: $style = $homedom_div_style;
5207: }
1.160.6.7 raeburn 5208: my $space;
5209: if ($islast && $num == 1) {
5210: $space = '<div display="inline-block"> </div>';
5211: }
5212: my $output =
5213: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
5214: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
5215: '<td valaign="top">'.$space.
5216: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 5217: for (my $i=0; $i<@rulenames; $i++) {
5218: my $rule = $rulenames[$i];
5219: my ($checked,$extra);
5220: if ($rulenames[$i] eq 'default') {
5221: $rule = '';
5222: }
5223: if ($rulenames[$i] eq 'specific') {
5224: if (ref($servers) eq 'HASH') {
5225: my $default;
5226: if (($current ne '') && (exists($servers->{$current}))) {
5227: $checked = ' checked="checked"';
5228: }
5229: unless ($checked) {
5230: $default = ' selected="selected"';
5231: }
1.160.6.7 raeburn 5232: $extra =
5233: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
5234: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
5235: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
5236: '<option value=""'.$default.'></option>'."\n";
5237: foreach my $server (sort(keys(%{$servers}))) {
5238: if (ref($currbalancer) eq 'HASH') {
5239: next if (exists($currbalancer->{$server}));
5240: }
1.150 raeburn 5241: my $selected;
1.160.6.7 raeburn 5242: if ($server eq $current) {
1.150 raeburn 5243: $selected = ' selected="selected"';
5244: }
1.160.6.7 raeburn 5245: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 5246: }
5247: $extra .= '</select>';
5248: }
5249: } elsif ($rule eq $current) {
5250: $checked = ' checked="checked"';
5251: }
5252: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 5253: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
5254: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
5255: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 5256: ')"'.$checked.' /> ';
1.160.6.56 raeburn 5257: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 5258: $output .= $ruletitles{'particular'};
5259: } else {
5260: $output .= $ruletitles{$rulenames[$i]};
5261: }
5262: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 5263: }
5264: $output .= '</div></td></tr>'."\n";
5265: return $output;
5266: }
5267:
5268: sub offloadtype_text {
5269: my %ruletitles = &Apache::lonlocal::texthash (
5270: 'default' => 'Offloads to default destinations',
5271: 'homeserver' => "Offloads to user's home server",
5272: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
5273: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 5274: 'none' => 'No offload',
1.160.6.26 raeburn 5275: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
5276: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 5277: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 5278: );
5279: return %ruletitles;
5280: }
5281:
5282: sub sparestype_titles {
5283: my %typestitles = &Apache::lonlocal::texthash (
5284: 'primary' => 'primary',
5285: 'default' => 'default',
5286: );
5287: return %typestitles;
5288: }
5289:
1.28 raeburn 5290: sub contact_titles {
5291: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 5292: 'supportemail' => 'Support E-mail address',
5293: 'adminemail' => 'Default Server Admin E-mail address',
5294: 'errormail' => 'Error reports to be e-mailed to',
5295: 'packagesmail' => 'Package update alerts to be e-mailed to',
5296: 'helpdeskmail' => "Helpdesk requests for this domain's users",
5297: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
5298: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
5299: 'requestsmail' => 'E-mail from course requests requiring approval',
5300: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 5301: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 5302: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.28 raeburn 5303: );
5304: my %short_titles = &Apache::lonlocal::texthash (
5305: adminemail => 'Admin E-mail address',
5306: supportemail => 'Support E-mail',
5307: );
5308: return (\%titles,\%short_titles);
5309: }
5310:
1.160.6.78 raeburn 5311: sub helpform_fields {
5312: my %titles = &Apache::lonlocal::texthash (
5313: 'username' => 'Name',
5314: 'user' => 'Username/domain',
5315: 'phone' => 'Phone',
5316: 'cc' => 'Cc e-mail',
5317: 'course' => 'Course Details',
5318: 'section' => 'Sections',
5319: 'screenshot' => 'File upload',
5320: );
5321: my @fields = ('username','phone','user','course','section','cc','screenshot');
5322: my %possoptions = (
5323: username => ['yes','no','req'],
5324: phone => ['yes','no','req'],
5325: user => ['yes','no'],
5326: cc => ['yes','no'],
5327: course => ['yes','no'],
5328: section => ['yes','no'],
5329: screenshot => ['yes','no'],
5330: );
5331: my %fieldoptions = &Apache::lonlocal::texthash (
5332: 'yes' => 'Optional',
5333: 'req' => 'Required',
5334: 'no' => "Not shown",
5335: );
5336: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
5337: }
5338:
1.72 raeburn 5339: sub tool_titles {
5340: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 5341: aboutme => 'Personal web page',
1.86 raeburn 5342: blog => 'Blog',
1.160.6.4 raeburn 5343: webdav => 'WebDAV',
1.86 raeburn 5344: portfolio => 'Portfolio',
1.88 bisitz 5345: official => 'Official courses (with institutional codes)',
5346: unofficial => 'Unofficial courses',
1.98 raeburn 5347: community => 'Communities',
1.160.6.30 raeburn 5348: textbook => 'Textbook courses',
1.86 raeburn 5349: );
1.72 raeburn 5350: return %titles;
5351: }
5352:
1.101 raeburn 5353: sub courserequest_titles {
5354: my %titles = &Apache::lonlocal::texthash (
5355: official => 'Official',
5356: unofficial => 'Unofficial',
5357: community => 'Communities',
1.160.6.30 raeburn 5358: textbook => 'Textbook',
1.101 raeburn 5359: norequest => 'Not allowed',
1.104 raeburn 5360: approval => 'Approval by Dom. Coord.',
1.101 raeburn 5361: validate => 'With validation',
5362: autolimit => 'Numerical limit',
1.103 raeburn 5363: unlimited => '(blank for unlimited)',
1.101 raeburn 5364: );
5365: return %titles;
5366: }
5367:
1.160.6.5 raeburn 5368: sub authorrequest_titles {
5369: my %titles = &Apache::lonlocal::texthash (
5370: norequest => 'Not allowed',
5371: approval => 'Approval by Dom. Coord.',
5372: automatic => 'Automatic approval',
5373: );
5374: return %titles;
5375: }
5376:
1.101 raeburn 5377: sub courserequest_conditions {
5378: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 5379: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 5380: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 5381: );
5382: return %conditions;
5383: }
5384:
5385:
1.27 raeburn 5386: sub print_usercreation {
1.30 raeburn 5387: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 5388: my $numinrow = 4;
1.28 raeburn 5389: my $datatable;
5390: if ($position eq 'top') {
1.30 raeburn 5391: $$rowtotal ++;
1.34 raeburn 5392: my $rowcount = 0;
1.32 raeburn 5393: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 5394: if (ref($rules) eq 'HASH') {
5395: if (keys(%{$rules}) > 0) {
1.32 raeburn 5396: $datatable .= &user_formats_row('username',$settings,$rules,
5397: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 5398: $$rowtotal ++;
1.32 raeburn 5399: $rowcount ++;
5400: }
5401: }
5402: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
5403: if (ref($idrules) eq 'HASH') {
5404: if (keys(%{$idrules}) > 0) {
5405: $datatable .= &user_formats_row('id',$settings,$idrules,
5406: $idruleorder,$numinrow,$rowcount);
5407: $$rowtotal ++;
5408: $rowcount ++;
1.28 raeburn 5409: }
5410: }
1.39 raeburn 5411: if ($rowcount == 0) {
5412: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
5413: $$rowtotal ++;
5414: $rowcount ++;
5415: }
1.34 raeburn 5416: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 5417: my @creators = ('author','course','requestcrs');
1.37 raeburn 5418: my ($rules,$ruleorder) =
5419: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 5420: my %lt = &usercreation_types();
5421: my %checked;
5422: if (ref($settings) eq 'HASH') {
5423: if (ref($settings->{'cancreate'}) eq 'HASH') {
5424: foreach my $item (@creators) {
5425: $checked{$item} = $settings->{'cancreate'}{$item};
5426: }
5427: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
5428: foreach my $item (@creators) {
5429: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
5430: $checked{$item} = 'none';
5431: }
5432: }
5433: }
5434: }
5435: my $rownum = 0;
5436: foreach my $item (@creators) {
5437: $rownum ++;
1.160.6.34 raeburn 5438: if ($checked{$item} eq '') {
5439: $checked{$item} = 'any';
1.34 raeburn 5440: }
5441: my $css_class;
5442: if ($rownum%2) {
5443: $css_class = '';
5444: } else {
5445: $css_class = ' class="LC_odd_row" ';
5446: }
5447: $datatable .= '<tr'.$css_class.'>'.
5448: '<td><span class="LC_nobreak">'.$lt{$item}.
5449: '</span></td><td align="right">';
1.160.6.34 raeburn 5450: my @options = ('any');
5451: if (ref($rules) eq 'HASH') {
5452: if (keys(%{$rules}) > 0) {
5453: push(@options,('official','unofficial'));
1.37 raeburn 5454: }
5455: }
1.160.6.34 raeburn 5456: push(@options,'none');
1.37 raeburn 5457: foreach my $option (@options) {
1.50 raeburn 5458: my $type = 'radio';
1.34 raeburn 5459: my $check = ' ';
1.160.6.34 raeburn 5460: if ($checked{$item} eq $option) {
5461: $check = ' checked="checked" ';
1.34 raeburn 5462: }
5463: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 5464: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 5465: $item.'" value="'.$option.'"'.$check.'/> '.
5466: $lt{$option}.'</label> </span>';
5467: }
5468: $datatable .= '</td></tr>';
5469: }
1.28 raeburn 5470: } else {
5471: my @contexts = ('author','course','domain');
5472: my @authtypes = ('int','krb4','krb5','loc');
5473: my %checked;
5474: if (ref($settings) eq 'HASH') {
5475: if (ref($settings->{'authtypes'}) eq 'HASH') {
5476: foreach my $item (@contexts) {
5477: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5478: foreach my $auth (@authtypes) {
5479: if ($settings->{'authtypes'}{$item}{$auth}) {
5480: $checked{$item}{$auth} = ' checked="checked" ';
5481: }
5482: }
5483: }
5484: }
1.27 raeburn 5485: }
1.35 raeburn 5486: } else {
5487: foreach my $item (@contexts) {
1.36 raeburn 5488: foreach my $auth (@authtypes) {
1.35 raeburn 5489: $checked{$item}{$auth} = ' checked="checked" ';
5490: }
5491: }
1.27 raeburn 5492: }
1.28 raeburn 5493: my %title = &context_names();
5494: my %authname = &authtype_names();
5495: my $rownum = 0;
5496: my $css_class;
5497: foreach my $item (@contexts) {
5498: if ($rownum%2) {
5499: $css_class = '';
5500: } else {
5501: $css_class = ' class="LC_odd_row" ';
5502: }
1.30 raeburn 5503: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5504: '<td>'.$title{$item}.
5505: '</td><td class="LC_left_item">'.
5506: '<span class="LC_nobreak">';
5507: foreach my $auth (@authtypes) {
5508: $datatable .= '<label>'.
5509: '<input type="checkbox" name="'.$item.'_auth" '.
5510: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5511: $authname{$auth}.'</label> ';
5512: }
5513: $datatable .= '</span></td></tr>';
5514: $rownum ++;
1.27 raeburn 5515: }
1.30 raeburn 5516: $$rowtotal += $rownum;
1.27 raeburn 5517: }
5518: return $datatable;
5519: }
5520:
1.160.6.34 raeburn 5521: sub print_selfcreation {
5522: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 5523: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
5524: $emaildomain,$datatable);
1.160.6.34 raeburn 5525: if (ref($settings) eq 'HASH') {
5526: if (ref($settings->{'cancreate'}) eq 'HASH') {
5527: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 5528: if (ref($createsettings) eq 'HASH') {
5529: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5530: @selfcreate = @{$createsettings->{'selfcreate'}};
5531: } elsif ($createsettings->{'selfcreate'} ne '') {
5532: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5533: @selfcreate = ('email','login','sso');
5534: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5535: @selfcreate = ($createsettings->{'selfcreate'});
5536: }
5537: }
5538: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5539: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 5540: }
1.160.6.93 raeburn 5541: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
5542: $emailoptions = $createsettings->{'emailoptions'};
5543: }
5544: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
5545: $emailverified = $createsettings->{'emailverified'};
5546: }
5547: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
5548: $emaildomain = $createsettings->{'emaildomain'};
5549: }
1.160.6.34 raeburn 5550: }
5551: }
5552: }
5553: my %radiohash;
5554: my $numinrow = 4;
5555: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 5556: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 5557: if ($position eq 'top') {
5558: my %choices = &Apache::lonlocal::texthash (
5559: cancreate_login => 'Institutional Login',
5560: cancreate_sso => 'Institutional Single Sign On',
5561: );
5562: my @toggles = sort(keys(%choices));
5563: my %defaultchecked = (
5564: 'cancreate_login' => 'off',
5565: 'cancreate_sso' => 'off',
5566: );
1.160.6.35 raeburn 5567: my ($onclick,$itemcount);
1.160.6.34 raeburn 5568: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5569: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 5570: $$rowtotal += $itemcount;
1.160.6.34 raeburn 5571:
5572: if (ref($usertypes) eq 'HASH') {
5573: if (keys(%{$usertypes}) > 0) {
5574: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5575: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 5576: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 5577: $$rowtotal ++;
5578: }
5579: }
1.160.6.44 raeburn 5580: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5581: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5582: $fieldtitles{'inststatus'} = &mt('Institutional status');
5583: my $rem;
5584: my $numperrow = 2;
5585: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5586: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 5587: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 5588: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 5589: '<table>'."\n";
1.160.6.44 raeburn 5590: for (my $i=0; $i<@fields; $i++) {
5591: $rem = $i%($numperrow);
5592: if ($rem == 0) {
5593: if ($i > 0) {
5594: $datatable .= '</tr>';
5595: }
5596: $datatable .= '<tr>';
5597: }
5598: my $currval;
1.160.6.51 raeburn 5599: if (ref($createsettings) eq 'HASH') {
5600: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5601: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5602: }
1.160.6.44 raeburn 5603: }
5604: $datatable .= '<td class="LC_left_item">'.
5605: '<span class="LC_nobreak">'.
5606: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5607: 'value="'.$currval.'" size="10" /> '.
5608: $fieldtitles{$fields[$i]}.'</span></td>';
5609: }
5610: my $colsleft = $numperrow - $rem;
5611: if ($colsleft > 1 ) {
5612: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5613: ' </td>';
5614: } elsif ($colsleft == 1) {
5615: $datatable .= '<td class="LC_left_item"> </td>';
5616: }
5617: $datatable .= '</tr></table></td></tr>';
5618: $$rowtotal ++;
1.160.6.34 raeburn 5619: } elsif ($position eq 'middle') {
5620: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 5621: my @posstypes;
1.160.6.34 raeburn 5622: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 5623: @posstypes = @{$types};
5624: }
5625: unless (grep(/^default$/,@posstypes)) {
5626: push(@posstypes,'default');
5627: }
5628: my %usertypeshash;
5629: if (ref($usertypes) eq 'HASH') {
5630: %usertypeshash = %{$usertypes};
5631: }
5632: $usertypeshash{'default'} = $othertitle;
5633: foreach my $status (@posstypes) {
5634: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
5635: $numinrow,$$rowtotal,\%usertypeshash);
5636: $$rowtotal ++;
1.160.6.34 raeburn 5637: }
5638: } else {
1.160.6.40 raeburn 5639: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 5640: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 5641: );
5642: my @toggles = sort(keys(%choices));
5643: my %defaultchecked = (
5644: 'cancreate_email' => 'off',
5645: );
1.160.6.93 raeburn 5646: my $customclass = 'LC_selfcreate_email';
5647: my $classprefix = 'LC_canmodify_emailusername_';
5648: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 5649: my $display = 'none';
1.160.6.93 raeburn 5650: my $rowstyle = 'display:none';
1.160.6.40 raeburn 5651: if (grep(/^\Qemail\E$/,@selfcreate)) {
5652: $display = 'block';
1.160.6.93 raeburn 5653: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 5654: }
1.160.6.93 raeburn 5655: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
5656: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5657: \%choices,$$rowtotal,$onclick);
5658: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
5659: $rowstyle);
5660: $$rowtotal ++;
5661: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
5662: $rowstyle);
5663: $$rowtotal ++;
5664: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 5665: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 5666: my ($emailrules,$emailruleorder) =
5667: &Apache::lonnet::inst_userrules($dom,'email');
5668: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5669: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5670: if (ref($types) eq 'ARRAY') {
5671: @posstypes = @{$types};
5672: }
5673: if (@posstypes) {
5674: unless (grep(/^default$/,@posstypes)) {
5675: push(@posstypes,'default');
1.160.6.89 raeburn 5676: }
5677: if (ref($usertypes) eq 'HASH') {
5678: %usertypeshash = %{$usertypes};
5679: }
1.160.6.93 raeburn 5680: my $currassign;
5681: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
5682: $currassign = {
5683: selfassign => $domdefaults{'inststatusguest'},
5684: };
5685: @ordered = @{$domdefaults{'inststatusguest'}};
5686: } else {
5687: $currassign = { selfassign => [] };
5688: }
5689: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
5690: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
5691: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
5692: $numinrow,$othertitle,'selfassign',
5693: $rowtotal,$onclicktypes,$customclass,
5694: $rowstyle);
5695: $$rowtotal ++;
1.160.6.89 raeburn 5696: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 5697: foreach my $status (@posstypes) {
5698: my $css_class;
5699: if ($$rowtotal%2) {
5700: $css_class = 'LC_odd_row ';
5701: }
5702: $css_class .= $customclass;
5703: my $rowid = $optionsprefix.$status;
5704: my $hidden = 1;
5705: my $currstyle = 'display:none';
5706: if (grep(/^\Q$status\E$/,@ordered)) {
5707: $currstyle = $rowstyle;
5708: $hidden = 0;
5709: }
5710: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
5711: $emailrules,$emailruleorder,$settings,$status,$rowid,
5712: $usertypeshash{$status},$css_class,$currstyle,$intdom);
5713: unless ($hidden) {
5714: $$rowtotal ++;
5715: }
1.160.6.89 raeburn 5716: }
5717: } else {
1.160.6.93 raeburn 5718: my $css_class;
5719: if ($$rowtotal%2) {
5720: $css_class = 'LC_odd_row ';
5721: }
5722: $css_class .= $customclass;
1.160.6.89 raeburn 5723: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 5724: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
5725: $emailrules,$emailruleorder,$settings,'default','',
5726: $othertitle,$css_class,$rowstyle,$intdom);
5727: $$rowtotal ++;
1.160.6.34 raeburn 5728: }
1.160.6.35 raeburn 5729: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5730: $numinrow = 1;
1.160.6.93 raeburn 5731: if (@posstypes) {
5732: foreach my $status (@posstypes) {
5733: my $rowid = $classprefix.$status;
5734: my $datarowstyle = 'display:none';
5735: if (grep(/^\Q$status\E$/,@ordered)) {
5736: $datarowstyle = $rowstyle;
5737: }
5738: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5739: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
5740: $infotitles,$rowid,$customclass,$datarowstyle);
5741: unless ($datarowstyle eq 'display:none') {
5742: $$rowtotal ++;
5743: }
1.160.6.34 raeburn 5744: }
1.160.6.93 raeburn 5745: } else {
5746: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
5747: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
5748: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 5749: }
5750: }
5751: return $datatable;
5752: }
5753:
1.160.6.93 raeburn 5754: sub selfcreate_javascript {
5755: return <<"ENDSCRIPT";
5756:
5757: <script type="text/javascript">
5758: // <![CDATA[
5759:
5760: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
5761: var x = document.getElementsByClassName(target);
5762: var insttypes = 0;
5763: var insttypeRegExp = new RegExp(prefix);
5764: if ((x.length != undefined) && (x.length > 0)) {
5765: if (form.elements[radio].length != undefined) {
5766: for (var i=0; i<form.elements[radio].length; i++) {
5767: if (form.elements[radio][i].checked) {
5768: if (form.elements[radio][i].value == 1) {
5769: for (var j=0; j<x.length; j++) {
5770: if (x[j].id == 'undefined') {
5771: x[j].style.display = 'table-row';
5772: } else if (insttypeRegExp.test(x[j].id)) {
5773: insttypes ++;
5774: } else {
5775: x[j].style.display = 'table-row';
5776: }
5777: }
5778: } else {
5779: for (var j=0; j<x.length; j++) {
5780: x[j].style.display = 'none';
5781: }
1.160.6.40 raeburn 5782: }
1.160.6.93 raeburn 5783: break;
5784: }
5785: }
5786: if (insttypes > 0) {
5787: toggleDataRow(form,checkbox,target,altprefix);
5788: toggleDataRow(form,checkbox,target,prefix,1);
5789: }
5790: }
5791: }
5792: return;
5793: }
5794:
5795: function toggleDataRow(form,checkbox,target,prefix,docount) {
5796: if (form.elements[checkbox].length != undefined) {
5797: var count = 0;
5798: if (docount) {
5799: for (var i=0; i<form.elements[checkbox].length; i++) {
5800: if (form.elements[checkbox][i].checked) {
5801: count ++;
5802: }
5803: }
5804: }
5805: for (var i=0; i<form.elements[checkbox].length; i++) {
5806: var type = form.elements[checkbox][i].value;
5807: if (document.getElementById(prefix+type)) {
5808: if (form.elements[checkbox][i].checked) {
5809: document.getElementById(prefix+type).style.display = 'table-row';
5810: if (count % 2 == 1) {
5811: document.getElementById(prefix+type).className = target+' LC_odd_row';
5812: } else {
5813: document.getElementById(prefix+type).className = target;
5814: }
5815: count ++;
1.160.6.40 raeburn 5816: } else {
1.160.6.93 raeburn 5817: document.getElementById(prefix+type).style.display = 'none';
5818: }
5819: }
5820: }
5821: }
5822: return;
5823: }
5824:
5825: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
5826: var caller = radio+'_'+status;
5827: if (form.elements[caller].length != undefined) {
5828: for (var i=0; i<form.elements[caller].length; i++) {
5829: if (form.elements[caller][i].checked) {
5830: if (document.getElementById(altprefix+'_inst_'+status)) {
5831: var curr = form.elements[caller][i].value;
5832: if (prefix) {
5833: document.getElementById(prefix+'_'+status).style.display = 'none';
5834: }
5835: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
5836: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
5837: if (curr == 'custom') {
5838: if (prefix) {
5839: document.getElementById(prefix+'_'+status).style.display = 'inline';
5840: }
5841: } else if (curr == 'inst') {
5842: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
5843: } else if (curr == 'noninst') {
5844: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 5845: }
1.160.6.93 raeburn 5846: break;
1.160.6.40 raeburn 5847: }
1.160.6.93 raeburn 5848: }
5849: }
5850: }
5851: }
5852:
5853: // ]]>
5854: </script>
5855:
5856: ENDSCRIPT
5857: }
5858:
5859: sub noninst_users {
5860: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
5861: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
5862: my $class = 'LC_left_item';
5863: if ($css_class) {
5864: $css_class = ' class="'.$css_class.'"';
5865: }
5866: if ($rowid) {
5867: $rowid = ' id="'.$rowid.'"';
5868: }
5869: if ($rowstyle) {
5870: $rowstyle = ' style="'.$rowstyle.'"';
5871: }
5872: my ($output,$description);
5873: if ($type eq 'default') {
5874: $description = &mt('Requests for: [_1]',$typetitle);
5875: } else {
5876: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
5877: }
5878: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
5879: "<td>$description</td>\n".
5880: '<td class="'.$class.'" colspan="2">'.
5881: '<table><tr>';
5882: my %headers = &Apache::lonlocal::texthash(
5883: approve => 'Processing',
5884: email => 'E-mail',
5885: username => 'Username',
5886: );
5887: foreach my $item ('approve','email','username') {
5888: $output .= '<th>'.$headers{$item}.'</th>';
5889: }
5890: $output .= '</tr><tr>';
5891: foreach my $item ('approve','email','username') {
5892: $output .= '<td valign="top">';
5893: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
5894: if ($item eq 'approve') {
5895: %choices = &Apache::lonlocal::texthash (
5896: automatic => 'Automatically approved',
5897: approval => 'Queued for approval',
5898: );
5899: @options = ('automatic','approval');
5900: $hashref = $processing;
5901: $defoption = 'automatic';
5902: $name = 'cancreate_emailprocess_'.$type;
5903: } elsif ($item eq 'email') {
5904: %choices = &Apache::lonlocal::texthash (
5905: any => 'Any e-mail',
5906: inst => 'Institutional only',
5907: noninst => 'Non-institutional only',
5908: custom => 'Custom restrictions',
5909: );
5910: @options = ('any','inst','noninst');
5911: my $showcustom;
5912: if (ref($emailrules) eq 'HASH') {
5913: if (keys(%{$emailrules}) > 0) {
5914: push(@options,'custom');
5915: $showcustom = 'cancreate_emailrule';
5916: if (ref($settings) eq 'HASH') {
5917: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
5918: foreach my $rule (@{$settings->{'email_rule'}}) {
5919: if (exists($emailrules->{$rule})) {
5920: $hascustom ++;
5921: }
5922: }
5923: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
5924: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
5925: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
5926: if (exists($emailrules->{$rule})) {
5927: $hascustom ++;
5928: }
5929: }
5930: }
5931: }
5932: }
5933: }
5934: }
5935: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
5936: "'cancreate_emaildomain','$type'".');"';
5937: $hashref = $emailoptions;
5938: $defoption = 'any';
5939: $name = 'cancreate_emailoptions_'.$type;
5940: } elsif ($item eq 'username') {
5941: %choices = &Apache::lonlocal::texthash (
5942: all => 'Same as e-mail',
5943: first => 'Omit @domain',
5944: free => 'Free to choose',
5945: );
5946: @options = ('all','first','free');
5947: $hashref = $emailverified;
5948: $defoption = 'all';
5949: $name = 'cancreate_usernameoptions_'.$type;
5950: }
5951: foreach my $option (@options) {
5952: my $checked;
5953: if (ref($hashref) eq 'HASH') {
5954: if ($type eq '') {
5955: if (!exists($hashref->{'default'})) {
5956: if ($option eq $defoption) {
5957: $checked = ' checked="checked"';
5958: }
5959: } else {
5960: if ($hashref->{'default'} eq $option) {
5961: $checked = ' checked="checked"';
5962: }
1.160.6.40 raeburn 5963: }
5964: } else {
1.160.6.93 raeburn 5965: if (!exists($hashref->{$type})) {
5966: if ($option eq $defoption) {
5967: $checked = ' checked="checked"';
5968: }
5969: } else {
5970: if ($hashref->{$type} eq $option) {
5971: $checked = ' checked="checked"';
5972: }
1.160.6.40 raeburn 5973: }
5974: }
1.160.6.93 raeburn 5975: } elsif (($item eq 'email') && ($hascustom)) {
5976: if ($option eq 'custom') {
5977: $checked = ' checked="checked"';
5978: }
5979: } elsif ($option eq $defoption) {
5980: $checked = ' checked="checked"';
5981: }
5982: $output .= '<span class="LC_nobreak"><label>'.
5983: '<input type="radio" name="'.$name.'"'.
5984: $checked.' value="'.$option.'"'.$onclick.' />'.
5985: $choices{$option}.'</label></span><br />';
5986: if ($item eq 'email') {
5987: if ($option eq 'custom') {
5988: my $id = 'cancreate_emailrule_'.$type;
5989: my $display = 'none';
5990: if ($checked) {
5991: $display = 'inline';
5992: }
5993: my $numinrow = 2;
5994: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
5995: '<legend>'.&mt('Disallow').'</legend><table>'.
5996: &user_formats_row('email',$settings,$emailrules,
5997: $emailruleorder,$numinrow,'',$type);
5998: '</table></fieldset>';
5999: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
6000: my %text = &Apache::lonlocal::texthash (
6001: inst => 'must end:',
6002: noninst => 'cannot end:',
6003: );
6004: my $value;
6005: if (ref($emaildomain) eq 'HASH') {
6006: if (ref($emaildomain->{$type}) eq 'HASH') {
6007: $value = $emaildomain->{$type}->{$option};
6008: }
6009: }
6010: if ($value eq '') {
6011: $value = '@'.$intdom;
6012: }
6013: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
6014: my $display = 'none';
6015: if ($checked) {
6016: $display = 'inline';
6017: }
6018: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
6019: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
6020: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
6021: '</div>';
6022: }
1.160.6.40 raeburn 6023: }
6024: }
1.160.6.93 raeburn 6025: $output .= '</td>'."\n";
1.160.6.40 raeburn 6026: }
1.160.6.93 raeburn 6027: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 6028: return $output;
6029: }
6030:
1.160.6.5 raeburn 6031: sub captcha_choice {
1.160.6.93 raeburn 6032: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 6033: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
6034: $vertext,$currver);
1.160.6.5 raeburn 6035: my %lt = &captcha_phrases();
6036: $keyentry = 'hidden';
1.160.6.98 raeburn 6037: my $colspan=2;
1.160.6.5 raeburn 6038: if ($context eq 'cancreate') {
1.160.6.34 raeburn 6039: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 6040: } elsif ($context eq 'login') {
6041: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98 raeburn 6042: } elsif ($context eq 'passwords') {
6043: $rowname = &mt('"Forgot Password" CAPTCHA validation');
6044: $colspan=1;
1.160.6.5 raeburn 6045: }
6046: if (ref($settings) eq 'HASH') {
6047: if ($settings->{'captcha'}) {
6048: $checked{$settings->{'captcha'}} = ' checked="checked"';
6049: } else {
6050: $checked{'original'} = ' checked="checked"';
6051: }
6052: if ($settings->{'captcha'} eq 'recaptcha') {
6053: $pubtext = $lt{'pub'};
6054: $privtext = $lt{'priv'};
6055: $keyentry = 'text';
1.160.6.69 raeburn 6056: $vertext = $lt{'ver'};
6057: $currver = $settings->{'recaptchaversion'};
6058: if ($currver ne '2') {
6059: $currver = 1;
6060: }
1.160.6.5 raeburn 6061: }
6062: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
6063: $currpub = $settings->{'recaptchakeys'}{'public'};
6064: $currpriv = $settings->{'recaptchakeys'}{'private'};
6065: }
6066: } else {
6067: $checked{'original'} = ' checked="checked"';
6068: }
1.160.6.93 raeburn 6069: my $css_class;
6070: if ($itemcount%2) {
6071: $css_class = 'LC_odd_row';
6072: }
6073: if ($customcss) {
6074: $css_class .= " $customcss";
6075: }
6076: $css_class =~ s/^\s+//;
6077: if ($css_class) {
6078: $css_class = ' class="'.$css_class.'"';
6079: }
6080: if ($rowstyle) {
6081: $css_class .= ' style="'.$rowstyle.'"';
6082: }
1.160.6.5 raeburn 6083: my $output = '<tr'.$css_class.'>'.
1.160.6.98 raeburn 6084: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 6085: '<table><tr><td>'."\n";
6086: foreach my $option ('original','recaptcha','notused') {
6087: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
6088: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
6089: $lt{$option}.'</label></span>';
6090: unless ($option eq 'notused') {
6091: $output .= (' 'x2)."\n";
6092: }
6093: }
6094: #
6095: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
6096: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
6097: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
6098: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
6099: #
6100: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 6101: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 6102: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
6103: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
6104: $currpub.'" size="40" /></span><br />'."\n".
6105: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
6106: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 6107: $currpriv.'" size="40" /></span><br />'.
6108: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
6109: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
6110: $currver.'" size="3" /></span><br />'.
6111: '</td></tr></table>'."\n".
1.160.6.5 raeburn 6112: '</td></tr>';
6113: return $output;
6114: }
6115:
1.32 raeburn 6116: sub user_formats_row {
1.160.6.93 raeburn 6117: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 6118: my $output;
6119: my %text = (
6120: 'username' => 'new usernames',
6121: 'id' => 'IDs',
6122: );
1.160.6.93 raeburn 6123: unless ($type eq 'email') {
6124: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6125: $output = '<tr '.$css_class.'>'.
6126: '<td><span class="LC_nobreak">'.
6127: &mt("Format rules to check for $text{$type}: ").
6128: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 6129: }
1.27 raeburn 6130: my $rem;
6131: if (ref($ruleorder) eq 'ARRAY') {
6132: for (my $i=0; $i<@{$ruleorder}; $i++) {
6133: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
6134: my $rem = $i%($numinrow);
6135: if ($rem == 0) {
6136: if ($i > 0) {
6137: $output .= '</tr>';
6138: }
6139: $output .= '<tr>';
6140: }
6141: my $check = ' ';
1.39 raeburn 6142: if (ref($settings) eq 'HASH') {
6143: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
6144: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
6145: $check = ' checked="checked" ';
6146: }
1.160.6.93 raeburn 6147: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
6148: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
6149: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
6150: $check = ' checked="checked" ';
6151: }
6152: }
1.27 raeburn 6153: }
6154: }
1.160.6.93 raeburn 6155: my $name = $type.'_rule';
6156: if ($type eq 'email') {
6157: $name .= '_'.$status;
6158: }
1.27 raeburn 6159: $output .= '<td class="LC_left_item">'.
6160: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 6161: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 6162: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
6163: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
6164: }
6165: }
6166: $rem = @{$ruleorder}%($numinrow);
6167: }
1.160.6.93 raeburn 6168: my $colsleft;
6169: if ($rem) {
6170: $colsleft = $numinrow - $rem;
6171: }
1.27 raeburn 6172: if ($colsleft > 1 ) {
6173: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6174: ' </td>';
6175: } elsif ($colsleft == 1) {
6176: $output .= '<td class="LC_left_item"> </td>';
6177: }
1.160.6.93 raeburn 6178: $output .= '</tr></table>';
6179: unless ($type eq 'email') {
6180: $output .= '</td></tr>';
6181: }
1.27 raeburn 6182: return $output;
6183: }
6184:
1.34 raeburn 6185: sub usercreation_types {
6186: my %lt = &Apache::lonlocal::texthash (
6187: author => 'When adding a co-author',
6188: course => 'When adding a user to a course',
1.100 raeburn 6189: requestcrs => 'When requesting a course',
1.34 raeburn 6190: any => 'Any',
6191: official => 'Institutional only ',
6192: unofficial => 'Non-institutional only',
6193: none => 'None',
6194: );
6195: return %lt;
1.48 raeburn 6196: }
1.34 raeburn 6197:
1.160.6.34 raeburn 6198: sub selfcreation_types {
6199: my %lt = &Apache::lonlocal::texthash (
6200: selfcreate => 'User creates own account',
6201: any => 'Any',
6202: official => 'Institutional only ',
6203: unofficial => 'Non-institutional only',
6204: email => 'E-mail address',
6205: login => 'Institutional Login',
6206: sso => 'SSO',
6207: );
6208: }
6209:
1.28 raeburn 6210: sub authtype_names {
6211: my %lt = &Apache::lonlocal::texthash(
6212: int => 'Internal',
6213: krb4 => 'Kerberos 4',
6214: krb5 => 'Kerberos 5',
6215: loc => 'Local',
6216: );
6217: return %lt;
6218: }
6219:
6220: sub context_names {
6221: my %context_title = &Apache::lonlocal::texthash(
6222: author => 'Creating users when an Author',
6223: course => 'Creating users when in a course',
6224: domain => 'Creating users when a Domain Coordinator',
6225: );
6226: return %context_title;
6227: }
6228:
1.33 raeburn 6229: sub print_usermodification {
6230: my ($position,$dom,$settings,$rowtotal) = @_;
6231: my $numinrow = 4;
6232: my ($context,$datatable,$rowcount);
6233: if ($position eq 'top') {
6234: $rowcount = 0;
6235: $context = 'author';
6236: foreach my $role ('ca','aa') {
6237: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6238: $numinrow,$rowcount);
6239: $$rowtotal ++;
6240: $rowcount ++;
6241: }
1.160.6.37 raeburn 6242: } elsif ($position eq 'bottom') {
1.33 raeburn 6243: $context = 'course';
6244: $rowcount = 0;
6245: foreach my $role ('st','ep','ta','in','cr') {
6246: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6247: $numinrow,$rowcount);
6248: $$rowtotal ++;
6249: $rowcount ++;
6250: }
6251: }
6252: return $datatable;
6253: }
6254:
1.43 raeburn 6255: sub print_defaults {
1.160.6.40 raeburn 6256: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 6257: my $rownum = 0;
1.160.6.80 raeburn 6258: my ($datatable,$css_class,$titles);
6259: unless ($position eq 'bottom') {
6260: $titles = &defaults_titles($dom);
6261: }
1.160.6.40 raeburn 6262: if ($position eq 'top') {
6263: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
6264: 'datelocale_def','portal_def');
6265: my %defaults;
6266: if (ref($settings) eq 'HASH') {
6267: %defaults = %{$settings};
1.43 raeburn 6268: } else {
1.160.6.40 raeburn 6269: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
6270: foreach my $item (@items) {
6271: $defaults{$item} = $domdefaults{$item};
6272: }
1.43 raeburn 6273: }
1.160.6.40 raeburn 6274: foreach my $item (@items) {
6275: if ($rownum%2) {
6276: $css_class = '';
6277: } else {
6278: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 6279: }
1.160.6.40 raeburn 6280: $datatable .= '<tr'.$css_class.'>'.
6281: '<td><span class="LC_nobreak">'.$titles->{$item}.
6282: '</span></td><td class="LC_right_item" colspan="3">';
6283: if ($item eq 'auth_def') {
6284: my @authtypes = ('internal','krb4','krb5','localauth');
6285: my %shortauth = (
6286: internal => 'int',
6287: krb4 => 'krb4',
6288: krb5 => 'krb5',
6289: localauth => 'loc'
6290: );
6291: my %authnames = &authtype_names();
6292: foreach my $auth (@authtypes) {
6293: my $checked = ' ';
6294: if ($defaults{$item} eq $auth) {
6295: $checked = ' checked="checked" ';
6296: }
6297: $datatable .= '<label><input type="radio" name="'.$item.
6298: '" value="'.$auth.'"'.$checked.'/>'.
6299: $authnames{$shortauth{$auth}}.'</label> ';
6300: }
6301: } elsif ($item eq 'timezone_def') {
6302: my $includeempty = 1;
6303: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
6304: } elsif ($item eq 'datelocale_def') {
1.160.6.98 raeburn 6305: my $includeempty = 1;
6306: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
6307: } elsif ($item eq 'lang_def') {
6308: my $includeempty = 1;
6309: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.80 raeburn 6310: } else {
1.160.6.98 raeburn 6311: my $size;
6312: if ($item eq 'portal_def') {
6313: $size = ' size="25"';
6314: }
1.160.6.80 raeburn 6315: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.98 raeburn 6316: $defaults{$item}.'"'.$size.' />';
1.160.6.80 raeburn 6317: }
6318: $datatable .= '</td></tr>';
6319: $rownum ++;
6320: }
1.160.6.40 raeburn 6321: } else {
1.160.6.80 raeburn 6322: my %defaults;
1.160.6.40 raeburn 6323: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 6324: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 6325: my $maxnum = @{$settings->{'inststatusorder'}};
6326: for (my $i=0; $i<$maxnum; $i++) {
6327: $css_class = $rownum%2?' class="LC_odd_row"':'';
6328: my $item = $settings->{'inststatusorder'}->[$i];
6329: my $title = $settings->{'inststatustypes'}->{$item};
6330: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
6331: $datatable .= '<tr'.$css_class.'>'.
6332: '<td><span class="LC_nobreak">'.
6333: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
6334: for (my $k=0; $k<=$maxnum; $k++) {
6335: my $vpos = $k+1;
6336: my $selstr;
6337: if ($k == $i) {
6338: $selstr = ' selected="selected" ';
6339: }
6340: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6341: }
6342: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
6343: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
6344: &mt('delete').'</span></td>'.
6345: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
6346: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 6347: '</span></td></tr>';
1.160.6.40 raeburn 6348: }
6349: $css_class = $rownum%2?' class="LC_odd_row"':'';
6350: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
6351: $datatable .= '<tr '.$css_class.'>'.
6352: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
6353: for (my $k=0; $k<=$maxnum; $k++) {
6354: my $vpos = $k+1;
6355: my $selstr;
6356: if ($k == $maxnum) {
6357: $selstr = ' selected="selected" ';
6358: }
6359: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6360: }
6361: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 6362: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 6363: ' '.&mt('(new)').
6364: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
6365: &mt('Name displayed:').
6366: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
6367: '</tr>'."\n";
6368: $rownum ++;
1.141 raeburn 6369: }
1.43 raeburn 6370: }
6371: }
6372: $$rowtotal += $rownum;
6373: return $datatable;
6374: }
6375:
1.160.6.5 raeburn 6376: sub get_languages_hash {
6377: my %langchoices;
6378: foreach my $id (&Apache::loncommon::languageids()) {
6379: my $code = &Apache::loncommon::supportedlanguagecode($id);
6380: if ($code ne '') {
6381: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
6382: }
6383: }
6384: return %langchoices;
6385: }
6386:
1.43 raeburn 6387: sub defaults_titles {
1.141 raeburn 6388: my ($dom) = @_;
1.43 raeburn 6389: my %titles = &Apache::lonlocal::texthash (
6390: 'auth_def' => 'Default authentication type',
6391: 'auth_arg_def' => 'Default authentication argument',
6392: 'lang_def' => 'Default language',
1.54 raeburn 6393: 'timezone_def' => 'Default timezone',
1.68 raeburn 6394: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 6395: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 6396: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
6397: 'intauth_check' => 'Check bcrypt cost if authenticated',
6398: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 6399: );
1.141 raeburn 6400: if ($dom) {
6401: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
6402: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
6403: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
6404: $protocol = 'http' if ($protocol ne 'https');
6405: if ($uint_dom) {
6406: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
6407: $uint_dom);
6408: }
6409: }
1.43 raeburn 6410: return (\%titles);
6411: }
6412:
1.160.6.97 raeburn 6413: sub print_scantron {
6414: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
6415: if ($position eq 'top') {
6416: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
6417: } else {
6418: return &print_scantronconfig($dom,$settings,\$rowtotal);
6419: }
6420: }
6421:
6422: sub scantron_javascript {
6423: return <<"ENDSCRIPT";
6424:
6425: <script type="text/javascript">
6426: // <![CDATA[
6427:
6428: function toggleScantron(form) {
6429: var csvfieldset = new Array();
6430: if (document.getElementById('scantroncsv_cols')) {
6431: csvfieldset.push(document.getElementById('scantroncsv_cols'));
6432: }
6433: if (document.getElementById('scantroncsv_options')) {
6434: csvfieldset.push(document.getElementById('scantroncsv_options'));
6435: }
6436: if (csvfieldset.length) {
6437: if (document.getElementById('scantronconfcsv')) {
6438: var scantroncsv = document.getElementById('scantronconfcsv');
6439: if (scantroncsv.checked) {
6440: for (var i=0; i<csvfieldset.length; i++) {
6441: csvfieldset[i].style.display = 'block';
6442: }
6443: } else {
6444: for (var i=0; i<csvfieldset.length; i++) {
6445: csvfieldset[i].style.display = 'none';
6446: }
6447: var csvselects = document.getElementsByClassName('scantronconfig_csv');
6448: if (csvselects.length) {
6449: for (var j=0; j<csvselects.length; j++) {
6450: csvselects[j].selectedIndex = 0;
6451: }
6452: }
6453: }
6454: }
6455: }
6456: return;
6457: }
6458: // ]]>
6459: </script>
6460:
6461: ENDSCRIPT
6462:
6463: }
6464:
1.46 raeburn 6465: sub print_scantronformat {
6466: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
6467: my $itemcount = 1;
1.60 raeburn 6468: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
6469: %confhash);
1.46 raeburn 6470: my $switchserver = &check_switchserver($dom,$confname);
6471: my %lt = &Apache::lonlocal::texthash (
1.95 www 6472: default => 'Default bubblesheet format file error',
6473: custom => 'Custom bubblesheet format file error',
1.46 raeburn 6474: );
6475: my %scantronfiles = (
6476: default => 'default.tab',
6477: custom => 'custom.tab',
6478: );
6479: foreach my $key (keys(%scantronfiles)) {
6480: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
6481: .$scantronfiles{$key};
6482: }
6483: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
6484: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
6485: if (!$switchserver) {
6486: my $servadm = $r->dir_config('lonAdmEMail');
6487: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
6488: if ($configuserok eq 'ok') {
6489: if ($author_ok eq 'ok') {
6490: my %legacyfile = (
1.160.6.97 raeburn 6491: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
6492: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 6493: );
6494: my %md5chk;
6495: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6496: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
6497: chomp($md5chk{$type});
1.46 raeburn 6498: }
6499: if ($md5chk{'default'} ne $md5chk{'custom'}) {
6500: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 6501: ($scantronurls{$type},my $error) =
1.46 raeburn 6502: &legacy_scantronformat($r,$dom,$confname,
6503: $type,$legacyfile{$type},
6504: $scantronurls{$type},
6505: $scantronfiles{$type});
1.60 raeburn 6506: if ($error ne '') {
6507: $error{$type} = $error;
6508: }
6509: }
6510: if (keys(%error) == 0) {
6511: $is_custom = 1;
1.160.6.97 raeburn 6512: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 6513: $scantronurls{'custom'};
1.160.6.97 raeburn 6514: my $putresult =
1.60 raeburn 6515: &Apache::lonnet::put_dom('configuration',
6516: \%confhash,$dom);
6517: if ($putresult ne 'ok') {
1.160.6.97 raeburn 6518: $error{'custom'} =
1.60 raeburn 6519: '<span class="LC_error">'.
6520: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6521: }
1.46 raeburn 6522: }
6523: } else {
1.60 raeburn 6524: ($scantronurls{'default'},my $error) =
1.46 raeburn 6525: &legacy_scantronformat($r,$dom,$confname,
6526: 'default',$legacyfile{'default'},
6527: $scantronurls{'default'},
6528: $scantronfiles{'default'});
1.60 raeburn 6529: if ($error eq '') {
6530: $confhash{'scantron'}{'scantronformat'} = '';
6531: my $putresult =
6532: &Apache::lonnet::put_dom('configuration',
6533: \%confhash,$dom);
6534: if ($putresult ne 'ok') {
6535: $error{'default'} =
6536: '<span class="LC_error">'.
6537: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6538: }
6539: } else {
6540: $error{'default'} = $error;
6541: }
1.46 raeburn 6542: }
6543: }
6544: }
6545: } else {
1.95 www 6546: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 6547: }
6548: }
6549: if (ref($settings) eq 'HASH') {
6550: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
6551: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
6552: if ((!@info) || ($info[0] eq 'no_such_dir')) {
6553: $scantronurl = '';
6554: } else {
6555: $scantronurl = $settings->{'scantronformat'};
6556: }
6557: $is_custom = 1;
6558: } else {
6559: $scantronurl = $scantronurls{'default'};
6560: }
6561: } else {
1.60 raeburn 6562: if ($is_custom) {
6563: $scantronurl = $scantronurls{'custom'};
6564: } else {
6565: $scantronurl = $scantronurls{'default'};
6566: }
1.46 raeburn 6567: }
6568: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6569: $datatable .= '<tr'.$css_class.'>';
6570: if (!$is_custom) {
1.65 raeburn 6571: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
6572: '<span class="LC_nobreak">';
1.46 raeburn 6573: if ($scantronurl) {
1.160.6.21 raeburn 6574: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
6575: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 6576: } else {
6577: $datatable = &mt('File unavailable for display');
6578: }
1.65 raeburn 6579: $datatable .= '</span></td>';
1.60 raeburn 6580: if (keys(%error) == 0) {
6581: $datatable .= '<td valign="bottom">';
6582: if (!$switchserver) {
6583: $datatable .= &mt('Upload:').'<br />';
6584: }
6585: } else {
6586: my $errorstr;
6587: foreach my $key (sort(keys(%error))) {
6588: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6589: }
6590: $datatable .= '<td>'.$errorstr;
6591: }
1.46 raeburn 6592: } else {
6593: if (keys(%error) > 0) {
6594: my $errorstr;
6595: foreach my $key (sort(keys(%error))) {
6596: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6597: }
1.60 raeburn 6598: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 6599: } elsif ($scantronurl) {
1.160.6.26 raeburn 6600: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 6601: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 6602: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 6603: $link.
6604: '<label><input type="checkbox" name="scantronformat_del"'.
6605: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 6606: '<td><span class="LC_nobreak"> '.
6607: &mt('Replace:').'</span><br />';
1.46 raeburn 6608: }
6609: }
6610: if (keys(%error) == 0) {
6611: if ($switchserver) {
6612: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6613: } else {
1.65 raeburn 6614: $datatable .='<span class="LC_nobreak"> '.
6615: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 6616: }
6617: }
6618: $datatable .= '</td></tr>';
6619: $$rowtotal ++;
6620: return $datatable;
6621: }
6622:
6623: sub legacy_scantronformat {
6624: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
6625: my ($url,$error);
6626: my @statinfo = &Apache::lonnet::stat_file($newurl);
6627: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
6628: (my $result,$url) =
6629: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
6630: '','',$newfile);
6631: if ($result ne 'ok') {
1.130 raeburn 6632: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 6633: }
6634: }
6635: return ($url,$error);
6636: }
1.43 raeburn 6637:
1.160.6.97 raeburn 6638: sub print_scantronconfig {
6639: my ($dom,$settings,$rowtotal) = @_;
6640: my $itemcount = 2;
6641: my $is_checked = ' checked="checked"';
6642: my %optionson = (
6643: hdr => ' checked="checked"',
6644: pad => ' checked="checked"',
6645: rem => ' checked="checked"',
6646: );
6647: my %optionsoff = (
6648: hdr => '',
6649: pad => '',
6650: rem => '',
6651: );
6652: my $currcsvsty = 'none';
6653: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
6654: my @fields = &scantroncsv_fields();
6655: my %titles = &scantronconfig_titles();
6656: if (ref($settings) eq 'HASH') {
6657: if (ref($settings->{config}) eq 'HASH') {
6658: if ($settings->{config}->{dat}) {
6659: $checked{'dat'} = $is_checked;
6660: }
6661: if (ref($settings->{config}->{csv}) eq 'HASH') {
6662: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
6663: %csvfields = %{$settings->{config}->{csv}->{fields}};
6664: if (keys(%csvfields) > 0) {
6665: $checked{'csv'} = $is_checked;
6666: $currcsvsty = 'block';
6667: }
6668: }
6669: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
6670: %csvoptions = %{$settings->{config}->{csv}->{options}};
6671: foreach my $option (keys(%optionson)) {
6672: unless ($csvoptions{$option}) {
6673: $optionsoff{$option} = $optionson{$option};
6674: $optionson{$option} = '';
6675: }
6676: }
6677: }
6678: }
6679: } else {
6680: $checked{'dat'} = $is_checked;
6681: }
6682: } else {
6683: $checked{'dat'} = $is_checked;
6684: }
6685: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
6686: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6687: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
6688: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
6689: foreach my $item ('dat','csv') {
6690: my $id;
6691: if ($item eq 'csv') {
6692: $id = 'id="scantronconfcsv" ';
6693: }
6694: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
6695: $titles{$item}.'</label>'.(' 'x3);
6696: if ($item eq 'csv') {
6697: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
6698: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
6699: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
6700: foreach my $col (@fields) {
6701: my $selnone;
6702: if ($csvfields{$col} eq '') {
6703: $selnone = ' selected="selected"';
6704: }
6705: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
6706: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
6707: '<option value=""'.$selnone.'></option>';
6708: for (my $i=0; $i<20; $i++) {
6709: my $shown = $i+1;
6710: my $sel;
6711: unless ($selnone) {
6712: if (exists($csvfields{$col})) {
6713: if ($csvfields{$col} == $i) {
6714: $sel = ' selected="selected"';
6715: }
6716: }
6717: }
6718: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
6719: }
6720: $datatable .= '</select></td></tr>';
6721: }
6722: $datatable .= '</table></fieldset>'.
6723: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
6724: '<legend>'.&mt('CSV Options').'</legend>';
6725: foreach my $option ('hdr','pad','rem') {
6726: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
6727: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
6728: &mt('Yes').'</label>'.(' 'x2)."\n".
6729: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
6730: }
6731: $datatable .= '</fieldset>';
6732: $itemcount ++;
6733: }
6734: }
6735: $datatable .= '</td></tr>';
6736: $$rowtotal ++;
6737: return $datatable;
6738: }
6739:
6740: sub scantronconfig_titles {
6741: return &Apache::lonlocal::texthash(
6742: dat => 'Standard format (.dat)',
6743: csv => 'Comma separated values (.csv)',
6744: hdr => 'Remove first line in file (contains column titles)',
6745: pad => 'Prepend 0s to PaperID',
6746: rem => 'Remove leading spaces (except Question Response columns)',
6747: CODE => 'CODE',
6748: ID => 'Student ID',
6749: PaperID => 'Paper ID',
6750: FirstName => 'First Name',
6751: LastName => 'Last Name',
6752: FirstQuestion => 'First Question Response',
6753: Section => 'Section',
6754: );
6755: }
6756:
6757: sub scantroncsv_fields {
6758: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
6759: }
6760:
1.49 raeburn 6761: sub print_coursecategories {
1.57 raeburn 6762: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
6763: my $datatable;
6764: if ($position eq 'top') {
1.160.6.42 raeburn 6765: my (%checked);
6766: my @catitems = ('unauth','auth');
6767: my @cattypes = ('std','domonly','codesrch','none');
6768: $checked{'unauth'} = 'std';
6769: $checked{'auth'} = 'std';
6770: if (ref($settings) eq 'HASH') {
6771: foreach my $type (@cattypes) {
6772: if ($type eq $settings->{'unauth'}) {
6773: $checked{'unauth'} = $type;
6774: }
6775: if ($type eq $settings->{'auth'}) {
6776: $checked{'auth'} = $type;
6777: }
6778: }
6779: }
6780: my %lt = &Apache::lonlocal::texthash (
6781: unauth => 'Catalog type for unauthenticated users',
6782: auth => 'Catalog type for authenticated users',
6783: none => 'No catalog',
6784: std => 'Standard catalog',
6785: domonly => 'Domain-only catalog',
6786: codesrch => "Code search form",
6787: );
6788: my $itemcount = 0;
6789: foreach my $item (@catitems) {
6790: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6791: $datatable .= '<tr '.$css_class.'>'.
6792: '<td>'.$lt{$item}.'</td>'.
6793: '<td class="LC_right_item"><span class="LC_nobreak">';
6794: foreach my $type (@cattypes) {
6795: my $ischecked;
6796: if ($checked{$item} eq $type) {
6797: $ischecked=' checked="checked"';
6798: }
6799: $datatable .= '<label>'.
6800: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
6801: ' />'.$lt{$type}.'</label> ';
6802: }
1.160.6.87 raeburn 6803: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 6804: $itemcount ++;
6805: }
6806: $$rowtotal += $itemcount;
6807: } elsif ($position eq 'middle') {
1.57 raeburn 6808: my $toggle_cats_crs = ' ';
6809: my $toggle_cats_dom = ' checked="checked" ';
6810: my $can_cat_crs = ' ';
6811: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 6812: my $toggle_catscomm_comm = ' ';
6813: my $toggle_catscomm_dom = ' checked="checked" ';
6814: my $can_catcomm_comm = ' ';
6815: my $can_catcomm_dom = ' checked="checked" ';
6816:
1.57 raeburn 6817: if (ref($settings) eq 'HASH') {
6818: if ($settings->{'togglecats'} eq 'crs') {
6819: $toggle_cats_crs = $toggle_cats_dom;
6820: $toggle_cats_dom = ' ';
6821: }
6822: if ($settings->{'categorize'} eq 'crs') {
6823: $can_cat_crs = $can_cat_dom;
6824: $can_cat_dom = ' ';
6825: }
1.120 raeburn 6826: if ($settings->{'togglecatscomm'} eq 'comm') {
6827: $toggle_catscomm_comm = $toggle_catscomm_dom;
6828: $toggle_catscomm_dom = ' ';
6829: }
6830: if ($settings->{'categorizecomm'} eq 'comm') {
6831: $can_catcomm_comm = $can_catcomm_dom;
6832: $can_catcomm_dom = ' ';
6833: }
1.57 raeburn 6834: }
6835: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 6836: togglecats => 'Show/Hide a course in catalog',
6837: togglecatscomm => 'Show/Hide a community in catalog',
6838: categorize => 'Assign a category to a course',
6839: categorizecomm => 'Assign a category to a community',
1.57 raeburn 6840: );
6841: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 6842: dom => 'Set in Domain',
6843: crs => 'Set in Course',
6844: comm => 'Set in Community',
1.57 raeburn 6845: );
6846: $datatable = '<tr class="LC_odd_row">'.
6847: '<td>'.$title{'togglecats'}.'</td>'.
6848: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6849: '<input type="radio" name="togglecats"'.
6850: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6851: '<label><input type="radio" name="togglecats"'.
6852: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
6853: '</tr><tr>'.
6854: '<td>'.$title{'categorize'}.'</td>'.
6855: '<td class="LC_right_item"><span class="LC_nobreak">'.
6856: '<label><input type="radio" name="categorize"'.
6857: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6858: '<label><input type="radio" name="categorize"'.
6859: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 6860: '</tr><tr class="LC_odd_row">'.
6861: '<td>'.$title{'togglecatscomm'}.'</td>'.
6862: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6863: '<input type="radio" name="togglecatscomm"'.
6864: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6865: '<label><input type="radio" name="togglecatscomm"'.
6866: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
6867: '</tr><tr>'.
6868: '<td>'.$title{'categorizecomm'}.'</td>'.
6869: '<td class="LC_right_item"><span class="LC_nobreak">'.
6870: '<label><input type="radio" name="categorizecomm"'.
6871: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6872: '<label><input type="radio" name="categorizecomm"'.
6873: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 6874: '</tr>';
1.120 raeburn 6875: $$rowtotal += 4;
1.57 raeburn 6876: } else {
6877: my $css_class;
6878: my $itemcount = 1;
6879: my $cathash;
6880: if (ref($settings) eq 'HASH') {
6881: $cathash = $settings->{'cats'};
6882: }
6883: if (ref($cathash) eq 'HASH') {
6884: my (@cats,@trails,%allitems,%idx,@jsarray);
6885: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
6886: \%allitems,\%idx,\@jsarray);
6887: my $maxdepth = scalar(@cats);
6888: my $colattrib = '';
6889: if ($maxdepth > 2) {
6890: $colattrib = ' colspan="2" ';
6891: }
6892: my @path;
6893: if (@cats > 0) {
6894: if (ref($cats[0]) eq 'ARRAY') {
6895: my $numtop = @{$cats[0]};
6896: my $maxnum = $numtop;
1.120 raeburn 6897: my %default_names = (
6898: instcode => &mt('Official courses'),
6899: communities => &mt('Communities'),
6900: );
6901:
6902: if ((!grep(/^instcode$/,@{$cats[0]})) ||
6903: ($cathash->{'instcode::0'} eq '') ||
6904: (!grep(/^communities$/,@{$cats[0]})) ||
6905: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 6906: $maxnum ++;
6907: }
6908: my $lastidx;
6909: for (my $i=0; $i<$numtop; $i++) {
6910: my $parent = $cats[0][$i];
6911: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6912: my $item = &escape($parent).'::0';
6913: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
6914: $lastidx = $idx{$item};
6915: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6916: .'<select name="'.$item.'"'.$chgstr.'>';
6917: for (my $k=0; $k<=$maxnum; $k++) {
6918: my $vpos = $k+1;
6919: my $selstr;
6920: if ($k == $i) {
6921: $selstr = ' selected="selected" ';
6922: }
6923: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6924: }
1.160.6.29 raeburn 6925: $datatable .= '</select></span></td><td>';
1.120 raeburn 6926: if ($parent eq 'instcode' || $parent eq 'communities') {
6927: $datatable .= '<span class="LC_nobreak">'
6928: .$default_names{$parent}.'</span>';
6929: if ($parent eq 'instcode') {
6930: $datatable .= '<br /><span class="LC_nobreak">('
6931: .&mt('with institutional codes')
6932: .')</span></td><td'.$colattrib.'>';
6933: } else {
6934: $datatable .= '<table><tr><td>';
6935: }
6936: $datatable .= '<span class="LC_nobreak">'
6937: .'<label><input type="radio" name="'
6938: .$parent.'" value="1" checked="checked" />'
6939: .&mt('Display').'</label>';
6940: if ($parent eq 'instcode') {
6941: $datatable .= ' ';
6942: } else {
6943: $datatable .= '</span></td></tr><tr><td>'
6944: .'<span class="LC_nobreak">';
6945: }
6946: $datatable .= '<label><input type="radio" name="'
6947: .$parent.'" value="0" />'
6948: .&mt('Do not display').'</label></span>';
6949: if ($parent eq 'communities') {
6950: $datatable .= '</td></tr></table>';
6951: }
6952: $datatable .= '</td>';
1.57 raeburn 6953: } else {
6954: $datatable .= $parent
1.160.6.29 raeburn 6955: .' <span class="LC_nobreak"><label>'
6956: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6957: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6958: }
6959: my $depth = 1;
6960: push(@path,$parent);
6961: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6962: pop(@path);
6963: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6964: $itemcount ++;
6965: }
1.48 raeburn 6966: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6967: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6968: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6969: for (my $k=0; $k<=$maxnum; $k++) {
6970: my $vpos = $k+1;
6971: my $selstr;
1.57 raeburn 6972: if ($k == $numtop) {
1.48 raeburn 6973: $selstr = ' selected="selected" ';
6974: }
6975: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6976: }
1.59 bisitz 6977: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6978: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6979: .'</tr>'."\n";
1.48 raeburn 6980: $itemcount ++;
1.120 raeburn 6981: foreach my $default ('instcode','communities') {
6982: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6983: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6984: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6985: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6986: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6987: for (my $k=0; $k<=$maxnum; $k++) {
6988: my $vpos = $k+1;
6989: my $selstr;
6990: if ($k == $maxnum) {
6991: $selstr = ' selected="selected" ';
6992: }
6993: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6994: }
1.120 raeburn 6995: $datatable .= '</select></span></td>'.
6996: '<td><span class="LC_nobreak">'.
6997: $default_names{$default}.'</span>';
6998: if ($default eq 'instcode') {
6999: $datatable .= '<br /><span class="LC_nobreak">('
7000: .&mt('with institutional codes').')</span>';
7001: }
7002: $datatable .= '</td>'
7003: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
7004: .&mt('Display').'</label> '
7005: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
7006: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 7007: }
7008: }
7009: }
1.57 raeburn 7010: } else {
7011: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 7012: }
7013: } else {
1.160.6.87 raeburn 7014: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 7015: .&initialize_categories($itemcount);
1.48 raeburn 7016: }
1.57 raeburn 7017: $$rowtotal += $itemcount;
1.48 raeburn 7018: }
7019: return $datatable;
7020: }
7021:
1.69 raeburn 7022: sub print_serverstatuses {
7023: my ($dom,$settings,$rowtotal) = @_;
7024: my $datatable;
7025: my @pages = &serverstatus_pages();
7026: my (%namedaccess,%machineaccess);
7027: foreach my $type (@pages) {
7028: $namedaccess{$type} = '';
7029: $machineaccess{$type}= '';
7030: }
7031: if (ref($settings) eq 'HASH') {
7032: foreach my $type (@pages) {
7033: if (exists($settings->{$type})) {
7034: if (ref($settings->{$type}) eq 'HASH') {
7035: foreach my $key (keys(%{$settings->{$type}})) {
7036: if ($key eq 'namedusers') {
7037: $namedaccess{$type} = $settings->{$type}->{$key};
7038: } elsif ($key eq 'machines') {
7039: $machineaccess{$type} = $settings->{$type}->{$key};
7040: }
7041: }
7042: }
7043: }
7044: }
7045: }
1.81 raeburn 7046: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7047: my $rownum = 0;
7048: my $css_class;
7049: foreach my $type (@pages) {
7050: $rownum ++;
7051: $css_class = $rownum%2?' class="LC_odd_row"':'';
7052: $datatable .= '<tr'.$css_class.'>'.
7053: '<td><span class="LC_nobreak">'.
7054: $titles->{$type}.'</span></td>'.
7055: '<td class="LC_left_item">'.
7056: '<input type="text" name="'.$type.'_namedusers" '.
7057: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
7058: '<td class="LC_right_item">'.
7059: '<span class="LC_nobreak">'.
7060: '<input type="text" name="'.$type.'_machines" '.
7061: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 7062: '</span></td></tr>'."\n";
1.69 raeburn 7063: }
7064: $$rowtotal += $rownum;
7065: return $datatable;
7066: }
7067:
7068: sub serverstatus_pages {
7069: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 7070: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 7071: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 7072: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 7073: }
7074:
1.160.6.40 raeburn 7075: sub defaults_javascript {
7076: my ($settings) = @_;
1.160.6.98 raeburn 7077: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 7078: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
7079: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
7080: if ($maxnum eq '') {
7081: $maxnum = 0;
7082: }
7083: $maxnum ++;
1.160.6.51 raeburn 7084: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 7085: return <<"ENDSCRIPT";
7086: <script type="text/javascript">
7087: // <![CDATA[
7088: function reorderTypes(form,caller) {
7089: var changedVal;
7090: $jstext
7091: var newpos = 'addinststatus_pos';
7092: var current = new Array;
7093: var maxh = $maxnum;
7094: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7095: var oldVal;
7096: if (caller == newpos) {
7097: changedVal = newitemVal;
7098: } else {
7099: var curritem = 'inststatus_pos_'+caller;
7100: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
7101: current[newitemVal] = newpos;
7102: }
7103: for (var i=0; i<inststatuses.length; i++) {
7104: if (inststatuses[i] != caller) {
7105: var elementName = 'inststatus_pos_'+inststatuses[i];
7106: if (form.elements[elementName]) {
7107: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7108: current[currVal] = elementName;
7109: }
7110: }
7111: }
7112: for (var j=0; j<maxh; j++) {
7113: if (current[j] == undefined) {
7114: oldVal = j;
7115: }
7116: }
7117: if (oldVal < changedVal) {
7118: for (var k=oldVal+1; k<=changedVal ; k++) {
7119: var elementName = current[k];
7120: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7121: }
7122: } else {
7123: for (var k=changedVal; k<oldVal; k++) {
7124: var elementName = current[k];
7125: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7126: }
7127: }
7128: return;
7129: }
7130:
7131: // ]]>
7132: </script>
7133:
7134: ENDSCRIPT
7135: }
7136: }
7137:
1.160.6.98 raeburn 7138: sub passwords_javascript {
1.160.6.99 raeburn 7139: my %intalert = &Apache::lonlocal::texthash (
7140: 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.',
7141: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
7142: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
7143: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
7144: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
7145: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
7146: );
7147: &js_escape(\%intalert);
7148: my $defmin = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 7149: my $intauthjs = <<"ENDSCRIPT";
7150:
7151: function warnIntAuth(field) {
7152: if (field.name == 'intauth_check') {
7153: if (field.value == '2') {
1.160.6.99 raeburn 7154: alert('$intalert{authcheck}');
1.160.6.98 raeburn 7155: }
7156: }
7157: if (field.name == 'intauth_cost') {
7158: field.value.replace(/\s/g,'');
7159: if (field.value != '') {
7160: var regexdigit=/^\\d+\$/;
7161: if (!regexdigit.test(field.value)) {
1.160.6.99 raeburn 7162: alert('$intalert{authcost}');
7163: }
7164: }
7165: }
7166: return;
7167: }
7168:
7169: function warnIntPass(field) {
7170: field.value.replace(/^\s+/,'');
7171: field.value.replace(/\s+\$/,'');
7172: var regexdigit=/^\\d+\$/;
7173: if (field.name == 'passwords_min') {
7174: if (field.value == '') {
7175: alert('$intalert{passmin}');
7176: field.value = '$defmin';
7177: } else {
7178: if (!regexdigit.test(field.value)) {
7179: alert('$intalert{passmin}');
7180: field.value = '$defmin';
7181: }
7182: var minval = parseInt(field.value,10);
7183: if (minval < $defmin) {
7184: alert('$intalert{passmin}');
7185: field.value = '$defmin';
7186: }
7187: }
7188: } else {
7189: if (field.value == '0') {
7190: field.value = '';
7191: }
7192: if (field.value != '') {
7193: if (field.name == 'passwords_expire') {
7194: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
7195: if (!regexpposnum.test(field.value)) {
7196: alert('$intalert{passexp}');
7197: field.value = '';
7198: } else {
7199: var expval = parseFloat(field.value);
7200: if (expval == 0) {
7201: alert('$intalert{passexp}');
7202: field.value = '';
7203: }
7204: }
7205: } else {
7206: if (!regexdigit.test(field.value)) {
7207: if (field.name == 'passwords_max') {
7208: alert('$intalert{passmax}');
7209: } else {
7210: if (field.name == 'passwords_numsaved') {
7211: alert('$intalert{passnum}');
7212: }
7213: }
7214: }
7215: field.value = '';
1.160.6.98 raeburn 7216: }
7217: }
7218: }
7219: return;
7220: }
7221:
7222: ENDSCRIPT
7223: return &Apache::lonhtmlcommon::scripttag($intauthjs);
7224: }
7225:
1.49 raeburn 7226: sub coursecategories_javascript {
7227: my ($settings) = @_;
1.57 raeburn 7228: my ($output,$jstext,$cathash);
1.49 raeburn 7229: if (ref($settings) eq 'HASH') {
1.57 raeburn 7230: $cathash = $settings->{'cats'};
7231: }
7232: if (ref($cathash) eq 'HASH') {
1.49 raeburn 7233: my (@cats,@jsarray,%idx);
1.57 raeburn 7234: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 7235: if (@jsarray > 0) {
7236: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
7237: for (my $i=0; $i<@jsarray; $i++) {
7238: if (ref($jsarray[$i]) eq 'ARRAY') {
7239: my $catstr = join('","',@{$jsarray[$i]});
7240: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
7241: }
7242: }
7243: }
7244: } else {
7245: $jstext = ' var categories = Array(1);'."\n".
7246: ' categories[0] = Array("instcode_pos");'."\n";
7247: }
1.160.6.42 raeburn 7248: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
7249: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 7250: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
7251: &js_escape(\$instcode_reserved);
7252: &js_escape(\$communities_reserved);
7253: &js_escape(\$choose_again);
1.49 raeburn 7254: $output = <<"ENDSCRIPT";
7255: <script type="text/javascript">
1.109 raeburn 7256: // <![CDATA[
1.49 raeburn 7257: function reorderCats(form,parent,item,idx) {
7258: var changedVal;
7259: $jstext
7260: var newpos = 'addcategory_pos';
7261: if (parent == '') {
7262: var has_instcode = 0;
7263: var maxtop = categories[idx].length;
7264: for (var j=0; j<maxtop; j++) {
7265: if (categories[idx][j] == 'instcode::0') {
7266: has_instcode == 1;
7267: }
7268: }
7269: if (has_instcode == 0) {
7270: categories[idx][maxtop] = 'instcode_pos';
7271: }
7272: } else {
7273: newpos += '_'+parent;
7274: }
7275: var maxh = 1 + categories[idx].length;
7276: var current = new Array;
7277: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7278: if (item == newpos) {
7279: changedVal = newitemVal;
7280: } else {
7281: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
7282: current[newitemVal] = newpos;
7283: }
7284: for (var i=0; i<categories[idx].length; i++) {
7285: var elementName = categories[idx][i];
7286: if (elementName != item) {
7287: if (form.elements[elementName]) {
7288: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7289: current[currVal] = elementName;
7290: }
7291: }
7292: }
7293: var oldVal;
7294: for (var j=0; j<maxh; j++) {
7295: if (current[j] == undefined) {
7296: oldVal = j;
7297: }
7298: }
7299: if (oldVal < changedVal) {
7300: for (var k=oldVal+1; k<=changedVal ; k++) {
7301: var elementName = current[k];
7302: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7303: }
7304: } else {
7305: for (var k=changedVal; k<oldVal; k++) {
7306: var elementName = current[k];
7307: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7308: }
7309: }
7310: return;
7311: }
1.120 raeburn 7312:
7313: function categoryCheck(form) {
7314: if (form.elements['addcategory_name'].value == 'instcode') {
7315: alert('$instcode_reserved\\n$choose_again');
7316: return false;
7317: }
7318: if (form.elements['addcategory_name'].value == 'communities') {
7319: alert('$communities_reserved\\n$choose_again');
7320: return false;
7321: }
7322: return true;
7323: }
7324:
1.109 raeburn 7325: // ]]>
1.49 raeburn 7326: </script>
7327:
7328: ENDSCRIPT
7329: return $output;
7330: }
7331:
1.48 raeburn 7332: sub initialize_categories {
7333: my ($itemcount) = @_;
1.120 raeburn 7334: my ($datatable,$css_class,$chgstr);
7335: my %default_names = (
7336: instcode => 'Official courses (with institutional codes)',
7337: communities => 'Communities',
7338: );
7339: my $select0 = ' selected="selected"';
7340: my $select1 = '';
7341: foreach my $default ('instcode','communities') {
7342: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 7343: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 7344: if ($default eq 'communities') {
7345: $select1 = $select0;
7346: $select0 = '';
7347: }
7348: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7349: .'<select name="'.$default.'_pos">'
7350: .'<option value="0"'.$select0.'>1</option>'
7351: .'<option value="1"'.$select1.'>2</option>'
7352: .'<option value="2">3</option></select> '
7353: .$default_names{$default}
7354: .'</span></td><td><span class="LC_nobreak">'
7355: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
7356: .&mt('Display').'</label> <label>'
7357: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 7358: .'</label></span></td></tr>';
1.120 raeburn 7359: $itemcount ++;
7360: }
1.48 raeburn 7361: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 7362: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 7363: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 7364: .'<select name="addcategory_pos"'.$chgstr.'>'
7365: .'<option value="0">1</option>'
7366: .'<option value="1">2</option>'
7367: .'<option value="2" selected="selected">3</option></select> '
1.160.6.87 raeburn 7368: .&mt('Add category').'</span></td><tda<span class="LC_nobreak">>'.&mt('Name:')
7369: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
7370: .'</td></tr>';
1.48 raeburn 7371: return $datatable;
7372: }
7373:
7374: sub build_category_rows {
1.49 raeburn 7375: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
7376: my ($text,$name,$item,$chgstr);
1.48 raeburn 7377: if (ref($cats) eq 'ARRAY') {
7378: my $maxdepth = scalar(@{$cats});
7379: if (ref($cats->[$depth]) eq 'HASH') {
7380: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
7381: my $numchildren = @{$cats->[$depth]{$parent}};
7382: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 7383: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 7384: my ($idxnum,$parent_name,$parent_item);
7385: my $higher = $depth - 1;
7386: if ($higher == 0) {
7387: $parent_name = &escape($parent).'::'.$higher;
7388: } else {
7389: if (ref($path) eq 'ARRAY') {
7390: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7391: }
7392: }
7393: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 7394: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 7395: if ($j < $numchildren) {
1.48 raeburn 7396: $name = $cats->[$depth]{$parent}[$j];
7397: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 7398: $idxnum = $idx->{$item};
7399: } else {
7400: $name = $parent_name;
7401: $item = $parent_item;
1.48 raeburn 7402: }
1.49 raeburn 7403: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
7404: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 7405: for (my $i=0; $i<=$numchildren; $i++) {
7406: my $vpos = $i+1;
7407: my $selstr;
7408: if ($j == $i) {
7409: $selstr = ' selected="selected" ';
7410: }
7411: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
7412: }
7413: $text .= '</select> ';
7414: if ($j < $numchildren) {
7415: my $deeper = $depth+1;
7416: $text .= $name.' '
7417: .'<label><input type="checkbox" name="deletecategory" value="'
7418: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
7419: if(ref($path) eq 'ARRAY') {
7420: push(@{$path},$name);
1.49 raeburn 7421: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 7422: pop(@{$path});
7423: }
7424: } else {
1.160.6.87 raeburn 7425: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 7426: if ($j == $numchildren) {
7427: $text .= $name;
7428: } else {
7429: $text .= $item;
7430: }
7431: $text .= '" value="" />';
7432: }
7433: $text .= '</td></tr>';
7434: }
7435: $text .= '</table></td>';
7436: } else {
7437: my $higher = $depth-1;
7438: if ($higher == 0) {
7439: $name = &escape($parent).'::'.$higher;
7440: } else {
7441: if (ref($path) eq 'ARRAY') {
7442: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7443: }
7444: }
7445: my $colspan;
7446: if ($parent ne 'instcode') {
7447: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 7448: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 7449: }
7450: }
7451: }
7452: }
7453: return $text;
7454: }
7455:
1.33 raeburn 7456: sub modifiable_userdata_row {
1.160.6.93 raeburn 7457: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
7458: $rowid,$customcss,$rowstyle) = @_;
1.160.6.35 raeburn 7459: my ($role,$rolename,$statustype);
7460: $role = $item;
1.160.6.34 raeburn 7461: if ($context eq 'cancreate') {
1.160.6.93 raeburn 7462: if ($item =~ /^(emailusername)_(.+)$/) {
7463: $role = $1;
7464: $statustype = $2;
1.160.6.35 raeburn 7465: if (ref($usertypes) eq 'HASH') {
7466: if ($usertypes->{$statustype}) {
7467: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
7468: } else {
7469: $rolename = &mt('Data provided by user');
7470: }
7471: }
1.160.6.34 raeburn 7472: }
7473: } elsif ($context eq 'selfcreate') {
1.63 raeburn 7474: if (ref($usertypes) eq 'HASH') {
7475: $rolename = $usertypes->{$role};
7476: } else {
7477: $rolename = $role;
7478: }
1.33 raeburn 7479: } else {
1.63 raeburn 7480: if ($role eq 'cr') {
7481: $rolename = &mt('Custom role');
7482: } else {
7483: $rolename = &Apache::lonnet::plaintext($role);
7484: }
1.33 raeburn 7485: }
1.160.6.34 raeburn 7486: my (@fields,%fieldtitles);
7487: if (ref($fieldsref) eq 'ARRAY') {
7488: @fields = @{$fieldsref};
7489: } else {
7490: @fields = ('lastname','firstname','middlename','generation',
7491: 'permanentemail','id');
7492: }
7493: if ((ref($titlesref) eq 'HASH')) {
7494: %fieldtitles = %{$titlesref};
7495: } else {
7496: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7497: }
1.33 raeburn 7498: my $output;
1.160.6.93 raeburn 7499: my $css_class;
7500: if ($rowcount%2) {
7501: $css_class = 'LC_odd_row';
7502: }
7503: if ($customcss) {
7504: $css_class .= " $customcss";
7505: }
7506: $css_class =~ s/^\s+//;
7507: if ($css_class) {
7508: $css_class = ' class="'.$css_class.'"';
7509: }
7510: if ($rowstyle) {
7511: $css_class .= ' style="'.$rowstyle.'"';
7512: }
7513: if ($rowid) {
7514: $rowid = ' id="'.$rowid.'"';
7515: }
7516:
7517: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 7518: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
7519: '<td class="LC_left_item" colspan="2"><table>';
7520: my $rem;
7521: my %checks;
7522: if (ref($settings) eq 'HASH') {
7523: if (ref($settings->{$context}) eq 'HASH') {
7524: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 7525: my $hashref = $settings->{$context}->{$role};
7526: if ($role eq 'emailusername') {
7527: if ($statustype) {
7528: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
7529: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 7530: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 7531: foreach my $field (@fields) {
7532: if ($hashref->{$field}) {
7533: $checks{$field} = $hashref->{$field};
7534: }
7535: }
7536: }
7537: }
7538: }
7539: } else {
7540: if (ref($hashref) eq 'HASH') {
7541: foreach my $field (@fields) {
7542: if ($hashref->{$field}) {
7543: $checks{$field} = ' checked="checked" ';
7544: }
7545: }
1.33 raeburn 7546: }
7547: }
7548: }
7549: }
7550: }
1.160.6.93 raeburn 7551:
7552: my $total = scalar(@fields);
7553: for (my $i=0; $i<$total; $i++) {
7554: $rem = $i%($numinrow);
1.33 raeburn 7555: if ($rem == 0) {
7556: if ($i > 0) {
7557: $output .= '</tr>';
7558: }
7559: $output .= '<tr>';
7560: }
7561: my $check = ' ';
1.160.6.35 raeburn 7562: unless ($role eq 'emailusername') {
7563: if (exists($checks{$fields[$i]})) {
1.160.6.98 raeburn 7564: $check = $checks{$fields[$i]};
1.160.6.35 raeburn 7565: } else {
7566: if ($role eq 'st') {
7567: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 7568: $check = ' checked="checked" ';
1.160.6.35 raeburn 7569: }
1.33 raeburn 7570: }
7571: }
7572: }
7573: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 7574: '<span class="LC_nobreak">';
7575: if ($role eq 'emailusername') {
7576: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
7577: $checks{$fields[$i]} = 'omit';
7578: }
7579: foreach my $option ('required','optional','omit') {
7580: my $checked='';
7581: if ($checks{$fields[$i]} eq $option) {
7582: $checked='checked="checked" ';
7583: }
7584: $output .= '<label>'.
7585: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
7586: &mt($option).'</label>'.(' ' x2);
7587: }
7588: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
7589: } else {
7590: $output .= '<label>'.
7591: '<input type="checkbox" name="canmodify_'.$role.'" '.
7592: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
7593: '</label>';
7594: }
7595: $output .= '</span></td>';
1.33 raeburn 7596: }
1.160.6.93 raeburn 7597: $rem = $total%$numinrow;
7598: my $colsleft;
7599: if ($rem) {
7600: $colsleft = $numinrow - $rem;
7601: }
7602: if ($colsleft > 1) {
1.33 raeburn 7603: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7604: ' </td>';
7605: } elsif ($colsleft == 1) {
7606: $output .= '<td class="LC_left_item"> </td>';
7607: }
7608: $output .= '</tr></table></td></tr>';
7609: return $output;
7610: }
1.28 raeburn 7611:
1.93 raeburn 7612: sub insttypes_row {
1.160.6.93 raeburn 7613: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
7614: $customcss,$rowstyle) = @_;
1.93 raeburn 7615: my %lt = &Apache::lonlocal::texthash (
7616: cansearch => 'Users allowed to search',
7617: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 7618: lockablenames => 'User preference to lock name',
1.160.6.93 raeburn 7619: selfassign => 'Self-reportable affiliations',
1.93 raeburn 7620: );
7621: my $showdom;
7622: if ($context eq 'cansearch') {
7623: $showdom = ' ('.$dom.')';
7624: }
1.160.6.5 raeburn 7625: my $class = 'LC_left_item';
7626: if ($context eq 'statustocreate') {
7627: $class = 'LC_right_item';
7628: }
1.160.6.93 raeburn 7629: my $css_class;
7630: if ($$rowtotal%2) {
7631: $css_class = 'LC_odd_row';
7632: }
7633: if ($customcss) {
7634: $css_class .= ' '.$customcss;
7635: }
7636: $css_class =~ s/^\s+//;
7637: if ($css_class) {
7638: $css_class = ' class="'.$css_class.'"';
7639: }
7640: if ($rowstyle) {
7641: $css_class .= ' style="'.$rowstyle.'"';
7642: }
7643: if ($onclick) {
7644: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 7645: }
7646: my $output = '<tr'.$css_class.'>'.
7647: '<td>'.$lt{$context}.$showdom.
7648: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 7649: my $rem;
7650: if (ref($types) eq 'ARRAY') {
7651: for (my $i=0; $i<@{$types}; $i++) {
7652: if (defined($usertypes->{$types->[$i]})) {
7653: my $rem = $i%($numinrow);
7654: if ($rem == 0) {
7655: if ($i > 0) {
7656: $output .= '</tr>';
7657: }
7658: $output .= '<tr>';
1.23 raeburn 7659: }
1.26 raeburn 7660: my $check = ' ';
1.99 raeburn 7661: if (ref($settings) eq 'HASH') {
7662: if (ref($settings->{$context}) eq 'ARRAY') {
7663: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
7664: $check = ' checked="checked" ';
7665: }
7666: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7667: $check = ' checked="checked" ';
7668: }
1.23 raeburn 7669: }
1.26 raeburn 7670: $output .= '<td class="LC_left_item">'.
7671: '<span class="LC_nobreak"><label>'.
1.93 raeburn 7672: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 7673: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
1.26 raeburn 7674: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 7675: }
7676: }
1.26 raeburn 7677: $rem = @{$types}%($numinrow);
1.23 raeburn 7678: }
7679: my $colsleft = $numinrow - $rem;
1.160.6.87 raeburn 7680: if ($rem == 0) {
1.131 raeburn 7681: $output .= '<tr>';
7682: }
1.23 raeburn 7683: if ($colsleft > 1) {
1.25 raeburn 7684: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 7685: } else {
1.25 raeburn 7686: $output .= '<td class="LC_left_item">';
1.23 raeburn 7687: }
7688: my $defcheck = ' ';
1.99 raeburn 7689: if (ref($settings) eq 'HASH') {
7690: if (ref($settings->{$context}) eq 'ARRAY') {
7691: if (grep(/^default$/,@{$settings->{$context}})) {
7692: $defcheck = ' checked="checked" ';
7693: }
7694: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7695: $defcheck = ' checked="checked" ';
7696: }
1.23 raeburn 7697: }
1.25 raeburn 7698: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 7699: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 7700: 'value="default"'.$defcheck.$onclick.'/>'.
1.25 raeburn 7701: $othertitle.'</label></span></td>'.
7702: '</tr></table></td></tr>';
7703: return $output;
1.23 raeburn 7704: }
7705:
7706: sub sorted_searchtitles {
7707: my %searchtitles = &Apache::lonlocal::texthash(
7708: 'uname' => 'username',
7709: 'lastname' => 'last name',
7710: 'lastfirst' => 'last name, first name',
7711: );
7712: my @titleorder = ('uname','lastname','lastfirst');
7713: return (\%searchtitles,\@titleorder);
7714: }
7715:
1.25 raeburn 7716: sub sorted_searchtypes {
7717: my %srchtypes_desc = (
7718: exact => 'is exact match',
7719: contains => 'contains ..',
7720: begins => 'begins with ..',
7721: );
7722: my @srchtypeorder = ('exact','begins','contains');
7723: return (\%srchtypes_desc,\@srchtypeorder);
7724: }
7725:
1.3 raeburn 7726: sub usertype_update_row {
7727: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
7728: my $datatable;
7729: my $numinrow = 4;
7730: foreach my $type (@{$types}) {
7731: if (defined($usertypes->{$type})) {
7732: $$rownums ++;
7733: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
7734: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
7735: '</td><td class="LC_left_item"><table>';
7736: for (my $i=0; $i<@{$fields}; $i++) {
7737: my $rem = $i%($numinrow);
7738: if ($rem == 0) {
7739: if ($i > 0) {
7740: $datatable .= '</tr>';
7741: }
7742: $datatable .= '<tr>';
7743: }
7744: my $check = ' ';
1.39 raeburn 7745: if (ref($settings) eq 'HASH') {
7746: if (ref($settings->{'fields'}) eq 'HASH') {
7747: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
7748: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
7749: $check = ' checked="checked" ';
7750: }
1.3 raeburn 7751: }
7752: }
7753: }
7754:
7755: if ($i == @{$fields}-1) {
7756: my $colsleft = $numinrow - $rem;
7757: if ($colsleft > 1) {
7758: $datatable .= '<td colspan="'.$colsleft.'">';
7759: } else {
7760: $datatable .= '<td>';
7761: }
7762: } else {
7763: $datatable .= '<td>';
7764: }
1.8 raeburn 7765: $datatable .= '<span class="LC_nobreak"><label>'.
7766: '<input type="checkbox" name="updateable_'.$type.
7767: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
7768: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 7769: }
7770: $datatable .= '</tr></table></td></tr>';
7771: }
7772: }
7773: return $datatable;
1.1 raeburn 7774: }
7775:
7776: sub modify_login {
1.160.6.24 raeburn 7777: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 7778: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
7779: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
7780: %title = ( coursecatalog => 'Display course catalog',
7781: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 7782: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 7783: newuser => 'Link for visitors to create a user account',
7784: loginheader => 'Log-in box header');
7785: @offon = ('off','on');
1.112 raeburn 7786: if (ref($domconfig{login}) eq 'HASH') {
7787: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
7788: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
7789: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
7790: }
7791: }
7792: }
1.9 raeburn 7793: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
7794: \%domconfig,\%loginhash);
1.160.6.14 raeburn 7795: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7796: foreach my $item (@toggles) {
7797: $loginhash{login}{$item} = $env{'form.'.$item};
7798: }
1.41 raeburn 7799: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 7800: if (ref($colchanges{'login'}) eq 'HASH') {
7801: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
7802: \%loginhash);
7803: }
1.110 raeburn 7804:
1.149 raeburn 7805: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 7806: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 7807: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 7808: if (keys(%servers) > 1) {
7809: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 7810: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
7811: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
7812: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
7813: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
7814: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
7815: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7816: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7817: $changes{'loginvia'}{$lonhost} = 1;
7818: } else {
7819: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
7820: $changes{'loginvia'}{$lonhost} = 1;
7821: }
7822: } else {
7823: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7824: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7825: $changes{'loginvia'}{$lonhost} = 1;
7826: }
7827: }
7828: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
7829: foreach my $item (@loginvia_attribs) {
7830: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
7831: }
7832: } else {
7833: foreach my $item (@loginvia_attribs) {
7834: my $new = $env{'form.'.$lonhost.'_'.$item};
7835: if (($item eq 'serverpath') && ($new eq 'custom')) {
7836: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
7837: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7838: $new = '/';
7839: }
7840: }
7841: if (($item eq 'custompath') &&
7842: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7843: $new = '';
7844: }
7845: if ($new ne $curr_loginvia{$lonhost}{$item}) {
7846: $changes{'loginvia'}{$lonhost} = 1;
7847: }
7848: if ($item eq 'exempt') {
1.160.6.56 raeburn 7849: $new = &check_exempt_addresses($new);
1.128 raeburn 7850: }
7851: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7852: }
7853: }
1.112 raeburn 7854: } else {
1.128 raeburn 7855: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7856: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 7857: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 7858: foreach my $item (@loginvia_attribs) {
7859: my $new = $env{'form.'.$lonhost.'_'.$item};
7860: if (($item eq 'serverpath') && ($new eq 'custom')) {
7861: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7862: $new = '/';
7863: }
7864: }
7865: if (($item eq 'custompath') &&
7866: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7867: $new = '';
7868: }
7869: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7870: }
1.110 raeburn 7871: }
7872: }
7873: }
7874: }
1.119 raeburn 7875:
1.160.6.5 raeburn 7876: my $servadm = $r->dir_config('lonAdmEMail');
7877: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
7878: if (ref($domconfig{'login'}) eq 'HASH') {
7879: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
7880: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
7881: if ($lang eq 'nolang') {
7882: push(@currlangs,$lang);
7883: } elsif (defined($langchoices{$lang})) {
7884: push(@currlangs,$lang);
7885: } else {
7886: next;
7887: }
7888: }
7889: }
7890: }
7891: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
7892: if (@currlangs > 0) {
7893: foreach my $lang (@currlangs) {
7894: if (grep(/^\Q$lang\E$/,@delurls)) {
7895: $changes{'helpurl'}{$lang} = 1;
7896: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
7897: $changes{'helpurl'}{$lang} = 1;
7898: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
7899: push(@newlangs,$lang);
7900: } else {
7901: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7902: }
7903: }
7904: }
7905: unless (grep(/^nolang$/,@currlangs)) {
7906: if ($env{'form.loginhelpurl_nolang.filename'}) {
7907: $changes{'helpurl'}{'nolang'} = 1;
7908: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
7909: push(@newlangs,'nolang');
7910: }
7911: }
7912: if ($env{'form.loginhelpurl_add_lang'}) {
7913: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
7914: ($env{'form.loginhelpurl_add_file.filename'})) {
7915: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
7916: $addedfile = $env{'form.loginhelpurl_add_lang'};
7917: }
7918: }
7919: if ((@newlangs > 0) || ($addedfile)) {
7920: my $error;
7921: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7922: if ($configuserok eq 'ok') {
7923: if ($switchserver) {
7924: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7925: } elsif ($author_ok eq 'ok') {
7926: my @allnew = @newlangs;
7927: if ($addedfile ne '') {
7928: push(@allnew,$addedfile);
7929: }
7930: foreach my $lang (@allnew) {
7931: my $formelem = 'loginhelpurl_'.$lang;
7932: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
7933: $formelem = 'loginhelpurl_add_file';
7934: }
7935: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7936: "help/$lang",'','',$newfile{$lang});
7937: if ($result eq 'ok') {
7938: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
7939: $changes{'helpurl'}{$lang} = 1;
7940: } else {
7941: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
7942: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7943: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
7944: (!grep(/^\Q$lang\E$/,@delurls))) {
7945: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7946: }
7947: }
7948: }
7949: } else {
7950: $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);
7951: }
7952: } else {
7953: $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);
7954: }
7955: if ($error) {
7956: &Apache::lonnet::logthis($error);
7957: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7958: }
7959: }
1.160.6.56 raeburn 7960:
7961: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
7962: if (ref($domconfig{'login'}) eq 'HASH') {
7963: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
7964: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
7965: if ($domservers{$lonhost}) {
7966: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7967: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 7968: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 7969: }
7970: }
7971: }
7972: }
7973: }
7974: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
7975: foreach my $lonhost (sort(keys(%domservers))) {
7976: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7977: $changes{'headtag'}{$lonhost} = 1;
7978: } else {
7979: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
7980: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
7981: }
7982: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
7983: push(@newhosts,$lonhost);
7984: } elsif ($currheadtagurls{$lonhost}) {
7985: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
7986: if ($currexempt{$lonhost}) {
7987: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
7988: $changes{'headtag'}{$lonhost} = 1;
7989: }
7990: } elsif ($possexempt{$lonhost}) {
7991: $changes{'headtag'}{$lonhost} = 1;
7992: }
7993: if ($possexempt{$lonhost}) {
7994: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7995: }
7996: }
7997: }
7998: }
7999: if (@newhosts) {
8000: my $error;
8001: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8002: if ($configuserok eq 'ok') {
8003: if ($switchserver) {
8004: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
8005: } elsif ($author_ok eq 'ok') {
8006: foreach my $lonhost (@newhosts) {
8007: my $formelem = 'loginheadtag_'.$lonhost;
8008: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8009: "login/headtag/$lonhost",'','',
8010: $env{'form.loginheadtag_'.$lonhost.'.filename'});
8011: if ($result eq 'ok') {
8012: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
8013: $changes{'headtag'}{$lonhost} = 1;
8014: if ($possexempt{$lonhost}) {
8015: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8016: }
8017: } else {
8018: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
8019: $newheadtagurls{$lonhost},$result);
8020: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
8021: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
8022: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
8023: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
8024: }
8025: }
8026: }
8027: } else {
8028: $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);
8029: }
8030: } else {
8031: $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);
8032: }
8033: if ($error) {
8034: &Apache::lonnet::logthis($error);
8035: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8036: }
8037: }
1.160.6.5 raeburn 8038: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
8039:
8040: my $defaulthelpfile = '/adm/loginproblems.html';
8041: my $defaulttext = &mt('Default in use');
8042:
1.1 raeburn 8043: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
8044: $dom);
8045: if ($putresult eq 'ok') {
1.160.6.14 raeburn 8046: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8047: my %defaultchecked = (
8048: 'coursecatalog' => 'on',
1.160.6.14 raeburn 8049: 'helpdesk' => 'on',
1.42 raeburn 8050: 'adminmail' => 'off',
1.43 raeburn 8051: 'newuser' => 'off',
1.42 raeburn 8052: );
1.55 raeburn 8053: if (ref($domconfig{'login'}) eq 'HASH') {
8054: foreach my $item (@toggles) {
8055: if ($defaultchecked{$item} eq 'on') {
8056: if (($domconfig{'login'}{$item} eq '0') &&
8057: ($env{'form.'.$item} eq '1')) {
8058: $changes{$item} = 1;
8059: } elsif (($domconfig{'login'}{$item} eq '' ||
8060: $domconfig{'login'}{$item} eq '1') &&
8061: ($env{'form.'.$item} eq '0')) {
8062: $changes{$item} = 1;
8063: }
8064: } elsif ($defaultchecked{$item} eq 'off') {
8065: if (($domconfig{'login'}{$item} eq '1') &&
8066: ($env{'form.'.$item} eq '0')) {
8067: $changes{$item} = 1;
8068: } elsif (($domconfig{'login'}{$item} eq '' ||
8069: $domconfig{'login'}{$item} eq '0') &&
8070: ($env{'form.'.$item} eq '1')) {
8071: $changes{$item} = 1;
8072: }
1.42 raeburn 8073: }
8074: }
1.41 raeburn 8075: }
1.6 raeburn 8076: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 8077: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8078: if (ref($lastactref) eq 'HASH') {
8079: $lastactref->{'domainconfig'} = 1;
8080: }
1.1 raeburn 8081: $resulttext = &mt('Changes made:').'<ul>';
8082: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 8083: if ($item eq 'loginvia') {
1.112 raeburn 8084: if (ref($changes{$item}) eq 'HASH') {
8085: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
8086: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 8087: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
8088: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
8089: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
8090: $protocol = 'http' if ($protocol ne 'https');
8091: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
8092:
8093: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
8094: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
8095: } else {
8096: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
8097: }
8098: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
8099: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
8100: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
8101: }
8102: $resulttext .= '</li>';
8103: } else {
8104: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
8105: }
1.112 raeburn 8106: } else {
1.128 raeburn 8107: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 8108: }
8109: }
1.128 raeburn 8110: $resulttext .= '</ul></li>';
1.112 raeburn 8111: }
1.160.6.5 raeburn 8112: } elsif ($item eq 'helpurl') {
8113: if (ref($changes{$item}) eq 'HASH') {
8114: foreach my $lang (sort(keys(%{$changes{$item}}))) {
8115: if (grep(/^\Q$lang\E$/,@delurls)) {
8116: my ($chg,$link);
8117: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
8118: if ($lang eq 'nolang') {
8119: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
8120: } else {
8121: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
8122: }
8123: $resulttext .= '<li>'.$chg.'</li>';
8124: } else {
8125: my $chg;
8126: if ($lang eq 'nolang') {
8127: $chg = &mt('custom log-in help file for no preferred language');
8128: } else {
8129: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
8130: }
8131: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
8132: $loginhash{'login'}{'helpurl'}{$lang}.
8133: '?inhibitmenu=yes',$chg,600,500).
8134: '</li>';
8135: }
8136: }
8137: }
1.160.6.56 raeburn 8138: } elsif ($item eq 'headtag') {
8139: if (ref($changes{$item}) eq 'HASH') {
8140: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
8141: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8142: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
8143: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8144: $resulttext .= '<li><a href="'.
8145: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
8146: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
8147: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
8148: if ($possexempt{$lonhost}) {
8149: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
8150: } else {
8151: $resulttext .= &mt('included for any client IP');
8152: }
8153: $resulttext .= '</li>';
8154: }
8155: }
8156: }
1.160.6.5 raeburn 8157: } elsif ($item eq 'captcha') {
8158: if (ref($loginhash{'login'}) eq 'HASH') {
8159: my $chgtxt;
8160: if ($loginhash{'login'}{$item} eq 'notused') {
8161: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
8162: } else {
8163: my %captchas = &captcha_phrases();
8164: if ($captchas{$loginhash{'login'}{$item}}) {
8165: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
8166: } else {
8167: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
8168: }
8169: }
8170: $resulttext .= '<li>'.$chgtxt.'</li>';
8171: }
8172: } elsif ($item eq 'recaptchakeys') {
8173: if (ref($loginhash{'login'}) eq 'HASH') {
8174: my ($privkey,$pubkey);
8175: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
8176: $pubkey = $loginhash{'login'}{$item}{'public'};
8177: $privkey = $loginhash{'login'}{$item}{'private'};
8178: }
8179: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
8180: if (!$pubkey) {
8181: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
8182: } else {
8183: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8184: }
8185: if (!$privkey) {
8186: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
8187: } else {
1.160.6.53 raeburn 8188: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 8189: }
8190: $chgtxt .= '</ul>';
8191: $resulttext .= '<li>'.$chgtxt.'</li>';
8192: }
1.160.6.69 raeburn 8193: } elsif ($item eq 'recaptchaversion') {
8194: if (ref($loginhash{'login'}) eq 'HASH') {
8195: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
8196: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
8197: '</li>';
8198: }
8199: }
1.41 raeburn 8200: } else {
8201: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
8202: }
1.1 raeburn 8203: }
1.6 raeburn 8204: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 8205: } else {
8206: $resulttext = &mt('No changes made to log-in page settings');
8207: }
8208: } else {
1.11 albertel 8209: $resulttext = '<span class="LC_error">'.
8210: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8211: }
1.6 raeburn 8212: if ($errors) {
1.9 raeburn 8213: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 8214: $errors.'</ul>';
8215: }
8216: return $resulttext;
8217: }
8218:
1.160.6.56 raeburn 8219: sub check_exempt_addresses {
8220: my ($iplist) = @_;
8221: $iplist =~ s/^\s+//;
8222: $iplist =~ s/\s+$//;
8223: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
8224: my (@okips,$new);
8225: foreach my $ip (@poss_ips) {
8226: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
8227: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
8228: push(@okips,$ip);
8229: }
8230: }
8231: }
8232: if (@okips > 0) {
8233: $new = join(',',@okips);
8234: } else {
8235: $new = '';
8236: }
8237: return $new;
8238: }
8239:
1.6 raeburn 8240: sub color_font_choices {
8241: my %choices =
8242: &Apache::lonlocal::texthash (
8243: img => "Header",
8244: bgs => "Background colors",
8245: links => "Link colors",
1.55 raeburn 8246: images => "Images",
1.6 raeburn 8247: font => "Font color",
1.160.6.22 raeburn 8248: fontmenu => "Font menu",
1.76 raeburn 8249: pgbg => "Page",
1.6 raeburn 8250: tabbg => "Header",
8251: sidebg => "Border",
8252: link => "Link",
8253: alink => "Active link",
8254: vlink => "Visited link",
8255: );
8256: return %choices;
8257: }
8258:
8259: sub modify_rolecolors {
1.160.6.24 raeburn 8260: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 8261: my ($resulttext,%rolehash);
8262: $rolehash{'rolecolors'} = {};
1.55 raeburn 8263: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
8264: if ($domconfig{'rolecolors'} eq '') {
8265: $domconfig{'rolecolors'} = {};
8266: }
8267: }
1.9 raeburn 8268: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 8269: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
8270: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
8271: $dom);
8272: if ($putresult eq 'ok') {
8273: if (keys(%changes) > 0) {
1.41 raeburn 8274: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8275: if (ref($lastactref) eq 'HASH') {
8276: $lastactref->{'domainconfig'} = 1;
8277: }
1.6 raeburn 8278: $resulttext = &display_colorchgs($dom,\%changes,$roles,
8279: $rolehash{'rolecolors'});
8280: } else {
8281: $resulttext = &mt('No changes made to default color schemes');
8282: }
8283: } else {
1.11 albertel 8284: $resulttext = '<span class="LC_error">'.
8285: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 8286: }
8287: if ($errors) {
8288: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8289: $errors.'</ul>';
8290: }
8291: return $resulttext;
8292: }
8293:
8294: sub modify_colors {
1.9 raeburn 8295: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 8296: my (%changes,%choices);
1.51 raeburn 8297: my @bgs;
1.6 raeburn 8298: my @links = ('link','alink','vlink');
1.41 raeburn 8299: my @logintext;
1.6 raeburn 8300: my @images;
8301: my $servadm = $r->dir_config('lonAdmEMail');
8302: my $errors;
1.160.6.22 raeburn 8303: my %defaults;
1.6 raeburn 8304: foreach my $role (@{$roles}) {
8305: if ($role eq 'login') {
1.12 raeburn 8306: %choices = &login_choices();
1.41 raeburn 8307: @logintext = ('textcol','bgcol');
1.12 raeburn 8308: } else {
8309: %choices = &color_font_choices();
8310: }
8311: if ($role eq 'login') {
1.41 raeburn 8312: @images = ('img','logo','domlogo','login');
1.51 raeburn 8313: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 8314: } else {
8315: @images = ('img');
1.160.6.22 raeburn 8316: @bgs = ('pgbg','tabbg','sidebg');
8317: }
8318: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
8319: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
8320: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
8321: }
8322: if ($role eq 'login') {
8323: foreach my $item (@logintext) {
1.160.6.39 raeburn 8324: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8325: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8326: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8327: }
8328: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 8329: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8330: }
8331: }
8332: } else {
1.160.6.39 raeburn 8333: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
8334: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
8335: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
8336: }
8337: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 8338: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
8339: }
1.6 raeburn 8340: }
1.160.6.22 raeburn 8341: foreach my $item (@bgs) {
1.160.6.39 raeburn 8342: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8343: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8344: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8345: }
8346: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 8347: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8348: }
8349: }
8350: foreach my $item (@links) {
1.160.6.39 raeburn 8351: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8352: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8353: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8354: }
8355: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 8356: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8357: }
1.6 raeburn 8358: }
1.46 raeburn 8359: my ($configuserok,$author_ok,$switchserver) =
8360: &config_check($dom,$confname,$servadm);
1.9 raeburn 8361: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 8362: if (ref($domconfig->{$role}) ne 'HASH') {
8363: $domconfig->{$role} = {};
8364: }
1.8 raeburn 8365: foreach my $img (@images) {
1.70 raeburn 8366: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
8367: if (defined($env{'form.login_showlogo_'.$img})) {
8368: $confhash->{$role}{'showlogo'}{$img} = 1;
8369: } else {
8370: $confhash->{$role}{'showlogo'}{$img} = 0;
8371: }
8372: }
1.18 albertel 8373: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
8374: && !defined($domconfig->{$role}{$img})
8375: && !$env{'form.'.$role.'_del_'.$img}
8376: && $env{'form.'.$role.'_import_'.$img}) {
8377: # import the old configured image from the .tab setting
8378: # if they haven't provided a new one
8379: $domconfig->{$role}{$img} =
8380: $env{'form.'.$role.'_import_'.$img};
8381: }
1.6 raeburn 8382: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 8383: my $error;
1.6 raeburn 8384: if ($configuserok eq 'ok') {
1.9 raeburn 8385: if ($switchserver) {
1.12 raeburn 8386: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 8387: } else {
8388: if ($author_ok eq 'ok') {
8389: my ($result,$logourl) =
8390: &publishlogo($r,'upload',$role.'_'.$img,
8391: $dom,$confname,$img,$width,$height);
8392: if ($result eq 'ok') {
8393: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 8394: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8395: } else {
1.12 raeburn 8396: $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 8397: }
8398: } else {
1.46 raeburn 8399: $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 8400: }
8401: }
8402: } else {
1.46 raeburn 8403: $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 8404: }
8405: if ($error) {
1.8 raeburn 8406: &Apache::lonnet::logthis($error);
1.11 albertel 8407: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 8408: }
8409: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 8410: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
8411: my $error;
8412: if ($configuserok eq 'ok') {
8413: # is confname an author?
8414: if ($switchserver eq '') {
8415: if ($author_ok eq 'ok') {
8416: my ($result,$logourl) =
8417: &publishlogo($r,'copy',$domconfig->{$role}{$img},
8418: $dom,$confname,$img,$width,$height);
8419: if ($result eq 'ok') {
8420: $confhash->{$role}{$img} = $logourl;
1.18 albertel 8421: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8422: }
8423: }
8424: }
8425: }
1.6 raeburn 8426: }
8427: }
8428: }
8429: if (ref($domconfig) eq 'HASH') {
8430: if (ref($domconfig->{$role}) eq 'HASH') {
8431: foreach my $img (@images) {
8432: if ($domconfig->{$role}{$img} ne '') {
8433: if ($env{'form.'.$role.'_del_'.$img}) {
8434: $confhash->{$role}{$img} = '';
1.12 raeburn 8435: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8436: } else {
1.9 raeburn 8437: if ($confhash->{$role}{$img} eq '') {
8438: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
8439: }
1.6 raeburn 8440: }
8441: } else {
8442: if ($env{'form.'.$role.'_del_'.$img}) {
8443: $confhash->{$role}{$img} = '';
1.12 raeburn 8444: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8445: }
8446: }
1.70 raeburn 8447: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
8448: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
8449: if ($confhash->{$role}{'showlogo'}{$img} ne
8450: $domconfig->{$role}{'showlogo'}{$img}) {
8451: $changes{$role}{'showlogo'}{$img} = 1;
8452: }
8453: } else {
8454: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8455: $changes{$role}{'showlogo'}{$img} = 1;
8456: }
8457: }
8458: }
8459: }
1.6 raeburn 8460: if ($domconfig->{$role}{'font'} ne '') {
8461: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
8462: $changes{$role}{'font'} = 1;
8463: }
8464: } else {
8465: if ($confhash->{$role}{'font'}) {
8466: $changes{$role}{'font'} = 1;
8467: }
8468: }
1.107 raeburn 8469: if ($role ne 'login') {
8470: if ($domconfig->{$role}{'fontmenu'} ne '') {
8471: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
8472: $changes{$role}{'fontmenu'} = 1;
8473: }
8474: } else {
8475: if ($confhash->{$role}{'fontmenu'}) {
8476: $changes{$role}{'fontmenu'} = 1;
8477: }
1.97 tempelho 8478: }
8479: }
1.6 raeburn 8480: foreach my $item (@bgs) {
8481: if ($domconfig->{$role}{$item} ne '') {
8482: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8483: $changes{$role}{'bgs'}{$item} = 1;
8484: }
8485: } else {
8486: if ($confhash->{$role}{$item}) {
8487: $changes{$role}{'bgs'}{$item} = 1;
8488: }
8489: }
8490: }
8491: foreach my $item (@links) {
8492: if ($domconfig->{$role}{$item} ne '') {
8493: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8494: $changes{$role}{'links'}{$item} = 1;
8495: }
8496: } else {
8497: if ($confhash->{$role}{$item}) {
8498: $changes{$role}{'links'}{$item} = 1;
8499: }
8500: }
8501: }
1.41 raeburn 8502: foreach my $item (@logintext) {
8503: if ($domconfig->{$role}{$item} ne '') {
8504: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8505: $changes{$role}{'logintext'}{$item} = 1;
8506: }
8507: } else {
8508: if ($confhash->{$role}{$item}) {
8509: $changes{$role}{'logintext'}{$item} = 1;
8510: }
8511: }
8512: }
1.6 raeburn 8513: } else {
8514: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8515: \@logintext,$confhash,\%changes);
1.6 raeburn 8516: }
8517: } else {
8518: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8519: \@logintext,$confhash,\%changes);
1.6 raeburn 8520: }
8521: }
8522: return ($errors,%changes);
8523: }
8524:
1.46 raeburn 8525: sub config_check {
8526: my ($dom,$confname,$servadm) = @_;
8527: my ($configuserok,$author_ok,$switchserver,%currroles);
8528: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8529: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8530: $confname,$servadm);
8531: if ($configuserok eq 'ok') {
8532: $switchserver = &check_switchserver($dom,$confname);
8533: if ($switchserver eq '') {
8534: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8535: }
8536: }
8537: return ($configuserok,$author_ok,$switchserver);
8538: }
8539:
1.6 raeburn 8540: sub default_change_checker {
1.41 raeburn 8541: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 8542: foreach my $item (@{$links}) {
8543: if ($confhash->{$role}{$item}) {
8544: $changes->{$role}{'links'}{$item} = 1;
8545: }
8546: }
8547: foreach my $item (@{$bgs}) {
8548: if ($confhash->{$role}{$item}) {
8549: $changes->{$role}{'bgs'}{$item} = 1;
8550: }
8551: }
1.41 raeburn 8552: foreach my $item (@{$logintext}) {
8553: if ($confhash->{$role}{$item}) {
8554: $changes->{$role}{'logintext'}{$item} = 1;
8555: }
8556: }
1.6 raeburn 8557: foreach my $img (@{$images}) {
8558: if ($env{'form.'.$role.'_del_'.$img}) {
8559: $confhash->{$role}{$img} = '';
1.12 raeburn 8560: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 8561: }
1.70 raeburn 8562: if ($role eq 'login') {
8563: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8564: $changes->{$role}{'showlogo'}{$img} = 1;
8565: }
8566: }
1.6 raeburn 8567: }
8568: if ($confhash->{$role}{'font'}) {
8569: $changes->{$role}{'font'} = 1;
8570: }
1.48 raeburn 8571: }
1.6 raeburn 8572:
8573: sub display_colorchgs {
8574: my ($dom,$changes,$roles,$confhash) = @_;
8575: my (%choices,$resulttext);
8576: if (!grep(/^login$/,@{$roles})) {
8577: $resulttext = &mt('Changes made:').'<br />';
8578: }
8579: foreach my $role (@{$roles}) {
8580: if ($role eq 'login') {
8581: %choices = &login_choices();
8582: } else {
8583: %choices = &color_font_choices();
8584: }
8585: if (ref($changes->{$role}) eq 'HASH') {
8586: if ($role ne 'login') {
8587: $resulttext .= '<h4>'.&mt($role).'</h4>';
8588: }
8589: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8590: if ($role ne 'login') {
8591: $resulttext .= '<ul>';
8592: }
8593: if (ref($changes->{$role}{$key}) eq 'HASH') {
8594: if ($role ne 'login') {
8595: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
8596: }
8597: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 8598: if (($role eq 'login') && ($key eq 'showlogo')) {
8599: if ($confhash->{$role}{$key}{$item}) {
8600: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
8601: } else {
8602: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
8603: }
8604: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 8605: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
8606: } else {
1.12 raeburn 8607: my $newitem = $confhash->{$role}{$item};
8608: if ($key eq 'images') {
8609: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
8610: }
8611: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 8612: }
8613: }
8614: if ($role ne 'login') {
8615: $resulttext .= '</ul></li>';
8616: }
8617: } else {
8618: if ($confhash->{$role}{$key} eq '') {
8619: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
8620: } else {
8621: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8622: }
8623: }
8624: if ($role ne 'login') {
8625: $resulttext .= '</ul>';
8626: }
8627: }
8628: }
8629: }
1.3 raeburn 8630: return $resulttext;
1.1 raeburn 8631: }
8632:
1.9 raeburn 8633: sub thumb_dimensions {
8634: return ('200','50');
8635: }
8636:
1.16 raeburn 8637: sub check_dimensions {
8638: my ($inputfile) = @_;
8639: my ($fullwidth,$fullheight);
8640: if ($inputfile =~ m|^[/\w.\-]+$|) {
8641: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8642: my $imageinfo = <PIPE>;
8643: if (!close(PIPE)) {
8644: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8645: }
8646: chomp($imageinfo);
8647: my ($fullsize) =
1.21 raeburn 8648: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 8649: if ($fullsize) {
8650: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8651: }
8652: }
8653: }
8654: return ($fullwidth,$fullheight);
8655: }
8656:
1.9 raeburn 8657: sub check_configuser {
8658: my ($uhome,$dom,$confname,$servadm) = @_;
8659: my ($configuserok,%currroles);
8660: if ($uhome eq 'no_host') {
8661: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98 raeburn 8662: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 8663: $configuserok =
8664: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8665: $configpass,'','','','','',undef,$servadm);
8666: } else {
8667: $configuserok = 'ok';
8668: %currroles =
8669: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
8670: }
8671: return ($configuserok,%currroles);
8672: }
8673:
8674: sub check_authorstatus {
8675: my ($dom,$confname,%currroles) = @_;
8676: my $author_ok;
1.40 raeburn 8677: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 8678: my $start = time;
8679: my $end = 0;
8680: $author_ok =
8681: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 8682: 'au',$end,$start,'','','domconfig');
1.9 raeburn 8683: } else {
8684: $author_ok = 'ok';
8685: }
8686: return $author_ok;
8687: }
8688:
8689: sub publishlogo {
1.46 raeburn 8690: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 8691: my ($output,$fname,$logourl);
8692: if ($action eq 'upload') {
8693: $fname=$env{'form.'.$formname.'.filename'};
8694: chop($env{'form.'.$formname});
8695: } else {
8696: ($fname) = ($formname =~ /([^\/]+)$/);
8697: }
1.46 raeburn 8698: if ($savefileas ne '') {
8699: $fname = $savefileas;
8700: }
1.9 raeburn 8701: $fname=&Apache::lonnet::clean_filename($fname);
8702: # See if there is anything left
8703: unless ($fname) { return ('error: no uploaded file'); }
8704: $fname="$subdir/$fname";
1.160.6.5 raeburn 8705: my $docroot=$r->dir_config('lonDocRoot');
8706: my $filepath="$docroot/priv";
8707: my $relpath = "$dom/$confname";
1.9 raeburn 8708: my ($fnamepath,$file,$fetchthumb);
8709: $file=$fname;
8710: if ($fname=~m|/|) {
8711: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
8712: }
1.160.6.26 raeburn 8713: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 8714: my $count;
1.160.6.5 raeburn 8715: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 8716: $filepath.="/$parts[$count]";
8717: if ((-e $filepath)!=1) {
8718: mkdir($filepath,02770);
8719: }
8720: }
8721: # Check for bad extension and disallow upload
8722: if ($file=~/\.(\w+)$/ &&
8723: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8724: $output =
1.160.6.25 raeburn 8725: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 8726: } elsif ($file=~/\.(\w+)$/ &&
8727: !defined(&Apache::loncommon::fileembstyle($1))) {
8728: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8729: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 8730: $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 8731: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 8732: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 8733: } else {
8734: my $source = $filepath.'/'.$file;
8735: my $logfile;
1.160.6.88 raeburn 8736: if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 8737: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 8738: }
8739: print $logfile
8740: "\n================= Publish ".localtime()." ================\n".
8741: $env{'user.name'}.':'.$env{'user.domain'}."\n";
8742: # Save the file
1.160.6.88 raeburn 8743: if (!open(FH,">",$source)) {
1.9 raeburn 8744: &Apache::lonnet::logthis('Failed to create '.$source);
8745: return (&mt('Failed to create file'));
8746: }
8747: if ($action eq 'upload') {
8748: if (!print FH ($env{'form.'.$formname})) {
8749: &Apache::lonnet::logthis('Failed to write to '.$source);
8750: return (&mt('Failed to write file'));
8751: }
8752: } else {
8753: my $original = &Apache::lonnet::filelocation('',$formname);
8754: if(!copy($original,$source)) {
8755: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
8756: return (&mt('Failed to write file'));
8757: }
8758: }
8759: close(FH);
8760: chmod(0660, $source); # Permissions to rw-rw---.
8761:
8762: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
8763: my $copyfile=$targetdir.'/'.$file;
8764:
8765: my @parts=split(/\//,$targetdir);
8766: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
8767: for (my $count=5;$count<=$#parts;$count++) {
8768: $path.="/$parts[$count]";
8769: if (!-e $path) {
8770: print $logfile "\nCreating directory ".$path;
8771: mkdir($path,02770);
8772: }
8773: }
8774: my $versionresult;
8775: if (-e $copyfile) {
8776: $versionresult = &logo_versioning($targetdir,$file,$logfile);
8777: } else {
8778: $versionresult = 'ok';
8779: }
8780: if ($versionresult eq 'ok') {
8781: if (copy($source,$copyfile)) {
8782: print $logfile "\nCopied original source to ".$copyfile."\n";
8783: $output = 'ok';
8784: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 8785: push(@{$modified_urls},[$copyfile,$source]);
8786: my $metaoutput =
8787: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
8788: unless ($registered_cleanup) {
8789: my $handlers = $r->get_handlers('PerlCleanupHandler');
8790: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8791: $registered_cleanup=1;
8792: }
1.9 raeburn 8793: } else {
8794: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
8795: $output = &mt('Failed to copy file to RES space').", $!";
8796: }
8797: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
8798: my $inputfile = $filepath.'/'.$file;
8799: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 8800: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
8801: if ($fullwidth ne '' && $fullheight ne '') {
8802: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
8803: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88 raeburn 8804: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
8805: system({$args[0]} @args);
1.16 raeburn 8806: chmod(0660, $filepath.'/tn-'.$file);
8807: if (-e $outfile) {
8808: my $copyfile=$targetdir.'/tn-'.$file;
8809: if (copy($outfile,$copyfile)) {
8810: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 8811: my $thumb_metaoutput =
8812: &write_metadata($dom,$confname,$formname,
8813: $targetdir,'tn-'.$file,$logfile);
8814: push(@{$modified_urls},[$copyfile,$outfile]);
8815: unless ($registered_cleanup) {
8816: my $handlers = $r->get_handlers('PerlCleanupHandler');
8817: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8818: $registered_cleanup=1;
8819: }
1.16 raeburn 8820: } else {
8821: print $logfile "\nUnable to write ".$copyfile.
8822: ':'.$!."\n";
8823: }
8824: }
1.9 raeburn 8825: }
8826: }
8827: }
8828: } else {
8829: $output = $versionresult;
8830: }
8831: }
8832: return ($output,$logourl);
8833: }
8834:
8835: sub logo_versioning {
8836: my ($targetdir,$file,$logfile) = @_;
8837: my $target = $targetdir.'/'.$file;
8838: my ($maxversion,$fn,$extn,$output);
8839: $maxversion = 0;
8840: if ($file =~ /^(.+)\.(\w+)$/) {
8841: $fn=$1;
8842: $extn=$2;
8843: }
8844: opendir(DIR,$targetdir);
8845: while (my $filename=readdir(DIR)) {
8846: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
8847: $maxversion=($1>$maxversion)?$1:$maxversion;
8848: }
8849: }
8850: $maxversion++;
8851: print $logfile "\nCreating old version ".$maxversion."\n";
8852: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
8853: if (copy($target,$copyfile)) {
8854: print $logfile "Copied old target to ".$copyfile."\n";
8855: $copyfile=$copyfile.'.meta';
8856: if (copy($target.'.meta',$copyfile)) {
8857: print $logfile "Copied old target metadata to ".$copyfile."\n";
8858: $output = 'ok';
8859: } else {
8860: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
8861: $output = &mt('Failed to copy old meta').", $!, ";
8862: }
8863: } else {
8864: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
8865: $output = &mt('Failed to copy old target').", $!, ";
8866: }
8867: return $output;
8868: }
8869:
8870: sub write_metadata {
8871: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
8872: my (%metadatafields,%metadatakeys,$output);
8873: $metadatafields{'title'}=$formname;
8874: $metadatafields{'creationdate'}=time;
8875: $metadatafields{'lastrevisiondate'}=time;
8876: $metadatafields{'copyright'}='public';
8877: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
8878: $env{'user.domain'};
8879: $metadatafields{'authorspace'}=$confname.':'.$dom;
8880: $metadatafields{'domain'}=$dom;
8881: {
8882: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
8883: my $mfh;
1.160.6.88 raeburn 8884: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 8885: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 8886: unless ($_=~/\./) {
8887: my $unikey=$_;
8888: $unikey=~/^([A-Za-z]+)/;
8889: my $tag=$1;
8890: $tag=~tr/A-Z/a-z/;
8891: print $mfh "\n\<$tag";
8892: foreach (split(/\,/,$metadatakeys{$unikey})) {
8893: my $value=$metadatafields{$unikey.'.'.$_};
8894: $value=~s/\"/\'\'/g;
8895: print $mfh ' '.$_.'="'.$value.'"';
8896: }
8897: print $mfh '>'.
8898: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
8899: .'</'.$tag.'>';
8900: }
8901: }
8902: $output = 'ok';
8903: print $logfile "\nWrote metadata";
8904: close($mfh);
8905: } else {
8906: print $logfile "\nFailed to open metadata file";
1.9 raeburn 8907: $output = &mt('Could not write metadata');
8908: }
8909: }
1.155 raeburn 8910: return $output;
8911: }
8912:
8913: sub notifysubscribed {
8914: foreach my $targetsource (@{$modified_urls}){
8915: next unless (ref($targetsource) eq 'ARRAY');
8916: my ($target,$source)=@{$targetsource};
8917: if ($source ne '') {
1.160.6.88 raeburn 8918: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 8919: print $logfh "\nCleanup phase: Notifications\n";
8920: my @subscribed=&subscribed_hosts($target);
8921: foreach my $subhost (@subscribed) {
8922: print $logfh "\nNotifying host ".$subhost.':';
8923: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
8924: print $logfh $reply;
8925: }
8926: my @subscribedmeta=&subscribed_hosts("$target.meta");
8927: foreach my $subhost (@subscribedmeta) {
8928: print $logfh "\nNotifying host for metadata only ".$subhost.':';
8929: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
8930: $subhost);
8931: print $logfh $reply;
8932: }
8933: print $logfh "\n============ Done ============\n";
1.160 raeburn 8934: close($logfh);
1.155 raeburn 8935: }
8936: }
8937: }
8938: return OK;
8939: }
8940:
8941: sub subscribed_hosts {
8942: my ($target) = @_;
8943: my @subscribed;
1.160.6.88 raeburn 8944: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 8945: while (my $subline=<$fh>) {
8946: if ($subline =~ /^($match_lonid):/) {
8947: my $host = $1;
8948: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
8949: unless (grep(/^\Q$host\E$/,@subscribed)) {
8950: push(@subscribed,$host);
8951: }
8952: }
8953: }
8954: }
8955: }
8956: return @subscribed;
1.9 raeburn 8957: }
8958:
8959: sub check_switchserver {
8960: my ($dom,$confname) = @_;
8961: my ($allowed,$switchserver);
8962: my $home = &Apache::lonnet::homeserver($confname,$dom);
8963: if ($home eq 'no_host') {
8964: $home = &Apache::lonnet::domain($dom,'primary');
8965: }
8966: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 8967: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
8968: if (!$allowed) {
1.160.6.11 raeburn 8969: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 8970: }
8971: return $switchserver;
8972: }
8973:
1.1 raeburn 8974: sub modify_quotas {
1.160.6.30 raeburn 8975: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 8976: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 8977: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 8978: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
8979: $validationfieldsref);
1.86 raeburn 8980: if ($action eq 'quotas') {
8981: $context = 'tools';
1.160.6.26 raeburn 8982: } else {
1.86 raeburn 8983: $context = $action;
8984: }
8985: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 8986: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 8987: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 8988: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
8989: %titles = &courserequest_titles();
8990: $toolregexp = join('|',@usertools);
8991: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 8992: $confname = $dom.'-domainconfig';
8993: my $servadm = $r->dir_config('lonAdmEMail');
8994: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 8995: ($validationitemsref,$validationnamesref,$validationfieldsref) =
8996: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 8997: } elsif ($context eq 'requestauthor') {
8998: @usertools = ('author');
8999: %titles = &authorrequest_titles();
1.86 raeburn 9000: } else {
1.160.6.4 raeburn 9001: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 9002: %titles = &tool_titles();
1.86 raeburn 9003: }
1.160.6.27 raeburn 9004: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 9005: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9006: foreach my $key (keys(%env)) {
1.101 raeburn 9007: if ($context eq 'requestcourses') {
9008: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
9009: my $item = $1;
9010: my $type = $2;
9011: if ($type =~ /^limit_(.+)/) {
9012: $limithash{$item}{$1} = $env{$key};
9013: } else {
9014: $confhash{$item}{$type} = $env{$key};
9015: }
9016: }
1.160.6.5 raeburn 9017: } elsif ($context eq 'requestauthor') {
9018: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
9019: $confhash{$1} = $env{$key};
9020: }
1.101 raeburn 9021: } else {
1.86 raeburn 9022: if ($key =~ /^form\.quota_(.+)$/) {
9023: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 9024: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
9025: $confhash{'authorquota'}{$1} = $env{$key};
9026: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 9027: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
9028: }
1.72 raeburn 9029: }
9030: }
1.160.6.5 raeburn 9031: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 9032: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 9033: @approvalnotify = sort(@approvalnotify);
9034: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 9035: my @crstypes = ('official','unofficial','community','textbook');
9036: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
9037: foreach my $type (@hasuniquecode) {
9038: if (grep(/^\Q$type\E$/,@crstypes)) {
9039: $confhash{'uniquecode'}{$type} = 1;
9040: }
9041: }
1.160.6.46 raeburn 9042: my (%newbook,%allpos);
1.160.6.30 raeburn 9043: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 9044: foreach my $type ('textbooks','templates') {
9045: @{$allpos{$type}} = ();
9046: my $invalid;
9047: if ($type eq 'textbooks') {
9048: $invalid = &mt('Invalid LON-CAPA course for textbook');
9049: } else {
9050: $invalid = &mt('Invalid LON-CAPA course for template');
9051: }
9052: if ($env{'form.'.$type.'_addbook'}) {
9053: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
9054: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
9055: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
9056: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
9057: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
9058: } else {
9059: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
9060: my $position = $env{'form.'.$type.'_addbook_pos'};
9061: $position =~ s/\D+//g;
9062: if ($position ne '') {
9063: $allpos{$type}[$position] = $newbook{$type};
9064: }
1.160.6.30 raeburn 9065: }
1.160.6.46 raeburn 9066: } else {
9067: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 9068: }
9069: }
1.160.6.46 raeburn 9070: }
1.160.6.30 raeburn 9071: }
1.102 raeburn 9072: if (ref($domconfig{$action}) eq 'HASH') {
9073: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
9074: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
9075: $changes{'notify'}{'approval'} = 1;
9076: }
9077: } else {
1.144 raeburn 9078: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9079: $changes{'notify'}{'approval'} = 1;
9080: }
9081: }
1.160.6.30 raeburn 9082: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
9083: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9084: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
9085: unless ($confhash{'uniquecode'}{$crstype}) {
9086: $changes{'uniquecode'} = 1;
9087: }
9088: }
9089: unless ($changes{'uniquecode'}) {
9090: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
9091: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
9092: $changes{'uniquecode'} = 1;
9093: }
9094: }
9095: }
9096: } else {
9097: $changes{'uniquecode'} = 1;
9098: }
9099: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
9100: $changes{'uniquecode'} = 1;
9101: }
9102: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 9103: foreach my $type ('textbooks','templates') {
9104: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9105: my %deletions;
9106: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
9107: if (@todelete) {
9108: map { $deletions{$_} = 1; } @todelete;
9109: }
9110: my %imgdeletions;
9111: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
9112: if (@todeleteimages) {
9113: map { $imgdeletions{$_} = 1; } @todeleteimages;
9114: }
9115: my $maxnum = $env{'form.'.$type.'_maxnum'};
9116: for (my $i=0; $i<=$maxnum; $i++) {
9117: my $itemid = $env{'form.'.$type.'_id_'.$i};
9118: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
9119: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
9120: if ($deletions{$key}) {
9121: if ($domconfig{$action}{$type}{$key}{'image'}) {
9122: #FIXME need to obsolete item in RES space
9123: }
9124: next;
9125: } else {
9126: my $newpos = $env{'form.'.$itemid};
9127: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 9128: foreach my $item ('subject','title','publisher','author') {
9129: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9130: ($type eq 'templates'));
1.160.6.46 raeburn 9131: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
9132: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
9133: $changes{$type}{$key} = 1;
9134: }
9135: }
9136: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 9137: }
1.160.6.46 raeburn 9138: if ($imgdeletions{$key}) {
9139: $changes{$type}{$key} = 1;
9140: #FIXME need to obsolete item in RES space
9141: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
9142: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 9143: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
9144: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
9145: } else {
9146: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
9147: $cdom,$cnum,$type,$configuserok,
9148: $switchserver,$author_ok);
9149: if ($imgurl) {
9150: $confhash{$type}{$key}{'image'} = $imgurl;
9151: $changes{$type}{$key} = 1;
9152: }
9153: if ($error) {
9154: &Apache::lonnet::logthis($error);
9155: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9156: }
1.160.6.46 raeburn 9157: }
9158: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
9159: $confhash{$type}{$key}{'image'} =
9160: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 9161: }
9162: }
9163: }
9164: }
9165: }
9166: }
1.102 raeburn 9167: } else {
1.144 raeburn 9168: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9169: $changes{'notify'}{'approval'} = 1;
9170: }
1.160.6.30 raeburn 9171: if (ref($confhash{'uniquecode'} eq 'HASH')) {
9172: $changes{'uniquecode'} = 1;
9173: }
9174: }
9175: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 9176: foreach my $type ('textbooks','templates') {
9177: if ($newbook{$type}) {
9178: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 9179: foreach my $item ('subject','title','publisher','author') {
9180: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9181: ($type eq 'template'));
1.160.6.46 raeburn 9182: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
9183: if ($env{'form.'.$type.'_addbook_'.$item}) {
9184: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
9185: }
9186: }
9187: if ($type eq 'textbooks') {
9188: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
9189: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 9190: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
9191: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
9192: } else {
9193: my ($imageurl,$error) =
9194: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
9195: $configuserok,$switchserver,$author_ok);
9196: if ($imageurl) {
9197: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
9198: }
9199: if ($error) {
9200: &Apache::lonnet::logthis($error);
9201: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9202: }
1.160.6.46 raeburn 9203: }
9204: }
1.160.6.30 raeburn 9205: }
9206: }
1.160.6.46 raeburn 9207: if (@{$allpos{$type}} > 0) {
9208: my $idx = 0;
9209: foreach my $item (@{$allpos{$type}}) {
9210: if ($item ne '') {
9211: $confhash{$type}{$item}{'order'} = $idx;
9212: if (ref($domconfig{$action}) eq 'HASH') {
9213: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9214: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
9215: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
9216: $changes{$type}{$item} = 1;
9217: }
1.160.6.30 raeburn 9218: }
9219: }
9220: }
1.160.6.46 raeburn 9221: $idx ++;
1.160.6.30 raeburn 9222: }
9223: }
9224: }
9225: }
1.160.6.39 raeburn 9226: if (ref($validationitemsref) eq 'ARRAY') {
9227: foreach my $item (@{$validationitemsref}) {
9228: if ($item eq 'fields') {
9229: my @changed;
9230: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
9231: if (@{$confhash{'validation'}{$item}} > 0) {
9232: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
9233: }
1.160.6.65 raeburn 9234: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9235: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9236: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
9237: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
9238: $domconfig{'requestcourses'}{'validation'}{$item});
9239: } else {
9240: @changed = @{$confhash{'validation'}{$item}};
9241: }
1.160.6.39 raeburn 9242: } else {
9243: @changed = @{$confhash{'validation'}{$item}};
9244: }
9245: } else {
9246: @changed = @{$confhash{'validation'}{$item}};
9247: }
9248: if (@changed) {
9249: if ($confhash{'validation'}{$item}) {
9250: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
9251: } else {
9252: $changes{'validation'}{$item} = &mt('None');
9253: }
9254: }
9255: } else {
9256: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
9257: if ($item eq 'markup') {
9258: if ($env{'form.requestcourses_validation_'.$item}) {
9259: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
9260: }
9261: }
1.160.6.65 raeburn 9262: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9263: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9264: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
9265: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9266: }
9267: } else {
9268: if ($confhash{'validation'}{$item} ne '') {
9269: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9270: }
1.160.6.39 raeburn 9271: }
9272: } else {
9273: if ($confhash{'validation'}{$item} ne '') {
9274: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9275: }
9276: }
9277: }
9278: }
9279: }
9280: if ($env{'form.validationdc'}) {
9281: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 9282: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 9283: if (exists($domcoords{$newval})) {
9284: $confhash{'validation'}{'dc'} = $newval;
9285: }
9286: }
9287: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 9288: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9289: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9290: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9291: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
9292: if ($confhash{'validation'}{'dc'} eq '') {
9293: $changes{'validation'}{'dc'} = &mt('None');
9294: } else {
9295: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9296: }
1.160.6.39 raeburn 9297: }
1.160.6.65 raeburn 9298: } elsif ($confhash{'validation'}{'dc'} ne '') {
9299: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 9300: }
9301: } elsif ($confhash{'validation'}{'dc'} ne '') {
9302: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9303: }
9304: } elsif ($confhash{'validation'}{'dc'} ne '') {
9305: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9306: }
1.160.6.65 raeburn 9307: } else {
9308: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9309: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9310: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9311: $changes{'validation'}{'dc'} = &mt('None');
9312: }
9313: }
1.160.6.39 raeburn 9314: }
9315: }
1.102 raeburn 9316: }
9317: } else {
1.86 raeburn 9318: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 9319: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 9320: }
1.72 raeburn 9321: foreach my $item (@usertools) {
9322: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 9323: my $unset;
1.101 raeburn 9324: if ($context eq 'requestcourses') {
1.104 raeburn 9325: $unset = '0';
9326: if ($type eq '_LC_adv') {
9327: $unset = '';
9328: }
1.101 raeburn 9329: if ($confhash{$item}{$type} eq 'autolimit') {
9330: $confhash{$item}{$type} .= '=';
9331: unless ($limithash{$item}{$type} =~ /\D/) {
9332: $confhash{$item}{$type} .= $limithash{$item}{$type};
9333: }
9334: }
1.160.6.5 raeburn 9335: } elsif ($context eq 'requestauthor') {
9336: $unset = '0';
9337: if ($type eq '_LC_adv') {
9338: $unset = '';
9339: }
1.72 raeburn 9340: } else {
1.101 raeburn 9341: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
9342: $confhash{$item}{$type} = 1;
9343: } else {
9344: $confhash{$item}{$type} = 0;
9345: }
1.72 raeburn 9346: }
1.86 raeburn 9347: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 9348: if ($action eq 'requestauthor') {
9349: if ($domconfig{$action}{$type} ne $confhash{$type}) {
9350: $changes{$type} = 1;
9351: }
9352: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 9353: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
9354: $changes{$item}{$type} = 1;
9355: }
9356: } else {
9357: if ($context eq 'requestcourses') {
1.104 raeburn 9358: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 9359: $changes{$item}{$type} = 1;
9360: }
9361: } else {
9362: if (!$confhash{$item}{$type}) {
9363: $changes{$item}{$type} = 1;
9364: }
9365: }
9366: }
9367: } else {
9368: if ($context eq 'requestcourses') {
1.104 raeburn 9369: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 9370: $changes{$item}{$type} = 1;
9371: }
1.160.6.5 raeburn 9372: } elsif ($context eq 'requestauthor') {
9373: if ($confhash{$type} ne $unset) {
9374: $changes{$type} = 1;
9375: }
1.72 raeburn 9376: } else {
9377: if (!$confhash{$item}{$type}) {
9378: $changes{$item}{$type} = 1;
9379: }
9380: }
9381: }
1.1 raeburn 9382: }
9383: }
1.160.6.5 raeburn 9384: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 9385: if (ref($domconfig{'quotas'}) eq 'HASH') {
9386: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9387: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
9388: if (exists($confhash{'defaultquota'}{$key})) {
9389: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
9390: $changes{'defaultquota'}{$key} = 1;
9391: }
9392: } else {
9393: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 9394: }
9395: }
1.86 raeburn 9396: } else {
9397: foreach my $key (keys(%{$domconfig{'quotas'}})) {
9398: if (exists($confhash{'defaultquota'}{$key})) {
9399: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
9400: $changes{'defaultquota'}{$key} = 1;
9401: }
9402: } else {
9403: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 9404: }
1.1 raeburn 9405: }
9406: }
1.160.6.20 raeburn 9407: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9408: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
9409: if (exists($confhash{'authorquota'}{$key})) {
9410: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
9411: $changes{'authorquota'}{$key} = 1;
9412: }
9413: } else {
9414: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
9415: }
9416: }
9417: }
1.1 raeburn 9418: }
1.86 raeburn 9419: if (ref($confhash{'defaultquota'}) eq 'HASH') {
9420: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
9421: if (ref($domconfig{'quotas'}) eq 'HASH') {
9422: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9423: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
9424: $changes{'defaultquota'}{$key} = 1;
9425: }
9426: } else {
9427: if (!exists($domconfig{'quotas'}{$key})) {
9428: $changes{'defaultquota'}{$key} = 1;
9429: }
1.72 raeburn 9430: }
9431: } else {
1.86 raeburn 9432: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 9433: }
1.1 raeburn 9434: }
9435: }
1.160.6.20 raeburn 9436: if (ref($confhash{'authorquota'}) eq 'HASH') {
9437: foreach my $key (keys(%{$confhash{'authorquota'}})) {
9438: if (ref($domconfig{'quotas'}) eq 'HASH') {
9439: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9440: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
9441: $changes{'authorquota'}{$key} = 1;
9442: }
9443: } else {
9444: $changes{'authorquota'}{$key} = 1;
9445: }
9446: } else {
9447: $changes{'authorquota'}{$key} = 1;
9448: }
9449: }
9450: }
1.1 raeburn 9451: }
1.72 raeburn 9452:
1.160.6.5 raeburn 9453: if ($context eq 'requestauthor') {
9454: $domdefaults{'requestauthor'} = \%confhash;
9455: } else {
9456: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 9457: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 9458: $domdefaults{$key} = $confhash{$key};
9459: }
1.160.6.5 raeburn 9460: }
1.72 raeburn 9461: }
1.160.6.5 raeburn 9462:
1.1 raeburn 9463: my %quotahash = (
1.86 raeburn 9464: $action => { %confhash }
1.1 raeburn 9465: );
9466: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
9467: $dom);
9468: if ($putresult eq 'ok') {
9469: if (keys(%changes) > 0) {
1.72 raeburn 9470: my $cachetime = 24*60*60;
9471: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 9472: if (ref($lastactref) eq 'HASH') {
9473: $lastactref->{'domdefaults'} = 1;
9474: }
1.1 raeburn 9475: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 9476: unless (($context eq 'requestcourses') ||
9477: ($context eq 'requestauthor')) {
1.86 raeburn 9478: if (ref($changes{'defaultquota'}) eq 'HASH') {
9479: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
9480: foreach my $type (@{$types},'default') {
9481: if (defined($changes{'defaultquota'}{$type})) {
9482: my $typetitle = $usertypes->{$type};
9483: if ($type eq 'default') {
9484: $typetitle = $othertitle;
9485: }
1.160.6.28 raeburn 9486: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 9487: }
9488: }
1.86 raeburn 9489: $resulttext .= '</ul></li>';
1.72 raeburn 9490: }
1.160.6.20 raeburn 9491: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 9492: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 9493: foreach my $type (@{$types},'default') {
9494: if (defined($changes{'authorquota'}{$type})) {
9495: my $typetitle = $usertypes->{$type};
9496: if ($type eq 'default') {
9497: $typetitle = $othertitle;
9498: }
1.160.6.28 raeburn 9499: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 9500: }
9501: }
9502: $resulttext .= '</ul></li>';
9503: }
1.72 raeburn 9504: }
1.80 raeburn 9505: my %newenv;
1.72 raeburn 9506: foreach my $item (@usertools) {
1.160.6.5 raeburn 9507: my (%haschgs,%inconf);
9508: if ($context eq 'requestauthor') {
9509: %haschgs = %changes;
9510: %inconf = %confhash;
9511: } else {
9512: if (ref($changes{$item}) eq 'HASH') {
9513: %haschgs = %{$changes{$item}};
9514: }
9515: if (ref($confhash{$item}) eq 'HASH') {
9516: %inconf = %{$confhash{$item}};
9517: }
9518: }
9519: if (keys(%haschgs) > 0) {
1.80 raeburn 9520: my $newacc =
9521: &Apache::lonnet::usertools_access($env{'user.name'},
9522: $env{'user.domain'},
1.86 raeburn 9523: $item,'reload',$context);
1.160.6.5 raeburn 9524: if (($context eq 'requestcourses') ||
9525: ($context eq 'requestauthor')) {
1.108 raeburn 9526: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9527: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 9528: }
9529: } else {
9530: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9531: $newenv{'environment.availabletools.'.$item} = $newacc;
9532: }
1.80 raeburn 9533: }
1.160.6.5 raeburn 9534: unless ($context eq 'requestauthor') {
9535: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9536: }
1.72 raeburn 9537: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 9538: if ($haschgs{$type}) {
1.72 raeburn 9539: my $typetitle = $usertypes->{$type};
9540: if ($type eq 'default') {
9541: $typetitle = $othertitle;
9542: } elsif ($type eq '_LC_adv') {
9543: $typetitle = 'LON-CAPA Advanced Users';
9544: }
1.160.6.5 raeburn 9545: if ($inconf{$type}) {
1.101 raeburn 9546: if ($context eq 'requestcourses') {
9547: my $cond;
1.160.6.5 raeburn 9548: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 9549: if ($1 eq '') {
9550: $cond = &mt('(Automatic processing of any request).');
9551: } else {
9552: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9553: }
9554: } else {
1.160.6.5 raeburn 9555: $cond = $conditions{$inconf{$type}};
1.101 raeburn 9556: }
9557: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 9558: } elsif ($context eq 'requestauthor') {
9559: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9560: $titles{$inconf{$type}},$typetitle);
9561:
1.101 raeburn 9562: } else {
9563: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9564: }
1.72 raeburn 9565: } else {
1.104 raeburn 9566: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 9567: if ($inconf{$type} eq '0') {
1.104 raeburn 9568: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9569: } else {
9570: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9571: }
9572: } else {
9573: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9574: }
1.72 raeburn 9575: }
9576: }
1.26 raeburn 9577: }
1.160.6.5 raeburn 9578: unless ($context eq 'requestauthor') {
9579: $resulttext .= '</ul></li>';
9580: }
1.26 raeburn 9581: }
1.1 raeburn 9582: }
1.160.6.5 raeburn 9583: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 9584: if (ref($changes{'notify'}) eq 'HASH') {
9585: if ($changes{'notify'}{'approval'}) {
9586: if (ref($confhash{'notify'}) eq 'HASH') {
9587: if ($confhash{'notify'}{'approval'}) {
9588: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9589: } else {
1.160.6.5 raeburn 9590: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 9591: }
9592: }
9593: }
9594: }
9595: }
1.160.6.30 raeburn 9596: if ($action eq 'requestcourses') {
9597: my @offon = ('off','on');
9598: if ($changes{'uniquecode'}) {
9599: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9600: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
9601: $resulttext .= '<li>'.
9602: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
9603: '</li>';
9604: } else {
9605: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
9606: '</li>';
9607: }
9608: }
1.160.6.46 raeburn 9609: foreach my $type ('textbooks','templates') {
9610: if (ref($changes{$type}) eq 'HASH') {
9611: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
9612: foreach my $key (sort(keys(%{$changes{$type}}))) {
9613: my %coursehash = &Apache::lonnet::coursedescription($key);
9614: my $coursetitle = $coursehash{'description'};
9615: my $position = $confhash{$type}{$key}{'order'} + 1;
9616: $resulttext .= '<li>';
1.160.6.47 raeburn 9617: foreach my $item ('subject','title','publisher','author') {
9618: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9619: ($type eq 'templates'));
1.160.6.46 raeburn 9620: my $name = $item.':';
9621: $name =~ s/^(\w)/\U$1/;
9622: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9623: }
9624: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9625: if ($type eq 'textbooks') {
9626: if ($confhash{$type}{$key}{'image'}) {
9627: $resulttext .= ' '.&mt('Image: [_1]',
9628: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9629: ' alt="Textbook cover" />').'<br />';
9630: }
9631: }
9632: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 9633: }
1.160.6.46 raeburn 9634: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 9635: }
9636: }
1.160.6.39 raeburn 9637: if (ref($changes{'validation'}) eq 'HASH') {
9638: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9639: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9640: foreach my $item (@{$validationitemsref}) {
9641: if (exists($changes{'validation'}{$item})) {
9642: if ($item eq 'markup') {
9643: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9644: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9645: } else {
9646: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9647: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9648: }
9649: }
9650: }
9651: if (exists($changes{'validation'}{'dc'})) {
9652: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9653: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9654: }
9655: }
9656: }
1.160.6.30 raeburn 9657: }
1.1 raeburn 9658: $resulttext .= '</ul>';
1.80 raeburn 9659: if (keys(%newenv)) {
9660: &Apache::lonnet::appenv(\%newenv);
9661: }
1.1 raeburn 9662: } else {
1.86 raeburn 9663: if ($context eq 'requestcourses') {
9664: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 9665: } elsif ($context eq 'requestauthor') {
9666: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 9667: } else {
1.90 weissno 9668: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 9669: }
1.1 raeburn 9670: }
9671: } else {
1.11 albertel 9672: $resulttext = '<span class="LC_error">'.
9673: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9674: }
1.160.6.30 raeburn 9675: if ($errors) {
9676: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
9677: '<ul>'.$errors.'</ul></p>';
9678: }
1.3 raeburn 9679: return $resulttext;
1.1 raeburn 9680: }
9681:
1.160.6.30 raeburn 9682: sub process_textbook_image {
1.160.6.46 raeburn 9683: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 9684: my $filename = $env{'form.'.$caller.'.filename'};
9685: my ($error,$url);
9686: my ($width,$height) = (50,50);
9687: if ($configuserok eq 'ok') {
9688: if ($switchserver) {
9689: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
9690: $switchserver);
9691: } elsif ($author_ok eq 'ok') {
9692: my ($result,$imageurl) =
9693: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88 raeburn 9694: "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 9695: if ($result eq 'ok') {
9696: $url = $imageurl;
9697: } else {
9698: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9699: }
9700: } else {
9701: $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);
9702: }
9703: } else {
9704: $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);
9705: }
9706: return ($url,$error);
9707: }
9708:
1.3 raeburn 9709: sub modify_autoenroll {
1.160.6.24 raeburn 9710: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 9711: my ($resulttext,%changes);
9712: my %currautoenroll;
9713: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
9714: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
9715: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
9716: }
9717: }
9718: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
9719: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 9720: sender => 'Sender for notification messages',
1.160.6.68 raeburn 9721: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
9722: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 9723: my @offon = ('off','on');
1.17 raeburn 9724: my $sender_uname = $env{'form.sender_uname'};
9725: my $sender_domain = $env{'form.sender_domain'};
9726: if ($sender_domain eq '') {
9727: $sender_uname = '';
9728: } elsif ($sender_uname eq '') {
9729: $sender_domain = '';
9730: }
1.129 raeburn 9731: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 9732: my $failsafe = $env{'form.autoenroll_failsafe'};
9733: $failsafe =~ s{^\s+|\s+$}{}g;
9734: if ($failsafe =~ /\D/) {
9735: undef($failsafe);
9736: }
1.1 raeburn 9737: my %autoenrollhash = (
1.129 raeburn 9738: autoenroll => { 'run' => $env{'form.autoenroll_run'},
9739: 'sender_uname' => $sender_uname,
9740: 'sender_domain' => $sender_domain,
9741: 'co-owners' => $coowners,
1.160.6.68 raeburn 9742: 'autofailsafe' => $failsafe,
1.1 raeburn 9743: }
9744: );
1.4 raeburn 9745: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
9746: $dom);
1.1 raeburn 9747: if ($putresult eq 'ok') {
9748: if (exists($currautoenroll{'run'})) {
9749: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
9750: $changes{'run'} = 1;
9751: }
9752: } elsif ($autorun) {
9753: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 9754: $changes{'run'} = 1;
1.1 raeburn 9755: }
9756: }
1.17 raeburn 9757: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 9758: $changes{'sender'} = 1;
9759: }
1.17 raeburn 9760: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 9761: $changes{'sender'} = 1;
9762: }
1.129 raeburn 9763: if ($currautoenroll{'co-owners'} ne '') {
9764: if ($currautoenroll{'co-owners'} ne $coowners) {
9765: $changes{'coowners'} = 1;
9766: }
9767: } elsif ($coowners) {
9768: $changes{'coowners'} = 1;
1.160.6.68 raeburn 9769: }
9770: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
9771: $changes{'autofailsafe'} = 1;
9772: }
1.1 raeburn 9773: if (keys(%changes) > 0) {
9774: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 9775: if ($changes{'run'}) {
1.1 raeburn 9776: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
9777: }
9778: if ($changes{'sender'}) {
1.17 raeburn 9779: if ($sender_uname eq '' || $sender_domain eq '') {
9780: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
9781: } else {
9782: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
9783: }
1.1 raeburn 9784: }
1.129 raeburn 9785: if ($changes{'coowners'}) {
9786: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
9787: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9788: if (ref($lastactref) eq 'HASH') {
9789: $lastactref->{'domainconfig'} = 1;
9790: }
1.129 raeburn 9791: }
1.160.6.68 raeburn 9792: if ($changes{'autofailsafe'}) {
9793: if ($failsafe ne '') {
1.160.6.82 raeburn 9794: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68 raeburn 9795: } else {
1.160.6.82 raeburn 9796: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68 raeburn 9797: }
9798: &Apache::lonnet::get_domain_defaults($dom,1);
9799: if (ref($lastactref) eq 'HASH') {
9800: $lastactref->{'domdefaults'} = 1;
9801: }
9802: }
1.1 raeburn 9803: $resulttext .= '</ul>';
9804: } else {
9805: $resulttext = &mt('No changes made to auto-enrollment settings');
9806: }
9807: } else {
1.11 albertel 9808: $resulttext = '<span class="LC_error">'.
9809: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9810: }
1.3 raeburn 9811: return $resulttext;
1.1 raeburn 9812: }
9813:
9814: sub modify_autoupdate {
1.3 raeburn 9815: my ($dom,%domconfig) = @_;
1.1 raeburn 9816: my ($resulttext,%currautoupdate,%fields,%changes);
9817: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
9818: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
9819: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
9820: }
9821: }
9822: my @offon = ('off','on');
9823: my %title = &Apache::lonlocal::texthash (
9824: run => 'Auto-update:',
9825: classlists => 'Updates to user information in classlists?'
9826: );
1.44 raeburn 9827: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9828: my %fieldtitles = &Apache::lonlocal::texthash (
9829: id => 'Student/Employee ID',
1.20 raeburn 9830: permanentemail => 'E-mail address',
1.1 raeburn 9831: lastname => 'Last Name',
9832: firstname => 'First Name',
9833: middlename => 'Middle Name',
1.132 raeburn 9834: generation => 'Generation',
1.1 raeburn 9835: );
1.142 raeburn 9836: $othertitle = &mt('All users');
1.1 raeburn 9837: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 9838: $othertitle = &mt('Other users');
1.1 raeburn 9839: }
9840: foreach my $key (keys(%env)) {
9841: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 9842: my ($usertype,$item) = ($1,$2);
9843: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
9844: if ($usertype eq 'default') {
9845: push(@{$fields{$1}},$2);
9846: } elsif (ref($types) eq 'ARRAY') {
9847: if (grep(/^\Q$usertype\E$/,@{$types})) {
9848: push(@{$fields{$1}},$2);
9849: }
9850: }
9851: }
1.1 raeburn 9852: }
9853: }
1.131 raeburn 9854: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
9855: @lockablenames = sort(@lockablenames);
9856: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
9857: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9858: if (@changed) {
9859: $changes{'lockablenames'} = 1;
9860: }
9861: } else {
9862: if (@lockablenames) {
9863: $changes{'lockablenames'} = 1;
9864: }
9865: }
1.1 raeburn 9866: my %updatehash = (
9867: autoupdate => { run => $env{'form.autoupdate_run'},
9868: classlists => $env{'form.classlists'},
9869: fields => {%fields},
1.131 raeburn 9870: lockablenames => \@lockablenames,
1.1 raeburn 9871: }
9872: );
9873: foreach my $key (keys(%currautoupdate)) {
9874: if (($key eq 'run') || ($key eq 'classlists')) {
9875: if (exists($updatehash{autoupdate}{$key})) {
9876: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
9877: $changes{$key} = 1;
9878: }
9879: }
9880: } elsif ($key eq 'fields') {
9881: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 9882: foreach my $item (@{$types},'default') {
1.1 raeburn 9883: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
9884: my $change = 0;
9885: foreach my $type (@{$currautoupdate{$key}{$item}}) {
9886: if (!exists($fields{$item})) {
9887: $change = 1;
1.132 raeburn 9888: last;
1.1 raeburn 9889: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 9890: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 9891: $change = 1;
1.132 raeburn 9892: last;
1.1 raeburn 9893: }
9894: }
9895: }
9896: if ($change) {
9897: push(@{$changes{$key}},$item);
9898: }
1.26 raeburn 9899: }
1.1 raeburn 9900: }
9901: }
1.131 raeburn 9902: } elsif ($key eq 'lockablenames') {
9903: if (ref($currautoupdate{$key}) eq 'ARRAY') {
9904: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9905: if (@changed) {
9906: $changes{'lockablenames'} = 1;
9907: }
9908: } else {
9909: if (@lockablenames) {
9910: $changes{'lockablenames'} = 1;
9911: }
9912: }
9913: }
9914: }
9915: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
9916: if (@lockablenames) {
9917: $changes{'lockablenames'} = 1;
1.1 raeburn 9918: }
9919: }
1.26 raeburn 9920: foreach my $item (@{$types},'default') {
9921: if (defined($fields{$item})) {
9922: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 9923: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
9924: my $change = 0;
9925: if (ref($fields{$item}) eq 'ARRAY') {
9926: foreach my $type (@{$fields{$item}}) {
9927: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
9928: $change = 1;
9929: last;
9930: }
9931: }
9932: }
9933: if ($change) {
9934: push(@{$changes{'fields'}},$item);
9935: }
9936: } else {
1.26 raeburn 9937: push(@{$changes{'fields'}},$item);
9938: }
9939: } else {
9940: push(@{$changes{'fields'}},$item);
1.1 raeburn 9941: }
9942: }
9943: }
9944: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
9945: $dom);
9946: if ($putresult eq 'ok') {
9947: if (keys(%changes) > 0) {
9948: $resulttext = &mt('Changes made:').'<ul>';
9949: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 9950: if ($key eq 'lockablenames') {
9951: $resulttext .= '<li>';
9952: if (@lockablenames) {
9953: $usertypes->{'default'} = $othertitle;
9954: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
9955: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
9956: } else {
9957: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
9958: }
9959: $resulttext .= '</li>';
9960: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 9961: foreach my $item (@{$changes{$key}}) {
9962: my @newvalues;
9963: foreach my $type (@{$fields{$item}}) {
9964: push(@newvalues,$fieldtitles{$type});
9965: }
1.3 raeburn 9966: my $newvaluestr;
9967: if (@newvalues > 0) {
9968: $newvaluestr = join(', ',@newvalues);
9969: } else {
9970: $newvaluestr = &mt('none');
1.6 raeburn 9971: }
1.1 raeburn 9972: if ($item eq 'default') {
1.26 raeburn 9973: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 9974: } else {
1.26 raeburn 9975: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 9976: }
9977: }
9978: } else {
9979: my $newvalue;
9980: if ($key eq 'run') {
9981: $newvalue = $offon[$env{'form.autoupdate_run'}];
9982: } else {
9983: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 9984: }
1.1 raeburn 9985: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
9986: }
9987: }
9988: $resulttext .= '</ul>';
9989: } else {
1.3 raeburn 9990: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 9991: }
9992: } else {
1.11 albertel 9993: $resulttext = '<span class="LC_error">'.
9994: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9995: }
1.3 raeburn 9996: return $resulttext;
1.1 raeburn 9997: }
9998:
1.125 raeburn 9999: sub modify_autocreate {
10000: my ($dom,%domconfig) = @_;
10001: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
10002: if (ref($domconfig{'autocreate'}) eq 'HASH') {
10003: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
10004: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
10005: }
10006: }
10007: my %title= ( xml => 'Auto-creation of courses in XML course description files',
10008: req => 'Auto-creation of validated requests for official courses',
10009: xmldc => 'Identity of course creator of courses from XML files',
10010: );
10011: my @types = ('xml','req');
10012: foreach my $item (@types) {
10013: $newvals{$item} = $env{'form.autocreate_'.$item};
10014: $newvals{$item} =~ s/\D//g;
10015: $newvals{$item} = 0 if ($newvals{$item} eq '');
10016: }
10017: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 10018: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 10019: unless (exists($domcoords{$newvals{'xmldc'}})) {
10020: $newvals{'xmldc'} = '';
10021: }
10022: %autocreatehash = (
10023: autocreate => { xml => $newvals{'xml'},
10024: req => $newvals{'req'},
10025: }
10026: );
10027: if ($newvals{'xmldc'} ne '') {
10028: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
10029: }
10030: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
10031: $dom);
10032: if ($putresult eq 'ok') {
10033: my @items = @types;
10034: if ($newvals{'xml'}) {
10035: push(@items,'xmldc');
10036: }
10037: foreach my $item (@items) {
10038: if (exists($currautocreate{$item})) {
10039: if ($currautocreate{$item} ne $newvals{$item}) {
10040: $changes{$item} = 1;
10041: }
10042: } elsif ($newvals{$item}) {
10043: $changes{$item} = 1;
10044: }
10045: }
10046: if (keys(%changes) > 0) {
10047: my @offon = ('off','on');
10048: $resulttext = &mt('Changes made:').'<ul>';
10049: foreach my $item (@types) {
10050: if ($changes{$item}) {
10051: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 10052: $resulttext .= '<li>'.
10053: &mt("$title{$item} set to [_1]$newtxt [_2]",
10054: '<b>','</b>').
10055: '</li>';
1.125 raeburn 10056: }
10057: }
10058: if ($changes{'xmldc'}) {
10059: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
10060: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 10061: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 10062: }
10063: $resulttext .= '</ul>';
10064: } else {
10065: $resulttext = &mt('No changes made to auto-creation settings');
10066: }
10067: } else {
10068: $resulttext = '<span class="LC_error">'.
10069: &mt('An error occurred: [_1]',$putresult).'</span>';
10070: }
10071: return $resulttext;
10072: }
10073:
1.23 raeburn 10074: sub modify_directorysrch {
1.160.6.81 raeburn 10075: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 10076: my ($resulttext,%changes);
10077: my %currdirsrch;
10078: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10079: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
10080: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
10081: }
10082: }
1.160.6.72 raeburn 10083: my %title = ( available => 'Institutional directory search available',
10084: localonly => 'Other domains can search institution',
10085: lcavailable => 'LON-CAPA directory search available',
10086: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 10087: searchby => 'Search types',
10088: searchtypes => 'Search latitude');
10089: my @offon = ('off','on');
1.24 raeburn 10090: my @otherdoms = ('Yes','No');
1.23 raeburn 10091:
1.25 raeburn 10092: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 10093: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
10094: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
10095:
1.44 raeburn 10096: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 10097: if (keys(%{$usertypes}) == 0) {
10098: @cansearch = ('default');
10099: } else {
10100: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
10101: foreach my $type (@{$currdirsrch{'cansearch'}}) {
10102: if (!grep(/^\Q$type\E$/,@cansearch)) {
10103: push(@{$changes{'cansearch'}},$type);
10104: }
1.23 raeburn 10105: }
1.26 raeburn 10106: foreach my $type (@cansearch) {
10107: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
10108: push(@{$changes{'cansearch'}},$type);
10109: }
1.23 raeburn 10110: }
1.26 raeburn 10111: } else {
10112: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 10113: }
10114: }
10115:
10116: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
10117: foreach my $by (@{$currdirsrch{'searchby'}}) {
10118: if (!grep(/^\Q$by\E$/,@searchby)) {
10119: push(@{$changes{'searchby'}},$by);
10120: }
10121: }
10122: foreach my $by (@searchby) {
10123: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
10124: push(@{$changes{'searchby'}},$by);
10125: }
10126: }
10127: } else {
10128: push(@{$changes{'searchby'}},@searchby);
10129: }
1.25 raeburn 10130:
10131: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
10132: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
10133: if (!grep(/^\Q$type\E$/,@searchtypes)) {
10134: push(@{$changes{'searchtypes'}},$type);
10135: }
10136: }
10137: foreach my $type (@searchtypes) {
10138: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
10139: push(@{$changes{'searchtypes'}},$type);
10140: }
10141: }
10142: } else {
10143: if (exists($currdirsrch{'searchtypes'})) {
10144: foreach my $type (@searchtypes) {
10145: if ($type ne $currdirsrch{'searchtypes'}) {
10146: push(@{$changes{'searchtypes'}},$type);
10147: }
10148: }
10149: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
10150: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
10151: }
10152: } else {
10153: push(@{$changes{'searchtypes'}},@searchtypes);
10154: }
10155: }
10156:
1.23 raeburn 10157: my %dirsrch_hash = (
10158: directorysrch => { available => $env{'form.dirsrch_available'},
10159: cansearch => \@cansearch,
1.160.6.72 raeburn 10160: localonly => $env{'form.dirsrch_instlocalonly'},
10161: lclocalonly => $env{'form.dirsrch_domlocalonly'},
10162: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 10163: searchby => \@searchby,
1.25 raeburn 10164: searchtypes => \@searchtypes,
1.23 raeburn 10165: }
10166: );
10167: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
10168: $dom);
10169: if ($putresult eq 'ok') {
10170: if (exists($currdirsrch{'available'})) {
10171: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
10172: $changes{'available'} = 1;
10173: }
10174: } else {
10175: if ($env{'form.dirsrch_available'} eq '1') {
10176: $changes{'available'} = 1;
10177: }
10178: }
1.160.6.72 raeburn 10179: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 10180: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
10181: $changes{'lcavailable'} = 1;
10182: }
1.24 raeburn 10183: } else {
1.160.6.72 raeburn 10184: if ($env{'form.dirsrch_lcavailable'} eq '1') {
10185: $changes{'lcavailable'} = 1;
10186: }
10187: }
10188: if (exists($currdirsrch{'localonly'})) {
10189: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 10190: $changes{'localonly'} = 1;
10191: }
1.160.6.72 raeburn 10192: } else {
10193: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
10194: $changes{'localonly'} = 1;
10195: }
10196: }
10197: if (exists($currdirsrch{'lclocalonly'})) {
10198: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
10199: $changes{'lclocalonly'} = 1;
10200: }
10201: } else {
10202: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
10203: $changes{'lclocalonly'} = 1;
10204: }
1.24 raeburn 10205: }
1.23 raeburn 10206: if (keys(%changes) > 0) {
10207: $resulttext = &mt('Changes made:').'<ul>';
10208: if ($changes{'available'}) {
10209: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
10210: }
1.160.6.72 raeburn 10211: if ($changes{'lcavailable'}) {
10212: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
10213: }
1.24 raeburn 10214: if ($changes{'localonly'}) {
1.160.6.72 raeburn 10215: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
10216: }
10217: if ($changes{'lclocalonly'}) {
10218: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 10219: }
1.23 raeburn 10220: if (ref($changes{'cansearch'}) eq 'ARRAY') {
10221: my $chgtext;
1.26 raeburn 10222: if (ref($usertypes) eq 'HASH') {
10223: if (keys(%{$usertypes}) > 0) {
10224: foreach my $type (@{$types}) {
10225: if (grep(/^\Q$type\E$/,@cansearch)) {
10226: $chgtext .= $usertypes->{$type}.'; ';
10227: }
10228: }
10229: if (grep(/^default$/,@cansearch)) {
10230: $chgtext .= $othertitle;
10231: } else {
10232: $chgtext =~ s/\; $//;
10233: }
1.160.6.13 raeburn 10234: $resulttext .=
10235: '<li>'.
10236: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
10237: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
10238: '</li>';
1.23 raeburn 10239: }
10240: }
10241: }
10242: if (ref($changes{'searchby'}) eq 'ARRAY') {
10243: my ($searchtitles,$titleorder) = &sorted_searchtitles();
10244: my $chgtext;
10245: foreach my $type (@{$titleorder}) {
10246: if (grep(/^\Q$type\E$/,@searchby)) {
10247: if (defined($searchtitles->{$type})) {
10248: $chgtext .= $searchtitles->{$type}.'; ';
10249: }
10250: }
10251: }
10252: $chgtext =~ s/\; $//;
10253: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
10254: }
1.25 raeburn 10255: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
10256: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
10257: my $chgtext;
10258: foreach my $type (@{$srchtypeorder}) {
10259: if (grep(/^\Q$type\E$/,@searchtypes)) {
10260: if (defined($srchtypes_desc->{$type})) {
10261: $chgtext .= $srchtypes_desc->{$type}.'; ';
10262: }
10263: }
10264: }
10265: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 10266: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 10267: }
10268: $resulttext .= '</ul>';
1.160.6.81 raeburn 10269: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
10270: if (ref($lastactref) eq 'HASH') {
10271: $lastactref->{'directorysrch'} = 1;
10272: }
1.23 raeburn 10273: } else {
1.160.6.72 raeburn 10274: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 10275: }
10276: } else {
10277: $resulttext = '<span class="LC_error">'.
1.27 raeburn 10278: &mt('An error occurred: [_1]',$putresult).'</span>';
10279: }
10280: return $resulttext;
10281: }
10282:
1.28 raeburn 10283: sub modify_contacts {
1.160.6.24 raeburn 10284: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 10285: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
10286: if (ref($domconfig{'contacts'}) eq 'HASH') {
10287: foreach my $key (keys(%{$domconfig{'contacts'}})) {
10288: $currsetting{$key} = $domconfig{'contacts'}{$key};
10289: }
10290: }
1.160.6.78 raeburn 10291: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 10292: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 10293: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 10294: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.23 raeburn 10295: my @toggles = ('reporterrors','reportupdates');
1.160.6.78 raeburn 10296: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 10297: foreach my $type (@mailings) {
10298: @{$newsetting{$type}} =
10299: &Apache::loncommon::get_env_multiple('form.'.$type);
10300: foreach my $item (@contacts) {
10301: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
10302: $contacts_hash{contacts}{$type}{$item} = 1;
10303: } else {
10304: $contacts_hash{contacts}{$type}{$item} = 0;
10305: }
1.160.6.78 raeburn 10306: }
1.28 raeburn 10307: $others{$type} = $env{'form.'.$type.'_others'};
10308: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 10309: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10310: $bcc{$type} = $env{'form.'.$type.'_bcc'};
10311: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 10312: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
10313: $includestr{$type} = $env{'form.'.$type.'_includestr'};
10314: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
10315: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
10316: }
1.134 raeburn 10317: }
1.28 raeburn 10318: }
10319: foreach my $item (@contacts) {
10320: $to{$item} = $env{'form.'.$item};
10321: $contacts_hash{'contacts'}{$item} = $to{$item};
10322: }
1.160.6.23 raeburn 10323: foreach my $item (@toggles) {
10324: if ($env{'form.'.$item} =~ /^(0|1)$/) {
10325: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
10326: }
10327: }
1.160.6.78 raeburn 10328: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
10329: foreach my $field (@{$fields}) {
10330: if (ref($possoptions->{$field}) eq 'ARRAY') {
10331: my $value = $env{'form.helpform_'.$field};
10332: $value =~ s/^\s+|\s+$//g;
10333: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
10334: $contacts_hash{contacts}{'helpform'}{$field} = $value;
10335: if ($field eq 'screenshot') {
10336: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
10337: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
10338: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
10339: }
10340: }
10341: }
10342: }
10343: }
10344: }
1.28 raeburn 10345: if (keys(%currsetting) > 0) {
10346: foreach my $item (@contacts) {
10347: if ($to{$item} ne $currsetting{$item}) {
10348: $changes{$item} = 1;
10349: }
10350: }
10351: foreach my $type (@mailings) {
10352: foreach my $item (@contacts) {
10353: if (ref($currsetting{$type}) eq 'HASH') {
10354: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
10355: push(@{$changes{$type}},$item);
10356: }
10357: } else {
10358: push(@{$changes{$type}},@{$newsetting{$type}});
10359: }
10360: }
10361: if ($others{$type} ne $currsetting{$type}{'others'}) {
10362: push(@{$changes{$type}},'others');
10363: }
1.160.6.78 raeburn 10364: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10365: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
10366: push(@{$changes{$type}},'bcc');
10367: }
1.160.6.78 raeburn 10368: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
10369: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
10370: push(@{$changes{$type}},'include');
10371: }
10372: }
10373: }
10374: if (ref($fields) eq 'ARRAY') {
10375: if (ref($currsetting{'helpform'}) eq 'HASH') {
10376: foreach my $field (@{$fields}) {
10377: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
10378: push(@{$changes{'helpform'}},$field);
10379: }
10380: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10381: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
10382: push(@{$changes{'helpform'}},'maxsize');
10383: }
10384: }
10385: }
10386: } else {
10387: foreach my $field (@{$fields}) {
10388: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10389: push(@{$changes{'helpform'}},$field);
10390: }
10391: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10392: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10393: push(@{$changes{'helpform'}},'maxsize');
10394: }
10395: }
10396: }
1.134 raeburn 10397: }
1.28 raeburn 10398: }
10399: } else {
10400: my %default;
10401: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
10402: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
10403: $default{'errormail'} = 'adminemail';
10404: $default{'packagesmail'} = 'adminemail';
10405: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 10406: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 10407: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 10408: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 10409: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 10410: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 10411: foreach my $item (@contacts) {
10412: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 10413: $changes{$item} = 1;
1.160.6.23 raeburn 10414: }
1.28 raeburn 10415: }
10416: foreach my $type (@mailings) {
10417: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
10418: push(@{$changes{$type}},@{$newsetting{$type}});
10419: }
10420: if ($others{$type} ne '') {
10421: push(@{$changes{$type}},'others');
1.134 raeburn 10422: }
1.160.6.78 raeburn 10423: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10424: if ($bcc{$type} ne '') {
10425: push(@{$changes{$type}},'bcc');
10426: }
1.160.6.78 raeburn 10427: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
10428: push(@{$changes{$type}},'include');
10429: }
10430: }
10431: }
10432: if (ref($fields) eq 'ARRAY') {
10433: foreach my $field (@{$fields}) {
10434: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10435: push(@{$changes{'helpform'}},$field);
10436: }
10437: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10438: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10439: push(@{$changes{'helpform'}},'maxsize');
10440: }
10441: }
1.134 raeburn 10442: }
1.28 raeburn 10443: }
10444: }
1.160.6.23 raeburn 10445: foreach my $item (@toggles) {
10446: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
10447: $changes{$item} = 1;
10448: } elsif ((!$env{'form.'.$item}) &&
10449: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
10450: $changes{$item} = 1;
10451: }
10452: }
1.28 raeburn 10453: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
10454: $dom);
10455: if ($putresult eq 'ok') {
10456: if (keys(%changes) > 0) {
1.160.6.24 raeburn 10457: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10458: if (ref($lastactref) eq 'HASH') {
10459: $lastactref->{'domainconfig'} = 1;
10460: }
1.28 raeburn 10461: my ($titles,$short_titles) = &contact_titles();
10462: $resulttext = &mt('Changes made:').'<ul>';
10463: foreach my $item (@contacts) {
10464: if ($changes{$item}) {
10465: $resulttext .= '<li>'.$titles->{$item}.
10466: &mt(' set to: ').
10467: '<span class="LC_cusr_emph">'.
10468: $to{$item}.'</span></li>';
10469: }
10470: }
10471: foreach my $type (@mailings) {
10472: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 10473: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
10474: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
10475: } else {
10476: $resulttext .= '<li>'.$titles->{$type}.': ';
10477: }
1.28 raeburn 10478: my @text;
10479: foreach my $item (@{$newsetting{$type}}) {
10480: push(@text,$short_titles->{$item});
10481: }
10482: if ($others{$type} ne '') {
10483: push(@text,$others{$type});
10484: }
1.160.6.78 raeburn 10485: if (@text) {
10486: $resulttext .= '<span class="LC_cusr_emph">'.
10487: join(', ',@text).'</span>';
10488: }
10489: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10490: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 10491: my $bcctext;
10492: if (@text) {
10493: $bcctext = ' '.&mt('with Bcc to');
10494: } else {
10495: $bcctext = '(Bcc)';
10496: }
10497: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
10498: } elsif (!@text) {
10499: $resulttext .= &mt('No one');
1.134 raeburn 10500: }
1.160.6.78 raeburn 10501: if ($includestr{$type} ne '') {
10502: if ($includeloc{$type} eq 'b') {
10503: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
10504: } elsif ($includeloc{$type} eq 's') {
10505: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
10506: }
10507: }
10508: } elsif (!@text) {
10509: $resulttext .= &mt('No recipients');
1.134 raeburn 10510: }
10511: $resulttext .= '</li>';
1.28 raeburn 10512: }
10513: }
1.160.6.23 raeburn 10514: my @offon = ('off','on');
10515: if ($changes{'reporterrors'}) {
10516: $resulttext .= '<li>'.
10517: &mt('E-mail error reports to [_1] set to "'.
10518: $offon[$env{'form.reporterrors'}].'".',
10519: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10520: &mt('LON-CAPA core group - MSU'),600,500)).
10521: '</li>';
10522: }
10523: if ($changes{'reportupdates'}) {
10524: $resulttext .= '<li>'.
10525: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
10526: $offon[$env{'form.reportupdates'}].'".',
10527: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10528: &mt('LON-CAPA core group - MSU'),600,500)).
10529: '</li>';
10530: }
1.160.6.78 raeburn 10531: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
10532: my (@optional,@required,@unused,$maxsizechg);
10533: foreach my $field (@{$changes{'helpform'}}) {
10534: if ($field eq 'maxsize') {
10535: $maxsizechg = 1;
10536: next;
10537: }
10538: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
10539: push(@optional,$field);
10540: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
10541: push(@unused,$field);
10542: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
10543: push(@required,$field);
10544: }
10545: }
10546: if (@optional) {
10547: $resulttext .= '<li>'.
10548: &mt('Help form fields changed to "Optional": [_1].',
10549: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
10550: '</li>';
10551: }
10552: if (@required) {
10553: $resulttext .= '<li>'.
10554: &mt('Help form fields changed to "Required": [_1].',
10555: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
10556: '</li>';
10557: }
10558: if (@unused) {
10559: $resulttext .= '<li>'.
10560: &mt('Help form fields changed to "Not shown": [_1].',
10561: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
10562: '</li>';
10563: }
10564: if ($maxsizechg) {
10565: $resulttext .= '<li>'.
10566: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
10567: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
10568: '</li>';
10569:
10570: }
10571: }
1.28 raeburn 10572: $resulttext .= '</ul>';
10573: } else {
1.160.6.78 raeburn 10574: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 10575: }
10576: } else {
10577: $resulttext = '<span class="LC_error">'.
10578: &mt('An error occurred: [_1].',$putresult).'</span>';
10579: }
10580: return $resulttext;
10581: }
10582:
1.160.6.98 raeburn 10583: sub modify_passwords {
10584: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
10585: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
10586: $updatedefaults,$updateconf);
10587: my $customfn = 'resetpw.html';
10588: if (ref($domconfig{'passwords'}) eq 'HASH') {
10589: %current = %{$domconfig{'passwords'}};
10590: }
10591: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10592: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10593: if (ref($types) eq 'ARRAY') {
10594: @oktypes = @{$types};
10595: }
10596: push(@oktypes,'default');
10597:
10598: my %titles = &Apache::lonlocal::texthash (
10599: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
10600: intauth_check => 'Check bcrypt cost if authenticated',
10601: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
10602: permanent => 'Permanent e-mail address',
10603: critical => 'Critical notification address',
10604: notify => 'Notification address',
10605: min => 'Minimum password length',
10606: max => 'Maximum password length',
10607: chars => 'Required characters',
10608: numsaved => 'Number of previous passwords to save',
10609: reset => 'Resetting Forgotten Password',
10610: intauth => 'Encryption of Stored Passwords (Internal Auth)',
10611: rules => 'Rules for LON-CAPA Passwords',
10612: crsownerchg => 'Course Owner Changing Student Passwords',
10613: username => 'Username',
10614: email => 'E-mail address',
10615: );
10616:
10617: #
10618: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
10619: #
10620: my (%curr_defaults,%save_defaults);
10621: if (ref($domconfig{'defaults'}) eq 'HASH') {
10622: foreach my $key (keys(%{$domconfig{'defaults'}})) {
10623: if ($key =~ /^intauth_(cost|check|switch)$/) {
10624: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
10625: } else {
10626: $save_defaults{$key} = $domconfig{'defaults'}{$key};
10627: }
10628: }
10629: }
10630: my %staticdefaults = (
10631: 'resetlink' => 2,
10632: 'resetcase' => \@oktypes,
10633: 'resetprelink' => 'both',
10634: 'resetemail' => ['critical','notify','permanent'],
10635: 'intauth_cost' => 10,
10636: 'intauth_check' => 0,
10637: 'intauth_switch' => 0,
10638: );
1.160.6.99 raeburn 10639: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 10640: foreach my $type (@oktypes) {
10641: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
10642: }
10643: my $linklife = $env{'form.passwords_link'};
10644: $linklife =~ s/^\s+|\s+$//g;
10645: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
10646: $newvalues{'resetlink'} = $linklife;
10647: if ($current{'resetlink'}) {
10648: if ($current{'resetlink'} ne $linklife) {
10649: $changes{'reset'} = 1;
10650: }
10651: } elsif (!exists($domconfig{passwords})) {
10652: if ($staticdefaults{'resetlink'} ne $linklife) {
10653: $changes{'reset'} = 1;
10654: }
10655: }
10656: } elsif ($current{'resetlink'}) {
10657: $changes{'reset'} = 1;
10658: }
10659: my @casesens;
10660: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
10661: foreach my $case (sort(@posscase)) {
10662: if (grep(/^\Q$case\E$/,@oktypes)) {
10663: push(@casesens,$case);
10664: }
10665: }
10666: $newvalues{'resetcase'} = \@casesens;
10667: if (ref($current{'resetcase'}) eq 'ARRAY') {
10668: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
10669: if (@diffs > 0) {
10670: $changes{'reset'} = 1;
10671: }
10672: } elsif (!exists($domconfig{passwords})) {
10673: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
10674: if (@diffs > 0) {
10675: $changes{'reset'} = 1;
10676: }
10677: }
10678: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
10679: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
10680: if (exists($current{'resetprelink'})) {
10681: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
10682: $changes{'reset'} = 1;
10683: }
10684: } elsif (!exists($domconfig{passwords})) {
10685: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
10686: $changes{'reset'} = 1;
10687: }
10688: }
10689: } elsif ($current{'resetprelink'}) {
10690: $changes{'reset'} = 1;
10691: }
10692: foreach my $type (@oktypes) {
10693: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
10694: my @postlink;
10695: foreach my $item (sort(@possplink)) {
10696: if ($item =~ /^(email|username)$/) {
10697: push(@postlink,$item);
10698: }
10699: }
10700: $newvalues{'resetpostlink'}{$type} = \@postlink;
10701: unless ($changes{'reset'}) {
10702: if (ref($current{'resetpostlink'}) eq 'HASH') {
10703: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
10704: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
10705: if (@diffs > 0) {
10706: $changes{'reset'} = 1;
10707: }
10708: } else {
10709: $changes{'reset'} = 1;
10710: }
10711: } elsif (!exists($domconfig{passwords})) {
10712: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
10713: if (@diffs > 0) {
10714: $changes{'reset'} = 1;
10715: }
10716: }
10717: }
10718: }
10719: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
10720: my @resetemail;
10721: foreach my $item (sort(@possemailsrc)) {
10722: if ($item =~ /^(permanent|critical|notify)$/) {
10723: push(@resetemail,$item);
10724: }
10725: }
10726: $newvalues{'resetemail'} = \@resetemail;
10727: unless ($changes{'reset'}) {
10728: if (ref($current{'resetemail'}) eq 'ARRAY') {
10729: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
10730: if (@diffs > 0) {
10731: $changes{'reset'} = 1;
10732: }
10733: } elsif (!exists($domconfig{passwords})) {
10734: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
10735: if (@diffs > 0) {
10736: $changes{'reset'} = 1;
10737: }
10738: }
10739: }
10740: if ($env{'form.passwords_stdtext'} == 0) {
10741: $newvalues{'resetremove'} = 1;
10742: unless ($current{'resetremove'}) {
10743: $changes{'reset'} = 1;
10744: }
10745: } elsif ($current{'resetremove'}) {
10746: $changes{'reset'} = 1;
10747: }
10748: if ($env{'form.passwords_customfile.filename'} ne '') {
10749: my $servadm = $r->dir_config('lonAdmEMail');
10750: my $servadm = $r->dir_config('lonAdmEMail');
10751: my ($configuserok,$author_ok,$switchserver) =
10752: &config_check($dom,$confname,$servadm);
10753: my $error;
10754: if ($configuserok eq 'ok') {
10755: if ($switchserver) {
10756: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
10757: } else {
10758: if ($author_ok eq 'ok') {
10759: my ($result,$customurl) =
10760: &publishlogo($r,'upload','passwords_customfile',$dom,
10761: $confname,'customtext/resetpw','','',$customfn);
10762: if ($result eq 'ok') {
10763: $newvalues{'resetcustom'} = $customurl;
10764: $changes{'reset'} = 1;
10765: } else {
10766: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
10767: }
10768: } else {
10769: $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);
10770: }
10771: }
10772: } else {
10773: $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);
10774: }
10775: if ($error) {
10776: &Apache::lonnet::logthis($error);
10777: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10778: }
10779: } elsif ($current{'resetcustom'}) {
10780: if ($env{'form.passwords_custom_del'}) {
10781: $changes{'reset'} = 1;
10782: } else {
10783: $newvalues{'resetcustom'} = $current{'resetcustom'};
10784: }
10785: }
10786: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
10787: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
10788: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
10789: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
10790: $changes{'intauth'} = 1;
10791: }
10792: } else {
10793: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
10794: }
10795: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
10796: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
10797: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
10798: $changes{'intauth'} = 1;
10799: }
10800: } else {
10801: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
10802: }
10803: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
10804: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
10805: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
10806: $changes{'intauth'} = 1;
10807: }
10808: } else {
10809: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
10810: }
10811: foreach my $item ('cost','check','switch') {
10812: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
10813: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
10814: $updatedefaults = 1;
10815: }
10816: }
10817: foreach my $rule ('min','max','numsaved') {
10818: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.160.6.99 raeburn 10819: my $ruleok;
10820: if ($rule eq 'min') {
10821: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
10822: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
10823: $ruleok = 1;
10824: }
10825: }
10826: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
10827: ($env{'form.passwords_'.$rule} ne '0')) {
10828: $ruleok = 1;
10829: }
10830: if ($ruleok) {
1.160.6.98 raeburn 10831: $newvalues{$rule} = $env{'form.passwords_'.$rule};
10832: if (exists($current{$rule})) {
10833: if ($newvalues{$rule} ne $current{$rule}) {
10834: $changes{'rules'} = 1;
10835: }
10836: } elsif ($rule eq 'min') {
10837: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
10838: $changes{'rules'} = 1;
10839: }
10840: }
10841: } elsif (exists($current{$rule})) {
10842: $changes{'rules'} = 1;
10843: }
10844: }
10845: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
10846: my @chars;
10847: foreach my $item (sort(@posschars)) {
10848: if ($item =~ /^(uc|lc|num|spec)$/) {
10849: push(@chars,$item);
10850: }
10851: }
10852: $newvalues{'chars'} = \@chars;
10853: unless ($changes{'rules'}) {
10854: if (ref($current{'chars'}) eq 'ARRAY') {
10855: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
10856: if (@diffs > 0) {
10857: $changes{'rules'} = 1;
10858: }
10859: } else {
10860: if (@chars > 0) {
10861: $changes{'rules'} = 1;
10862: }
10863: }
10864: }
10865: my %crsownerchg = (
10866: by => [],
10867: for => [],
10868: );
10869: foreach my $item ('by','for') {
10870: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
10871: foreach my $type (sort(@posstypes)) {
10872: if (grep(/^\Q$type\E$/,@oktypes)) {
10873: push(@{$crsownerchg{$item}},$type);
10874: }
10875: }
10876: }
10877: $newvalues{'crsownerchg'} = \%crsownerchg;
10878: if (ref($current{'crsownerchg'}) eq 'HASH') {
10879: foreach my $item ('by','for') {
10880: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
10881: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
10882: if (@diffs > 0) {
10883: $changes{'crsownerchg'} = 1;
10884: last;
10885: }
10886: }
10887: }
10888: } elsif (!exists($domconfig{passwords})) {
10889: foreach my $item ('by','for') {
10890: if (@{$crsownerchg{$item}} > 0) {
10891: $changes{'crsownerchg'} = 1;
10892: last;
10893: }
10894: }
10895: }
10896:
10897: my %confighash = (
10898: defaults => \%save_defaults,
10899: passwords => \%newvalues,
10900: );
10901: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
10902:
10903: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
10904: if ($putresult eq 'ok') {
10905: if (keys(%changes) > 0) {
10906: $resulttext = &mt('Changes made: ').'<ul>';
10907: foreach my $key ('reset','intauth','rules','crsownerchg') {
10908: if ($changes{$key}) {
10909: unless ($key eq 'intauth') {
10910: $updateconf = 1;
10911: }
10912: $resulttext .= '<li>'.$titles{$key}.':<ul>';
10913: if ($key eq 'reset') {
10914: if ($confighash{'passwords'}{'captcha'} eq 'original') {
10915: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
10916: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
10917: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
10918: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />'.
10919: &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchapub'}).'</br>'.
10920: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchapriv'}).'</li>';
10921: } else {
10922: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
10923: }
10924: if ($confighash{'passwords'}{'resetlink'}) {
10925: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
10926: } else {
10927: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
10928: &mt('Will default to 2 hours').'</li>';
10929: }
10930: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
10931: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
10932: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
10933: } else {
10934: my $casesens;
10935: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
10936: if ($type eq 'default') {
10937: $casesens .= $othertitle.', ';
10938: } elsif ($usertypes->{$type} ne '') {
10939: $casesens .= $usertypes->{$type}.', ';
10940: }
10941: }
10942: $casesens =~ s/\Q, \E$//;
10943: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
10944: }
10945: } else {
10946: $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>';
10947: }
10948: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
10949: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
10950: } else {
10951: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
10952: }
10953: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
10954: my $output;
10955: if (ref($types) eq 'ARRAY') {
10956: foreach my $type (@{$types}) {
10957: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
10958: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
10959: $output .= $usertypes->{$type}.' -- '.&mt('none');
10960: } else {
10961: $output .= $usertypes->{$type}.' -- '.
10962: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
10963: }
10964: }
10965: }
10966: }
10967: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
10968: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
10969: $output .= $othertitle.' -- '.&mt('none');
10970: } else {
10971: $output .= $othertitle.' -- '.
10972: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
10973: }
10974: }
10975: if ($output) {
10976: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
10977: } else {
10978: $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>';
10979: }
10980: } else {
10981: $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>';
10982: }
10983: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
10984: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
10985: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
10986: } else {
10987: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
10988: }
10989: } else {
10990: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA usedfor verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
10991: }
10992: if ($confighash{'passwords'}{'resetremove'}) {
10993: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
10994: } else {
10995: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
10996: }
10997: if ($confighash{'passwords'}{'resetcustom'}) {
10998: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
10999: $titles{custom},600,500);
11000: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes [_1]',$customlink).'</li>';
11001: } else {
11002: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
11003: }
11004: } elsif ($key eq 'intauth') {
11005: foreach my $item ('cost','switch','check') {
11006: my $value = $save_defaults{$key.'_'.$item};
11007: if ($item eq 'switch') {
11008: my %optiondesc = &Apache::lonlocal::texthash (
11009: 0 => 'No',
11010: 1 => 'Yes',
11011: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
11012: );
11013: if ($value =~ /^(0|1|2)$/) {
11014: $value = $optiondesc{$value};
11015: } else {
11016: $value = &mt('none -- defaults to No');
11017: }
11018: } elsif ($item eq 'check') {
11019: my %optiondesc = &Apache::lonlocal::texthash (
11020: 0 => 'No',
11021: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
11022: 2 => 'Yes, disallow login if stored cost is less than domain default',
11023: );
11024: if ($value =~ /^(0|1|2)$/) {
11025: $value = $optiondesc{$value};
11026: } else {
11027: $value = &mt('none -- defaults to No');
11028: }
11029: }
11030: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
11031: }
11032: } elsif ($key eq 'rules') {
11033: foreach my $rule ('min','max','numsaved') {
11034: if ($confighash{'passwords'}{$rule} eq '') {
11035: if ($rule eq 'min') {
11036: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99 raeburn 11037: ' '.&mt('Default of [_1] will be used',
11038: $Apache::lonnet::passwdmin).'</li>';
1.160.6.98 raeburn 11039: } else {
11040: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
11041: }
11042: } else {
11043: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
11044: }
11045: }
11046: } elsif ($key eq 'crsownerchg') {
11047: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
11048: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
11049: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
11050: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
11051: } else {
11052: my %crsownerstr;
11053: foreach my $item ('by','for') {
11054: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
11055: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
11056: if ($type eq 'default') {
11057: $crsownerstr{$item} .= $othertitle.', ';
11058: } elsif ($usertypes->{$type} ne '') {
11059: $crsownerstr{$item} .= $usertypes->{$type}.', ';
11060: }
11061: }
11062: $crsownerstr{$item} =~ s/\Q, \E$//;
11063: }
11064: }
11065: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
11066: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
11067: }
11068: } else {
11069: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
11070: }
11071: }
11072: $resulttext .= '</ul></li>';
11073: }
11074: }
11075: $resulttext .= '</ul>';
11076: } else {
11077: $resulttext = &mt('No changes made to password settings');
11078: }
11079: my $cachetime = 24*60*60;
11080: if ($updatedefaults) {
11081: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11082: if (ref($lastactref) eq 'HASH') {
11083: $lastactref->{'domdefaults'} = 1;
11084: }
11085: }
11086: if ($updateconf) {
11087: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
11088: if (ref($lastactref) eq 'HASH') {
11089: $lastactref->{'passwdconf'} = 1;
11090: }
11091: }
11092: } else {
11093: $resulttext = '<span class="LC_error">'.
11094: &mt('An error occurred: [_1]',$putresult).'</span>';
11095: }
11096: if ($errors) {
11097: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
11098: $errors.'</ul></p>';
11099: }
11100: return $resulttext;
11101: }
11102:
1.28 raeburn 11103: sub modify_usercreation {
1.27 raeburn 11104: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 11105: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 11106: my $warningmsg;
1.27 raeburn 11107: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11108: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 11109: if ($key eq 'cancreate') {
11110: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11111: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 11112: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 11113: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 11114: } else {
11115: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 11116: }
1.50 raeburn 11117: }
1.43 raeburn 11118: }
1.160.6.34 raeburn 11119: } elsif ($key eq 'email_rule') {
11120: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11121: } else {
11122: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 11123: }
11124: }
1.34 raeburn 11125: }
1.160.6.34 raeburn 11126: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
11127: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
11128: my @contexts = ('author','course','requestcrs');
11129: foreach my $item(@contexts) {
11130: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 11131: }
1.34 raeburn 11132: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11133: foreach my $item (@contexts) {
1.160.6.34 raeburn 11134: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
11135: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 11136: }
1.27 raeburn 11137: }
1.34 raeburn 11138: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
11139: foreach my $item (@contexts) {
1.43 raeburn 11140: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 11141: if ($cancreate{$item} ne 'any') {
11142: push(@{$changes{'cancreate'}},$item);
11143: }
11144: } else {
11145: if ($cancreate{$item} ne 'none') {
11146: push(@{$changes{'cancreate'}},$item);
11147: }
1.27 raeburn 11148: }
11149: }
11150: } else {
1.43 raeburn 11151: foreach my $item (@contexts) {
1.34 raeburn 11152: push(@{$changes{'cancreate'}},$item);
11153: }
1.27 raeburn 11154: }
1.34 raeburn 11155:
1.27 raeburn 11156: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
11157: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
11158: if (!grep(/^\Q$type\E$/,@username_rule)) {
11159: push(@{$changes{'username_rule'}},$type);
11160: }
11161: }
11162: foreach my $type (@username_rule) {
11163: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
11164: push(@{$changes{'username_rule'}},$type);
11165: }
11166: }
11167: } else {
11168: push(@{$changes{'username_rule'}},@username_rule);
11169: }
11170:
1.32 raeburn 11171: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
11172: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
11173: if (!grep(/^\Q$type\E$/,@id_rule)) {
11174: push(@{$changes{'id_rule'}},$type);
11175: }
11176: }
11177: foreach my $type (@id_rule) {
11178: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
11179: push(@{$changes{'id_rule'}},$type);
11180: }
11181: }
11182: } else {
11183: push(@{$changes{'id_rule'}},@id_rule);
11184: }
11185:
1.43 raeburn 11186: my @authen_contexts = ('author','course','domain');
1.28 raeburn 11187: my @authtypes = ('int','krb4','krb5','loc');
11188: my %authhash;
1.43 raeburn 11189: foreach my $item (@authen_contexts) {
1.28 raeburn 11190: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
11191: foreach my $auth (@authtypes) {
11192: if (grep(/^\Q$auth\E$/,@authallowed)) {
11193: $authhash{$item}{$auth} = 1;
11194: } else {
11195: $authhash{$item}{$auth} = 0;
11196: }
11197: }
11198: }
11199: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 11200: foreach my $item (@authen_contexts) {
1.28 raeburn 11201: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
11202: foreach my $auth (@authtypes) {
11203: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
11204: push(@{$changes{'authtypes'}},$item);
11205: last;
11206: }
11207: }
11208: }
11209: }
11210: } else {
1.43 raeburn 11211: foreach my $item (@authen_contexts) {
1.28 raeburn 11212: push(@{$changes{'authtypes'}},$item);
11213: }
11214: }
11215:
1.160.6.34 raeburn 11216: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
11217: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
11218: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
11219: $save_usercreate{'id_rule'} = \@id_rule;
11220: $save_usercreate{'username_rule'} = \@username_rule,
11221: $save_usercreate{'authtypes'} = \%authhash;
11222:
1.27 raeburn 11223: my %usercreation_hash = (
1.160.6.34 raeburn 11224: usercreation => \%save_usercreate,
11225: );
1.27 raeburn 11226:
11227: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
11228: $dom);
1.50 raeburn 11229:
1.160.6.34 raeburn 11230: if ($putresult eq 'ok') {
11231: if (keys(%changes) > 0) {
11232: $resulttext = &mt('Changes made:').'<ul>';
11233: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11234: my %lt = &usercreation_types();
11235: foreach my $type (@{$changes{'cancreate'}}) {
11236: my $chgtext = $lt{$type}.', ';
11237: if ($cancreate{$type} eq 'none') {
11238: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
11239: } elsif ($cancreate{$type} eq 'any') {
11240: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
11241: } elsif ($cancreate{$type} eq 'official') {
11242: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
11243: } elsif ($cancreate{$type} eq 'unofficial') {
11244: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
11245: }
11246: $resulttext .= '<li>'.$chgtext.'</li>';
11247: }
11248: }
11249: if (ref($changes{'username_rule'}) eq 'ARRAY') {
11250: my ($rules,$ruleorder) =
11251: &Apache::lonnet::inst_userrules($dom,'username');
11252: my $chgtext = '<ul>';
11253: foreach my $type (@username_rule) {
11254: if (ref($rules->{$type}) eq 'HASH') {
11255: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
11256: }
11257: }
11258: $chgtext .= '</ul>';
11259: if (@username_rule > 0) {
11260: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11261: } else {
11262: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
11263: }
11264: }
11265: if (ref($changes{'id_rule'}) eq 'ARRAY') {
11266: my ($idrules,$idruleorder) =
11267: &Apache::lonnet::inst_userrules($dom,'id');
11268: my $chgtext = '<ul>';
11269: foreach my $type (@id_rule) {
11270: if (ref($idrules->{$type}) eq 'HASH') {
11271: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
11272: }
11273: }
11274: $chgtext .= '</ul>';
11275: if (@id_rule > 0) {
11276: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11277: } else {
11278: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
11279: }
11280: }
11281: my %authname = &authtype_names();
11282: my %context_title = &context_names();
11283: if (ref($changes{'authtypes'}) eq 'ARRAY') {
11284: my $chgtext = '<ul>';
11285: foreach my $type (@{$changes{'authtypes'}}) {
11286: my @allowed;
11287: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
11288: foreach my $auth (@authtypes) {
11289: if ($authhash{$type}{$auth}) {
11290: push(@allowed,$authname{$auth});
11291: }
11292: }
11293: if (@allowed > 0) {
11294: $chgtext .= join(', ',@allowed).'</li>';
11295: } else {
11296: $chgtext .= &mt('none').'</li>';
11297: }
11298: }
11299: $chgtext .= '</ul>';
11300: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
11301: $resulttext .= '</li>';
11302: }
11303: $resulttext .= '</ul>';
11304: } else {
11305: $resulttext = &mt('No changes made to user creation settings');
11306: }
11307: } else {
11308: $resulttext = '<span class="LC_error">'.
11309: &mt('An error occurred: [_1]',$putresult).'</span>';
11310: }
11311: if ($warningmsg ne '') {
11312: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11313: }
11314: return $resulttext;
11315: }
11316:
11317: sub modify_selfcreation {
1.160.6.93 raeburn 11318: my ($dom,$lastactref,%domconfig) = @_;
11319: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
11320: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
11321: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11322: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
11323: if (ref($typesref) eq 'ARRAY') {
11324: @types = @{$typesref};
11325: }
11326: if (ref($usertypesref) eq 'HASH') {
11327: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 11328: }
1.160.6.93 raeburn 11329: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 11330: #
11331: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
11332: #
11333: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11334: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
11335: if ($key eq 'cancreate') {
11336: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11337: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
11338: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 11339: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
11340: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
11341: ($item eq 'emailusername') || ($item eq 'shibenv') ||
11342: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
11343: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 11344: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11345: } else {
11346: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11347: }
11348: }
11349: }
11350: } elsif ($key eq 'email_rule') {
11351: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11352: } else {
11353: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11354: }
11355: }
11356: }
11357: #
11358: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
11359: #
11360: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11361: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
11362: if ($key eq 'selfcreate') {
11363: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
11364: } else {
11365: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
11366: }
11367: }
11368: }
1.160.6.93 raeburn 11369: #
11370: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
11371: #
11372: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11373: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
11374: if ($key eq 'inststatusguest') {
11375: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
11376: } else {
11377: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
11378: }
11379: }
11380: }
1.160.6.34 raeburn 11381:
11382: my @contexts = ('selfcreate');
11383: @{$cancreate{'selfcreate'}} = ();
11384: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 11385: if (@types) {
11386: @{$cancreate{'statustocreate'}} = ();
11387: }
1.160.6.40 raeburn 11388: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 11389: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 11390: %{$cancreate{'emailverified'}} = ();
11391: %{$cancreate{'emailoptions'}} = ();
11392: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 11393: my %selfcreatetypes = (
11394: sso => 'users authenticated by institutional single sign on',
11395: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 11396: email => 'users verified by e-mail',
1.50 raeburn 11397: );
1.160.6.34 raeburn 11398: #
11399: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
11400: # is permitted.
11401: #
1.160.6.40 raeburn 11402:
1.160.6.93 raeburn 11403: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 11404:
1.160.6.93 raeburn 11405: my (@statuses,%email_rule);
1.160.6.35 raeburn 11406: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 11407: if ($item eq 'email') {
1.160.6.40 raeburn 11408: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 11409: if (@types) {
11410: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
11411: foreach my $status (@poss_statuses) {
11412: if (grep(/^\Q$status\E$/,(@types,'default'))) {
11413: push(@statuses,$status);
11414: }
11415: }
11416: $save_inststatus{'inststatusguest'} = \@statuses;
11417: } else {
11418: push(@statuses,'default');
11419: }
11420: if (@statuses) {
11421: my %curr_rule;
11422: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
11423: foreach my $type (@statuses) {
11424: $curr_rule{$type} = $curr_usercreation{'email_rule'};
11425: }
11426: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
11427: foreach my $type (@statuses) {
11428: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
11429: }
11430: }
11431: push(@{$cancreate{'selfcreate'}},'email');
11432: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
11433: my %curremaildom;
11434: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
11435: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
11436: }
11437: foreach my $type (@statuses) {
11438: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
11439: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
11440: }
11441: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
11442: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
11443: }
11444: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
11445: #
11446: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
11447: #
11448: my $chosen = $1;
11449: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
11450: my $emaildom;
11451: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
11452: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
11453: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
11454: if (ref($curremaildom{$type}) eq 'HASH') {
11455: if (exists($curremaildom{$type}{$chosen})) {
11456: if ($curremaildom{$type}{$chosen} ne $emaildom) {
11457: push(@{$changes{'cancreate'}},'emaildomain');
11458: }
11459: } elsif ($emaildom ne '') {
11460: push(@{$changes{'cancreate'}},'emaildomain');
11461: }
11462: } elsif ($emaildom ne '') {
11463: push(@{$changes{'cancreate'}},'emaildomain');
11464: }
11465: }
11466: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
11467: } elsif ($chosen eq 'custom') {
11468: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
11469: $email_rule{$type} = [];
11470: if (ref($emailrules) eq 'HASH') {
11471: foreach my $rule (@possemail_rules) {
11472: if (exists($emailrules->{$rule})) {
11473: push(@{$email_rule{$type}},$rule);
11474: }
11475: }
11476: }
11477: if (@{$email_rule{$type}}) {
11478: $cancreate{'emailoptions'}{$type} = 'custom';
11479: if (ref($curr_rule{$type}) eq 'ARRAY') {
11480: if (@{$curr_rule{$type}} > 0) {
11481: foreach my $rule (@{$curr_rule{$type}}) {
11482: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
11483: push(@{$changes{'email_rule'}},$type);
11484: }
11485: }
11486: }
11487: foreach my $type (@{$email_rule{$type}}) {
11488: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
11489: push(@{$changes{'email_rule'}},$type);
11490: }
11491: }
11492: } else {
11493: push(@{$changes{'email_rule'}},$type);
11494: }
11495: }
11496: } else {
11497: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
11498: }
11499: }
11500: }
11501: if (@types) {
11502: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
11503: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
11504: if (@changed) {
11505: push(@{$changes{'inststatus'}},'inststatusguest');
11506: }
11507: } else {
11508: push(@{$changes{'inststatus'}},'inststatusguest');
11509: }
11510: }
11511: } else {
11512: delete($env{'form.cancreate_email'});
11513: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
11514: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
11515: push(@{$changes{'inststatus'}},'inststatusguest');
11516: }
11517: }
11518: }
11519: } else {
11520: $save_inststatus{'inststatusguest'} = [];
11521: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
11522: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
11523: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 11524: }
11525: }
1.160.6.34 raeburn 11526: }
11527: } else {
11528: if ($env{'form.cancreate_'.$item}) {
11529: push(@{$cancreate{'selfcreate'}},$item);
11530: }
11531: }
11532: }
1.160.6.93 raeburn 11533: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 11534: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
11535: #
1.160.6.35 raeburn 11536: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
11537: # 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 11538: #
1.160.6.40 raeburn 11539:
1.160.6.48 raeburn 11540: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 11541: push(@contexts,'emailusername');
1.160.6.93 raeburn 11542: if (@statuses) {
11543: foreach my $type (@statuses) {
1.160.6.35 raeburn 11544: if (ref($infofields) eq 'ARRAY') {
11545: foreach my $field (@{$infofields}) {
11546: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
11547: $cancreate{'emailusername'}{$type}{$field} = $1;
11548: }
11549: }
1.160.6.34 raeburn 11550: }
11551: }
11552: }
11553: #
11554: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 11555: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 11556: #
11557:
11558: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
11559: @approvalnotify = sort(@approvalnotify);
11560: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
11561: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11562: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
11563: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
11564: push(@{$changes{'cancreate'}},'notify');
11565: }
11566: } else {
11567: if ($cancreate{'notify'}{'approval'}) {
11568: push(@{$changes{'cancreate'}},'notify');
11569: }
11570: }
11571: } elsif ($cancreate{'notify'}{'approval'}) {
11572: push(@{$changes{'cancreate'}},'notify');
11573: }
11574:
11575: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
11576: }
11577: #
1.160.6.40 raeburn 11578: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 11579: # institutional log-in.
11580: #
11581: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
11582: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
11583: ($domdefaults{'auth_def'} eq 'localauth'))) {
11584: $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.').' '.
11585: &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.');
11586: }
11587: }
11588: my @fields = ('lastname','firstname','middlename','generation',
11589: 'permanentemail','id');
1.160.6.44 raeburn 11590: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 11591: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11592: #
11593: # Where usernames may created for institutional log-in and/or institutional single sign on:
11594: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
11595: # may self-create accounts
11596: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
11597: # which the user may supply, if institutional data is unavailable.
11598: #
11599: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 11600: if (@types) {
11601: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
11602: push(@contexts,'statustocreate');
11603: foreach my $type (@types) {
1.160.6.34 raeburn 11604: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
11605: foreach my $field (@fields) {
11606: if (grep(/^\Q$field\E$/,@modifiable)) {
11607: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
11608: } else {
11609: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
11610: }
11611: }
11612: }
11613: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 11614: foreach my $type (@types) {
1.160.6.34 raeburn 11615: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
11616: foreach my $field (@fields) {
11617: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
11618: $curr_usermodify{'selfcreate'}{$type}{$field}) {
11619: push(@{$changes{'selfcreate'}},$type);
11620: last;
11621: }
11622: }
11623: }
11624: }
11625: } else {
1.160.6.93 raeburn 11626: foreach my $type (@types) {
1.160.6.34 raeburn 11627: push(@{$changes{'selfcreate'}},$type);
11628: }
11629: }
11630: }
1.160.6.44 raeburn 11631: foreach my $field (@shibfields) {
11632: if ($env{'form.shibenv_'.$field} ne '') {
11633: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
11634: }
11635: }
11636: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11637: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
11638: foreach my $field (@shibfields) {
11639: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
11640: push(@{$changes{'cancreate'}},'shibenv');
11641: }
11642: }
11643: } else {
11644: foreach my $field (@shibfields) {
11645: if ($env{'form.shibenv_'.$field}) {
11646: push(@{$changes{'cancreate'}},'shibenv');
11647: last;
11648: }
11649: }
11650: }
11651: }
1.160.6.34 raeburn 11652: }
11653: foreach my $item (@contexts) {
11654: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
11655: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
11656: if (ref($cancreate{$item}) eq 'ARRAY') {
11657: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
11658: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11659: push(@{$changes{'cancreate'}},$item);
11660: }
11661: }
11662: }
11663: }
11664: if (ref($cancreate{$item}) eq 'ARRAY') {
11665: foreach my $type (@{$cancreate{$item}}) {
11666: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
11667: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11668: push(@{$changes{'cancreate'}},$item);
11669: }
11670: }
11671: }
11672: }
11673: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
11674: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 11675: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
11676: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
11677: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
11678: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 11679: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11680: push(@{$changes{'cancreate'}},$item);
11681: }
11682: }
11683: }
1.160.6.93 raeburn 11684: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
11685: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 11686: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11687: push(@{$changes{'cancreate'}},$item);
11688: }
1.160.6.34 raeburn 11689: }
11690: }
11691: }
1.160.6.93 raeburn 11692: foreach my $type (keys(%{$cancreate{$item}})) {
11693: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11694: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11695: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
11696: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 11697: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11698: push(@{$changes{'cancreate'}},$item);
11699: }
11700: }
11701: } else {
11702: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11703: push(@{$changes{'cancreate'}},$item);
11704: }
11705: }
11706: }
1.160.6.93 raeburn 11707: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
11708: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 11709: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11710: push(@{$changes{'cancreate'}},$item);
11711: }
1.160.6.34 raeburn 11712: }
11713: }
11714: }
11715: }
11716: } elsif ($curr_usercreation{'cancreate'}{$item}) {
11717: if (ref($cancreate{$item}) eq 'ARRAY') {
11718: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
11719: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11720: push(@{$changes{'cancreate'}},$item);
11721: }
11722: }
1.160.6.93 raeburn 11723: }
11724: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
11725: if (ref($cancreate{$item}) eq 'HASH') {
11726: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11727: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 11728: }
11729: }
11730: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 11731: if (ref($cancreate{$item}) eq 'HASH') {
11732: foreach my $type (keys(%{$cancreate{$item}})) {
11733: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11734: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11735: if ($cancreate{$item}{$type}{$field}) {
11736: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11737: push(@{$changes{'cancreate'}},$item);
11738: }
11739: last;
11740: }
11741: }
11742: }
11743: }
1.160.6.34 raeburn 11744: }
11745: }
11746: }
11747: #
11748: # Populate %save_usercreate hash with updates to self-creation configuration.
11749: #
11750: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
11751: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 11752: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 11753: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
11754: if (ref($cancreate{'notify'}) eq 'HASH') {
11755: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
11756: }
1.160.6.40 raeburn 11757: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
11758: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
11759: }
1.160.6.93 raeburn 11760: if (ref($cancreate{'emailverified'}) eq 'HASH') {
11761: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
11762: }
11763: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
11764: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
11765: }
11766: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
11767: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
11768: }
1.160.6.34 raeburn 11769: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11770: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
11771: }
1.160.6.44 raeburn 11772: if (ref($cancreate{'shibenv'}) eq 'HASH') {
11773: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
11774: }
1.160.6.34 raeburn 11775: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 11776: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 11777:
11778: my %userconfig_hash = (
11779: usercreation => \%save_usercreate,
11780: usermodification => \%save_usermodify,
1.160.6.93 raeburn 11781: inststatus => \%save_inststatus,
1.160.6.34 raeburn 11782: );
1.160.6.93 raeburn 11783:
1.160.6.34 raeburn 11784: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
11785: $dom);
11786: #
1.160.6.93 raeburn 11787: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 11788: #
1.27 raeburn 11789: if ($putresult eq 'ok') {
11790: if (keys(%changes) > 0) {
11791: $resulttext = &mt('Changes made:').'<ul>';
11792: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 11793: my %lt = &selfcreation_types();
1.34 raeburn 11794: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 11795: my $chgtext = '';
1.45 raeburn 11796: if ($type eq 'selfcreate') {
1.50 raeburn 11797: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 11798: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 11799: } else {
1.160.6.34 raeburn 11800: $chgtext .= &mt('Self-creation of a new account is permitted for:').
11801: '<ul>';
1.50 raeburn 11802: foreach my $case (@{$cancreate{$type}}) {
11803: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
11804: }
11805: $chgtext .= '</ul>';
1.100 raeburn 11806: if (ref($cancreate{$type}) eq 'ARRAY') {
11807: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
11808: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11809: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 11810: $chgtext .= '<span class="LC_warning">'.
11811: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
11812: '</span><br />';
1.100 raeburn 11813: }
11814: }
11815: }
1.160.6.93 raeburn 11816: if (grep(/^email$/,@{$cancreate{$type}})) {
11817: if (!@statuses) {
11818: $chgtext .= '<span class="LC_warning">'.
11819: &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.").
11820: '</span><br />';
11821:
11822: }
11823: }
1.100 raeburn 11824: }
1.43 raeburn 11825: }
1.160.6.44 raeburn 11826: } elsif ($type eq 'shibenv') {
11827: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 11828: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 11829: } else {
11830: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
11831: '<ul>';
11832: foreach my $field (@shibfields) {
11833: next if ($cancreate{$type}{$field} eq '');
11834: if ($field eq 'inststatus') {
11835: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
11836: } else {
11837: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
11838: }
11839: }
11840: $chgtext .= '</ul>';
1.160.6.93 raeburn 11841: }
1.93 raeburn 11842: } elsif ($type eq 'statustocreate') {
1.96 raeburn 11843: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
11844: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
11845: if (@{$cancreate{'selfcreate'}} > 0) {
11846: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 11847: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 11848: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 11849: $chgtext .= '<br />'.
11850: '<span class="LC_warning">'.
11851: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11852: '</span>';
11853: }
1.160.6.93 raeburn 11854: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 11855: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 11856: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
11857: } else {
11858: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
11859: }
11860: $chgtext .= '<ul>';
11861: foreach my $case (@{$cancreate{$type}}) {
11862: if ($case eq 'default') {
11863: $chgtext .= '<li>'.$othertitle.'</li>';
11864: } else {
1.160.6.93 raeburn 11865: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 11866: }
11867: }
1.100 raeburn 11868: $chgtext .= '</ul>';
11869: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 11870: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 11871: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
11872: '</span>';
1.100 raeburn 11873: }
11874: }
11875: } else {
11876: if (@{$cancreate{$type}} == 0) {
11877: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
11878: } else {
11879: $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 11880: }
11881: }
1.160.6.93 raeburn 11882: $chgtext .= '<br />';
1.93 raeburn 11883: }
1.160.6.40 raeburn 11884: } elsif ($type eq 'selfcreateprocessing') {
11885: my %choices = &Apache::lonlocal::texthash (
11886: automatic => 'Automatic approval',
11887: approval => 'Queued for approval',
11888: );
1.160.6.93 raeburn 11889: if (@types) {
11890: if (@statuses) {
11891: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
11892: '<ul>';
11893: foreach my $status (@statuses) {
11894: if ($status eq 'default') {
11895: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
11896: } else {
11897: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
11898: }
11899: }
11900: $chgtext .= '</ul>';
11901: }
11902: } else {
11903: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
11904: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
11905: }
11906: } elsif ($type eq 'emailverified') {
11907: my %options = &Apache::lonlocal::texthash (
11908: all => 'Same as e-mail',
11909: first => 'Omit @domain',
11910: free => 'Free to choose',
11911: );
11912: if (@types) {
11913: if (@statuses) {
11914: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
11915: '<ul>';
11916: foreach my $status (@statuses) {
11917: if ($status eq 'default') {
11918: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
11919: } else {
11920: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
11921: }
11922: }
11923: $chgtext .= '</ul>';
11924: }
1.160.6.40 raeburn 11925: } else {
1.160.6.93 raeburn 11926: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
11927: $options{$cancreate{'emailverified'}{'default'}});
11928: }
11929: } elsif ($type eq 'emailoptions') {
11930: my %options = &Apache::lonlocal::texthash (
11931: any => 'Any e-mail',
11932: inst => 'Institutional only',
11933: noninst => 'Non-institutional only',
11934: custom => 'Custom restrictions',
11935: );
11936: if (@types) {
11937: if (@statuses) {
11938: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
11939: '<ul>';
11940: foreach my $status (@statuses) {
11941: if ($type eq 'default') {
11942: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
11943: } else {
11944: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
11945: }
11946: }
11947: $chgtext .= '</ul>';
11948: }
11949: } else {
11950: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
11951: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
11952: } else {
11953: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
11954: $options{$cancreate{'emailoptions'}{'default'}});
11955: }
11956: }
11957: } elsif ($type eq 'emaildomain') {
11958: my $output;
11959: if (@statuses) {
11960: foreach my $type (@statuses) {
11961: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
11962: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
11963: if ($type eq 'default') {
11964: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
11965: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
11966: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
11967: } else {
11968: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
11969: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
11970: }
11971: } else {
11972: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
11973: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
11974: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
11975: } else {
11976: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
11977: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
11978: }
11979: }
11980: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
11981: if ($type eq 'default') {
11982: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
11983: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
11984: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
11985: } else {
11986: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
11987: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
11988: }
11989: } else {
11990: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
11991: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
11992: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
11993: } else {
11994: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
11995: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
11996: }
11997: }
11998: }
11999: }
12000: }
12001: }
12002: if ($output ne '') {
12003: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
12004: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 12005: }
1.160.6.5 raeburn 12006: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 12007: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 12008: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
12009: } else {
12010: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 12011: if ($captchas{$savecaptcha{$type}}) {
12012: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 12013: } else {
12014: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
12015: }
12016: }
12017: } elsif ($type eq 'recaptchakeys') {
12018: my ($privkey,$pubkey);
1.160.6.34 raeburn 12019: if (ref($savecaptcha{$type}) eq 'HASH') {
12020: $pubkey = $savecaptcha{$type}{'public'};
12021: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 12022: }
12023: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
12024: if (!$pubkey) {
12025: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
12026: } else {
12027: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12028: }
12029: if (!$privkey) {
12030: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
12031: } else {
12032: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
12033: }
12034: $chgtext .= '</ul>';
1.160.6.69 raeburn 12035: } elsif ($type eq 'recaptchaversion') {
12036: if ($savecaptcha{'captcha'} eq 'recaptcha') {
12037: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
12038: }
1.160.6.34 raeburn 12039: } elsif ($type eq 'emailusername') {
12040: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 12041: if (@statuses) {
12042: foreach my $type (@statuses) {
1.160.6.35 raeburn 12043: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
12044: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 12045: $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 12046: '<ul>';
12047: foreach my $field (@{$infofields}) {
12048: if ($cancreate{'emailusername'}{$type}{$field}) {
12049: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
12050: }
12051: }
1.160.6.50 raeburn 12052: $chgtext .= '</ul>';
12053: } else {
1.160.6.93 raeburn 12054: $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 12055: }
12056: } else {
1.160.6.93 raeburn 12057: $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 12058: }
12059: }
12060: }
12061: }
12062: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 12063: my $numapprove = 0;
1.160.6.34 raeburn 12064: if (ref($changes{'cancreate'}) eq 'ARRAY') {
12065: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
12066: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 12067: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
12068: $numapprove ++;
1.160.6.34 raeburn 12069: }
12070: }
1.43 raeburn 12071: }
1.160.6.93 raeburn 12072: unless ($numapprove) {
12073: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
12074: }
1.34 raeburn 12075: }
1.160.6.34 raeburn 12076: if ($chgtext) {
12077: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 12078: }
12079: }
12080: }
1.160.6.93 raeburn 12081: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 12082: my ($emailrules,$emailruleorder) =
12083: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 12084: foreach my $type (@{$changes{'email_rule'}}) {
12085: if (ref($email_rule{$type}) eq 'ARRAY') {
12086: my $chgtext = '<ul>';
12087: foreach my $rule (@{$email_rule{$type}}) {
12088: if (ref($emailrules->{$rule}) eq 'HASH') {
12089: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
12090: }
12091: }
12092: $chgtext .= '</ul>';
12093: my $typename;
12094: if (@types) {
12095: if ($type eq 'default') {
12096: $typename = $othertitle;
12097: } else {
12098: $typename = $usertypes{$type};
12099: }
12100: $chgtext .= &mt('(Affiliation: [_1])',$typename);
12101: }
12102: if (@{$email_rule{$type}} > 0) {
12103: $resulttext .= '<li>'.
12104: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
12105: $usertypes{$type}).
12106: $chgtext.
12107: '</li>';
12108: } else {
12109: $resulttext .= '<li>'.
12110: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
12111: '</li>'.
12112: &mt('(Affiliation: [_1])',$typename);
12113: }
1.43 raeburn 12114: }
12115: }
1.160.6.93 raeburn 12116: }
12117: if (ref($changes{'inststatus'}) eq 'ARRAY') {
12118: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
12119: if (@{$save_inststatus{'inststatusguest'}} > 0) {
12120: my $chgtext = '<ul>';
12121: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
12122: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
12123: }
12124: $chgtext .= '</ul>';
12125: $resulttext .= '<li>'.
12126: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
12127: $chgtext.
12128: '</li>';
12129: } else {
12130: $resulttext .= '<li>'.
12131: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
12132: '</li>';
12133: }
1.43 raeburn 12134: }
12135: }
1.160.6.34 raeburn 12136: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
12137: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
12138: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12139: foreach my $type (@{$changes{'selfcreate'}}) {
12140: my $typename = $type;
1.160.6.93 raeburn 12141: if (keys(%usertypes) > 0) {
12142: if ($usertypes{$type} ne '') {
12143: $typename = $usertypes{$type};
1.28 raeburn 12144: }
12145: }
1.160.6.34 raeburn 12146: my @modifiable;
12147: $resulttext .= '<li>'.
12148: &mt('Self-creation of account by users with status: [_1]',
12149: '<span class="LC_cusr_emph">'.$typename.'</span>').
12150: ' - '.&mt('modifiable fields (if institutional data blank): ');
12151: foreach my $field (@fields) {
12152: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
12153: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
12154: }
12155: }
12156: if (@modifiable > 0) {
12157: $resulttext .= join(', ',@modifiable);
1.43 raeburn 12158: } else {
1.160.6.34 raeburn 12159: $resulttext .= &mt('none');
1.43 raeburn 12160: }
1.160.6.34 raeburn 12161: $resulttext .= '</li>';
1.28 raeburn 12162: }
1.160.6.34 raeburn 12163: $resulttext .= '</ul></li>';
1.28 raeburn 12164: }
1.27 raeburn 12165: $resulttext .= '</ul>';
1.160.6.93 raeburn 12166: my $cachetime = 24*60*60;
12167: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
12168: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12169: if (ref($lastactref) eq 'HASH') {
12170: $lastactref->{'domdefaults'} = 1;
12171: }
1.27 raeburn 12172: } else {
1.160.6.34 raeburn 12173: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 12174: }
12175: } else {
12176: $resulttext = '<span class="LC_error">'.
1.23 raeburn 12177: &mt('An error occurred: [_1]',$putresult).'</span>';
12178: }
1.43 raeburn 12179: if ($warningmsg ne '') {
12180: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
12181: }
1.23 raeburn 12182: return $resulttext;
12183: }
12184:
1.160.6.5 raeburn 12185: sub process_captcha {
12186: my ($container,$changes,$newsettings,$current) = @_;
12187: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
12188: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
12189: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
12190: $newsettings->{'captcha'} = 'original';
12191: }
12192: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
12193: if ($container eq 'cancreate') {
12194: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12195: push(@{$changes->{'cancreate'}},'captcha');
12196: } elsif (!defined($changes->{'cancreate'})) {
12197: $changes->{'cancreate'} = ['captcha'];
12198: }
12199: } else {
12200: $changes->{'captcha'} = 1;
12201: }
12202: }
1.160.6.69 raeburn 12203: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 12204: if ($newsettings->{'captcha'} eq 'recaptcha') {
12205: $newpub = $env{'form.'.$container.'_recaptchapub'};
12206: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 12207: $newpub =~ s/[^\w\-]//g;
12208: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 12209: $newsettings->{'recaptchakeys'} = {
12210: public => $newpub,
12211: private => $newpriv,
12212: };
1.160.6.69 raeburn 12213: $newversion = $env{'form.'.$container.'_recaptchaversion'};
12214: $newversion =~ s/\D//g;
12215: if ($newversion ne '2') {
12216: $newversion = 1;
12217: }
12218: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 12219: }
12220: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
12221: $currpub = $current->{'recaptchakeys'}{'public'};
12222: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 12223: unless ($newsettings->{'captcha'} eq 'recaptcha') {
12224: $newsettings->{'recaptchakeys'} = {
12225: public => '',
12226: private => '',
12227: }
12228: }
1.160.6.5 raeburn 12229: }
1.160.6.69 raeburn 12230: if ($current->{'captcha'} eq 'recaptcha') {
12231: $currversion = $current->{'recaptchaversion'};
12232: if ($currversion ne '2') {
12233: $currversion = 1;
12234: }
12235: }
12236: if ($currversion ne $newversion) {
12237: if ($container eq 'cancreate') {
12238: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12239: push(@{$changes->{'cancreate'}},'recaptchaversion');
12240: } elsif (!defined($changes->{'cancreate'})) {
12241: $changes->{'cancreate'} = ['recaptchaversion'];
12242: }
12243: } else {
12244: $changes->{'recaptchaversion'} = 1;
12245: }
12246: }
1.160.6.5 raeburn 12247: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
12248: if ($container eq 'cancreate') {
12249: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12250: push(@{$changes->{'cancreate'}},'recaptchakeys');
12251: } elsif (!defined($changes->{'cancreate'})) {
12252: $changes->{'cancreate'} = ['recaptchakeys'];
12253: }
12254: } else {
12255: $changes->{'recaptchakeys'} = 1;
12256: }
12257: }
12258: return;
12259: }
12260:
1.33 raeburn 12261: sub modify_usermodification {
12262: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 12263: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 12264: if (ref($domconfig{'usermodification'}) eq 'HASH') {
12265: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 12266: if ($key eq 'selfcreate') {
12267: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
12268: } else {
12269: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
12270: }
1.33 raeburn 12271: }
12272: }
1.160.6.34 raeburn 12273: my @contexts = ('author','course');
1.33 raeburn 12274: my %context_title = (
12275: author => 'In author context',
12276: course => 'In course context',
12277: );
12278: my @fields = ('lastname','firstname','middlename','generation',
12279: 'permanentemail','id');
12280: my %roles = (
12281: author => ['ca','aa'],
12282: course => ['st','ep','ta','in','cr'],
12283: );
12284: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12285: foreach my $context (@contexts) {
12286: foreach my $role (@{$roles{$context}}) {
12287: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
12288: foreach my $item (@fields) {
12289: if (grep(/^\Q$item\E$/,@modifiable)) {
12290: $modifyhash{$context}{$role}{$item} = 1;
12291: } else {
12292: $modifyhash{$context}{$role}{$item} = 0;
12293: }
12294: }
12295: }
12296: if (ref($curr_usermodification{$context}) eq 'HASH') {
12297: foreach my $role (@{$roles{$context}}) {
12298: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
12299: foreach my $field (@fields) {
12300: if ($modifyhash{$context}{$role}{$field} ne
12301: $curr_usermodification{$context}{$role}{$field}) {
12302: push(@{$changes{$context}},$role);
12303: last;
12304: }
12305: }
12306: }
12307: }
12308: } else {
12309: foreach my $context (@contexts) {
12310: foreach my $role (@{$roles{$context}}) {
12311: push(@{$changes{$context}},$role);
12312: }
12313: }
12314: }
12315: }
12316: my %usermodification_hash = (
12317: usermodification => \%modifyhash,
12318: );
12319: my $putresult = &Apache::lonnet::put_dom('configuration',
12320: \%usermodification_hash,$dom);
12321: if ($putresult eq 'ok') {
12322: if (keys(%changes) > 0) {
12323: $resulttext = &mt('Changes made: ').'<ul>';
12324: foreach my $context (@contexts) {
12325: if (ref($changes{$context}) eq 'ARRAY') {
12326: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
12327: if (ref($changes{$context}) eq 'ARRAY') {
12328: foreach my $role (@{$changes{$context}}) {
12329: my $rolename;
1.160.6.34 raeburn 12330: if ($role eq 'cr') {
12331: $rolename = &mt('Custom');
1.33 raeburn 12332: } else {
1.160.6.34 raeburn 12333: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 12334: }
12335: my @modifiable;
1.160.6.34 raeburn 12336: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 12337: foreach my $field (@fields) {
12338: if ($modifyhash{$context}{$role}{$field}) {
12339: push(@modifiable,$fieldtitles{$field});
12340: }
12341: }
12342: if (@modifiable > 0) {
12343: $resulttext .= join(', ',@modifiable);
12344: } else {
12345: $resulttext .= &mt('none');
12346: }
12347: $resulttext .= '</li>';
12348: }
12349: $resulttext .= '</ul></li>';
12350: }
12351: }
12352: }
12353: $resulttext .= '</ul>';
12354: } else {
12355: $resulttext = &mt('No changes made to user modification settings');
12356: }
12357: } else {
12358: $resulttext = '<span class="LC_error">'.
12359: &mt('An error occurred: [_1]',$putresult).'</span>';
12360: }
12361: return $resulttext;
12362: }
12363:
1.43 raeburn 12364: sub modify_defaults {
1.160.6.27 raeburn 12365: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 12366: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 12367: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 12368: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98 raeburn 12369: 'portal_def');
1.43 raeburn 12370: my @authtypes = ('internal','krb4','krb5','localauth');
12371: foreach my $item (@items) {
12372: $newvalues{$item} = $env{'form.'.$item};
12373: if ($item eq 'auth_def') {
12374: if ($newvalues{$item} ne '') {
12375: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
12376: push(@errors,$item);
12377: }
12378: }
12379: } elsif ($item eq 'lang_def') {
12380: if ($newvalues{$item} ne '') {
12381: if ($newvalues{$item} =~ /^(\w+)/) {
12382: my $langcode = $1;
1.103 raeburn 12383: if ($langcode ne 'x_chef') {
12384: if (code2language($langcode) eq '') {
12385: push(@errors,$item);
12386: }
1.43 raeburn 12387: }
12388: } else {
12389: push(@errors,$item);
12390: }
12391: }
1.54 raeburn 12392: } elsif ($item eq 'timezone_def') {
12393: if ($newvalues{$item} ne '') {
1.62 raeburn 12394: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 12395: push(@errors,$item);
12396: }
12397: }
1.68 raeburn 12398: } elsif ($item eq 'datelocale_def') {
12399: if ($newvalues{$item} ne '') {
12400: my @datelocale_ids = DateTime::Locale->ids();
12401: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
12402: push(@errors,$item);
12403: }
12404: }
1.141 raeburn 12405: } elsif ($item eq 'portal_def') {
12406: if ($newvalues{$item} ne '') {
12407: 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])\/?$/) {
12408: push(@errors,$item);
12409: }
12410: }
1.43 raeburn 12411: }
12412: if (grep(/^\Q$item\E$/,@errors)) {
12413: $newvalues{$item} = $domdefaults{$item};
12414: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
12415: $changes{$item} = 1;
12416: }
1.72 raeburn 12417: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 12418: }
1.160.6.98 raeburn 12419: my %staticdefaults = (
12420: 'intauth_cost' => 10,
12421: 'intauth_check' => 0,
12422: 'intauth_switch' => 0,
12423: );
12424: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
12425: if (exists($domdefaults{$item})) {
12426: $newvalues{$item} = $domdefaults{$item};
12427: } else {
12428: $newvalues{$item} = $staticdefaults{$item};
12429: }
12430: }
1.43 raeburn 12431: my %defaults_hash = (
1.72 raeburn 12432: defaults => \%newvalues,
12433: );
1.43 raeburn 12434: my $title = &defaults_titles();
1.160.6.40 raeburn 12435:
12436: my $currinststatus;
12437: if (ref($domconfig{'inststatus'}) eq 'HASH') {
12438: $currinststatus = $domconfig{'inststatus'};
12439: } else {
12440: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12441: $currinststatus = {
12442: inststatustypes => $usertypes,
12443: inststatusorder => $types,
12444: inststatusguest => [],
12445: };
12446: }
12447: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
12448: my @allpos;
12449: my %alltypes;
1.160.6.93 raeburn 12450: my @inststatusguest;
12451: if (ref($currinststatus) eq 'HASH') {
12452: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
12453: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
12454: unless (grep(/^\Q$type\E$/,@todelete)) {
12455: push(@inststatusguest,$type);
12456: }
12457: }
12458: }
12459: }
12460: my ($currtitles,$currorder);
1.160.6.40 raeburn 12461: if (ref($currinststatus) eq 'HASH') {
12462: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
12463: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
12464: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
12465: if ($currinststatus->{inststatustypes}->{$type} ne '') {
12466: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
12467: }
12468: }
12469: unless (grep(/^\Q$type\E$/,@todelete)) {
12470: my $position = $env{'form.inststatus_pos_'.$type};
12471: $position =~ s/\D+//g;
12472: $allpos[$position] = $type;
12473: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
12474: $alltypes{$type} =~ s/`//g;
12475: }
12476: }
12477: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
12478: $currtitles =~ s/,$//;
12479: }
12480: }
12481: if ($env{'form.addinststatus'}) {
12482: my $newtype = $env{'form.addinststatus'};
12483: $newtype =~ s/\W//g;
12484: unless (exists($alltypes{$newtype})) {
12485: $alltypes{$newtype} = $env{'form.addinststatus_title'};
12486: $alltypes{$newtype} =~ s/`//g;
12487: my $position = $env{'form.addinststatus_pos'};
12488: $position =~ s/\D+//g;
12489: if ($position ne '') {
12490: $allpos[$position] = $newtype;
12491: }
12492: }
12493: }
1.160.6.93 raeburn 12494: my @orderedstatus;
1.160.6.40 raeburn 12495: foreach my $type (@allpos) {
12496: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
12497: push(@orderedstatus,$type);
12498: }
12499: }
12500: foreach my $type (keys(%alltypes)) {
12501: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
12502: delete($alltypes{$type});
12503: }
12504: }
12505: $defaults_hash{'inststatus'} = {
12506: inststatustypes => \%alltypes,
12507: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 12508: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 12509: };
12510: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
12511: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
12512: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
12513: }
12514: }
12515: if ($currorder ne join(',',@orderedstatus)) {
12516: $changes{'inststatus'}{'inststatusorder'} = 1;
12517: }
12518: my $newtitles;
12519: foreach my $item (@orderedstatus) {
12520: $newtitles .= $alltypes{$item}.',';
12521: }
12522: $newtitles =~ s/,$//;
12523: if ($currtitles ne $newtitles) {
12524: $changes{'inststatus'}{'inststatustypes'} = 1;
12525: }
1.43 raeburn 12526: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
12527: $dom);
12528: if ($putresult eq 'ok') {
12529: if (keys(%changes) > 0) {
12530: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 12531: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 12532: 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";
12533: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 12534: if ($item eq 'inststatus') {
12535: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 12536: if (@orderedstatus) {
1.160.6.40 raeburn 12537: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
12538: foreach my $type (@orderedstatus) {
12539: $resulttext .= $alltypes{$type}.', ';
12540: }
12541: $resulttext =~ s/, $//;
12542: $resulttext .= '</li>';
1.160.6.93 raeburn 12543: } else {
12544: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 12545: }
12546: }
12547: } else {
12548: my $value = $env{'form.'.$item};
12549: if ($value eq '') {
12550: $value = &mt('none');
12551: } elsif ($item eq 'auth_def') {
12552: my %authnames = &authtype_names();
12553: my %shortauth = (
12554: internal => 'int',
12555: krb4 => 'krb4',
12556: krb5 => 'krb5',
12557: localauth => 'loc',
12558: );
12559: $value = $authnames{$shortauth{$value}};
12560: }
12561: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
12562: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 12563: }
12564: }
12565: $resulttext .= '</ul>';
12566: $mailmsgtext .= "\n";
12567: my $cachetime = 24*60*60;
1.72 raeburn 12568: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 12569: if (ref($lastactref) eq 'HASH') {
12570: $lastactref->{'domdefaults'} = 1;
12571: }
1.68 raeburn 12572: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 12573: my $notify = 1;
12574: if (ref($domconfig{'contacts'}) eq 'HASH') {
12575: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
12576: $notify = 0;
12577: }
12578: }
12579: if ($notify) {
12580: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
12581: "LON-CAPA Domain Settings Change - $dom",
12582: $mailmsgtext);
12583: }
1.54 raeburn 12584: }
1.43 raeburn 12585: } else {
1.54 raeburn 12586: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 12587: }
12588: } else {
12589: $resulttext = '<span class="LC_error">'.
12590: &mt('An error occurred: [_1]',$putresult).'</span>';
12591: }
12592: if (@errors > 0) {
12593: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
12594: foreach my $item (@errors) {
12595: $resulttext .= ' "'.$title->{$item}.'",';
12596: }
12597: $resulttext =~ s/,$//;
12598: }
12599: return $resulttext;
12600: }
12601:
1.46 raeburn 12602: sub modify_scantron {
1.160.6.24 raeburn 12603: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 12604: my ($resulttext,%confhash,%changes,$errors);
12605: my $custom = 'custom.tab';
12606: my $default = 'default.tab';
12607: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 12608: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 12609: &config_check($dom,$confname,$servadm);
12610: if ($env{'form.scantronformat.filename'} ne '') {
12611: my $error;
12612: if ($configuserok eq 'ok') {
12613: if ($switchserver) {
1.130 raeburn 12614: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 12615: } else {
12616: if ($author_ok eq 'ok') {
12617: my ($result,$scantronurl) =
12618: &publishlogo($r,'upload','scantronformat',$dom,
12619: $confname,'scantron','','',$custom);
12620: if ($result eq 'ok') {
12621: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 12622: $changes{'scantronformat'} = 1;
1.46 raeburn 12623: } else {
12624: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
12625: }
12626: } else {
12627: $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);
12628: }
12629: }
12630: } else {
12631: $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);
12632: }
12633: if ($error) {
12634: &Apache::lonnet::logthis($error);
12635: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12636: }
12637: }
1.48 raeburn 12638: if (ref($domconfig{'scantron'}) eq 'HASH') {
12639: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
12640: if ($env{'form.scantronformat_del'}) {
12641: $confhash{'scantron'}{'scantronformat'} = '';
12642: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 12643: } else {
12644: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
12645: }
12646: }
12647: }
12648: my @options = ('hdr','pad','rem');
12649: my @fields = &scantroncsv_fields();
12650: my %titles = &scantronconfig_titles();
12651: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
12652: my ($newdat,$currdat,%newcol,%currcol);
12653: if (grep(/^dat$/,@formats)) {
12654: $confhash{'scantron'}{config}{dat} = 1;
12655: $newdat = 1;
12656: } else {
12657: $newdat = 0;
12658: }
12659: if (grep(/^csv$/,@formats)) {
12660: my %bynum;
12661: foreach my $field (@fields) {
12662: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
12663: my $posscol = $1;
12664: if (($posscol < 20) && (!$bynum{$posscol})) {
12665: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
12666: $bynum{$posscol} = $field;
12667: $newcol{$field} = $posscol;
12668: }
12669: }
12670: }
12671: if (keys(%newcol)) {
12672: foreach my $option (@options) {
12673: if ($env{'form.scantroncsv_'.$option}) {
12674: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
12675: }
12676: }
12677: }
12678: }
12679: $currdat = 1;
12680: if (ref($domconfig{'scantron'}) eq 'HASH') {
12681: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
12682: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
12683: $currdat = 0;
12684: }
12685: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
12686: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
12687: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
12688: }
12689: }
12690: }
12691: }
12692: if ($currdat != $newdat) {
12693: $changes{'config'} = 1;
12694: } else {
12695: foreach my $field (@fields) {
12696: if ($currcol{$field} ne '') {
12697: if ($currcol{$field} ne $newcol{$field}) {
12698: $changes{'config'} = 1;
12699: last;
12700: }
12701: } elsif ($newcol{$field} ne '') {
12702: $changes{'config'} = 1;
12703: last;
1.46 raeburn 12704: }
12705: }
12706: }
12707: if (keys(%confhash) > 0) {
12708: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
12709: $dom);
12710: if ($putresult eq 'ok') {
12711: if (keys(%changes) > 0) {
1.48 raeburn 12712: if (ref($confhash{'scantron'}) eq 'HASH') {
12713: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 12714: if ($changes{'scantronformat'}) {
12715: if ($confhash{'scantron'}{'scantronformat'} eq '') {
12716: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
12717: } else {
12718: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
12719: }
12720: }
12721: if ($changes{'config'}) {
12722: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
12723: if ($confhash{'scantron'}{'config'}{'dat'}) {
12724: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
12725: }
12726: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
12727: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
12728: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
12729: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
12730: foreach my $field (@fields) {
12731: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
12732: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
12733: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
12734: }
12735: }
12736: $resulttext .= '</ul></li>';
12737: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
12738: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
12739: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
12740: foreach my $option (@options) {
12741: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
12742: $resulttext .= '<li>'.$titles{$option}.'</li>';
12743: }
12744: }
12745: $resulttext .= '</ul></li>';
12746: }
12747: }
12748: }
12749: }
12750: }
12751: } else {
12752: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
12753: }
1.46 raeburn 12754: }
1.48 raeburn 12755: $resulttext .= '</ul>';
12756: } else {
1.130 raeburn 12757: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 12758: }
12759: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 12760: if (ref($lastactref) eq 'HASH') {
12761: $lastactref->{'domainconfig'} = 1;
12762: }
1.46 raeburn 12763: } else {
1.160.6.97 raeburn 12764: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 12765: }
12766: } else {
12767: $resulttext = '<span class="LC_error">'.
12768: &mt('An error occurred: [_1]',$putresult).'</span>';
12769: }
12770: } else {
1.160.6.97 raeburn 12771: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 12772: }
12773: if ($errors) {
12774: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12775: $errors.'</ul>';
12776: }
12777: return $resulttext;
12778: }
12779:
1.48 raeburn 12780: sub modify_coursecategories {
1.160.6.43 raeburn 12781: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 12782: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
12783: $cathash);
1.48 raeburn 12784: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 12785: my @catitems = ('unauth','auth');
12786: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 12787: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 12788: $cathash = $domconfig{'coursecategories'}{'cats'};
12789: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
12790: $changes{'togglecats'} = 1;
12791: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
12792: }
12793: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
12794: $changes{'categorize'} = 1;
12795: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
12796: }
1.120 raeburn 12797: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
12798: $changes{'togglecatscomm'} = 1;
12799: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
12800: }
12801: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
12802: $changes{'categorizecomm'} = 1;
12803: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
12804: }
1.160.6.42 raeburn 12805: foreach my $item (@catitems) {
12806: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12807: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
12808: $changes{$item} = 1;
12809: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12810: }
12811: }
12812: }
1.57 raeburn 12813: } else {
12814: $changes{'togglecats'} = 1;
12815: $changes{'categorize'} = 1;
1.124 raeburn 12816: $changes{'togglecatscomm'} = 1;
12817: $changes{'categorizecomm'} = 1;
1.87 raeburn 12818: $domconfig{'coursecategories'} = {
12819: togglecats => $env{'form.togglecats'},
12820: categorize => $env{'form.categorize'},
1.124 raeburn 12821: togglecatscomm => $env{'form.togglecatscomm'},
12822: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 12823: };
1.160.6.42 raeburn 12824: foreach my $item (@catitems) {
12825: if ($env{'form.coursecat_'.$item} ne 'std') {
12826: $changes{$item} = 1;
12827: }
12828: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12829: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12830: }
12831: }
1.57 raeburn 12832: }
12833: if (ref($cathash) eq 'HASH') {
12834: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 12835: push (@deletecategory,'instcode::0');
12836: }
1.120 raeburn 12837: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
12838: push(@deletecategory,'communities::0');
12839: }
1.48 raeburn 12840: }
1.57 raeburn 12841: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
12842: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12843: if (@deletecategory > 0) {
12844: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 12845: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 12846: foreach my $item (@deletecategory) {
1.57 raeburn 12847: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
12848: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 12849: $deletions{$item} = 1;
1.57 raeburn 12850: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 12851: }
12852: }
12853: }
1.57 raeburn 12854: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 12855: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 12856: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 12857: $reorderings{$item} = 1;
1.57 raeburn 12858: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 12859: }
12860: if ($env{'form.addcategory_name_'.$item} ne '') {
12861: my $newcat = $env{'form.addcategory_name_'.$item};
12862: my $newdepth = $depth+1;
12863: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12864: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 12865: $adds{$newitem} = 1;
12866: }
12867: if ($env{'form.subcat_'.$item} ne '') {
12868: my $newcat = $env{'form.subcat_'.$item};
12869: my $newdepth = $depth+1;
12870: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12871: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 12872: $adds{$newitem} = 1;
12873: }
12874: }
12875: }
12876: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 12877: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12878: my $newitem = 'instcode::0';
1.57 raeburn 12879: if ($cathash->{$newitem} eq '') {
12880: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12881: $adds{$newitem} = 1;
12882: }
12883: } else {
12884: my $newitem = 'instcode::0';
1.57 raeburn 12885: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12886: $adds{$newitem} = 1;
12887: }
12888: }
1.120 raeburn 12889: if ($env{'form.communities'} eq '1') {
12890: if (ref($cathash) eq 'HASH') {
12891: my $newitem = 'communities::0';
12892: if ($cathash->{$newitem} eq '') {
12893: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12894: $adds{$newitem} = 1;
12895: }
12896: } else {
12897: my $newitem = 'communities::0';
12898: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12899: $adds{$newitem} = 1;
12900: }
12901: }
1.48 raeburn 12902: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 12903: if (($env{'form.addcategory_name'} ne 'instcode') &&
12904: ($env{'form.addcategory_name'} ne 'communities')) {
12905: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
12906: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
12907: $adds{$newitem} = 1;
12908: }
1.48 raeburn 12909: }
1.57 raeburn 12910: my $putresult;
1.48 raeburn 12911: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12912: if (keys(%deletions) > 0) {
12913: foreach my $key (keys(%deletions)) {
12914: if ($predelallitems{$key} ne '') {
12915: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
12916: }
12917: }
12918: }
12919: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 12920: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 12921: if (ref($chkcats[0]) eq 'ARRAY') {
12922: my $depth = 0;
12923: my $chg = 0;
12924: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
12925: my $name = $chkcats[0][$i];
12926: my $item;
12927: if ($name eq '') {
12928: $chg ++;
12929: } else {
12930: $item = &escape($name).'::0';
12931: if ($chg) {
1.57 raeburn 12932: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 12933: }
12934: $depth ++;
1.57 raeburn 12935: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 12936: $depth --;
12937: }
12938: }
12939: }
1.57 raeburn 12940: }
12941: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12942: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 12943: if ($putresult eq 'ok') {
1.57 raeburn 12944: my %title = (
1.120 raeburn 12945: togglecats => 'Show/Hide a course in catalog',
12946: categorize => 'Assign a category to a course',
12947: togglecatscomm => 'Show/Hide a community in catalog',
12948: categorizecomm => 'Assign a category to a community',
1.57 raeburn 12949: );
12950: my %level = (
1.120 raeburn 12951: dom => 'set in Domain ("Modify Course/Community")',
12952: crs => 'set in Course ("Course Configuration")',
12953: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 12954: none => 'No catalog',
12955: std => 'Standard catalog',
12956: domonly => 'Domain-only catalog',
12957: codesrch => 'Code search form',
1.57 raeburn 12958: );
1.48 raeburn 12959: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 12960: if ($changes{'togglecats'}) {
12961: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
12962: }
12963: if ($changes{'categorize'}) {
12964: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 12965: }
1.120 raeburn 12966: if ($changes{'togglecatscomm'}) {
12967: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
12968: }
12969: if ($changes{'categorizecomm'}) {
12970: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
12971: }
1.160.6.42 raeburn 12972: if ($changes{'unauth'}) {
12973: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
12974: }
12975: if ($changes{'auth'}) {
12976: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
12977: }
1.57 raeburn 12978: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12979: my $cathash;
12980: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
12981: $cathash = $domconfig{'coursecategories'}{'cats'};
12982: } else {
12983: $cathash = {};
12984: }
12985: my (@cats,@trails,%allitems);
12986: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
12987: if (keys(%deletions) > 0) {
12988: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
12989: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
12990: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
12991: }
12992: $resulttext .= '</ul></li>';
12993: }
12994: if (keys(%reorderings) > 0) {
12995: my %sort_by_trail;
12996: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
12997: foreach my $key (keys(%reorderings)) {
12998: if ($allitems{$key} ne '') {
12999: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
13000: }
1.48 raeburn 13001: }
1.57 raeburn 13002: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
13003: $resulttext .= '<li>'.$trails[$trail].'</li>';
13004: }
13005: $resulttext .= '</ul></li>';
1.48 raeburn 13006: }
1.57 raeburn 13007: if (keys(%adds) > 0) {
13008: my %sort_by_trail;
13009: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
13010: foreach my $key (keys(%adds)) {
13011: if ($allitems{$key} ne '') {
13012: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
13013: }
13014: }
13015: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
13016: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 13017: }
1.57 raeburn 13018: $resulttext .= '</ul></li>';
1.48 raeburn 13019: }
1.160.6.92 raeburn 13020: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
13021: if (ref($lastactref) eq 'HASH') {
13022: $lastactref->{'cats'} = 1;
13023: }
1.48 raeburn 13024: }
13025: $resulttext .= '</ul>';
1.160.6.43 raeburn 13026: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 13027: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
13028: if ($changes{'auth'}) {
13029: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
13030: }
13031: if ($changes{'unauth'}) {
13032: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
13033: }
13034: my $cachetime = 24*60*60;
13035: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 13036: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 13037: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 13038: }
13039: }
1.48 raeburn 13040: } else {
13041: $resulttext = '<span class="LC_error">'.
1.57 raeburn 13042: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 13043: }
13044: } else {
1.120 raeburn 13045: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 13046: }
13047: return $resulttext;
13048: }
13049:
1.69 raeburn 13050: sub modify_serverstatuses {
13051: my ($dom,%domconfig) = @_;
13052: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
13053: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
13054: %currserverstatus = %{$domconfig{'serverstatuses'}};
13055: }
13056: my @pages = &serverstatus_pages();
13057: foreach my $type (@pages) {
13058: $newserverstatus{$type}{'namedusers'} = '';
13059: $newserverstatus{$type}{'machines'} = '';
13060: if (defined($env{'form.'.$type.'_namedusers'})) {
13061: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
13062: my @okusers;
13063: foreach my $user (@users) {
13064: my ($uname,$udom) = split(/:/,$user);
13065: if (($udom =~ /^$match_domain$/) &&
13066: (&Apache::lonnet::domain($udom)) &&
13067: ($uname =~ /^$match_username$/)) {
13068: if (!grep(/^\Q$user\E/,@okusers)) {
13069: push(@okusers,$user);
13070: }
13071: }
13072: }
13073: if (@okusers > 0) {
13074: @okusers = sort(@okusers);
13075: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
13076: }
13077: }
13078: if (defined($env{'form.'.$type.'_machines'})) {
13079: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
13080: my @okmachines;
13081: foreach my $ip (@machines) {
13082: my @parts = split(/\./,$ip);
13083: next if (@parts < 4);
13084: my $badip = 0;
13085: for (my $i=0; $i<4; $i++) {
13086: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
13087: $badip = 1;
13088: last;
13089: }
13090: }
13091: if (!$badip) {
13092: push(@okmachines,$ip);
13093: }
13094: }
13095: @okmachines = sort(@okmachines);
13096: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
13097: }
13098: }
13099: my %serverstatushash = (
13100: serverstatuses => \%newserverstatus,
13101: );
13102: foreach my $type (@pages) {
1.83 raeburn 13103: foreach my $setting ('namedusers','machines') {
1.84 raeburn 13104: my (@current,@new);
1.83 raeburn 13105: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 13106: if ($currserverstatus{$type}{$setting} ne '') {
13107: @current = split(/,/,$currserverstatus{$type}{$setting});
13108: }
13109: }
13110: if ($newserverstatus{$type}{$setting} ne '') {
13111: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 13112: }
13113: if (@current > 0) {
13114: if (@new > 0) {
13115: foreach my $item (@current) {
13116: if (!grep(/^\Q$item\E$/,@new)) {
13117: $changes{$type}{$setting} = 1;
1.82 raeburn 13118: last;
13119: }
13120: }
1.84 raeburn 13121: foreach my $item (@new) {
13122: if (!grep(/^\Q$item\E$/,@current)) {
13123: $changes{$type}{$setting} = 1;
13124: last;
1.82 raeburn 13125: }
13126: }
13127: } else {
1.83 raeburn 13128: $changes{$type}{$setting} = 1;
1.69 raeburn 13129: }
1.83 raeburn 13130: } elsif (@new > 0) {
13131: $changes{$type}{$setting} = 1;
1.69 raeburn 13132: }
13133: }
13134: }
13135: if (keys(%changes) > 0) {
1.81 raeburn 13136: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 13137: my $putresult = &Apache::lonnet::put_dom('configuration',
13138: \%serverstatushash,$dom);
13139: if ($putresult eq 'ok') {
13140: $resulttext .= &mt('Changes made:').'<ul>';
13141: foreach my $type (@pages) {
1.84 raeburn 13142: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 13143: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 13144: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 13145: if ($newserverstatus{$type}{'namedusers'} eq '') {
13146: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
13147: } else {
13148: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
13149: }
1.84 raeburn 13150: }
13151: if ($changes{$type}{'machines'}) {
1.69 raeburn 13152: if ($newserverstatus{$type}{'machines'} eq '') {
13153: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
13154: } else {
13155: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
13156: }
13157:
13158: }
13159: $resulttext .= '</ul></li>';
13160: }
13161: }
13162: $resulttext .= '</ul>';
13163: } else {
13164: $resulttext = '<span class="LC_error">'.
13165: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
13166:
13167: }
13168: } else {
13169: $resulttext = &mt('No changes made to access to server status pages');
13170: }
13171: return $resulttext;
13172: }
13173:
1.118 jms 13174: sub modify_helpsettings {
1.160.6.77 raeburn 13175: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 13176: my ($resulttext,$errors,%changes,%helphash);
13177: my %defaultchecked = ('submitbugs' => 'on');
13178: my @offon = ('off','on');
1.118 jms 13179: my @toggles = ('submitbugs');
1.160.6.77 raeburn 13180: my %current = ('submitbugs' => '',
13181: 'adhoc' => {},
13182: );
1.118 jms 13183: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 13184: %current = %{$domconfig{'helpsettings'}};
13185: }
1.160.6.77 raeburn 13186: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 13187: foreach my $item (@toggles) {
13188: if ($defaultchecked{$item} eq 'on') {
13189: if ($current{$item} eq '') {
13190: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 13191: $changes{$item} = 1;
13192: }
1.160.6.73 raeburn 13193: } elsif ($current{$item} ne $env{'form.'.$item}) {
13194: $changes{$item} = 1;
13195: }
13196: } elsif ($defaultchecked{$item} eq 'off') {
13197: if ($current{$item} eq '') {
13198: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 13199: $changes{$item} = 1;
13200: }
1.160.6.73 raeburn 13201: } elsif ($current{$item} ne $env{'form.'.$item}) {
13202: $changes{$item} = 1;
13203: }
13204: }
13205: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
13206: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
13207: }
13208: }
1.160.6.77 raeburn 13209: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 13210: my $confname = $dom.'-domainconfig';
13211: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 13212: my (@allpos,%newsettings,%changedprivs,$newrole);
13213: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 13214: my @accesstypes = ('all','dh','da','none','status','inc','exc');
13215: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 13216: my %lt = &Apache::lonlocal::texthash(
13217: s => 'system',
13218: d => 'domain',
13219: order => 'Display order',
13220: access => 'Role usage',
1.160.6.79 raeburn 13221: all => 'All with domain helpdesk or helpdesk assistant role',
13222: dh => 'All with domain helpdesk role',
13223: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 13224: none => 'None',
13225: status => 'Determined based on institutional status',
13226: inc => 'Include all, but exclude specific personnel',
13227: exc => 'Exclude all, but include specific personnel',
13228: );
13229: for (my $num=0; $num<=$maxnum; $num++) {
13230: my ($prefix,$identifier,$rolename,%curr);
13231: if ($num == $maxnum) {
13232: next unless ($env{'form.newcusthelp'} == $maxnum);
13233: $identifier = 'custhelp'.$num;
13234: $prefix = 'helproles_'.$num;
13235: $rolename = $env{'form.custhelpname'.$num};
13236: $rolename=~s/[^A-Za-z0-9]//gs;
13237: next if ($rolename eq '');
13238: next if (exists($existing{'rolesdef_'.$rolename}));
13239: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
13240: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
13241: $newprivs{'c'},$confname,$dom);
13242: if ($result ne 'ok') {
13243: $errors .= '<li><span class="LC_error">'.
13244: &mt('An error occurred storing the new custom role: [_1]',
13245: $result).'</span></li>';
13246: next;
13247: } else {
13248: $changedprivs{$rolename} = \%newprivs;
13249: $newrole = $rolename;
13250: }
13251: } else {
13252: $prefix = 'helproles_'.$num;
13253: $rolename = $env{'form.'.$prefix};
13254: next if ($rolename eq '');
13255: next unless (exists($existing{'rolesdef_'.$rolename}));
13256: $identifier = 'custhelp'.$num;
13257: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
13258: my %currprivs;
13259: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
13260: split(/\_/,$existing{'rolesdef_'.$rolename});
13261: foreach my $level ('c','d','s') {
13262: if ($newprivs{$level} ne $currprivs{$level}) {
13263: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
13264: $newprivs{'c'},$confname,$dom);
13265: if ($result ne 'ok') {
13266: $errors .= '<li><span class="LC_error">'.
13267: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
13268: $rolename,$result).'</span></li>';
13269: } else {
13270: $changedprivs{$rolename} = \%newprivs;
13271: }
13272: last;
13273: }
13274: }
13275: if (ref($current{'adhoc'}) eq 'HASH') {
13276: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
13277: %curr = %{$current{'adhoc'}{$rolename}};
13278: }
13279: }
13280: }
13281: my $newpos = $env{'form.'.$prefix.'_pos'};
13282: $newpos =~ s/\D+//g;
13283: $allpos[$newpos] = $rolename;
13284: my $newdesc = $env{'form.'.$prefix.'_desc'};
13285: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
13286: if ($curr{'desc'}) {
13287: if ($curr{'desc'} ne $newdesc) {
13288: $changes{'customrole'}{$rolename}{'desc'} = 1;
13289: $newsettings{$rolename}{'desc'} = $newdesc;
13290: }
13291: } elsif ($newdesc ne '') {
13292: $changes{'customrole'}{$rolename}{'desc'} = 1;
13293: $newsettings{$rolename}{'desc'} = $newdesc;
13294: }
13295: my $access = $env{'form.'.$prefix.'_access'};
13296: if (grep(/^\Q$access\E$/,@accesstypes)) {
13297: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
13298: if ($access eq 'status') {
13299: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
13300: if (scalar(@statuses) == 0) {
13301: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
13302: } else {
13303: my (@shownstatus,$numtypes);
13304: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
13305: if (ref($types) eq 'ARRAY') {
13306: $numtypes = scalar(@{$types});
13307: foreach my $type (sort(@statuses)) {
13308: if ($type eq 'default') {
13309: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
13310: } elsif (grep(/^\Q$type\E$/,@{$types})) {
13311: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
13312: push(@shownstatus,$usertypes->{$type});
13313: }
1.160.6.73 raeburn 13314: }
13315: }
1.160.6.77 raeburn 13316: if (grep(/^default$/,@statuses)) {
13317: push(@shownstatus,$othertitle);
13318: }
13319: if (scalar(@shownstatus) == 1+$numtypes) {
13320: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
13321: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
13322: } else {
13323: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
13324: if (ref($curr{'status'}) eq 'ARRAY') {
13325: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
13326: if (@diffs) {
13327: $changes{'customrole'}{$rolename}{$access} = 1;
13328: }
13329: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13330: $changes{'customrole'}{$rolename}{$access} = 1;
13331: }
13332: }
13333: }
13334: } elsif (($access eq 'inc') || ($access eq 'exc')) {
13335: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
13336: my @newspecstaff;
13337: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
13338: foreach my $person (sort(@personnel)) {
13339: if ($domhelpdesk{$person}) {
13340: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
13341: }
13342: }
13343: if (ref($curr{$access}) eq 'ARRAY') {
13344: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
13345: if (@diffs) {
13346: $changes{'customrole'}{$rolename}{$access} = 1;
13347: }
13348: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13349: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 13350: }
1.160.6.77 raeburn 13351: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13352: my ($uname,$udom) = split(/:/,$person);
13353: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
13354: }
13355: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 13356: }
1.160.6.77 raeburn 13357: } else {
13358: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
13359: }
13360: unless ($curr{'access'} eq $access) {
13361: $changes{'customrole'}{$rolename}{'access'} = 1;
13362: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 13363: }
13364: }
1.160.6.77 raeburn 13365: if (@allpos > 0) {
13366: my $idx = 0;
13367: foreach my $rolename (@allpos) {
13368: if ($rolename ne '') {
13369: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
13370: if (ref($current{'adhoc'}) eq 'HASH') {
13371: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
13372: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
13373: $changes{'customrole'}{$rolename}{'order'} = 1;
13374: $newsettings{$rolename}{'order'} = $idx+1;
13375: }
13376: }
1.160.6.73 raeburn 13377: }
1.160.6.77 raeburn 13378: $idx ++;
1.122 jms 13379: }
13380: }
1.118 jms 13381: }
1.123 jms 13382: my $putresult;
13383: if (keys(%changes) > 0) {
1.160.6.5 raeburn 13384: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
13385: if ($putresult eq 'ok') {
1.160.6.77 raeburn 13386: if (ref($helphash{'helpsettings'}) eq 'HASH') {
13387: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
13388: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
13389: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
13390: }
13391: }
13392: my $cachetime = 24*60*60;
13393: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13394: if (ref($lastactref) eq 'HASH') {
13395: $lastactref->{'domdefaults'} = 1;
13396: }
13397: } else {
13398: $errors .= '<li><span class="LC_error">'.
13399: &mt('An error occurred storing the settings: [_1]',
13400: $putresult).'</span></li>';
13401: }
13402: }
13403: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
13404: $resulttext = &mt('Changes made:').'<ul>';
13405: my (%shownprivs,@levelorder);
13406: @levelorder = ('c','d','s');
13407: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 13408: foreach my $item (sort(keys(%changes))) {
13409: if ($item eq 'submitbugs') {
13410: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
13411: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
13412: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 13413: } elsif ($item eq 'customrole') {
13414: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 13415: my @keyorder = ('order','desc','access','status','exc','inc');
13416: my %keytext = &Apache::lonlocal::texthash(
13417: order => 'Order',
13418: desc => 'Role description',
13419: access => 'Role usage',
1.160.6.83 raeburn 13420: status => 'Allowed institutional types',
1.160.6.77 raeburn 13421: exc => 'Allowed personnel',
13422: inc => 'Disallowed personnel',
13423: );
1.160.6.73 raeburn 13424: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 13425: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
13426: if ($role eq $newrole) {
13427: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
13428: $role).'<ul>';
13429: } else {
13430: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
13431: $role).'<ul>';
13432: }
13433: foreach my $key (@keyorder) {
13434: if ($changes{'customrole'}{$role}{$key}) {
13435: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
13436: $keytext{$key},$newsettings{$role}{$key}).
13437: '</li>';
13438: }
13439: }
13440: if (ref($changedprivs{$role}) eq 'HASH') {
13441: $shownprivs{$role} = 1;
13442: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
13443: foreach my $level (@levelorder) {
13444: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13445: next if ($item eq '');
13446: my ($priv) = split(/\&/,$item,2);
13447: if (&Apache::lonnet::plaintext($priv)) {
13448: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13449: unless ($level eq 'c') {
13450: $resulttext .= ' ('.$lt{$level}.')';
13451: }
13452: $resulttext .= '</li>';
13453: }
13454: }
13455: }
13456: $resulttext .= '</ul>';
13457: }
13458: $resulttext .= '</ul></li>';
13459: }
1.160.6.73 raeburn 13460: }
13461: }
1.160.6.5 raeburn 13462: }
13463: }
13464: }
1.160.6.77 raeburn 13465: if (keys(%changedprivs)) {
13466: foreach my $role (sort(keys(%changedprivs))) {
13467: unless ($shownprivs{$role}) {
13468: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
13469: $role).'<ul>'.
13470: '<li>'.&mt('Privileges set to :').'<ul>';
13471: foreach my $level (@levelorder) {
13472: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13473: next if ($item eq '');
13474: my ($priv) = split(/\&/,$item,2);
13475: if (&Apache::lonnet::plaintext($priv)) {
13476: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13477: unless ($level eq 'c') {
13478: $resulttext .= ' ('.$lt{$level}.')';
13479: }
13480: $resulttext .= '</li>';
13481: }
13482: }
13483: }
13484: $resulttext .= '</ul></li></ul></li>';
13485: }
13486: }
13487: }
13488: $resulttext .= '</ul>';
13489: } else {
13490: $resulttext = &mt('No changes made to help settings');
1.118 jms 13491: }
13492: if ($errors) {
1.160.6.5 raeburn 13493: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 13494: $errors.'</ul>';
1.118 jms 13495: }
13496: return $resulttext;
13497: }
13498:
1.121 raeburn 13499: sub modify_coursedefaults {
1.160.6.27 raeburn 13500: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 13501: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 13502: my %defaultchecked = (
13503: 'uselcmath' => 'on',
13504: 'usejsme' => 'on'
13505: );
13506: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 13507: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 13508: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
13509: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 13510: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 13511: my %staticdefaults = (
13512: anonsurvey_threshold => 10,
13513: uploadquota => 500,
1.160.6.57 raeburn 13514: postsubmit => 60,
1.160.6.70 raeburn 13515: mysqltables => 172800,
1.160.6.21 raeburn 13516: );
1.160.6.90 raeburn 13517: my %texoptions = (
13518: MathJax => 'MathJax',
13519: mimetex => &mt('Convert to Images'),
13520: tth => &mt('TeX to HTML'),
13521: );
1.121 raeburn 13522: $defaultshash{'coursedefaults'} = {};
13523:
13524: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
13525: if ($domconfig{'coursedefaults'} eq '') {
13526: $domconfig{'coursedefaults'} = {};
13527: }
13528: }
13529:
13530: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
13531: foreach my $item (@toggles) {
13532: if ($defaultchecked{$item} eq 'on') {
13533: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13534: ($env{'form.'.$item} eq '0')) {
13535: $changes{$item} = 1;
1.160.6.16 raeburn 13536: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 13537: $changes{$item} = 1;
13538: }
13539: } elsif ($defaultchecked{$item} eq 'off') {
13540: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13541: ($env{'form.'.$item} eq '1')) {
13542: $changes{$item} = 1;
13543: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
13544: $changes{$item} = 1;
13545: }
13546: }
13547: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
13548: }
1.160.6.21 raeburn 13549: foreach my $item (@numbers) {
13550: my ($currdef,$newdef);
1.160.6.26 raeburn 13551: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 13552: if ($item eq 'anonsurvey_threshold') {
13553: $currdef = $domconfig{'coursedefaults'}{$item};
13554: $newdef =~ s/\D//g;
13555: if ($newdef eq '' || $newdef < 1) {
13556: $newdef = 1;
13557: }
13558: $defaultshash{'coursedefaults'}{$item} = $newdef;
13559: } else {
1.160.6.70 raeburn 13560: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
13561: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
13562: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 13563: }
13564: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 13565: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 13566: }
13567: if ($currdef ne $newdef) {
13568: if ($item eq 'anonsurvey_threshold') {
13569: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
13570: $changes{$item} = 1;
13571: }
1.160.6.70 raeburn 13572: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
13573: my $setting = $1;
13574: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
13575: $changes{$setting} = 1;
1.160.6.21 raeburn 13576: }
13577: }
1.139 raeburn 13578: }
13579: }
1.160.6.90 raeburn 13580: my $texengine;
13581: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
13582: $texengine = $env{'form.texengine'};
13583: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
13584: if ($currdef eq '') {
13585: unless ($texengine eq $Apache::lonnet::deftex) {
13586: $changes{'texengine'} = 1;
13587: }
13588: } elsif ($currdef ne $texengine) {
13589: $changes{'texengine'} = 1;
13590: }
13591: }
13592: if ($texengine ne '') {
13593: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
13594: }
1.160.6.64 raeburn 13595: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
13596: my @currclonecode;
13597: if (ref($currclone) eq 'HASH') {
13598: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
13599: @currclonecode = @{$currclone->{'instcode'}};
13600: }
13601: }
13602: my $newclone;
13603: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
13604: $newclone = $env{'form.canclone'};
13605: }
13606: if ($newclone eq 'instcode') {
13607: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
13608: my (%codedefaults,@code_order,@clonecode);
13609: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
13610: \@code_order);
13611: foreach my $item (@code_order) {
13612: if (grep(/^\Q$item\E$/,@newcodes)) {
13613: push(@clonecode,$item);
13614: }
13615: }
13616: if (@clonecode) {
13617: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
13618: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
13619: if (@diffs) {
13620: $changes{'canclone'} = 1;
13621: }
13622: } else {
13623: $newclone eq '';
13624: }
13625: } elsif ($newclone ne '') {
13626: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
13627: }
13628: if ($newclone ne $currclone) {
13629: $changes{'canclone'} = 1;
13630: }
1.160.6.57 raeburn 13631: my %credits;
13632: foreach my $type (@types) {
13633: unless ($type eq 'community') {
13634: $credits{$type} = $env{'form.'.$type.'_credits'};
13635: $credits{$type} =~ s/[^\d.]+//g;
13636: }
13637: }
13638: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
13639: ($env{'form.coursecredits'} eq '1')) {
13640: $changes{'coursecredits'} = 1;
13641: foreach my $type (keys(%credits)) {
13642: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13643: }
13644: } else {
13645: if ($env{'form.coursecredits'} eq '1') {
13646: foreach my $type (@types) {
13647: unless ($type eq 'community') {
13648: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
13649: $changes{'coursecredits'} = 1;
13650: }
13651: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13652: }
13653: }
13654: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13655: foreach my $type (@types) {
13656: unless ($type eq 'community') {
13657: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
13658: $changes{'coursecredits'} = 1;
13659: last;
13660: }
13661: }
13662: }
13663: }
13664: }
13665: if ($env{'form.postsubmit'} eq '1') {
13666: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
13667: my %currtimeout;
13668: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13669: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
13670: $changes{'postsubmit'} = 1;
13671: }
13672: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13673: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
13674: }
13675: } else {
13676: $changes{'postsubmit'} = 1;
13677: }
13678: foreach my $type (@types) {
13679: my $timeout = $env{'form.'.$type.'_timeout'};
13680: $timeout =~ s/\D//g;
13681: if ($timeout == $staticdefaults{'postsubmit'}) {
13682: $timeout = '';
13683: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
13684: $timeout = '0';
13685: }
13686: unless ($timeout eq '') {
13687: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
13688: }
13689: if (exists($currtimeout{$type})) {
13690: if ($timeout ne $currtimeout{$type}) {
13691: $changes{'postsubmit'} = 1;
13692: }
13693: } elsif ($timeout ne '') {
13694: $changes{'postsubmit'} = 1;
13695: }
13696: }
13697: } else {
13698: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
13699: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13700: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
13701: $changes{'postsubmit'} = 1;
13702: }
13703: } else {
13704: $changes{'postsubmit'} = 1;
13705: }
1.160.6.16 raeburn 13706: }
1.121 raeburn 13707: }
13708: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13709: $dom);
13710: if ($putresult eq 'ok') {
13711: if (keys(%changes) > 0) {
1.160.6.27 raeburn 13712: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 13713: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 13714: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.90 raeburn 13715: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
13716: foreach my $item ('uselcmath','usejsme','texengine') {
1.160.6.57 raeburn 13717: if ($changes{$item}) {
13718: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
13719: }
1.160.6.16 raeburn 13720: }
13721: if ($changes{'coursecredits'}) {
13722: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 13723: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
13724: $domdefaults{$type.'credits'} =
13725: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
13726: }
13727: }
13728: }
13729: if ($changes{'postsubmit'}) {
13730: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13731: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
13732: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13733: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
13734: $domdefaults{$type.'postsubtimeout'} =
13735: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13736: }
13737: }
1.160.6.16 raeburn 13738: }
13739: }
1.160.6.21 raeburn 13740: if ($changes{'uploadquota'}) {
13741: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13742: foreach my $type (@types) {
13743: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
13744: }
13745: }
13746: }
1.160.6.64 raeburn 13747: if ($changes{'canclone'}) {
13748: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13749: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13750: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
13751: if (@clonecodes) {
13752: $domdefaults{'canclone'} = join('+',@clonecodes);
13753: }
13754: }
13755: } else {
13756: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
13757: }
13758: }
1.121 raeburn 13759: my $cachetime = 24*60*60;
13760: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 13761: if (ref($lastactref) eq 'HASH') {
13762: $lastactref->{'domdefaults'} = 1;
13763: }
1.121 raeburn 13764: }
13765: $resulttext = &mt('Changes made:').'<ul>';
13766: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 13767: if ($item eq 'uselcmath') {
1.121 raeburn 13768: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 13769: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 13770: } else {
1.160.6.57 raeburn 13771: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
13772: }
13773: } elsif ($item eq 'usejsme') {
13774: if ($env{'form.'.$item} eq '1') {
13775: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
13776: } else {
13777: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 13778: }
1.160.6.90 raeburn 13779: } elsif ($item eq 'texengine') {
13780: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
13781: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
13782: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
13783: }
1.139 raeburn 13784: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 13785: $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 13786: } elsif ($item eq 'uploadquota') {
13787: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13788: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
13789: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
13790: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 13791: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
13792:
1.160.6.21 raeburn 13793: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
13794: '</ul>'.
13795: '</li>';
13796: } else {
13797: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
13798: }
1.160.6.70 raeburn 13799: } elsif ($item eq 'mysqltables') {
13800: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
13801: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
13802: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
13803: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
13804: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
13805: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
13806: '</ul>'.
13807: '</li>';
13808: } else {
13809: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
13810: }
1.160.6.57 raeburn 13811: } elsif ($item eq 'postsubmit') {
13812: if ($domdefaults{'postsubmit'} eq 'off') {
13813: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
13814: } else {
13815: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
13816: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13817: $resulttext .= &mt('durations:').'<ul>';
13818: foreach my $type (@types) {
13819: $resulttext .= '<li>';
13820: my $timeout;
13821: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13822: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13823: }
13824: my $display;
13825: if ($timeout eq '0') {
13826: $display = &mt('unlimited');
13827: } elsif ($timeout eq '') {
13828: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
13829: } else {
13830: $display = &mt('[quant,_1,second]',$timeout);
13831: }
13832: if ($type eq 'community') {
13833: $resulttext .= &mt('Communities');
13834: } elsif ($type eq 'official') {
13835: $resulttext .= &mt('Official courses');
13836: } elsif ($type eq 'unofficial') {
13837: $resulttext .= &mt('Unofficial courses');
13838: } elsif ($type eq 'textbook') {
13839: $resulttext .= &mt('Textbook courses');
13840: }
13841: $resulttext .= ' -- '.$display.'</li>';
13842: }
13843: $resulttext .= '</ul>';
13844: }
13845: $resulttext .= '</li>';
13846: }
1.160.6.16 raeburn 13847: } elsif ($item eq 'coursecredits') {
13848: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13849: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 13850: ($domdefaults{'unofficialcredits'} eq '') &&
13851: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 13852: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13853: } else {
13854: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
13855: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
13856: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 13857: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 13858: '</ul>'.
13859: '</li>';
13860: }
13861: } else {
13862: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13863: }
1.160.6.64 raeburn 13864: } elsif ($item eq 'canclone') {
13865: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13866: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13867: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
13868: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
13869: }
13870: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
13871: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
13872: } else {
13873: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
13874: }
1.140 raeburn 13875: }
1.121 raeburn 13876: }
13877: $resulttext .= '</ul>';
13878: } else {
13879: $resulttext = &mt('No changes made to course defaults');
13880: }
13881: } else {
13882: $resulttext = '<span class="LC_error">'.
13883: &mt('An error occurred: [_1]',$putresult).'</span>';
13884: }
13885: return $resulttext;
13886: }
13887:
1.160.6.37 raeburn 13888: sub modify_selfenrollment {
13889: my ($dom,$lastactref,%domconfig) = @_;
13890: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
13891: my @types = ('official','unofficial','community','textbook');
13892: my %titles = &tool_titles();
13893: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
13894: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
13895: $ordered{'default'} = ['types','registered','approval','limit'];
13896:
13897: my (%roles,%shown,%toplevel);
13898: $roles{'0'} = &Apache::lonnet::plaintext('dc');
13899:
13900: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
13901: if ($domconfig{'selfenrollment'} eq '') {
13902: $domconfig{'selfenrollment'} = {};
13903: }
13904: }
13905: %toplevel = (
13906: admin => 'Configuration Rights',
13907: default => 'Default settings',
13908: validation => 'Validation of self-enrollment requests',
13909: );
13910: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
13911:
13912: if (ref($ordered{'admin'}) eq 'ARRAY') {
13913: foreach my $item (@{$ordered{'admin'}}) {
13914: foreach my $type (@types) {
13915: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
13916: $selfenrollhash{'admin'}{$type}{$item} = 1;
13917: } else {
13918: $selfenrollhash{'admin'}{$type}{$item} = 0;
13919: }
13920: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
13921: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
13922: if ($selfenrollhash{'admin'}{$type}{$item} ne
13923: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
13924: push(@{$changes{'admin'}{$type}},$item);
13925: }
13926: } else {
13927: if (!$selfenrollhash{'admin'}{$type}{$item}) {
13928: push(@{$changes{'admin'}{$type}},$item);
13929: }
13930: }
13931: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
13932: push(@{$changes{'admin'}{$type}},$item);
13933: }
13934: }
13935: }
13936: }
13937:
13938: foreach my $item (@{$ordered{'default'}}) {
13939: foreach my $type (@types) {
13940: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
13941: if ($item eq 'types') {
13942: unless (($value eq 'all') || ($value eq 'dom')) {
13943: $value = '';
13944: }
13945: } elsif ($item eq 'registered') {
13946: unless ($value eq '1') {
13947: $value = 0;
13948: }
13949: } elsif ($item eq 'approval') {
13950: unless ($value =~ /^[012]$/) {
13951: $value = 0;
13952: }
13953: } else {
13954: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13955: $value = 'none';
13956: }
13957: }
13958: $selfenrollhash{'default'}{$type}{$item} = $value;
13959: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
13960: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13961: if ($selfenrollhash{'default'}{$type}{$item} ne
13962: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
13963: push(@{$changes{'default'}{$type}},$item);
13964: }
13965: } else {
13966: push(@{$changes{'default'}{$type}},$item);
13967: }
13968: } else {
13969: push(@{$changes{'default'}{$type}},$item);
13970: }
13971: if ($item eq 'limit') {
13972: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13973: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
13974: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
13975: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
13976: }
13977: } else {
13978: $selfenrollhash{'default'}{$type}{'cap'} = '';
13979: }
13980: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13981: if ($selfenrollhash{'default'}{$type}{'cap'} ne
13982: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
13983: push(@{$changes{'default'}{$type}},'cap');
13984: }
13985: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
13986: push(@{$changes{'default'}{$type}},'cap');
13987: }
13988: }
13989: }
13990: }
13991:
13992: foreach my $item (@{$itemsref}) {
13993: if ($item eq 'fields') {
13994: my @changed;
13995: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
13996: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
13997: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
13998: }
13999: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
14000: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
14001: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
14002: $domconfig{'selfenrollment'}{'validation'}{$item});
14003: } else {
14004: @changed = @{$selfenrollhash{'validation'}{$item}};
14005: }
14006: } else {
14007: @changed = @{$selfenrollhash{'validation'}{$item}};
14008: }
14009: if (@changed) {
14010: if ($selfenrollhash{'validation'}{$item}) {
14011: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
14012: } else {
14013: $changes{'validation'}{$item} = &mt('None');
14014: }
14015: }
14016: } else {
14017: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
14018: if ($item eq 'markup') {
14019: if ($env{'form.selfenroll_validation_'.$item}) {
14020: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14021: }
14022: }
14023: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
14024: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
14025: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
14026: }
14027: }
14028: }
14029: }
14030:
14031: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
14032: $dom);
14033: if ($putresult eq 'ok') {
14034: if (keys(%changes) > 0) {
14035: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14036: $resulttext = &mt('Changes made:').'<ul>';
14037: foreach my $key ('admin','default','validation') {
14038: if (ref($changes{$key}) eq 'HASH') {
14039: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
14040: if ($key eq 'validation') {
14041: foreach my $item (@{$itemsref}) {
14042: if (exists($changes{$key}{$item})) {
14043: if ($item eq 'markup') {
14044: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
14045: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
14046: } else {
14047: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
14048: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
14049: }
14050: }
14051: }
14052: } else {
14053: foreach my $type (@types) {
14054: if ($type eq 'community') {
14055: $roles{'1'} = &mt('Community personnel');
14056: } else {
14057: $roles{'1'} = &mt('Course personnel');
14058: }
14059: if (ref($changes{$key}{$type}) eq 'ARRAY') {
14060: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
14061: if ($key eq 'admin') {
14062: my @mgrdc = ();
14063: if (ref($ordered{$key}) eq 'ARRAY') {
14064: foreach my $item (@{$ordered{'admin'}}) {
14065: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
14066: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
14067: push(@mgrdc,$item);
14068: }
14069: }
14070: }
14071: if (@mgrdc) {
14072: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
14073: } else {
14074: delete($domdefaults{$type.'selfenrolladmdc'});
14075: }
14076: }
14077: } else {
14078: if (ref($ordered{$key}) eq 'ARRAY') {
14079: foreach my $item (@{$ordered{$key}}) {
14080: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
14081: $domdefaults{$type.'selfenroll'.$item} =
14082: $selfenrollhash{$key}{$type}{$item};
14083: }
14084: }
14085: }
14086: }
14087: }
14088: $resulttext .= '<li>'.$titles{$type}.'<ul>';
14089: foreach my $item (@{$ordered{$key}}) {
14090: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
14091: $resulttext .= '<li>';
14092: if ($key eq 'admin') {
14093: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
14094: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
14095: } else {
14096: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
14097: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
14098: }
14099: $resulttext .= '</li>';
14100: }
14101: }
14102: $resulttext .= '</ul></li>';
14103: }
14104: }
14105: $resulttext .= '</ul></li>';
14106: }
14107: }
1.160.6.93 raeburn 14108: }
14109: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
14110: my $cachetime = 24*60*60;
14111: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14112: if (ref($lastactref) eq 'HASH') {
14113: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 14114: }
14115: }
14116: $resulttext .= '</ul>';
14117: } else {
14118: $resulttext = &mt('No changes made to self-enrollment settings');
14119: }
14120: } else {
14121: $resulttext = '<span class="LC_error">'.
14122: &mt('An error occurred: [_1]',$putresult).'</span>';
14123: }
14124: return $resulttext;
14125: }
14126:
1.137 raeburn 14127: sub modify_usersessions {
1.160.6.27 raeburn 14128: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 14129: my @hostingtypes = ('version','excludedomain','includedomain');
14130: my @offloadtypes = ('primary','default');
14131: my %types = (
14132: remote => \@hostingtypes,
14133: hosted => \@hostingtypes,
14134: spares => \@offloadtypes,
14135: );
14136: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 14137: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 14138: my (%by_ip,%by_location,@intdoms);
14139: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
14140: my @locations = sort(keys(%by_location));
1.137 raeburn 14141: my (%defaultshash,%changes);
14142: foreach my $prefix (@prefixes) {
14143: $defaultshash{'usersessions'}{$prefix} = {};
14144: }
1.160.6.27 raeburn 14145: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 14146: my $resulttext;
1.138 raeburn 14147: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 14148: foreach my $prefix (@prefixes) {
1.145 raeburn 14149: next if ($prefix eq 'spares');
14150: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 14151: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14152: if ($type eq 'version') {
14153: my $value = $env{'form.'.$prefix.'_'.$type};
14154: my $okvalue;
14155: if ($value ne '') {
14156: if (grep(/^\Q$value\E$/,@lcversions)) {
14157: $okvalue = $value;
14158: }
14159: }
14160: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14161: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
14162: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
14163: if ($inuse == 0) {
14164: $changes{$prefix}{$type} = 1;
14165: } else {
14166: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
14167: $changes{$prefix}{$type} = 1;
14168: }
14169: if ($okvalue ne '') {
14170: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14171: }
14172: }
14173: } else {
14174: if (($inuse == 1) && ($okvalue ne '')) {
14175: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14176: $changes{$prefix}{$type} = 1;
14177: }
14178: }
14179: } else {
14180: if (($inuse == 1) && ($okvalue ne '')) {
14181: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14182: $changes{$prefix}{$type} = 1;
14183: }
14184: }
14185: } else {
14186: if (($inuse == 1) && ($okvalue ne '')) {
14187: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14188: $changes{$prefix}{$type} = 1;
14189: }
14190: }
14191: } else {
14192: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14193: my @okvals;
14194: foreach my $val (@vals) {
1.138 raeburn 14195: if ($val =~ /:/) {
14196: my @items = split(/:/,$val);
14197: foreach my $item (@items) {
14198: if (ref($by_location{$item}) eq 'ARRAY') {
14199: push(@okvals,$item);
14200: }
14201: }
14202: } else {
14203: if (ref($by_location{$val}) eq 'ARRAY') {
14204: push(@okvals,$val);
14205: }
1.137 raeburn 14206: }
14207: }
14208: @okvals = sort(@okvals);
14209: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14210: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
14211: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
14212: if ($inuse == 0) {
14213: $changes{$prefix}{$type} = 1;
14214: } else {
14215: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14216: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
14217: if (@changed > 0) {
14218: $changes{$prefix}{$type} = 1;
14219: }
14220: }
14221: } else {
14222: if ($inuse == 1) {
14223: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14224: $changes{$prefix}{$type} = 1;
14225: }
14226: }
14227: } else {
14228: if ($inuse == 1) {
14229: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14230: $changes{$prefix}{$type} = 1;
14231: }
14232: }
14233: } else {
14234: if ($inuse == 1) {
14235: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14236: $changes{$prefix}{$type} = 1;
14237: }
14238: }
14239: }
14240: }
14241: }
1.145 raeburn 14242:
14243: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 14244: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 14245: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
14246: my $savespares;
14247:
14248: foreach my $lonhost (sort(keys(%servers))) {
14249: my $serverhomeID =
14250: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 14251: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 14252: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
14253: my %spareschg;
14254: foreach my $type (@{$types{'spares'}}) {
14255: my @okspares;
14256: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
14257: foreach my $server (@checked) {
1.152 raeburn 14258: if (&Apache::lonnet::hostname($server) ne '') {
14259: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
14260: unless (grep(/^\Q$server\E$/,@okspares)) {
14261: push(@okspares,$server);
14262: }
1.145 raeburn 14263: }
14264: }
14265: }
14266: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
14267: my $newspare;
1.152 raeburn 14268: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
14269: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 14270: $newspare = $new;
14271: }
14272: }
1.152 raeburn 14273: my @spares;
14274: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
14275: @spares = sort(@okspares,$newspare);
14276: } else {
14277: @spares = sort(@okspares);
14278: }
14279: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 14280: if (ref($spareid{$lonhost}) eq 'HASH') {
14281: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 14282: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 14283: if (@diffs > 0) {
14284: $spareschg{$type} = 1;
14285: }
14286: }
14287: }
14288: }
14289: if (keys(%spareschg) > 0) {
14290: $changes{'spares'}{$lonhost} = \%spareschg;
14291: }
14292: }
1.160.6.61 raeburn 14293: $defaultshash{'usersessions'}{'offloadnow'} = {};
14294: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
14295: my @okoffload;
14296: if (@offloadnow) {
14297: foreach my $server (@offloadnow) {
14298: if (&Apache::lonnet::hostname($server) ne '') {
14299: unless (grep(/^\Q$server\E$/,@okoffload)) {
14300: push(@okoffload,$server);
14301: }
14302: }
14303: }
14304: if (@okoffload) {
14305: foreach my $lonhost (@okoffload) {
14306: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
14307: }
14308: }
14309: }
1.145 raeburn 14310: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14311: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
14312: if (ref($changes{'spares'}) eq 'HASH') {
14313: if (keys(%{$changes{'spares'}}) > 0) {
14314: $savespares = 1;
14315: }
14316: }
14317: } else {
14318: $savespares = 1;
14319: }
1.160.6.61 raeburn 14320: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
14321: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
14322: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
14323: $changes{'offloadnow'} = 1;
14324: last;
14325: }
14326: }
14327: unless ($changes{'offloadnow'}) {
14328: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
14329: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
14330: $changes{'offloadnow'} = 1;
14331: last;
14332: }
14333: }
14334: }
14335: } elsif (@okoffload) {
14336: $changes{'offloadnow'} = 1;
14337: }
14338: } elsif (@okoffload) {
14339: $changes{'offloadnow'} = 1;
1.145 raeburn 14340: }
1.147 raeburn 14341: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
14342: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 14343: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14344: $dom);
14345: if ($putresult eq 'ok') {
14346: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
14347: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
14348: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
14349: }
14350: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
14351: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
14352: }
1.160.6.61 raeburn 14353: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
14354: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
14355: }
1.137 raeburn 14356: }
14357: my $cachetime = 24*60*60;
14358: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 14359: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 14360: if (ref($lastactref) eq 'HASH') {
14361: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 14362: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 14363: }
1.147 raeburn 14364: if (keys(%changes) > 0) {
14365: my %lt = &usersession_titles();
14366: $resulttext = &mt('Changes made:').'<ul>';
14367: foreach my $prefix (@prefixes) {
14368: if (ref($changes{$prefix}) eq 'HASH') {
14369: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
14370: if ($prefix eq 'spares') {
14371: if (ref($changes{$prefix}) eq 'HASH') {
14372: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
14373: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 14374: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 14375: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
14376: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 14377: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
14378: foreach my $type (@{$types{$prefix}}) {
14379: if ($changes{$prefix}{$lonhost}{$type}) {
14380: my $offloadto = &mt('None');
14381: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
14382: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
14383: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
14384: }
1.145 raeburn 14385: }
1.147 raeburn 14386: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 14387: }
1.137 raeburn 14388: }
14389: }
1.147 raeburn 14390: $resulttext .= '</li>';
1.137 raeburn 14391: }
14392: }
1.147 raeburn 14393: } else {
14394: foreach my $type (@{$types{$prefix}}) {
14395: if (defined($changes{$prefix}{$type})) {
14396: my $newvalue;
14397: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
14398: if (ref($defaultshash{'usersessions'}{$prefix})) {
14399: if ($type eq 'version') {
14400: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
14401: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
14402: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
14403: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
14404: }
1.145 raeburn 14405: }
14406: }
14407: }
1.147 raeburn 14408: if ($newvalue eq '') {
14409: if ($type eq 'version') {
14410: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
14411: } else {
14412: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
14413: }
1.145 raeburn 14414: } else {
1.147 raeburn 14415: if ($type eq 'version') {
14416: $newvalue .= ' '.&mt('(or later)');
14417: }
14418: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 14419: }
1.137 raeburn 14420: }
14421: }
14422: }
1.147 raeburn 14423: $resulttext .= '</ul>';
1.137 raeburn 14424: }
14425: }
1.160.6.61 raeburn 14426: if ($changes{'offloadnow'}) {
14427: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
14428: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
14429: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
14430: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
14431: $resulttext .= '<li>'.$lonhost.'</li>';
14432: }
14433: $resulttext .= '</ul>';
14434: } else {
14435: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
14436: }
14437: } else {
14438: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
14439: }
14440: }
1.147 raeburn 14441: $resulttext .= '</ul>';
14442: } else {
14443: $resulttext = $nochgmsg;
1.137 raeburn 14444: }
14445: } else {
14446: $resulttext = '<span class="LC_error">'.
14447: &mt('An error occurred: [_1]',$putresult).'</span>';
14448: }
14449: } else {
1.147 raeburn 14450: $resulttext = $nochgmsg;
1.137 raeburn 14451: }
14452: return $resulttext;
14453: }
14454:
1.150 raeburn 14455: sub modify_loadbalancing {
14456: my ($dom,%domconfig) = @_;
14457: my $primary_id = &Apache::lonnet::domain($dom,'primary');
14458: my $intdom = &Apache::lonnet::internet_dom($primary_id);
14459: my ($othertitle,$usertypes,$types) =
14460: &Apache::loncommon::sorted_inst_types($dom);
14461: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 14462: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 14463: my @sparestypes = ('primary','default');
14464: my %typetitles = &sparestype_titles();
14465: my $resulttext;
1.160.6.94 raeburn 14466: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 14467: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14468: %existing = %{$domconfig{'loadbalancing'}};
14469: }
14470: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 14471: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 14472: my ($saveloadbalancing,%defaultshash,%changes);
14473: my ($alltypes,$othertypes,$titles) =
14474: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
14475: my %ruletitles = &offloadtype_text();
14476: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
14477: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
14478: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
14479: if ($balancer eq '') {
14480: next;
14481: }
14482: if (!exists($servers{$balancer})) {
14483: if (exists($currbalancer{$balancer})) {
14484: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 14485: }
1.160.6.7 raeburn 14486: next;
14487: }
14488: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
14489: push(@{$changes{'delete'}},$balancer);
14490: next;
14491: }
14492: if (!exists($currbalancer{$balancer})) {
14493: push(@{$changes{'add'}},$balancer);
14494: }
14495: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
14496: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
14497: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
14498: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14499: $saveloadbalancing = 1;
14500: }
14501: foreach my $sparetype (@sparestypes) {
14502: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
14503: my @offloadto;
14504: foreach my $target (@targets) {
14505: if (($servers{$target}) && ($target ne $balancer)) {
14506: if ($sparetype eq 'default') {
14507: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
14508: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 14509: }
14510: }
1.160.6.7 raeburn 14511: unless(grep(/^\Q$target\E$/,@offloadto)) {
14512: push(@offloadto,$target);
14513: }
1.150 raeburn 14514: }
14515: }
1.160.6.76 raeburn 14516: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
14517: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
14518: push(@offloadto,$balancer);
14519: }
14520: }
14521: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 14522: }
1.160.6.94 raeburn 14523: if ($env{'form.loadbalancing_cookie_'.$i}) {
14524: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
14525: if (exists($currbalancer{$balancer})) {
14526: unless ($currcookies{$balancer}) {
14527: $changes{'curr'}{$balancer}{'cookie'} = 1;
14528: }
14529: }
14530: } elsif (exists($currbalancer{$balancer})) {
14531: if ($currcookies{$balancer}) {
14532: $changes{'curr'}{$balancer}{'cookie'} = 1;
14533: }
14534: }
1.160.6.7 raeburn 14535: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 14536: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 14537: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
14538: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 14539: if (@targetdiffs > 0) {
1.160.6.7 raeburn 14540: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14541: }
1.160.6.7 raeburn 14542: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14543: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14544: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14545: }
14546: }
14547: }
14548: } else {
1.160.6.7 raeburn 14549: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
14550: foreach my $sparetype (@sparestypes) {
14551: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14552: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14553: $changes{'curr'}{$balancer}{'targets'} = 1;
14554: }
1.150 raeburn 14555: }
14556: }
1.160.6.7 raeburn 14557: }
1.150 raeburn 14558: }
14559: my $ishomedom;
1.160.6.7 raeburn 14560: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
14561: $ishomedom = 1;
1.150 raeburn 14562: }
14563: if (ref($alltypes) eq 'ARRAY') {
14564: foreach my $type (@{$alltypes}) {
14565: my $rule;
1.160.6.7 raeburn 14566: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 14567: (!$ishomedom)) {
1.160.6.7 raeburn 14568: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
14569: }
14570: if ($rule eq 'specific') {
1.160.6.55 raeburn 14571: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
14572: if (exists($servers{$specifiedhost})) {
14573: $rule = $specifiedhost;
14574: }
1.150 raeburn 14575: }
1.160.6.7 raeburn 14576: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
14577: if (ref($currrules{$balancer}) eq 'HASH') {
14578: if ($rule ne $currrules{$balancer}{$type}) {
14579: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14580: }
14581: } elsif ($rule ne '') {
1.160.6.7 raeburn 14582: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14583: }
14584: }
14585: }
1.160.6.7 raeburn 14586: }
14587: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
14588: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
14589: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
14590: $defaultshash{'loadbalancing'} = {};
14591: }
14592: my $putresult = &Apache::lonnet::put_dom('configuration',
14593: \%defaultshash,$dom);
14594: if ($putresult eq 'ok') {
14595: if (keys(%changes) > 0) {
1.160.6.54 raeburn 14596: my %toupdate;
1.160.6.7 raeburn 14597: if (ref($changes{'delete'}) eq 'ARRAY') {
14598: foreach my $balancer (sort(@{$changes{'delete'}})) {
14599: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 14600: $toupdate{$balancer} = 1;
1.150 raeburn 14601: }
1.160.6.7 raeburn 14602: }
14603: if (ref($changes{'add'}) eq 'ARRAY') {
14604: foreach my $balancer (sort(@{$changes{'add'}})) {
14605: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 14606: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 14607: }
14608: }
14609: if (ref($changes{'curr'}) eq 'HASH') {
14610: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 14611: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 14612: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
14613: if ($changes{'curr'}{$balancer}{'targets'}) {
14614: my %offloadstr;
14615: foreach my $sparetype (@sparestypes) {
14616: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14617: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14618: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14619: }
14620: }
1.150 raeburn 14621: }
1.160.6.7 raeburn 14622: if (keys(%offloadstr) == 0) {
14623: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 14624: } else {
1.160.6.7 raeburn 14625: my $showoffload;
14626: foreach my $sparetype (@sparestypes) {
14627: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
14628: if (defined($offloadstr{$sparetype})) {
14629: $showoffload .= $offloadstr{$sparetype};
14630: } else {
14631: $showoffload .= &mt('None');
14632: }
14633: $showoffload .= (' 'x3);
14634: }
14635: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 14636: }
14637: }
14638: }
1.160.6.7 raeburn 14639: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
14640: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
14641: foreach my $type (@{$alltypes}) {
14642: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
14643: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14644: my $balancetext;
14645: if ($rule eq '') {
14646: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 14647: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 14648: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
14649: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 14650: foreach my $sparetype (@sparestypes) {
14651: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14652: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14653: }
14654: }
1.160.6.55 raeburn 14655: foreach my $item (@{$alltypes}) {
14656: next if ($item =~ /^_LC_ipchange/);
14657: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
14658: if ($hasrule eq 'homeserver') {
14659: map { $toupdate{$_} = 1; } (keys(%libraryservers));
14660: } else {
14661: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
14662: if ($servers{$hasrule}) {
14663: $toupdate{$hasrule} = 1;
14664: }
14665: }
14666: }
14667: }
14668: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
14669: $balancetext = $ruletitles{$rule};
14670: } else {
14671: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14672: $balancetext = $ruletitles{'particular'}.' '.$receiver;
14673: if ($receiver) {
14674: $toupdate{$receiver};
14675: }
14676: }
14677: } else {
14678: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 14679: }
1.160.6.7 raeburn 14680: } else {
14681: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
14682: }
1.160.6.26 raeburn 14683: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 14684: }
14685: }
14686: }
14687: }
1.160.6.94 raeburn 14688: if ($changes{'curr'}{$balancer}{'cookie'}) {
14689: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
14690: $balancer).'</li>';
14691: }
1.160.6.54 raeburn 14692: if (keys(%toupdate)) {
14693: my %thismachine;
14694: my $updatedhere;
14695: my $cachetime = 60*60*24;
14696: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
14697: foreach my $lonhost (keys(%toupdate)) {
14698: if ($thismachine{$lonhost}) {
14699: unless ($updatedhere) {
14700: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
14701: $defaultshash{'loadbalancing'},
14702: $cachetime);
14703: $updatedhere = 1;
14704: }
14705: } else {
14706: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
14707: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
14708: }
14709: }
14710: }
1.150 raeburn 14711: }
1.160.6.7 raeburn 14712: }
14713: if ($resulttext ne '') {
14714: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 14715: } else {
14716: $resulttext = $nochgmsg;
14717: }
14718: } else {
1.160.6.7 raeburn 14719: $resulttext = $nochgmsg;
1.150 raeburn 14720: }
14721: } else {
1.160.6.7 raeburn 14722: $resulttext = '<span class="LC_error">'.
14723: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 14724: }
14725: } else {
1.160.6.7 raeburn 14726: $resulttext = $nochgmsg;
1.150 raeburn 14727: }
14728: return $resulttext;
14729: }
14730:
1.48 raeburn 14731: sub recurse_check {
14732: my ($chkcats,$categories,$depth,$name) = @_;
14733: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
14734: my $chg = 0;
14735: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
14736: my $category = $chkcats->[$depth]{$name}[$j];
14737: my $item;
14738: if ($category eq '') {
14739: $chg ++;
14740: } else {
14741: my $deeper = $depth + 1;
14742: $item = &escape($category).':'.&escape($name).':'.$depth;
14743: if ($chg) {
14744: $categories->{$item} -= $chg;
14745: }
14746: &recurse_check($chkcats,$categories,$deeper,$category);
14747: $deeper --;
14748: }
14749: }
14750: }
14751: return;
14752: }
14753:
14754: sub recurse_cat_deletes {
14755: my ($item,$coursecategories,$deletions) = @_;
14756: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14757: my $subdepth = $depth + 1;
14758: if (ref($coursecategories) eq 'HASH') {
14759: foreach my $subitem (keys(%{$coursecategories})) {
14760: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
14761: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
14762: delete($coursecategories->{$subitem});
14763: $deletions->{$subitem} = 1;
14764: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 14765: }
1.48 raeburn 14766: }
14767: }
14768: return;
14769: }
14770:
1.125 raeburn 14771: sub active_dc_picker {
1.160.6.16 raeburn 14772: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 14773: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 14774: my @domcoord = keys(%domcoords);
14775: if (keys(%currhash)) {
14776: foreach my $dc (keys(%currhash)) {
14777: unless (exists($domcoords{$dc})) {
14778: push(@domcoord,$dc);
14779: }
14780: }
14781: }
14782: @domcoord = sort(@domcoord);
14783: my $numdcs = scalar(@domcoord);
14784: my $rows = 0;
14785: my $table;
1.125 raeburn 14786: if ($numdcs > 1) {
1.160.6.16 raeburn 14787: $table = '<table>';
14788: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 14789: my $rem = $i%($numinrow);
14790: if ($rem == 0) {
14791: if ($i > 0) {
1.160.6.16 raeburn 14792: $table .= '</tr>';
1.125 raeburn 14793: }
1.160.6.16 raeburn 14794: $table .= '<tr>';
14795: $rows ++;
1.125 raeburn 14796: }
1.160.6.16 raeburn 14797: my $check = '';
14798: if ($inputtype eq 'radio') {
14799: if (keys(%currhash) == 0) {
14800: if (!$i) {
14801: $check = ' checked="checked"';
14802: }
14803: } elsif (exists($currhash{$domcoord[$i]})) {
14804: $check = ' checked="checked"';
14805: }
14806: } else {
14807: if (exists($currhash{$domcoord[$i]})) {
14808: $check = ' checked="checked"';
1.125 raeburn 14809: }
14810: }
1.160.6.16 raeburn 14811: if ($i == @domcoord - 1) {
1.125 raeburn 14812: my $colsleft = $numinrow - $rem;
14813: if ($colsleft > 1) {
1.160.6.16 raeburn 14814: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 14815: } else {
1.160.6.16 raeburn 14816: $table .= '<td class="LC_left_item">';
1.125 raeburn 14817: }
14818: } else {
1.160.6.16 raeburn 14819: $table .= '<td class="LC_left_item">';
14820: }
14821: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
14822: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
14823: $table .= '<span class="LC_nobreak"><label>'.
14824: '<input type="'.$inputtype.'" name="'.$name.'"'.
14825: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
14826: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 14827: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 14828: }
1.160.6.33 raeburn 14829: $table .= '</label></span></td>';
1.125 raeburn 14830: }
1.160.6.16 raeburn 14831: $table .= '</tr></table>';
14832: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 14833: my ($dcname,$dcdom) = split(':',$domcoord[0]);
14834: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 14835: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 14836: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 14837: if ($user ne $dcname.':'.$dcdom) {
14838: $table .= ' ('.$dcname.':'.$dcdom.')';
14839: }
1.160.6.16 raeburn 14840: } else {
14841: my $check;
14842: if (exists($currhash{$domcoord[0]})) {
14843: $check = ' checked="checked"';
14844: }
1.160.6.50 raeburn 14845: $table = '<span class="LC_nobreak"><label>'.
14846: '<input type="checkbox" name="'.$name.'" '.
14847: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 14848: if ($user ne $dcname.':'.$dcdom) {
14849: $table .= ' ('.$dcname.':'.$dcdom.')';
14850: }
14851: $table .= '</label></span>';
1.160.6.16 raeburn 14852: $rows ++;
14853: }
1.125 raeburn 14854: }
1.160.6.16 raeburn 14855: return ($numdcs,$table,$rows);
1.125 raeburn 14856: }
14857:
1.137 raeburn 14858: sub usersession_titles {
14859: return &Apache::lonlocal::texthash(
14860: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
14861: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 14862: spares => 'Servers offloaded to, when busy',
1.137 raeburn 14863: version => 'LON-CAPA version requirement',
1.138 raeburn 14864: excludedomain => 'Allow all, but exclude specific domains',
14865: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 14866: primary => 'Primary (checked first)',
1.154 raeburn 14867: default => 'Default',
1.137 raeburn 14868: );
14869: }
14870:
1.152 raeburn 14871: sub id_for_thisdom {
14872: my (%servers) = @_;
14873: my %altids;
14874: foreach my $server (keys(%servers)) {
14875: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
14876: if ($serverhome ne $server) {
14877: $altids{$serverhome} = $server;
14878: }
14879: }
14880: return %altids;
14881: }
14882:
1.150 raeburn 14883: sub count_servers {
14884: my ($currbalancer,%servers) = @_;
14885: my (@spares,$numspares);
14886: foreach my $lonhost (sort(keys(%servers))) {
14887: next if ($currbalancer eq $lonhost);
14888: push(@spares,$lonhost);
14889: }
14890: if ($currbalancer) {
14891: $numspares = scalar(@spares);
14892: } else {
14893: $numspares = scalar(@spares) - 1;
14894: }
14895: return ($numspares,@spares);
14896: }
14897:
14898: sub lonbalance_targets_js {
1.160.6.7 raeburn 14899: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 14900: my $select = &mt('Select');
14901: my ($alltargets,$allishome,$allinsttypes,@alltypes);
14902: if (ref($servers) eq 'HASH') {
14903: $alltargets = join("','",sort(keys(%{$servers})));
14904: my @homedoms;
14905: foreach my $server (sort(keys(%{$servers}))) {
14906: if (&Apache::lonnet::host_domain($server) eq $dom) {
14907: push(@homedoms,'1');
14908: } else {
14909: push(@homedoms,'0');
14910: }
14911: }
14912: $allishome = join("','",@homedoms);
14913: }
14914: if (ref($types) eq 'ARRAY') {
14915: if (@{$types} > 0) {
14916: @alltypes = @{$types};
14917: }
14918: }
14919: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
14920: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 14921: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 14922: if (ref($settings) eq 'HASH') {
14923: %existing = %{$settings};
14924: }
14925: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 14926: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 14927: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 14928: return <<"END";
14929:
14930: <script type="text/javascript">
14931: // <![CDATA[
14932:
1.160.6.7 raeburn 14933: currBalancers = new Array('$balancers');
14934:
14935: function toggleTargets(balnum) {
14936: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14937: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
14938: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
14939: var prevbalancer = prevhostitem.value;
14940: var baltotal = document.getElementById('loadbalancing_total').value;
14941: prevhostitem.value = balancer;
14942: if (prevbalancer != '') {
14943: var prevIdx = currBalancers.indexOf(prevbalancer);
14944: if (prevIdx != -1) {
14945: currBalancers.splice(prevIdx,1);
14946: }
14947: }
1.150 raeburn 14948: if (balancer == '') {
1.160.6.7 raeburn 14949: hideSpares(balnum);
1.150 raeburn 14950: } else {
1.160.6.7 raeburn 14951: var currIdx = currBalancers.indexOf(balancer);
14952: if (currIdx == -1) {
14953: currBalancers.push(balancer);
14954: }
1.150 raeburn 14955: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 14956: var ishomedom = homedoms[lonhostitem.selectedIndex];
14957: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 14958: }
1.160.6.7 raeburn 14959: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 14960: return;
14961: }
14962:
1.160.6.7 raeburn 14963: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 14964: var alltargets = new Array('$alltargets');
14965: var insttypes = new Array('$allinsttypes');
1.151 raeburn 14966: var offloadtypes = new Array('primary','default');
14967:
1.160.6.7 raeburn 14968: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
14969: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 14970:
1.151 raeburn 14971: for (var i=0; i<offloadtypes.length; i++) {
14972: var count = 0;
14973: for (var j=0; j<alltargets.length; j++) {
14974: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 14975: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
14976: item.value = alltargets[j];
14977: item.style.textAlign='left';
14978: item.style.textFace='normal';
14979: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
14980: if (currBalancers.indexOf(alltargets[j]) == -1) {
14981: item.disabled = '';
14982: } else {
14983: item.disabled = 'disabled';
14984: item.checked = false;
14985: }
1.151 raeburn 14986: count ++;
14987: }
1.150 raeburn 14988: }
14989: }
1.151 raeburn 14990: for (var k=0; k<insttypes.length; k++) {
14991: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 14992: if (ishomedom == 1) {
1.160.6.7 raeburn 14993: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14994: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14995: } else {
1.160.6.7 raeburn 14996: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14997: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 14998: }
14999: } else {
1.160.6.7 raeburn 15000: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
15001: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 15002: }
1.151 raeburn 15003: if ((insttypes[k] != '_LC_external') &&
15004: ((insttypes[k] != '_LC_internetdom') ||
15005: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 15006: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
15007: item.options.length = 0;
15008: item.options[0] = new Option("","",true,true);
15009: var idx = 0;
1.151 raeburn 15010: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 15011: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
15012: idx ++;
15013: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 15014: }
15015: }
15016: }
15017: }
15018: return;
15019: }
15020:
1.160.6.7 raeburn 15021: function hideSpares(balnum) {
1.150 raeburn 15022: var alltargets = new Array('$alltargets');
15023: var insttypes = new Array('$allinsttypes');
15024: var offloadtypes = new Array('primary','default');
15025:
1.160.6.7 raeburn 15026: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
15027: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 15028:
15029: var total = alltargets.length - 1;
15030: for (var i=0; i<offloadtypes; i++) {
15031: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 15032: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
15033: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
15034: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 15035: }
1.150 raeburn 15036: }
15037: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 15038: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
15039: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 15040: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 15041: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
15042: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 15043: }
15044: }
15045: return;
15046: }
15047:
1.160.6.7 raeburn 15048: function checkOffloads(item,balnum,type) {
1.150 raeburn 15049: var alltargets = new Array('$alltargets');
15050: var offloadtypes = new Array('primary','default');
15051: if (item.checked) {
15052: var total = alltargets.length - 1;
15053: var other;
15054: if (type == offloadtypes[0]) {
1.151 raeburn 15055: other = offloadtypes[1];
1.150 raeburn 15056: } else {
1.151 raeburn 15057: other = offloadtypes[0];
1.150 raeburn 15058: }
15059: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 15060: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 15061: if (server == item.value) {
1.160.6.7 raeburn 15062: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
15063: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 15064: }
15065: }
15066: }
15067: }
15068: return;
15069: }
15070:
1.160.6.7 raeburn 15071: function singleServerToggle(balnum,type) {
15072: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 15073: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 15074: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
15075: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 15076:
15077: } else {
1.160.6.7 raeburn 15078: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
15079: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 15080: }
15081: return;
15082: }
15083:
1.160.6.7 raeburn 15084: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 15085: if (type == '_LC_external') {
1.160.6.26 raeburn 15086: return;
1.150 raeburn 15087: }
1.160.6.7 raeburn 15088: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 15089: for (var i=0; i<typesRules.length; i++) {
15090: if (formname.elements[typesRules[i]].checked) {
15091: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 15092: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
15093: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 15094: } else {
1.160.6.7 raeburn 15095: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
15096: }
15097: }
15098: }
15099: return;
15100: }
15101:
15102: function balancerDeleteChange(balnum) {
15103: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
15104: var baltotal = document.getElementById('loadbalancing_total').value;
15105: var addtarget;
15106: var removetarget;
15107: var action = 'delete';
15108: if (document.getElementById('loadbalancing_delete_'+balnum)) {
15109: var lonhost = hostitem.value;
15110: var currIdx = currBalancers.indexOf(lonhost);
15111: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
15112: if (currIdx != -1) {
15113: currBalancers.splice(currIdx,1);
15114: }
15115: addtarget = lonhost;
15116: } else {
15117: if (currIdx == -1) {
15118: currBalancers.push(lonhost);
15119: }
15120: removetarget = lonhost;
15121: action = 'undelete';
15122: }
15123: balancerChange(balnum,baltotal,action,addtarget,removetarget);
15124: }
15125: return;
15126: }
15127:
15128: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
15129: if (baltotal > 1) {
15130: var offloadtypes = new Array('primary','default');
15131: var alltargets = new Array('$alltargets');
15132: var insttypes = new Array('$allinsttypes');
15133: for (var i=0; i<baltotal; i++) {
15134: if (i != balnum) {
15135: for (var j=0; j<offloadtypes.length; j++) {
15136: var total = alltargets.length - 1;
15137: for (var k=0; k<total; k++) {
15138: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
15139: var server = serveritem.value;
15140: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
15141: if (server == addtarget) {
15142: serveritem.disabled = '';
15143: }
15144: }
15145: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
15146: if (server == removetarget) {
15147: serveritem.disabled = 'disabled';
15148: serveritem.checked = false;
15149: }
15150: }
15151: }
15152: }
15153: for (var j=0; j<insttypes.length; j++) {
15154: if (insttypes[j] != '_LC_external') {
15155: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
15156: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
15157: var currSel = singleserver.selectedIndex;
15158: var currVal = singleserver.options[currSel].value;
15159: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
15160: var numoptions = singleserver.options.length;
15161: var needsnew = 1;
15162: for (var k=0; k<numoptions; k++) {
15163: if (singleserver.options[k] == addtarget) {
15164: needsnew = 0;
15165: break;
15166: }
15167: }
15168: if (needsnew == 1) {
15169: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
15170: }
15171: }
15172: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
15173: singleserver.options.length = 0;
15174: if ((currVal) && (currVal != removetarget)) {
15175: singleserver.options[0] = new Option("","",false,false);
15176: } else {
15177: singleserver.options[0] = new Option("","",true,true);
15178: }
15179: var idx = 0;
15180: for (var m=0; m<alltargets.length; m++) {
15181: if (currBalancers.indexOf(alltargets[m]) == -1) {
15182: idx ++;
15183: if (currVal == alltargets[m]) {
15184: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
15185: } else {
15186: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
15187: }
15188: }
15189: }
15190: }
15191: }
15192: }
15193: }
1.150 raeburn 15194: }
15195: }
15196: }
15197: return;
15198: }
15199:
1.152 raeburn 15200: // ]]>
15201: </script>
15202:
15203: END
15204: }
15205:
15206: sub new_spares_js {
15207: my @sparestypes = ('primary','default');
15208: my $types = join("','",@sparestypes);
15209: my $select = &mt('Select');
15210: return <<"END";
15211:
15212: <script type="text/javascript">
15213: // <![CDATA[
15214:
15215: function updateNewSpares(formname,lonhost) {
15216: var types = new Array('$types');
15217: var include = new Array();
15218: var exclude = new Array();
15219: for (var i=0; i<types.length; i++) {
15220: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
15221: for (var j=0; j<spareboxes.length; j++) {
15222: if (formname.elements[spareboxes[j]].checked) {
15223: exclude.push(formname.elements[spareboxes[j]].value);
15224: } else {
15225: include.push(formname.elements[spareboxes[j]].value);
15226: }
15227: }
15228: }
15229: for (var i=0; i<types.length; i++) {
15230: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
15231: var selIdx = newSpare.selectedIndex;
15232: var currnew = newSpare.options[selIdx].value;
15233: var okSpares = new Array();
15234: for (var j=0; j<newSpare.options.length; j++) {
15235: var possible = newSpare.options[j].value;
15236: if (possible != '') {
15237: if (exclude.indexOf(possible) == -1) {
15238: okSpares.push(possible);
15239: } else {
15240: if (currnew == possible) {
15241: selIdx = 0;
15242: }
15243: }
15244: }
15245: }
15246: for (var k=0; k<include.length; k++) {
15247: if (okSpares.indexOf(include[k]) == -1) {
15248: okSpares.push(include[k]);
15249: }
15250: }
15251: okSpares.sort();
15252: newSpare.options.length = 0;
15253: if (selIdx == 0) {
15254: newSpare.options[0] = new Option("$select","",true,true);
15255: } else {
15256: newSpare.options[0] = new Option("$select","",false,false);
15257: }
15258: for (var m=0; m<okSpares.length; m++) {
15259: var idx = m+1;
15260: var selThis = 0;
15261: if (selIdx != 0) {
15262: if (okSpares[m] == currnew) {
15263: selThis = 1;
15264: }
15265: }
15266: if (selThis == 1) {
15267: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
15268: } else {
15269: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
15270: }
15271: }
15272: }
15273: return;
15274: }
15275:
15276: function checkNewSpares(lonhost,type) {
15277: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
15278: var chosen = newSpare.options[newSpare.selectedIndex].value;
15279: if (chosen != '') {
15280: var othertype;
15281: var othernewSpare;
15282: if (type == 'primary') {
15283: othernewSpare = document.getElementById('newspare_default_'+lonhost);
15284: }
15285: if (type == 'default') {
15286: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
15287: }
15288: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
15289: othernewSpare.selectedIndex = 0;
15290: }
15291: }
15292: return;
15293: }
15294:
15295: // ]]>
15296: </script>
15297:
15298: END
15299:
15300: }
15301:
15302: sub common_domprefs_js {
15303: return <<"END";
15304:
15305: <script type="text/javascript">
15306: // <![CDATA[
15307:
1.150 raeburn 15308: function getIndicesByName(formname,item) {
1.152 raeburn 15309: var group = new Array();
1.150 raeburn 15310: for (var i=0;i<formname.elements.length;i++) {
15311: if (formname.elements[i].name == item) {
1.152 raeburn 15312: group.push(formname.elements[i].id);
1.150 raeburn 15313: }
15314: }
1.152 raeburn 15315: return group;
1.150 raeburn 15316: }
15317:
15318: // ]]>
15319: </script>
15320:
15321: END
1.152 raeburn 15322:
1.150 raeburn 15323: }
15324:
1.160.6.5 raeburn 15325: sub recaptcha_js {
15326: my %lt = &captcha_phrases();
15327: return <<"END";
15328:
15329: <script type="text/javascript">
15330: // <![CDATA[
15331:
15332: function updateCaptcha(caller,context) {
15333: var privitem;
15334: var pubitem;
15335: var privtext;
15336: var pubtext;
1.160.6.69 raeburn 15337: var versionitem;
15338: var versiontext;
1.160.6.5 raeburn 15339: if (document.getElementById(context+'_recaptchapub')) {
15340: pubitem = document.getElementById(context+'_recaptchapub');
15341: } else {
15342: return;
15343: }
15344: if (document.getElementById(context+'_recaptchapriv')) {
15345: privitem = document.getElementById(context+'_recaptchapriv');
15346: } else {
15347: return;
15348: }
15349: if (document.getElementById(context+'_recaptchapubtxt')) {
15350: pubtext = document.getElementById(context+'_recaptchapubtxt');
15351: } else {
15352: return;
15353: }
15354: if (document.getElementById(context+'_recaptchaprivtxt')) {
15355: privtext = document.getElementById(context+'_recaptchaprivtxt');
15356: } else {
15357: return;
15358: }
1.160.6.69 raeburn 15359: if (document.getElementById(context+'_recaptchaversion')) {
15360: versionitem = document.getElementById(context+'_recaptchaversion');
15361: } else {
15362: return;
15363: }
15364: if (document.getElementById(context+'_recaptchavertxt')) {
15365: versiontext = document.getElementById(context+'_recaptchavertxt');
15366: } else {
15367: return;
15368: }
1.160.6.5 raeburn 15369: if (caller.checked) {
15370: if (caller.value == 'recaptcha') {
15371: pubitem.type = 'text';
15372: privitem.type = 'text';
15373: pubitem.size = '40';
15374: privitem.size = '40';
15375: pubtext.innerHTML = "$lt{'pub'}";
15376: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 15377: versionitem.type = 'text';
15378: versionitem.size = '3';
15379: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 15380: } else {
15381: pubitem.type = 'hidden';
15382: privitem.type = 'hidden';
1.160.6.69 raeburn 15383: versionitem.type = 'hidden';
1.160.6.5 raeburn 15384: pubtext.innerHTML = '';
15385: privtext.innerHTML = '';
1.160.6.69 raeburn 15386: versiontext.innerHTML = '';
1.160.6.5 raeburn 15387: }
15388: }
15389: return;
15390: }
15391:
15392: // ]]>
15393: </script>
15394:
15395: END
15396:
15397: }
15398:
1.160.6.40 raeburn 15399: sub toggle_display_js {
1.160.6.16 raeburn 15400: return <<"END";
15401:
15402: <script type="text/javascript">
15403: // <![CDATA[
15404:
1.160.6.40 raeburn 15405: function toggleDisplay(domForm,caller) {
15406: if (document.getElementById(caller)) {
15407: var divitem = document.getElementById(caller);
15408: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 15409: var checkval = 1;
15410: var dispval = 'block';
1.160.6.93 raeburn 15411: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 15412: if (caller == 'emailoptions') {
15413: optionsElement = domForm.cancreate_email;
15414: }
1.160.6.57 raeburn 15415: if (caller == 'studentsubmission') {
15416: optionsElement = domForm.postsubmit;
15417: }
1.160.6.64 raeburn 15418: if (caller == 'cloneinstcode') {
15419: optionsElement = domForm.canclone;
15420: checkval = 'instcode';
15421: }
1.160.6.93 raeburn 15422: if (selfcreateRegExp.test(caller)) {
15423: optionsElement = domForm.elements[caller];
15424: checkval = 'other';
15425: dispval = 'inline'
15426: }
1.160.6.40 raeburn 15427: if (optionsElement.length) {
1.160.6.16 raeburn 15428: var currval;
1.160.6.40 raeburn 15429: for (var i=0; i<optionsElement.length; i++) {
15430: if (optionsElement[i].checked) {
15431: currval = optionsElement[i].value;
1.160.6.16 raeburn 15432: }
15433: }
1.160.6.64 raeburn 15434: if (currval == checkval) {
15435: divitem.style.display = dispval;
1.160.6.16 raeburn 15436: } else {
1.160.6.40 raeburn 15437: divitem.style.display = 'none';
1.160.6.16 raeburn 15438: }
15439: }
15440: }
15441: return;
15442: }
15443:
15444: // ]]>
15445: </script>
15446:
15447: END
15448:
15449: }
15450:
1.160.6.5 raeburn 15451: sub captcha_phrases {
15452: return &Apache::lonlocal::texthash (
15453: priv => 'Private key',
15454: pub => 'Public key',
15455: original => 'original (CAPTCHA)',
15456: recaptcha => 'successor (ReCAPTCHA)',
15457: notused => 'unused',
1.160.6.69 raeburn 15458: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 15459: );
15460: }
15461:
1.160.6.24 raeburn 15462: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 15463: my ($dom,$cachekeys) = @_;
15464: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 15465: my %servers = &Apache::lonnet::internet_dom_servers($dom);
15466: my %thismachine;
15467: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.98 raeburn 15468: my @posscached = ('domainconfig','domdefaults','usersessions',
15469: 'directorysrch','passwdconf','cats');
1.160.6.61 raeburn 15470: if (keys(%servers)) {
1.160.6.24 raeburn 15471: foreach my $server (keys(%servers)) {
15472: next if ($thismachine{$server});
1.160.6.27 raeburn 15473: my @cached;
15474: foreach my $name (@posscached) {
15475: if ($cachekeys->{$name}) {
15476: push(@cached,&escape($name).':'.&escape($dom));
15477: }
15478: }
15479: if (@cached) {
15480: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
15481: }
1.160.6.24 raeburn 15482: }
15483: }
15484: return;
15485: }
15486:
1.3 raeburn 15487: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>