Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.98
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.98! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.97 2019/08/17 19:24:29 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: }
! 4115: $casesens{'default'} = 1;
! 4116: $postlink{'default'} = ['username','email'];
! 4117: $prelink = 'both';
! 4118: %emailsrc = (
! 4119: permanent => 1,
! 4120: critical => 1,
! 4121: notify => 1,
! 4122: );
! 4123: }
! 4124: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
! 4125: $itemcount ++;
! 4126: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 4127: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
! 4128: '<td class="LC_left_item">'.
! 4129: '<input type="textbox" value="'.$shownlinklife.'" '.
! 4130: 'name="passwords_link" size="3" /></td></tr>';
! 4131: $itemcount ++;
! 4132: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 4133: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
! 4134: '<td class="LC_left_item">';
! 4135: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
! 4136: foreach my $item (@{$types}) {
! 4137: my $checkedcase;
! 4138: if ($casesens{$item}) {
! 4139: $checkedcase = ' checked="checked"';
! 4140: }
! 4141: $datatable .= '<span class="LC_nobreak"><label>'.
! 4142: '<input type="checkbox" name="passwords_case_sensitive" value="'.
! 4143: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
! 4144: '<span> ';
! 4145: }
! 4146: }
! 4147: my $checkedcase;
! 4148: if ($casesens{'default'}) {
! 4149: $checkedcase = ' checked="checked"';
! 4150: }
! 4151: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
! 4152: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
! 4153: $othertitle.'</label></span></td>';
! 4154: $itemcount ++;
! 4155: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 4156: my %checkedpre = (
! 4157: both => ' checked="checked"',
! 4158: either => '',
! 4159: );
! 4160: if ($prelink eq 'either') {
! 4161: $checkedpre{either} = ' checked="checked"';
! 4162: $checkedpre{both} = '';
! 4163: }
! 4164: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
! 4165: '<td class="LC_left_item"><span class="LC_nobreak">'.
! 4166: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
! 4167: &mt('Both username and e-mail address').'</label></span> '.
! 4168: '<span class="LC_nobreak"><label>'.
! 4169: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
! 4170: &mt('Either username or e-mail address').'</label></span></td></tr>';
! 4171: $itemcount ++;
! 4172: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 4173: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
! 4174: '<td class="LC_left_item">';
! 4175: my %postlinked;
! 4176: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
! 4177: foreach my $item (@{$types}) {
! 4178: undef(%postlinked);
! 4179: $datatable .= '<fieldset style="display: inline-block;">'.
! 4180: '<legend>'.$usertypes->{$item}.'</legend>';
! 4181: if (ref($postlink{$item}) eq 'ARRAY') {
! 4182: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
! 4183: }
! 4184: foreach my $field ('email','username') {
! 4185: my $checked;
! 4186: if ($postlinked{$field}) {
! 4187: $checked = ' checked="checked"';
! 4188: }
! 4189: $datatable .= '<span class="LC_nobreak"><label>'.
! 4190: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
! 4191: $field.'"'.$checked.' />'.$field.'</label>'.
! 4192: '<span> ';
! 4193: }
! 4194: $datatable .= '</fieldset>';
! 4195: }
! 4196: }
! 4197: if (ref($postlink{'default'}) eq 'ARRAY') {
! 4198: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
! 4199: }
! 4200: $datatable .= '<fieldset style="display: inline-block;">'.
! 4201: '<legend>'.$othertitle.'</legend>';
! 4202: foreach my $field ('email','username') {
! 4203: my $checked;
! 4204: if ($postlinked{$field}) {
! 4205: $checked = ' checked="checked"';
! 4206: }
! 4207: $datatable .= '<span class="LC_nobreak"><label>'.
! 4208: '<input type="checkbox" name="passwords_postlink_default" value="'.
! 4209: $field.'"'.$checked.' />'.$field.'</label>'.
! 4210: '<span> ';
! 4211: }
! 4212: $datatable .= '</fieldset></td></tr>';
! 4213: $itemcount ++;
! 4214: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 4215: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
! 4216: '<td class="LC_left_item">';
! 4217: foreach my $type ('permanent','critical','notify') {
! 4218: my $checkedemail;
! 4219: if ($emailsrc{$type}) {
! 4220: $checkedemail = ' checked="checked"';
! 4221: }
! 4222: $datatable .= '<span class="LC_nobreak"><label>'.
! 4223: '<input type="checkbox" name="passwords_emailsrc" value="'.
! 4224: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
! 4225: '<span> ';
! 4226: }
! 4227: $datatable .= '</td></tr>';
! 4228: $itemcount ++;
! 4229: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 4230: my $switchserver = &check_switchserver($dom,$confname);
! 4231: my ($showstd,$noshowstd);
! 4232: if ($nostdtext) {
! 4233: $noshowstd = ' checked="checked"';
! 4234: } else {
! 4235: $showstd = ' checked="checked"';
! 4236: }
! 4237: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
! 4238: '<td class="LC_left_item"><span class="LC_nobreak">'.
! 4239: &mt('Retain standard text:').
! 4240: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
! 4241: &mt('Yes').'</label>'.' '.
! 4242: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
! 4243: &mt('No').'</label></span><br />'.
! 4244: '<span class="LC_fontsize_small">'.
! 4245: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
! 4246: &mt('Include custom text:');
! 4247: if ($customurl) {
! 4248: my $link = &Apache::loncommon::modal_link($customurl,&mt('Custom text file'),600,500,
! 4249: undef,undef,undef,undef,'background-color:#ffffff');
! 4250: $datatable .= '<span class="LC_nobreak"> '.$link.
! 4251: '<label><input type="checkbox" name="passwords_custom_del"'.
! 4252: ' value="1" />'.&mt('Delete?').'</label></span>'.
! 4253: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
! 4254: }
! 4255: if ($switchserver) {
! 4256: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
! 4257: } else {
! 4258: $datatable .='<span class="LC_nobreak"> '.
! 4259: '<input type="file" name="passwords_customfile" /></span>';
! 4260: }
! 4261: $datatable .= '</td></tr>';
! 4262: } elsif ($position eq 'middle') {
! 4263: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
! 4264: my @items = ('intauth_cost','intauth_check','intauth_switch');
! 4265: my %defaults;
! 4266: if (ref($domconf{'defaults'}) eq 'HASH') {
! 4267: %defaults = %{$domconf{'defaults'}};
! 4268: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
! 4269: $defaults{'intauth_cost'} = 10;
! 4270: }
! 4271: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
! 4272: $defaults{'intauth_check'} = 0;
! 4273: }
! 4274: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
! 4275: $defaults{'intauth_switch'} = 0;
! 4276: }
! 4277: } else {
! 4278: %defaults = (
! 4279: 'intauth_cost' => 10,
! 4280: 'intauth_check' => 0,
! 4281: 'intauth_switch' => 0,
! 4282: );
! 4283: }
! 4284: foreach my $item (@items) {
! 4285: if ($itemcount%2) {
! 4286: $css_class = '';
! 4287: } else {
! 4288: $css_class = ' class="LC_odd_row" ';
! 4289: }
! 4290: $datatable .= '<tr'.$css_class.'>'.
! 4291: '<td><span class="LC_nobreak">'.$titles{$item}.
! 4292: '</span></td><td class="LC_left_item" colspan="3">';
! 4293: if ($item eq 'intauth_switch') {
! 4294: my @options = (0,1,2);
! 4295: my %optiondesc = &Apache::lonlocal::texthash (
! 4296: 0 => 'No',
! 4297: 1 => 'Yes',
! 4298: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
! 4299: );
! 4300: $datatable .= '<table width="100%">';
! 4301: foreach my $option (@options) {
! 4302: my $checked = ' ';
! 4303: if ($defaults{$item} eq $option) {
! 4304: $checked = ' checked="checked"';
! 4305: }
! 4306: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
! 4307: '<label><input type="radio" name="'.$item.
! 4308: '" value="'.$option.'"'.$checked.' />'.
! 4309: $optiondesc{$option}.'</label></span></td></tr>';
! 4310: }
! 4311: $datatable .= '</table>';
! 4312: } elsif ($item eq 'intauth_check') {
! 4313: my @options = (0,1,2);
! 4314: my %optiondesc = &Apache::lonlocal::texthash (
! 4315: 0 => 'No',
! 4316: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
! 4317: 2 => 'Yes, disallow login if stored cost is less than domain default',
! 4318: );
! 4319: $datatable .= '<table width="100%">';
! 4320: foreach my $option (@options) {
! 4321: my $checked = ' ';
! 4322: my $onclick;
! 4323: if ($defaults{$item} eq $option) {
! 4324: $checked = ' checked="checked"';
! 4325: }
! 4326: if ($option == 2) {
! 4327: $onclick = ' onclick="javascript:warnIntAuth(this);"';
! 4328: }
! 4329: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
! 4330: '<label><input type="radio" name="'.$item.
! 4331: '" value="'.$option.'"'.$checked.$onclick.' />'.
! 4332: $optiondesc{$option}.'</label></span></td></tr>';
! 4333: }
! 4334: $datatable .= '</table>';
! 4335: } else {
! 4336: $datatable .= '<input type="text" name="'.$item.'" value="'.
! 4337: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
! 4338: }
! 4339: $datatable .= '</td></tr>';
! 4340: $itemcount ++;
! 4341: }
! 4342: } elsif ($position eq 'lower') {
! 4343: my ($min,$max,%chars,$numsaved);
! 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: } else {
! 4358: $min = '7';
! 4359: }
! 4360: my %rulenames = &Apache::lonlocal::texthash(
! 4361: uc => 'At least one upper case letter',
! 4362: lc => 'At least one lower case letter',
! 4363: num => 'At least one number',
! 4364: spec => 'At least one non-alphanumeric',
! 4365: );
! 4366: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 4367: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
! 4368: '<td class="LC_left_item"><span class="LC_nobreak">'.
! 4369: '<input type="text" name="passwords_min" value="'.$min.'" size="3" />'.
! 4370: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no minimum)').'</span>'.
! 4371: '</span></td></tr>';
! 4372: $itemcount ++;
! 4373: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 4374: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
! 4375: '<td class="LC_left_item"><span class="LC_nobreak">'.
! 4376: '<input type="text" name="passwords_max" value="'.$max.'" size="3" />'.
! 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">'.
! 4416: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" />'.
! 4417: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
! 4418: '</span></td></tr>';
! 4419: } else {
! 4420: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
! 4421: my %ownerchg = (
! 4422: by => {},
! 4423: for => {},
! 4424: );
! 4425: my %ownertitles = &Apache::lonlocal::texthash (
! 4426: by => 'Course owner status(es) allowed',
! 4427: for => 'Student status(es) allowed',
! 4428: );
! 4429: if (ref($settings) eq 'HASH') {
! 4430: if (ref($settings->{crsownerchg}) eq 'HASH') {
! 4431: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
! 4432: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
! 4433: }
! 4434: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
! 4435: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
! 4436: }
! 4437: }
! 4438: }
! 4439: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 4440: $datatable .= '<tr '.$css_class.'>'.
! 4441: '<td>'.
! 4442: &mt('Requirements').'<ul>'.
! 4443: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
! 4444: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
! 4445: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
! 4446: '<li>'.&mt('User, course, and student share same domain').'</li>'.
! 4447: '</ul>'.
! 4448: '</td>'.
! 4449: '<td class="LC_left_item">';
! 4450: foreach my $item ('by','for') {
! 4451: $datatable .= '<fieldset style="display: inline-block;">'.
! 4452: '<legend>'.$ownertitles{$item}.'</legend>';
! 4453: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
! 4454: foreach my $type (@{$types}) {
! 4455: my $checked;
! 4456: if ($ownerchg{$item}{$type}) {
! 4457: $checked = ' checked="checked"';
! 4458: }
! 4459: $datatable .= '<span class="LC_nobreak"><label>'.
! 4460: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
! 4461: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
! 4462: '<span> ';
! 4463: }
! 4464: }
! 4465: my $checked;
! 4466: if ($ownerchg{$item}{'default'}) {
! 4467: $checked = ' checked="checked"';
! 4468: }
! 4469: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
! 4470: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
! 4471: $othertitle.'</label></span></fieldset>';
! 4472: }
! 4473: $datatable .= '</td></tr>';
! 4474: }
! 4475: return $datatable;
! 4476: }
! 4477:
1.137 raeburn 4478: sub print_usersessions {
4479: my ($position,$dom,$settings,$rowtotal) = @_;
4480: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 4481: my (%by_ip,%by_location,@intdoms);
4482: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 4483:
4484: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 4485: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 4486: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 4487: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 4488: my $itemcount = 1;
4489: if ($position eq 'top') {
1.152 raeburn 4490: if (keys(%serverhomes) > 1) {
1.145 raeburn 4491: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.61 raeburn 4492: my $curroffloadnow;
4493: if (ref($settings) eq 'HASH') {
4494: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4495: $curroffloadnow = $settings->{'offloadnow'};
4496: }
4497: }
4498: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 4499: } else {
1.140 raeburn 4500: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 4501: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 4502: }
1.137 raeburn 4503: } else {
1.145 raeburn 4504: if (keys(%by_location) == 0) {
4505: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 4506: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 4507: } else {
4508: my %lt = &usersession_titles();
4509: my $numinrow = 5;
4510: my $prefix;
4511: my @types;
4512: if ($position eq 'bottom') {
4513: $prefix = 'remote';
4514: @types = ('version','excludedomain','includedomain');
4515: } else {
4516: $prefix = 'hosted';
4517: @types = ('excludedomain','includedomain');
4518: }
4519: my (%current,%checkedon,%checkedoff);
4520: my @lcversions = &Apache::lonnet::all_loncaparevs();
4521: my @locations = sort(keys(%by_location));
4522: foreach my $type (@types) {
4523: $checkedon{$type} = '';
4524: $checkedoff{$type} = ' checked="checked"';
4525: }
4526: if (ref($settings) eq 'HASH') {
4527: if (ref($settings->{$prefix}) eq 'HASH') {
4528: foreach my $key (keys(%{$settings->{$prefix}})) {
4529: $current{$key} = $settings->{$prefix}{$key};
4530: if ($key eq 'version') {
4531: if ($current{$key} ne '') {
4532: $checkedon{$key} = ' checked="checked"';
4533: $checkedoff{$key} = '';
4534: }
4535: } elsif (ref($current{$key}) eq 'ARRAY') {
4536: $checkedon{$key} = ' checked="checked"';
4537: $checkedoff{$key} = '';
4538: }
1.137 raeburn 4539: }
4540: }
4541: }
1.145 raeburn 4542: foreach my $type (@types) {
4543: next if ($type ne 'version' && !@locations);
4544: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4545: $datatable .= '<tr'.$css_class.'>
4546: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
4547: <span class="LC_nobreak">
4548: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4549: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4550: if ($type eq 'version') {
4551: my $selector = '<select name="'.$prefix.'_version">';
4552: foreach my $version (@lcversions) {
4553: my $selected = '';
4554: if ($current{'version'} eq $version) {
4555: $selected = ' selected="selected"';
4556: }
4557: $selector .= ' <option value="'.$version.'"'.
4558: $selected.'>'.$version.'</option>';
4559: }
4560: $selector .= '</select> ';
4561: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4562: } else {
4563: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4564: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4565: ' />'.(' 'x2).
4566: '<input type="button" value="'.&mt('uncheck all').'" '.
4567: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4568: "\n".
4569: '</div><div><table>';
4570: my $rem;
4571: for (my $i=0; $i<@locations; $i++) {
4572: my ($showloc,$value,$checkedtype);
4573: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
4574: my $ip = $by_location{$locations[$i]}->[0];
4575: if (ref($by_ip{$ip}) eq 'ARRAY') {
4576: $value = join(':',@{$by_ip{$ip}});
4577: $showloc = join(', ',@{$by_ip{$ip}});
4578: if (ref($current{$type}) eq 'ARRAY') {
4579: foreach my $loc (@{$by_ip{$ip}}) {
4580: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4581: $checkedtype = ' checked="checked"';
4582: last;
4583: }
4584: }
1.138 raeburn 4585: }
4586: }
4587: }
1.145 raeburn 4588: $rem = $i%($numinrow);
4589: if ($rem == 0) {
4590: if ($i > 0) {
4591: $datatable .= '</tr>';
4592: }
4593: $datatable .= '<tr>';
4594: }
4595: $datatable .= '<td class="LC_left_item">'.
4596: '<span class="LC_nobreak"><label>'.
4597: '<input type="checkbox" name="'.$prefix.'_'.$type.
4598: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4599: '</label></span></td>';
1.137 raeburn 4600: }
1.145 raeburn 4601: $rem = @locations%($numinrow);
4602: my $colsleft = $numinrow - $rem;
4603: if ($colsleft > 1 ) {
4604: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4605: ' </td>';
4606: } elsif ($colsleft == 1) {
4607: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4608: }
1.145 raeburn 4609: $datatable .= '</tr></table>';
1.137 raeburn 4610: }
1.145 raeburn 4611: $datatable .= '</td></tr>';
4612: $itemcount ++;
1.137 raeburn 4613: }
4614: }
4615: }
4616: $$rowtotal += $itemcount;
4617: return $datatable;
4618: }
4619:
1.138 raeburn 4620: sub build_location_hashes {
4621: my ($intdoms,$by_ip,$by_location) = @_;
4622: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
4623: (ref($by_location) eq 'HASH'));
4624: my %iphost = &Apache::lonnet::get_iphost();
4625: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4626: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4627: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4628: foreach my $id (@{$iphost{$primary_ip}}) {
4629: my $intdom = &Apache::lonnet::internet_dom($id);
4630: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4631: push(@{$intdoms},$intdom);
4632: }
4633: }
4634: }
4635: foreach my $ip (keys(%iphost)) {
4636: if (ref($iphost{$ip}) eq 'ARRAY') {
4637: foreach my $id (@{$iphost{$ip}}) {
4638: my $location = &Apache::lonnet::internet_dom($id);
4639: if ($location) {
4640: next if (grep(/^\Q$location\E$/,@{$intdoms}));
4641: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4642: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4643: push(@{$by_ip->{$ip}},$location);
4644: }
4645: } else {
4646: $by_ip->{$ip} = [$location];
4647: }
4648: }
4649: }
4650: }
4651: }
4652: foreach my $ip (sort(keys(%{$by_ip}))) {
4653: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4654: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4655: my $first = $by_ip->{$ip}->[0];
4656: if (ref($by_location->{$first}) eq 'ARRAY') {
4657: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4658: push(@{$by_location->{$first}},$ip);
4659: }
4660: } else {
4661: $by_location->{$first} = [$ip];
4662: }
4663: }
4664: }
4665: return;
4666: }
4667:
1.145 raeburn 4668: sub current_offloads_to {
4669: my ($dom,$settings,$servers) = @_;
4670: my (%spareid,%otherdomconfigs);
1.152 raeburn 4671: if (ref($servers) eq 'HASH') {
1.145 raeburn 4672: foreach my $lonhost (sort(keys(%{$servers}))) {
4673: my $gotspares;
1.152 raeburn 4674: if (ref($settings) eq 'HASH') {
4675: if (ref($settings->{'spares'}) eq 'HASH') {
4676: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4677: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4678: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4679: $gotspares = 1;
4680: }
1.145 raeburn 4681: }
4682: }
4683: unless ($gotspares) {
4684: my $gotspares;
4685: my $serverhomeID =
4686: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4687: my $serverhomedom =
4688: &Apache::lonnet::host_domain($serverhomeID);
4689: if ($serverhomedom ne $dom) {
4690: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4691: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4692: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4693: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4694: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4695: $gotspares = 1;
4696: }
4697: }
4698: } else {
4699: $otherdomconfigs{$serverhomedom} =
4700: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4701: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4702: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4703: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4704: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4705: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4706: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4707: $gotspares = 1;
4708: }
4709: }
4710: }
4711: }
4712: }
4713: }
4714: }
4715: unless ($gotspares) {
4716: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4717: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4718: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4719: } else {
4720: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4721: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4722: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4723: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4724: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4725: } else {
1.150 raeburn 4726: my %what = (
4727: spareid => 1,
4728: );
4729: my ($result,$returnhash) =
4730: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4731: if ($result eq 'ok') {
4732: if (ref($returnhash) eq 'HASH') {
4733: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4734: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4735: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4736: }
4737: }
1.145 raeburn 4738: }
4739: }
4740: }
4741: }
4742: }
4743: }
4744: return %spareid;
4745: }
4746:
4747: sub spares_row {
1.160.6.61 raeburn 4748: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4749: my $css_class;
4750: my $numinrow = 4;
4751: my $itemcount = 1;
4752: my $datatable;
1.152 raeburn 4753: my %typetitles = &sparestype_titles();
4754: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4755: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4756: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4757: my ($othercontrol,$serverdom);
4758: if ($serverhome ne $server) {
4759: $serverdom = &Apache::lonnet::host_domain($serverhome);
4760: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4761: } else {
4762: $serverdom = &Apache::lonnet::host_domain($server);
4763: if ($serverdom ne $dom) {
4764: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4765: }
4766: }
4767: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61 raeburn 4768: my $checkednow;
4769: if (ref($curroffloadnow) eq 'HASH') {
4770: if ($curroffloadnow->{$server}) {
4771: $checkednow = ' checked="checked"';
4772: }
4773: }
1.145 raeburn 4774: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4775: $datatable .= '<tr'.$css_class.'>
4776: <td rowspan="2">
1.160.6.13 raeburn 4777: <span class="LC_nobreak">'.
4778: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 4779: ,'<b>'.$server.'</b>').'</span><br />'.
4780: '<span class="LC_nobreak">'."\n".
4781: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4782: ' '.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13 raeburn 4783: "\n";
1.145 raeburn 4784: my (%current,%canselect);
1.152 raeburn 4785: my @choices =
4786: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4787: foreach my $type ('primary','default') {
4788: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4789: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4790: my @spares = @{$spareid->{$server}{$type}};
4791: if (@spares > 0) {
1.152 raeburn 4792: if ($othercontrol) {
4793: $current{$type} = join(', ',@spares);
4794: } else {
4795: $current{$type} .= '<table>';
4796: my $numspares = scalar(@spares);
4797: for (my $i=0; $i<@spares; $i++) {
4798: my $rem = $i%($numinrow);
4799: if ($rem == 0) {
4800: if ($i > 0) {
4801: $current{$type} .= '</tr>';
4802: }
4803: $current{$type} .= '<tr>';
1.145 raeburn 4804: }
1.152 raeburn 4805: $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'".');" /> '.
4806: $spareid->{$server}{$type}[$i].
4807: '</label></td>'."\n";
4808: }
4809: my $rem = @spares%($numinrow);
4810: my $colsleft = $numinrow - $rem;
4811: if ($colsleft > 1 ) {
4812: $current{$type} .= '<td colspan="'.$colsleft.
4813: '" class="LC_left_item">'.
4814: ' </td>';
4815: } elsif ($colsleft == 1) {
4816: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4817: }
1.152 raeburn 4818: $current{$type} .= '</tr></table>';
1.150 raeburn 4819: }
1.145 raeburn 4820: }
4821: }
4822: if ($current{$type} eq '') {
4823: $current{$type} = &mt('None specified');
4824: }
1.152 raeburn 4825: if ($othercontrol) {
4826: if ($type eq 'primary') {
4827: $canselect{$type} = $othercontrol;
4828: }
4829: } else {
4830: $canselect{$type} =
4831: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4832: '<select name="newspare_'.$type.'_'.$server.'" '.
4833: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4834: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4835: if (@choices > 0) {
4836: foreach my $lonhost (@choices) {
4837: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4838: }
4839: }
4840: $canselect{$type} .= '</select>'."\n";
4841: }
4842: } else {
4843: $current{$type} = &mt('Could not be determined');
4844: if ($type eq 'primary') {
4845: $canselect{$type} = $othercontrol;
4846: }
1.145 raeburn 4847: }
1.152 raeburn 4848: if ($type eq 'default') {
4849: $datatable .= '<tr'.$css_class.'>';
4850: }
4851: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4852: '<td>'.$current{$type}.'</td>'."\n".
4853: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 4854: }
4855: $itemcount ++;
4856: }
4857: }
4858: $$rowtotal += $itemcount;
4859: return $datatable;
4860: }
4861:
1.152 raeburn 4862: sub possible_newspares {
4863: my ($server,$currspares,$serverhomes,$altids) = @_;
4864: my $serverhostname = &Apache::lonnet::hostname($server);
4865: my %excluded;
4866: if ($serverhostname ne '') {
4867: %excluded = (
4868: $serverhostname => 1,
4869: );
4870: }
4871: if (ref($currspares) eq 'HASH') {
4872: foreach my $type (keys(%{$currspares})) {
4873: if (ref($currspares->{$type}) eq 'ARRAY') {
4874: if (@{$currspares->{$type}} > 0) {
4875: foreach my $curr (@{$currspares->{$type}}) {
4876: my $hostname = &Apache::lonnet::hostname($curr);
4877: $excluded{$hostname} = 1;
4878: }
4879: }
4880: }
4881: }
4882: }
4883: my @choices;
4884: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4885: if (keys(%{$serverhomes}) > 1) {
4886: foreach my $name (sort(keys(%{$serverhomes}))) {
4887: unless ($excluded{$name}) {
4888: if (exists($altids->{$serverhomes->{$name}})) {
4889: push(@choices,$altids->{$serverhomes->{$name}});
4890: } else {
4891: push(@choices,$serverhomes->{$name});
1.145 raeburn 4892: }
4893: }
4894: }
4895: }
4896: }
1.152 raeburn 4897: return sort(@choices);
1.145 raeburn 4898: }
4899:
1.150 raeburn 4900: sub print_loadbalancing {
4901: my ($dom,$settings,$rowtotal) = @_;
4902: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4903: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4904: my $numinrow = 1;
4905: my $datatable;
4906: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 4907: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 4908: if (ref($settings) eq 'HASH') {
4909: %existing = %{$settings};
4910: }
4911: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
4912: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 4913: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 4914: } else {
4915: return;
4916: }
4917: my ($othertitle,$usertypes,$types) =
4918: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 4919: my $rownum = 8;
1.150 raeburn 4920: if (ref($types) eq 'ARRAY') {
4921: $rownum += scalar(@{$types});
4922: }
1.160.6.7 raeburn 4923: my @css_class = ('LC_odd_row','LC_even_row');
4924: my $balnum = 0;
4925: my $islast;
4926: my (@toshow,$disabledtext);
4927: if (keys(%currbalancer) > 0) {
4928: @toshow = sort(keys(%currbalancer));
4929: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
4930: push(@toshow,'');
4931: }
4932: } else {
4933: @toshow = ('');
4934: $disabledtext = &mt('No existing load balancer');
4935: }
4936: foreach my $lonhost (@toshow) {
4937: if ($balnum == scalar(@toshow)-1) {
4938: $islast = 1;
4939: } else {
4940: $islast = 0;
4941: }
4942: my $cssidx = $balnum%2;
4943: my $targets_div_style = 'display: none';
4944: my $disabled_div_style = 'display: block';
4945: my $homedom_div_style = 'display: none';
4946: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
4947: '<td rowspan="'.$rownum.'" valign="top">'.
4948: '<p>';
4949: if ($lonhost eq '') {
4950: $datatable .= '<span class="LC_nobreak">';
4951: if (keys(%currbalancer) > 0) {
4952: $datatable .= &mt('Add balancer:');
4953: } else {
4954: $datatable .= &mt('Enable balancer:');
4955: }
4956: $datatable .= ' '.
4957: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
4958: ' id="loadbalancing_lonhost_'.$balnum.'"'.
4959: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
4960: '<option value="" selected="selected">'.&mt('None').
4961: '</option>'."\n";
4962: foreach my $server (sort(keys(%servers))) {
4963: next if ($currbalancer{$server});
4964: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4965: }
4966: $datatable .=
4967: '</select>'."\n".
4968: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4969: } else {
4970: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4971: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4972: &mt('Stop balancing').'</label>'.
4973: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4974: $targets_div_style = 'display: block';
4975: $disabled_div_style = 'display: none';
4976: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
4977: $homedom_div_style = 'display: block';
4978: }
4979: }
4980: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
4981: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
4982: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
4983: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
4984: my ($numspares,@spares) = &count_servers($lonhost,%servers);
4985: my @sparestypes = ('primary','default');
4986: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 4987: my %hostherechecked = (
4988: no => ' checked="checked"',
4989: );
1.160.6.94 raeburn 4990: my %balcookiechecked = (
4991: no => ' checked="checked"',
4992: );
1.160.6.7 raeburn 4993: foreach my $sparetype (@sparestypes) {
4994: my $targettable;
4995: for (my $i=0; $i<$numspares; $i++) {
4996: my $checked;
4997: if (ref($currtargets{$lonhost}) eq 'HASH') {
4998: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4999: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5000: $checked = ' checked="checked"';
5001: }
5002: }
5003: }
5004: my ($chkboxval,$disabled);
5005: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5006: $chkboxval = $spares[$i];
5007: }
5008: if (exists($currbalancer{$spares[$i]})) {
5009: $disabled = ' disabled="disabled"';
5010: }
5011: $targettable .=
1.160.6.55 raeburn 5012: '<td><span class="LC_nobreak"><label>'.
5013: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 5014: $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 5015: '</span></label></span></td>';
1.160.6.7 raeburn 5016: my $rem = $i%($numinrow);
5017: if ($rem == 0) {
5018: if (($i > 0) && ($i < $numspares-1)) {
5019: $targettable .= '</tr>';
5020: }
5021: if ($i < $numspares-1) {
5022: $targettable .= '<tr>';
1.150 raeburn 5023: }
5024: }
5025: }
1.160.6.7 raeburn 5026: if ($targettable ne '') {
5027: my $rem = $numspares%($numinrow);
5028: my $colsleft = $numinrow - $rem;
5029: if ($colsleft > 1 ) {
5030: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5031: ' </td>';
5032: } elsif ($colsleft == 1) {
5033: $targettable .= '<td class="LC_left_item"> </td>';
5034: }
5035: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5036: '<table><tr>'.$targettable.'</tr></table><br />';
5037: }
1.160.6.76 raeburn 5038: $hostherechecked{$sparetype} = '';
5039: if (ref($currtargets{$lonhost}) eq 'HASH') {
5040: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5041: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5042: $hostherechecked{$sparetype} = ' checked="checked"';
5043: $hostherechecked{'no'} = '';
5044: }
5045: }
5046: }
5047: }
1.160.6.94 raeburn 5048: if ($currcookies{$lonhost}) {
5049: %balcookiechecked = (
5050: yes => ' checked="checked"',
5051: );
5052: }
1.160.6.76 raeburn 5053: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5054: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5055: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5056: foreach my $sparetype (@sparestypes) {
5057: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5058: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5059: '</i></label><br />';
1.160.6.7 raeburn 5060: }
1.160.6.94 raeburn 5061: $datatable .= &mt('Use balancer cookie').'<br />'.
5062: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
5063: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
5064: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
5065: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
5066: '</div></td></tr>'.
1.160.6.7 raeburn 5067: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5068: $othertitle,$usertypes,$types,\%servers,
5069: \%currbalancer,$lonhost,
5070: $targets_div_style,$homedom_div_style,
5071: $css_class[$cssidx],$balnum,$islast);
5072: $$rowtotal += $rownum;
5073: $balnum ++;
5074: }
5075: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5076: return $datatable;
5077: }
5078:
5079: sub get_loadbalancers_config {
1.160.6.94 raeburn 5080: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 5081: return unless ((ref($servers) eq 'HASH') &&
5082: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 5083: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
5084: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 5085: if (keys(%{$existing}) > 0) {
5086: my $oldlonhost;
5087: foreach my $key (sort(keys(%{$existing}))) {
5088: if ($key eq 'lonhost') {
5089: $oldlonhost = $existing->{'lonhost'};
5090: $currbalancer->{$oldlonhost} = 1;
5091: } elsif ($key eq 'targets') {
5092: if ($oldlonhost) {
5093: $currtargets->{$oldlonhost} = $existing->{'targets'};
5094: }
5095: } elsif ($key eq 'rules') {
5096: if ($oldlonhost) {
5097: $currrules->{$oldlonhost} = $existing->{'rules'};
5098: }
5099: } elsif (ref($existing->{$key}) eq 'HASH') {
5100: $currbalancer->{$key} = 1;
5101: $currtargets->{$key} = $existing->{$key}{'targets'};
5102: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 5103: if ($existing->{$key}{'cookie'}) {
5104: $currcookies->{$key} = 1;
5105: }
1.150 raeburn 5106: }
5107: }
1.160.6.7 raeburn 5108: } else {
5109: my ($balancerref,$targetsref) =
5110: &Apache::lonnet::get_lonbalancer_config($servers);
5111: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5112: foreach my $server (sort(keys(%{$balancerref}))) {
5113: $currbalancer->{$server} = 1;
5114: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 5115: }
5116: }
5117: }
1.160.6.7 raeburn 5118: return;
1.150 raeburn 5119: }
5120:
5121: sub loadbalancing_rules {
5122: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 5123: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5124: $css_class,$balnum,$islast) = @_;
1.150 raeburn 5125: my $output;
1.160.6.7 raeburn 5126: my $num = 0;
5127: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 5128: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5129: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5130: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 5131: $num ++;
1.150 raeburn 5132: my $current;
5133: if (ref($currrules) eq 'HASH') {
5134: $current = $currrules->{$type};
5135: }
1.160.6.55 raeburn 5136: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 5137: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 5138: $current = '';
5139: }
5140: }
5141: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 5142: $servers,$currbalancer,$lonhost,$dom,
5143: $targets_div_style,$homedom_div_style,
5144: $css_class,$balnum,$num,$islast);
1.150 raeburn 5145: }
5146: }
5147: return $output;
5148: }
5149:
5150: sub loadbalancing_titles {
5151: my ($dom,$intdom,$usertypes,$types) = @_;
5152: my %othertypes = (
5153: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5154: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5155: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5156: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 5157: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5158: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 5159: );
1.160.6.26 raeburn 5160: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 5161: my @available;
1.150 raeburn 5162: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 5163: @available = @{$types};
1.150 raeburn 5164: }
1.160.6.89 raeburn 5165: unless (grep(/^default$/,@available)) {
5166: push(@available,'default');
5167: }
5168: unshift(@alltypes,@available);
1.150 raeburn 5169: my %titles;
5170: foreach my $type (@alltypes) {
5171: if ($type =~ /^_LC_/) {
5172: $titles{$type} = $othertypes{$type};
5173: } elsif ($type eq 'default') {
5174: $titles{$type} = &mt('All users from [_1]',$dom);
5175: if (ref($types) eq 'ARRAY') {
5176: if (@{$types} > 0) {
5177: $titles{$type} = &mt('Other users from [_1]',$dom);
5178: }
5179: }
5180: } elsif (ref($usertypes) eq 'HASH') {
5181: $titles{$type} = $usertypes->{$type};
5182: }
5183: }
5184: return (\@alltypes,\%othertypes,\%titles);
5185: }
5186:
5187: sub loadbalance_rule_row {
1.160.6.7 raeburn 5188: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
5189: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 5190: my @rulenames;
1.150 raeburn 5191: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 5192: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 5193: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 5194: } else {
1.160.6.26 raeburn 5195: @rulenames = ('default','homeserver');
5196: if ($type eq '_LC_external') {
5197: push(@rulenames,'externalbalancer');
5198: } else {
5199: push(@rulenames,'specific');
5200: }
5201: push(@rulenames,'none');
1.150 raeburn 5202: }
5203: my $style = $targets_div_style;
1.160.6.55 raeburn 5204: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 5205: $style = $homedom_div_style;
5206: }
1.160.6.7 raeburn 5207: my $space;
5208: if ($islast && $num == 1) {
5209: $space = '<div display="inline-block"> </div>';
5210: }
5211: my $output =
5212: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
5213: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
5214: '<td valaign="top">'.$space.
5215: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 5216: for (my $i=0; $i<@rulenames; $i++) {
5217: my $rule = $rulenames[$i];
5218: my ($checked,$extra);
5219: if ($rulenames[$i] eq 'default') {
5220: $rule = '';
5221: }
5222: if ($rulenames[$i] eq 'specific') {
5223: if (ref($servers) eq 'HASH') {
5224: my $default;
5225: if (($current ne '') && (exists($servers->{$current}))) {
5226: $checked = ' checked="checked"';
5227: }
5228: unless ($checked) {
5229: $default = ' selected="selected"';
5230: }
1.160.6.7 raeburn 5231: $extra =
5232: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
5233: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
5234: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
5235: '<option value=""'.$default.'></option>'."\n";
5236: foreach my $server (sort(keys(%{$servers}))) {
5237: if (ref($currbalancer) eq 'HASH') {
5238: next if (exists($currbalancer->{$server}));
5239: }
1.150 raeburn 5240: my $selected;
1.160.6.7 raeburn 5241: if ($server eq $current) {
1.150 raeburn 5242: $selected = ' selected="selected"';
5243: }
1.160.6.7 raeburn 5244: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 5245: }
5246: $extra .= '</select>';
5247: }
5248: } elsif ($rule eq $current) {
5249: $checked = ' checked="checked"';
5250: }
5251: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 5252: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
5253: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
5254: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 5255: ')"'.$checked.' /> ';
1.160.6.56 raeburn 5256: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 5257: $output .= $ruletitles{'particular'};
5258: } else {
5259: $output .= $ruletitles{$rulenames[$i]};
5260: }
5261: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 5262: }
5263: $output .= '</div></td></tr>'."\n";
5264: return $output;
5265: }
5266:
5267: sub offloadtype_text {
5268: my %ruletitles = &Apache::lonlocal::texthash (
5269: 'default' => 'Offloads to default destinations',
5270: 'homeserver' => "Offloads to user's home server",
5271: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
5272: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 5273: 'none' => 'No offload',
1.160.6.26 raeburn 5274: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
5275: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 5276: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 5277: );
5278: return %ruletitles;
5279: }
5280:
5281: sub sparestype_titles {
5282: my %typestitles = &Apache::lonlocal::texthash (
5283: 'primary' => 'primary',
5284: 'default' => 'default',
5285: );
5286: return %typestitles;
5287: }
5288:
1.28 raeburn 5289: sub contact_titles {
5290: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 5291: 'supportemail' => 'Support E-mail address',
5292: 'adminemail' => 'Default Server Admin E-mail address',
5293: 'errormail' => 'Error reports to be e-mailed to',
5294: 'packagesmail' => 'Package update alerts to be e-mailed to',
5295: 'helpdeskmail' => "Helpdesk requests for this domain's users",
5296: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
5297: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
5298: 'requestsmail' => 'E-mail from course requests requiring approval',
5299: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 5300: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 5301: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.28 raeburn 5302: );
5303: my %short_titles = &Apache::lonlocal::texthash (
5304: adminemail => 'Admin E-mail address',
5305: supportemail => 'Support E-mail',
5306: );
5307: return (\%titles,\%short_titles);
5308: }
5309:
1.160.6.78 raeburn 5310: sub helpform_fields {
5311: my %titles = &Apache::lonlocal::texthash (
5312: 'username' => 'Name',
5313: 'user' => 'Username/domain',
5314: 'phone' => 'Phone',
5315: 'cc' => 'Cc e-mail',
5316: 'course' => 'Course Details',
5317: 'section' => 'Sections',
5318: 'screenshot' => 'File upload',
5319: );
5320: my @fields = ('username','phone','user','course','section','cc','screenshot');
5321: my %possoptions = (
5322: username => ['yes','no','req'],
5323: phone => ['yes','no','req'],
5324: user => ['yes','no'],
5325: cc => ['yes','no'],
5326: course => ['yes','no'],
5327: section => ['yes','no'],
5328: screenshot => ['yes','no'],
5329: );
5330: my %fieldoptions = &Apache::lonlocal::texthash (
5331: 'yes' => 'Optional',
5332: 'req' => 'Required',
5333: 'no' => "Not shown",
5334: );
5335: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
5336: }
5337:
1.72 raeburn 5338: sub tool_titles {
5339: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 5340: aboutme => 'Personal web page',
1.86 raeburn 5341: blog => 'Blog',
1.160.6.4 raeburn 5342: webdav => 'WebDAV',
1.86 raeburn 5343: portfolio => 'Portfolio',
1.88 bisitz 5344: official => 'Official courses (with institutional codes)',
5345: unofficial => 'Unofficial courses',
1.98 raeburn 5346: community => 'Communities',
1.160.6.30 raeburn 5347: textbook => 'Textbook courses',
1.86 raeburn 5348: );
1.72 raeburn 5349: return %titles;
5350: }
5351:
1.101 raeburn 5352: sub courserequest_titles {
5353: my %titles = &Apache::lonlocal::texthash (
5354: official => 'Official',
5355: unofficial => 'Unofficial',
5356: community => 'Communities',
1.160.6.30 raeburn 5357: textbook => 'Textbook',
1.101 raeburn 5358: norequest => 'Not allowed',
1.104 raeburn 5359: approval => 'Approval by Dom. Coord.',
1.101 raeburn 5360: validate => 'With validation',
5361: autolimit => 'Numerical limit',
1.103 raeburn 5362: unlimited => '(blank for unlimited)',
1.101 raeburn 5363: );
5364: return %titles;
5365: }
5366:
1.160.6.5 raeburn 5367: sub authorrequest_titles {
5368: my %titles = &Apache::lonlocal::texthash (
5369: norequest => 'Not allowed',
5370: approval => 'Approval by Dom. Coord.',
5371: automatic => 'Automatic approval',
5372: );
5373: return %titles;
5374: }
5375:
1.101 raeburn 5376: sub courserequest_conditions {
5377: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 5378: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 5379: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 5380: );
5381: return %conditions;
5382: }
5383:
5384:
1.27 raeburn 5385: sub print_usercreation {
1.30 raeburn 5386: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 5387: my $numinrow = 4;
1.28 raeburn 5388: my $datatable;
5389: if ($position eq 'top') {
1.30 raeburn 5390: $$rowtotal ++;
1.34 raeburn 5391: my $rowcount = 0;
1.32 raeburn 5392: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 5393: if (ref($rules) eq 'HASH') {
5394: if (keys(%{$rules}) > 0) {
1.32 raeburn 5395: $datatable .= &user_formats_row('username',$settings,$rules,
5396: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 5397: $$rowtotal ++;
1.32 raeburn 5398: $rowcount ++;
5399: }
5400: }
5401: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
5402: if (ref($idrules) eq 'HASH') {
5403: if (keys(%{$idrules}) > 0) {
5404: $datatable .= &user_formats_row('id',$settings,$idrules,
5405: $idruleorder,$numinrow,$rowcount);
5406: $$rowtotal ++;
5407: $rowcount ++;
1.28 raeburn 5408: }
5409: }
1.39 raeburn 5410: if ($rowcount == 0) {
5411: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
5412: $$rowtotal ++;
5413: $rowcount ++;
5414: }
1.34 raeburn 5415: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 5416: my @creators = ('author','course','requestcrs');
1.37 raeburn 5417: my ($rules,$ruleorder) =
5418: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 5419: my %lt = &usercreation_types();
5420: my %checked;
5421: if (ref($settings) eq 'HASH') {
5422: if (ref($settings->{'cancreate'}) eq 'HASH') {
5423: foreach my $item (@creators) {
5424: $checked{$item} = $settings->{'cancreate'}{$item};
5425: }
5426: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
5427: foreach my $item (@creators) {
5428: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
5429: $checked{$item} = 'none';
5430: }
5431: }
5432: }
5433: }
5434: my $rownum = 0;
5435: foreach my $item (@creators) {
5436: $rownum ++;
1.160.6.34 raeburn 5437: if ($checked{$item} eq '') {
5438: $checked{$item} = 'any';
1.34 raeburn 5439: }
5440: my $css_class;
5441: if ($rownum%2) {
5442: $css_class = '';
5443: } else {
5444: $css_class = ' class="LC_odd_row" ';
5445: }
5446: $datatable .= '<tr'.$css_class.'>'.
5447: '<td><span class="LC_nobreak">'.$lt{$item}.
5448: '</span></td><td align="right">';
1.160.6.34 raeburn 5449: my @options = ('any');
5450: if (ref($rules) eq 'HASH') {
5451: if (keys(%{$rules}) > 0) {
5452: push(@options,('official','unofficial'));
1.37 raeburn 5453: }
5454: }
1.160.6.34 raeburn 5455: push(@options,'none');
1.37 raeburn 5456: foreach my $option (@options) {
1.50 raeburn 5457: my $type = 'radio';
1.34 raeburn 5458: my $check = ' ';
1.160.6.34 raeburn 5459: if ($checked{$item} eq $option) {
5460: $check = ' checked="checked" ';
1.34 raeburn 5461: }
5462: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 5463: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 5464: $item.'" value="'.$option.'"'.$check.'/> '.
5465: $lt{$option}.'</label> </span>';
5466: }
5467: $datatable .= '</td></tr>';
5468: }
1.28 raeburn 5469: } else {
5470: my @contexts = ('author','course','domain');
5471: my @authtypes = ('int','krb4','krb5','loc');
5472: my %checked;
5473: if (ref($settings) eq 'HASH') {
5474: if (ref($settings->{'authtypes'}) eq 'HASH') {
5475: foreach my $item (@contexts) {
5476: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5477: foreach my $auth (@authtypes) {
5478: if ($settings->{'authtypes'}{$item}{$auth}) {
5479: $checked{$item}{$auth} = ' checked="checked" ';
5480: }
5481: }
5482: }
5483: }
1.27 raeburn 5484: }
1.35 raeburn 5485: } else {
5486: foreach my $item (@contexts) {
1.36 raeburn 5487: foreach my $auth (@authtypes) {
1.35 raeburn 5488: $checked{$item}{$auth} = ' checked="checked" ';
5489: }
5490: }
1.27 raeburn 5491: }
1.28 raeburn 5492: my %title = &context_names();
5493: my %authname = &authtype_names();
5494: my $rownum = 0;
5495: my $css_class;
5496: foreach my $item (@contexts) {
5497: if ($rownum%2) {
5498: $css_class = '';
5499: } else {
5500: $css_class = ' class="LC_odd_row" ';
5501: }
1.30 raeburn 5502: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5503: '<td>'.$title{$item}.
5504: '</td><td class="LC_left_item">'.
5505: '<span class="LC_nobreak">';
5506: foreach my $auth (@authtypes) {
5507: $datatable .= '<label>'.
5508: '<input type="checkbox" name="'.$item.'_auth" '.
5509: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5510: $authname{$auth}.'</label> ';
5511: }
5512: $datatable .= '</span></td></tr>';
5513: $rownum ++;
1.27 raeburn 5514: }
1.30 raeburn 5515: $$rowtotal += $rownum;
1.27 raeburn 5516: }
5517: return $datatable;
5518: }
5519:
1.160.6.34 raeburn 5520: sub print_selfcreation {
5521: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 5522: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
5523: $emaildomain,$datatable);
1.160.6.34 raeburn 5524: if (ref($settings) eq 'HASH') {
5525: if (ref($settings->{'cancreate'}) eq 'HASH') {
5526: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 5527: if (ref($createsettings) eq 'HASH') {
5528: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5529: @selfcreate = @{$createsettings->{'selfcreate'}};
5530: } elsif ($createsettings->{'selfcreate'} ne '') {
5531: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5532: @selfcreate = ('email','login','sso');
5533: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5534: @selfcreate = ($createsettings->{'selfcreate'});
5535: }
5536: }
5537: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5538: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 5539: }
1.160.6.93 raeburn 5540: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
5541: $emailoptions = $createsettings->{'emailoptions'};
5542: }
5543: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
5544: $emailverified = $createsettings->{'emailverified'};
5545: }
5546: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
5547: $emaildomain = $createsettings->{'emaildomain'};
5548: }
1.160.6.34 raeburn 5549: }
5550: }
5551: }
5552: my %radiohash;
5553: my $numinrow = 4;
5554: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 5555: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 5556: if ($position eq 'top') {
5557: my %choices = &Apache::lonlocal::texthash (
5558: cancreate_login => 'Institutional Login',
5559: cancreate_sso => 'Institutional Single Sign On',
5560: );
5561: my @toggles = sort(keys(%choices));
5562: my %defaultchecked = (
5563: 'cancreate_login' => 'off',
5564: 'cancreate_sso' => 'off',
5565: );
1.160.6.35 raeburn 5566: my ($onclick,$itemcount);
1.160.6.34 raeburn 5567: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5568: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 5569: $$rowtotal += $itemcount;
1.160.6.34 raeburn 5570:
5571: if (ref($usertypes) eq 'HASH') {
5572: if (keys(%{$usertypes}) > 0) {
5573: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5574: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 5575: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 5576: $$rowtotal ++;
5577: }
5578: }
1.160.6.44 raeburn 5579: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5580: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5581: $fieldtitles{'inststatus'} = &mt('Institutional status');
5582: my $rem;
5583: my $numperrow = 2;
5584: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5585: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 5586: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 5587: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 5588: '<table>'."\n";
1.160.6.44 raeburn 5589: for (my $i=0; $i<@fields; $i++) {
5590: $rem = $i%($numperrow);
5591: if ($rem == 0) {
5592: if ($i > 0) {
5593: $datatable .= '</tr>';
5594: }
5595: $datatable .= '<tr>';
5596: }
5597: my $currval;
1.160.6.51 raeburn 5598: if (ref($createsettings) eq 'HASH') {
5599: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5600: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5601: }
1.160.6.44 raeburn 5602: }
5603: $datatable .= '<td class="LC_left_item">'.
5604: '<span class="LC_nobreak">'.
5605: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5606: 'value="'.$currval.'" size="10" /> '.
5607: $fieldtitles{$fields[$i]}.'</span></td>';
5608: }
5609: my $colsleft = $numperrow - $rem;
5610: if ($colsleft > 1 ) {
5611: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5612: ' </td>';
5613: } elsif ($colsleft == 1) {
5614: $datatable .= '<td class="LC_left_item"> </td>';
5615: }
5616: $datatable .= '</tr></table></td></tr>';
5617: $$rowtotal ++;
1.160.6.34 raeburn 5618: } elsif ($position eq 'middle') {
5619: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 5620: my @posstypes;
1.160.6.34 raeburn 5621: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 5622: @posstypes = @{$types};
5623: }
5624: unless (grep(/^default$/,@posstypes)) {
5625: push(@posstypes,'default');
5626: }
5627: my %usertypeshash;
5628: if (ref($usertypes) eq 'HASH') {
5629: %usertypeshash = %{$usertypes};
5630: }
5631: $usertypeshash{'default'} = $othertitle;
5632: foreach my $status (@posstypes) {
5633: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
5634: $numinrow,$$rowtotal,\%usertypeshash);
5635: $$rowtotal ++;
1.160.6.34 raeburn 5636: }
5637: } else {
1.160.6.40 raeburn 5638: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 5639: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 5640: );
5641: my @toggles = sort(keys(%choices));
5642: my %defaultchecked = (
5643: 'cancreate_email' => 'off',
5644: );
1.160.6.93 raeburn 5645: my $customclass = 'LC_selfcreate_email';
5646: my $classprefix = 'LC_canmodify_emailusername_';
5647: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 5648: my $display = 'none';
1.160.6.93 raeburn 5649: my $rowstyle = 'display:none';
1.160.6.40 raeburn 5650: if (grep(/^\Qemail\E$/,@selfcreate)) {
5651: $display = 'block';
1.160.6.93 raeburn 5652: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 5653: }
1.160.6.93 raeburn 5654: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
5655: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5656: \%choices,$$rowtotal,$onclick);
5657: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
5658: $rowstyle);
5659: $$rowtotal ++;
5660: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
5661: $rowstyle);
5662: $$rowtotal ++;
5663: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 5664: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 5665: my ($emailrules,$emailruleorder) =
5666: &Apache::lonnet::inst_userrules($dom,'email');
5667: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5668: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5669: if (ref($types) eq 'ARRAY') {
5670: @posstypes = @{$types};
5671: }
5672: if (@posstypes) {
5673: unless (grep(/^default$/,@posstypes)) {
5674: push(@posstypes,'default');
1.160.6.89 raeburn 5675: }
5676: if (ref($usertypes) eq 'HASH') {
5677: %usertypeshash = %{$usertypes};
5678: }
1.160.6.93 raeburn 5679: my $currassign;
5680: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
5681: $currassign = {
5682: selfassign => $domdefaults{'inststatusguest'},
5683: };
5684: @ordered = @{$domdefaults{'inststatusguest'}};
5685: } else {
5686: $currassign = { selfassign => [] };
5687: }
5688: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
5689: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
5690: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
5691: $numinrow,$othertitle,'selfassign',
5692: $rowtotal,$onclicktypes,$customclass,
5693: $rowstyle);
5694: $$rowtotal ++;
1.160.6.89 raeburn 5695: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 5696: foreach my $status (@posstypes) {
5697: my $css_class;
5698: if ($$rowtotal%2) {
5699: $css_class = 'LC_odd_row ';
5700: }
5701: $css_class .= $customclass;
5702: my $rowid = $optionsprefix.$status;
5703: my $hidden = 1;
5704: my $currstyle = 'display:none';
5705: if (grep(/^\Q$status\E$/,@ordered)) {
5706: $currstyle = $rowstyle;
5707: $hidden = 0;
5708: }
5709: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
5710: $emailrules,$emailruleorder,$settings,$status,$rowid,
5711: $usertypeshash{$status},$css_class,$currstyle,$intdom);
5712: unless ($hidden) {
5713: $$rowtotal ++;
5714: }
1.160.6.89 raeburn 5715: }
5716: } else {
1.160.6.93 raeburn 5717: my $css_class;
5718: if ($$rowtotal%2) {
5719: $css_class = 'LC_odd_row ';
5720: }
5721: $css_class .= $customclass;
1.160.6.89 raeburn 5722: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 5723: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
5724: $emailrules,$emailruleorder,$settings,'default','',
5725: $othertitle,$css_class,$rowstyle,$intdom);
5726: $$rowtotal ++;
1.160.6.34 raeburn 5727: }
1.160.6.35 raeburn 5728: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5729: $numinrow = 1;
1.160.6.93 raeburn 5730: if (@posstypes) {
5731: foreach my $status (@posstypes) {
5732: my $rowid = $classprefix.$status;
5733: my $datarowstyle = 'display:none';
5734: if (grep(/^\Q$status\E$/,@ordered)) {
5735: $datarowstyle = $rowstyle;
5736: }
5737: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5738: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
5739: $infotitles,$rowid,$customclass,$datarowstyle);
5740: unless ($datarowstyle eq 'display:none') {
5741: $$rowtotal ++;
5742: }
1.160.6.34 raeburn 5743: }
1.160.6.93 raeburn 5744: } else {
5745: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
5746: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
5747: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 5748: }
5749: }
5750: return $datatable;
5751: }
5752:
1.160.6.93 raeburn 5753: sub selfcreate_javascript {
5754: return <<"ENDSCRIPT";
5755:
5756: <script type="text/javascript">
5757: // <![CDATA[
5758:
5759: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
5760: var x = document.getElementsByClassName(target);
5761: var insttypes = 0;
5762: var insttypeRegExp = new RegExp(prefix);
5763: if ((x.length != undefined) && (x.length > 0)) {
5764: if (form.elements[radio].length != undefined) {
5765: for (var i=0; i<form.elements[radio].length; i++) {
5766: if (form.elements[radio][i].checked) {
5767: if (form.elements[radio][i].value == 1) {
5768: for (var j=0; j<x.length; j++) {
5769: if (x[j].id == 'undefined') {
5770: x[j].style.display = 'table-row';
5771: } else if (insttypeRegExp.test(x[j].id)) {
5772: insttypes ++;
5773: } else {
5774: x[j].style.display = 'table-row';
5775: }
5776: }
5777: } else {
5778: for (var j=0; j<x.length; j++) {
5779: x[j].style.display = 'none';
5780: }
1.160.6.40 raeburn 5781: }
1.160.6.93 raeburn 5782: break;
5783: }
5784: }
5785: if (insttypes > 0) {
5786: toggleDataRow(form,checkbox,target,altprefix);
5787: toggleDataRow(form,checkbox,target,prefix,1);
5788: }
5789: }
5790: }
5791: return;
5792: }
5793:
5794: function toggleDataRow(form,checkbox,target,prefix,docount) {
5795: if (form.elements[checkbox].length != undefined) {
5796: var count = 0;
5797: if (docount) {
5798: for (var i=0; i<form.elements[checkbox].length; i++) {
5799: if (form.elements[checkbox][i].checked) {
5800: count ++;
5801: }
5802: }
5803: }
5804: for (var i=0; i<form.elements[checkbox].length; i++) {
5805: var type = form.elements[checkbox][i].value;
5806: if (document.getElementById(prefix+type)) {
5807: if (form.elements[checkbox][i].checked) {
5808: document.getElementById(prefix+type).style.display = 'table-row';
5809: if (count % 2 == 1) {
5810: document.getElementById(prefix+type).className = target+' LC_odd_row';
5811: } else {
5812: document.getElementById(prefix+type).className = target;
5813: }
5814: count ++;
1.160.6.40 raeburn 5815: } else {
1.160.6.93 raeburn 5816: document.getElementById(prefix+type).style.display = 'none';
5817: }
5818: }
5819: }
5820: }
5821: return;
5822: }
5823:
5824: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
5825: var caller = radio+'_'+status;
5826: if (form.elements[caller].length != undefined) {
5827: for (var i=0; i<form.elements[caller].length; i++) {
5828: if (form.elements[caller][i].checked) {
5829: if (document.getElementById(altprefix+'_inst_'+status)) {
5830: var curr = form.elements[caller][i].value;
5831: if (prefix) {
5832: document.getElementById(prefix+'_'+status).style.display = 'none';
5833: }
5834: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
5835: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
5836: if (curr == 'custom') {
5837: if (prefix) {
5838: document.getElementById(prefix+'_'+status).style.display = 'inline';
5839: }
5840: } else if (curr == 'inst') {
5841: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
5842: } else if (curr == 'noninst') {
5843: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 5844: }
1.160.6.93 raeburn 5845: break;
1.160.6.40 raeburn 5846: }
1.160.6.93 raeburn 5847: }
5848: }
5849: }
5850: }
5851:
5852: // ]]>
5853: </script>
5854:
5855: ENDSCRIPT
5856: }
5857:
5858: sub noninst_users {
5859: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
5860: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
5861: my $class = 'LC_left_item';
5862: if ($css_class) {
5863: $css_class = ' class="'.$css_class.'"';
5864: }
5865: if ($rowid) {
5866: $rowid = ' id="'.$rowid.'"';
5867: }
5868: if ($rowstyle) {
5869: $rowstyle = ' style="'.$rowstyle.'"';
5870: }
5871: my ($output,$description);
5872: if ($type eq 'default') {
5873: $description = &mt('Requests for: [_1]',$typetitle);
5874: } else {
5875: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
5876: }
5877: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
5878: "<td>$description</td>\n".
5879: '<td class="'.$class.'" colspan="2">'.
5880: '<table><tr>';
5881: my %headers = &Apache::lonlocal::texthash(
5882: approve => 'Processing',
5883: email => 'E-mail',
5884: username => 'Username',
5885: );
5886: foreach my $item ('approve','email','username') {
5887: $output .= '<th>'.$headers{$item}.'</th>';
5888: }
5889: $output .= '</tr><tr>';
5890: foreach my $item ('approve','email','username') {
5891: $output .= '<td valign="top">';
5892: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
5893: if ($item eq 'approve') {
5894: %choices = &Apache::lonlocal::texthash (
5895: automatic => 'Automatically approved',
5896: approval => 'Queued for approval',
5897: );
5898: @options = ('automatic','approval');
5899: $hashref = $processing;
5900: $defoption = 'automatic';
5901: $name = 'cancreate_emailprocess_'.$type;
5902: } elsif ($item eq 'email') {
5903: %choices = &Apache::lonlocal::texthash (
5904: any => 'Any e-mail',
5905: inst => 'Institutional only',
5906: noninst => 'Non-institutional only',
5907: custom => 'Custom restrictions',
5908: );
5909: @options = ('any','inst','noninst');
5910: my $showcustom;
5911: if (ref($emailrules) eq 'HASH') {
5912: if (keys(%{$emailrules}) > 0) {
5913: push(@options,'custom');
5914: $showcustom = 'cancreate_emailrule';
5915: if (ref($settings) eq 'HASH') {
5916: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
5917: foreach my $rule (@{$settings->{'email_rule'}}) {
5918: if (exists($emailrules->{$rule})) {
5919: $hascustom ++;
5920: }
5921: }
5922: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
5923: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
5924: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
5925: if (exists($emailrules->{$rule})) {
5926: $hascustom ++;
5927: }
5928: }
5929: }
5930: }
5931: }
5932: }
5933: }
5934: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
5935: "'cancreate_emaildomain','$type'".');"';
5936: $hashref = $emailoptions;
5937: $defoption = 'any';
5938: $name = 'cancreate_emailoptions_'.$type;
5939: } elsif ($item eq 'username') {
5940: %choices = &Apache::lonlocal::texthash (
5941: all => 'Same as e-mail',
5942: first => 'Omit @domain',
5943: free => 'Free to choose',
5944: );
5945: @options = ('all','first','free');
5946: $hashref = $emailverified;
5947: $defoption = 'all';
5948: $name = 'cancreate_usernameoptions_'.$type;
5949: }
5950: foreach my $option (@options) {
5951: my $checked;
5952: if (ref($hashref) eq 'HASH') {
5953: if ($type eq '') {
5954: if (!exists($hashref->{'default'})) {
5955: if ($option eq $defoption) {
5956: $checked = ' checked="checked"';
5957: }
5958: } else {
5959: if ($hashref->{'default'} eq $option) {
5960: $checked = ' checked="checked"';
5961: }
1.160.6.40 raeburn 5962: }
5963: } else {
1.160.6.93 raeburn 5964: if (!exists($hashref->{$type})) {
5965: if ($option eq $defoption) {
5966: $checked = ' checked="checked"';
5967: }
5968: } else {
5969: if ($hashref->{$type} eq $option) {
5970: $checked = ' checked="checked"';
5971: }
1.160.6.40 raeburn 5972: }
5973: }
1.160.6.93 raeburn 5974: } elsif (($item eq 'email') && ($hascustom)) {
5975: if ($option eq 'custom') {
5976: $checked = ' checked="checked"';
5977: }
5978: } elsif ($option eq $defoption) {
5979: $checked = ' checked="checked"';
5980: }
5981: $output .= '<span class="LC_nobreak"><label>'.
5982: '<input type="radio" name="'.$name.'"'.
5983: $checked.' value="'.$option.'"'.$onclick.' />'.
5984: $choices{$option}.'</label></span><br />';
5985: if ($item eq 'email') {
5986: if ($option eq 'custom') {
5987: my $id = 'cancreate_emailrule_'.$type;
5988: my $display = 'none';
5989: if ($checked) {
5990: $display = 'inline';
5991: }
5992: my $numinrow = 2;
5993: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
5994: '<legend>'.&mt('Disallow').'</legend><table>'.
5995: &user_formats_row('email',$settings,$emailrules,
5996: $emailruleorder,$numinrow,'',$type);
5997: '</table></fieldset>';
5998: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
5999: my %text = &Apache::lonlocal::texthash (
6000: inst => 'must end:',
6001: noninst => 'cannot end:',
6002: );
6003: my $value;
6004: if (ref($emaildomain) eq 'HASH') {
6005: if (ref($emaildomain->{$type}) eq 'HASH') {
6006: $value = $emaildomain->{$type}->{$option};
6007: }
6008: }
6009: if ($value eq '') {
6010: $value = '@'.$intdom;
6011: }
6012: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
6013: my $display = 'none';
6014: if ($checked) {
6015: $display = 'inline';
6016: }
6017: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
6018: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
6019: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
6020: '</div>';
6021: }
1.160.6.40 raeburn 6022: }
6023: }
1.160.6.93 raeburn 6024: $output .= '</td>'."\n";
1.160.6.40 raeburn 6025: }
1.160.6.93 raeburn 6026: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 6027: return $output;
6028: }
6029:
1.160.6.5 raeburn 6030: sub captcha_choice {
1.160.6.93 raeburn 6031: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 6032: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
6033: $vertext,$currver);
1.160.6.5 raeburn 6034: my %lt = &captcha_phrases();
6035: $keyentry = 'hidden';
1.160.6.98! raeburn 6036: my $colspan=2;
1.160.6.5 raeburn 6037: if ($context eq 'cancreate') {
1.160.6.34 raeburn 6038: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 6039: } elsif ($context eq 'login') {
6040: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98! raeburn 6041: } elsif ($context eq 'passwords') {
! 6042: $rowname = &mt('"Forgot Password" CAPTCHA validation');
! 6043: $colspan=1;
1.160.6.5 raeburn 6044: }
6045: if (ref($settings) eq 'HASH') {
6046: if ($settings->{'captcha'}) {
6047: $checked{$settings->{'captcha'}} = ' checked="checked"';
6048: } else {
6049: $checked{'original'} = ' checked="checked"';
6050: }
6051: if ($settings->{'captcha'} eq 'recaptcha') {
6052: $pubtext = $lt{'pub'};
6053: $privtext = $lt{'priv'};
6054: $keyentry = 'text';
1.160.6.69 raeburn 6055: $vertext = $lt{'ver'};
6056: $currver = $settings->{'recaptchaversion'};
6057: if ($currver ne '2') {
6058: $currver = 1;
6059: }
1.160.6.5 raeburn 6060: }
6061: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
6062: $currpub = $settings->{'recaptchakeys'}{'public'};
6063: $currpriv = $settings->{'recaptchakeys'}{'private'};
6064: }
6065: } else {
6066: $checked{'original'} = ' checked="checked"';
6067: }
1.160.6.93 raeburn 6068: my $css_class;
6069: if ($itemcount%2) {
6070: $css_class = 'LC_odd_row';
6071: }
6072: if ($customcss) {
6073: $css_class .= " $customcss";
6074: }
6075: $css_class =~ s/^\s+//;
6076: if ($css_class) {
6077: $css_class = ' class="'.$css_class.'"';
6078: }
6079: if ($rowstyle) {
6080: $css_class .= ' style="'.$rowstyle.'"';
6081: }
1.160.6.5 raeburn 6082: my $output = '<tr'.$css_class.'>'.
1.160.6.98! raeburn 6083: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 6084: '<table><tr><td>'."\n";
6085: foreach my $option ('original','recaptcha','notused') {
6086: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
6087: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
6088: $lt{$option}.'</label></span>';
6089: unless ($option eq 'notused') {
6090: $output .= (' 'x2)."\n";
6091: }
6092: }
6093: #
6094: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
6095: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
6096: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
6097: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
6098: #
6099: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 6100: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 6101: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
6102: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
6103: $currpub.'" size="40" /></span><br />'."\n".
6104: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
6105: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 6106: $currpriv.'" size="40" /></span><br />'.
6107: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
6108: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
6109: $currver.'" size="3" /></span><br />'.
6110: '</td></tr></table>'."\n".
1.160.6.5 raeburn 6111: '</td></tr>';
6112: return $output;
6113: }
6114:
1.32 raeburn 6115: sub user_formats_row {
1.160.6.93 raeburn 6116: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 6117: my $output;
6118: my %text = (
6119: 'username' => 'new usernames',
6120: 'id' => 'IDs',
6121: );
1.160.6.93 raeburn 6122: unless ($type eq 'email') {
6123: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6124: $output = '<tr '.$css_class.'>'.
6125: '<td><span class="LC_nobreak">'.
6126: &mt("Format rules to check for $text{$type}: ").
6127: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 6128: }
1.27 raeburn 6129: my $rem;
6130: if (ref($ruleorder) eq 'ARRAY') {
6131: for (my $i=0; $i<@{$ruleorder}; $i++) {
6132: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
6133: my $rem = $i%($numinrow);
6134: if ($rem == 0) {
6135: if ($i > 0) {
6136: $output .= '</tr>';
6137: }
6138: $output .= '<tr>';
6139: }
6140: my $check = ' ';
1.39 raeburn 6141: if (ref($settings) eq 'HASH') {
6142: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
6143: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
6144: $check = ' checked="checked" ';
6145: }
1.160.6.93 raeburn 6146: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
6147: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
6148: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
6149: $check = ' checked="checked" ';
6150: }
6151: }
1.27 raeburn 6152: }
6153: }
1.160.6.93 raeburn 6154: my $name = $type.'_rule';
6155: if ($type eq 'email') {
6156: $name .= '_'.$status;
6157: }
1.27 raeburn 6158: $output .= '<td class="LC_left_item">'.
6159: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 6160: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 6161: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
6162: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
6163: }
6164: }
6165: $rem = @{$ruleorder}%($numinrow);
6166: }
1.160.6.93 raeburn 6167: my $colsleft;
6168: if ($rem) {
6169: $colsleft = $numinrow - $rem;
6170: }
1.27 raeburn 6171: if ($colsleft > 1 ) {
6172: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6173: ' </td>';
6174: } elsif ($colsleft == 1) {
6175: $output .= '<td class="LC_left_item"> </td>';
6176: }
1.160.6.93 raeburn 6177: $output .= '</tr></table>';
6178: unless ($type eq 'email') {
6179: $output .= '</td></tr>';
6180: }
1.27 raeburn 6181: return $output;
6182: }
6183:
1.34 raeburn 6184: sub usercreation_types {
6185: my %lt = &Apache::lonlocal::texthash (
6186: author => 'When adding a co-author',
6187: course => 'When adding a user to a course',
1.100 raeburn 6188: requestcrs => 'When requesting a course',
1.34 raeburn 6189: any => 'Any',
6190: official => 'Institutional only ',
6191: unofficial => 'Non-institutional only',
6192: none => 'None',
6193: );
6194: return %lt;
1.48 raeburn 6195: }
1.34 raeburn 6196:
1.160.6.34 raeburn 6197: sub selfcreation_types {
6198: my %lt = &Apache::lonlocal::texthash (
6199: selfcreate => 'User creates own account',
6200: any => 'Any',
6201: official => 'Institutional only ',
6202: unofficial => 'Non-institutional only',
6203: email => 'E-mail address',
6204: login => 'Institutional Login',
6205: sso => 'SSO',
6206: );
6207: }
6208:
1.28 raeburn 6209: sub authtype_names {
6210: my %lt = &Apache::lonlocal::texthash(
6211: int => 'Internal',
6212: krb4 => 'Kerberos 4',
6213: krb5 => 'Kerberos 5',
6214: loc => 'Local',
6215: );
6216: return %lt;
6217: }
6218:
6219: sub context_names {
6220: my %context_title = &Apache::lonlocal::texthash(
6221: author => 'Creating users when an Author',
6222: course => 'Creating users when in a course',
6223: domain => 'Creating users when a Domain Coordinator',
6224: );
6225: return %context_title;
6226: }
6227:
1.33 raeburn 6228: sub print_usermodification {
6229: my ($position,$dom,$settings,$rowtotal) = @_;
6230: my $numinrow = 4;
6231: my ($context,$datatable,$rowcount);
6232: if ($position eq 'top') {
6233: $rowcount = 0;
6234: $context = 'author';
6235: foreach my $role ('ca','aa') {
6236: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6237: $numinrow,$rowcount);
6238: $$rowtotal ++;
6239: $rowcount ++;
6240: }
1.160.6.37 raeburn 6241: } elsif ($position eq 'bottom') {
1.33 raeburn 6242: $context = 'course';
6243: $rowcount = 0;
6244: foreach my $role ('st','ep','ta','in','cr') {
6245: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6246: $numinrow,$rowcount);
6247: $$rowtotal ++;
6248: $rowcount ++;
6249: }
6250: }
6251: return $datatable;
6252: }
6253:
1.43 raeburn 6254: sub print_defaults {
1.160.6.40 raeburn 6255: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 6256: my $rownum = 0;
1.160.6.80 raeburn 6257: my ($datatable,$css_class,$titles);
6258: unless ($position eq 'bottom') {
6259: $titles = &defaults_titles($dom);
6260: }
1.160.6.40 raeburn 6261: if ($position eq 'top') {
6262: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
6263: 'datelocale_def','portal_def');
6264: my %defaults;
6265: if (ref($settings) eq 'HASH') {
6266: %defaults = %{$settings};
1.43 raeburn 6267: } else {
1.160.6.40 raeburn 6268: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
6269: foreach my $item (@items) {
6270: $defaults{$item} = $domdefaults{$item};
6271: }
1.43 raeburn 6272: }
1.160.6.40 raeburn 6273: foreach my $item (@items) {
6274: if ($rownum%2) {
6275: $css_class = '';
6276: } else {
6277: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 6278: }
1.160.6.40 raeburn 6279: $datatable .= '<tr'.$css_class.'>'.
6280: '<td><span class="LC_nobreak">'.$titles->{$item}.
6281: '</span></td><td class="LC_right_item" colspan="3">';
6282: if ($item eq 'auth_def') {
6283: my @authtypes = ('internal','krb4','krb5','localauth');
6284: my %shortauth = (
6285: internal => 'int',
6286: krb4 => 'krb4',
6287: krb5 => 'krb5',
6288: localauth => 'loc'
6289: );
6290: my %authnames = &authtype_names();
6291: foreach my $auth (@authtypes) {
6292: my $checked = ' ';
6293: if ($defaults{$item} eq $auth) {
6294: $checked = ' checked="checked" ';
6295: }
6296: $datatable .= '<label><input type="radio" name="'.$item.
6297: '" value="'.$auth.'"'.$checked.'/>'.
6298: $authnames{$shortauth{$auth}}.'</label> ';
6299: }
6300: } elsif ($item eq 'timezone_def') {
6301: my $includeempty = 1;
6302: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
6303: } elsif ($item eq 'datelocale_def') {
1.160.6.98! raeburn 6304: my $includeempty = 1;
! 6305: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
! 6306: } elsif ($item eq 'lang_def') {
! 6307: my $includeempty = 1;
! 6308: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.80 raeburn 6309: } else {
1.160.6.98! raeburn 6310: my $size;
! 6311: if ($item eq 'portal_def') {
! 6312: $size = ' size="25"';
! 6313: }
1.160.6.80 raeburn 6314: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.98! raeburn 6315: $defaults{$item}.'"'.$size.' />';
1.160.6.80 raeburn 6316: }
6317: $datatable .= '</td></tr>';
6318: $rownum ++;
6319: }
1.160.6.40 raeburn 6320: } else {
1.160.6.80 raeburn 6321: my %defaults;
1.160.6.40 raeburn 6322: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 6323: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 6324: my $maxnum = @{$settings->{'inststatusorder'}};
6325: for (my $i=0; $i<$maxnum; $i++) {
6326: $css_class = $rownum%2?' class="LC_odd_row"':'';
6327: my $item = $settings->{'inststatusorder'}->[$i];
6328: my $title = $settings->{'inststatustypes'}->{$item};
6329: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
6330: $datatable .= '<tr'.$css_class.'>'.
6331: '<td><span class="LC_nobreak">'.
6332: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
6333: for (my $k=0; $k<=$maxnum; $k++) {
6334: my $vpos = $k+1;
6335: my $selstr;
6336: if ($k == $i) {
6337: $selstr = ' selected="selected" ';
6338: }
6339: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6340: }
6341: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
6342: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
6343: &mt('delete').'</span></td>'.
6344: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
6345: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 6346: '</span></td></tr>';
1.160.6.40 raeburn 6347: }
6348: $css_class = $rownum%2?' class="LC_odd_row"':'';
6349: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
6350: $datatable .= '<tr '.$css_class.'>'.
6351: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
6352: for (my $k=0; $k<=$maxnum; $k++) {
6353: my $vpos = $k+1;
6354: my $selstr;
6355: if ($k == $maxnum) {
6356: $selstr = ' selected="selected" ';
6357: }
6358: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6359: }
6360: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 6361: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 6362: ' '.&mt('(new)').
6363: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
6364: &mt('Name displayed:').
6365: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
6366: '</tr>'."\n";
6367: $rownum ++;
1.141 raeburn 6368: }
1.43 raeburn 6369: }
6370: }
6371: $$rowtotal += $rownum;
6372: return $datatable;
6373: }
6374:
1.160.6.5 raeburn 6375: sub get_languages_hash {
6376: my %langchoices;
6377: foreach my $id (&Apache::loncommon::languageids()) {
6378: my $code = &Apache::loncommon::supportedlanguagecode($id);
6379: if ($code ne '') {
6380: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
6381: }
6382: }
6383: return %langchoices;
6384: }
6385:
1.43 raeburn 6386: sub defaults_titles {
1.141 raeburn 6387: my ($dom) = @_;
1.43 raeburn 6388: my %titles = &Apache::lonlocal::texthash (
6389: 'auth_def' => 'Default authentication type',
6390: 'auth_arg_def' => 'Default authentication argument',
6391: 'lang_def' => 'Default language',
1.54 raeburn 6392: 'timezone_def' => 'Default timezone',
1.68 raeburn 6393: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 6394: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 6395: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
6396: 'intauth_check' => 'Check bcrypt cost if authenticated',
6397: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 6398: );
1.141 raeburn 6399: if ($dom) {
6400: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
6401: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
6402: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
6403: $protocol = 'http' if ($protocol ne 'https');
6404: if ($uint_dom) {
6405: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
6406: $uint_dom);
6407: }
6408: }
1.43 raeburn 6409: return (\%titles);
6410: }
6411:
1.160.6.97 raeburn 6412: sub print_scantron {
6413: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
6414: if ($position eq 'top') {
6415: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
6416: } else {
6417: return &print_scantronconfig($dom,$settings,\$rowtotal);
6418: }
6419: }
6420:
6421: sub scantron_javascript {
6422: return <<"ENDSCRIPT";
6423:
6424: <script type="text/javascript">
6425: // <![CDATA[
6426:
6427: function toggleScantron(form) {
6428: var csvfieldset = new Array();
6429: if (document.getElementById('scantroncsv_cols')) {
6430: csvfieldset.push(document.getElementById('scantroncsv_cols'));
6431: }
6432: if (document.getElementById('scantroncsv_options')) {
6433: csvfieldset.push(document.getElementById('scantroncsv_options'));
6434: }
6435: if (csvfieldset.length) {
6436: if (document.getElementById('scantronconfcsv')) {
6437: var scantroncsv = document.getElementById('scantronconfcsv');
6438: if (scantroncsv.checked) {
6439: for (var i=0; i<csvfieldset.length; i++) {
6440: csvfieldset[i].style.display = 'block';
6441: }
6442: } else {
6443: for (var i=0; i<csvfieldset.length; i++) {
6444: csvfieldset[i].style.display = 'none';
6445: }
6446: var csvselects = document.getElementsByClassName('scantronconfig_csv');
6447: if (csvselects.length) {
6448: for (var j=0; j<csvselects.length; j++) {
6449: csvselects[j].selectedIndex = 0;
6450: }
6451: }
6452: }
6453: }
6454: }
6455: return;
6456: }
6457: // ]]>
6458: </script>
6459:
6460: ENDSCRIPT
6461:
6462: }
6463:
1.46 raeburn 6464: sub print_scantronformat {
6465: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
6466: my $itemcount = 1;
1.60 raeburn 6467: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
6468: %confhash);
1.46 raeburn 6469: my $switchserver = &check_switchserver($dom,$confname);
6470: my %lt = &Apache::lonlocal::texthash (
1.95 www 6471: default => 'Default bubblesheet format file error',
6472: custom => 'Custom bubblesheet format file error',
1.46 raeburn 6473: );
6474: my %scantronfiles = (
6475: default => 'default.tab',
6476: custom => 'custom.tab',
6477: );
6478: foreach my $key (keys(%scantronfiles)) {
6479: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
6480: .$scantronfiles{$key};
6481: }
6482: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
6483: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
6484: if (!$switchserver) {
6485: my $servadm = $r->dir_config('lonAdmEMail');
6486: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
6487: if ($configuserok eq 'ok') {
6488: if ($author_ok eq 'ok') {
6489: my %legacyfile = (
1.160.6.97 raeburn 6490: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
6491: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 6492: );
6493: my %md5chk;
6494: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6495: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
6496: chomp($md5chk{$type});
1.46 raeburn 6497: }
6498: if ($md5chk{'default'} ne $md5chk{'custom'}) {
6499: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 6500: ($scantronurls{$type},my $error) =
1.46 raeburn 6501: &legacy_scantronformat($r,$dom,$confname,
6502: $type,$legacyfile{$type},
6503: $scantronurls{$type},
6504: $scantronfiles{$type});
1.60 raeburn 6505: if ($error ne '') {
6506: $error{$type} = $error;
6507: }
6508: }
6509: if (keys(%error) == 0) {
6510: $is_custom = 1;
1.160.6.97 raeburn 6511: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 6512: $scantronurls{'custom'};
1.160.6.97 raeburn 6513: my $putresult =
1.60 raeburn 6514: &Apache::lonnet::put_dom('configuration',
6515: \%confhash,$dom);
6516: if ($putresult ne 'ok') {
1.160.6.97 raeburn 6517: $error{'custom'} =
1.60 raeburn 6518: '<span class="LC_error">'.
6519: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6520: }
1.46 raeburn 6521: }
6522: } else {
1.60 raeburn 6523: ($scantronurls{'default'},my $error) =
1.46 raeburn 6524: &legacy_scantronformat($r,$dom,$confname,
6525: 'default',$legacyfile{'default'},
6526: $scantronurls{'default'},
6527: $scantronfiles{'default'});
1.60 raeburn 6528: if ($error eq '') {
6529: $confhash{'scantron'}{'scantronformat'} = '';
6530: my $putresult =
6531: &Apache::lonnet::put_dom('configuration',
6532: \%confhash,$dom);
6533: if ($putresult ne 'ok') {
6534: $error{'default'} =
6535: '<span class="LC_error">'.
6536: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6537: }
6538: } else {
6539: $error{'default'} = $error;
6540: }
1.46 raeburn 6541: }
6542: }
6543: }
6544: } else {
1.95 www 6545: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 6546: }
6547: }
6548: if (ref($settings) eq 'HASH') {
6549: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
6550: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
6551: if ((!@info) || ($info[0] eq 'no_such_dir')) {
6552: $scantronurl = '';
6553: } else {
6554: $scantronurl = $settings->{'scantronformat'};
6555: }
6556: $is_custom = 1;
6557: } else {
6558: $scantronurl = $scantronurls{'default'};
6559: }
6560: } else {
1.60 raeburn 6561: if ($is_custom) {
6562: $scantronurl = $scantronurls{'custom'};
6563: } else {
6564: $scantronurl = $scantronurls{'default'};
6565: }
1.46 raeburn 6566: }
6567: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6568: $datatable .= '<tr'.$css_class.'>';
6569: if (!$is_custom) {
1.65 raeburn 6570: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
6571: '<span class="LC_nobreak">';
1.46 raeburn 6572: if ($scantronurl) {
1.160.6.21 raeburn 6573: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
6574: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 6575: } else {
6576: $datatable = &mt('File unavailable for display');
6577: }
1.65 raeburn 6578: $datatable .= '</span></td>';
1.60 raeburn 6579: if (keys(%error) == 0) {
6580: $datatable .= '<td valign="bottom">';
6581: if (!$switchserver) {
6582: $datatable .= &mt('Upload:').'<br />';
6583: }
6584: } else {
6585: my $errorstr;
6586: foreach my $key (sort(keys(%error))) {
6587: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6588: }
6589: $datatable .= '<td>'.$errorstr;
6590: }
1.46 raeburn 6591: } else {
6592: if (keys(%error) > 0) {
6593: my $errorstr;
6594: foreach my $key (sort(keys(%error))) {
6595: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6596: }
1.60 raeburn 6597: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 6598: } elsif ($scantronurl) {
1.160.6.26 raeburn 6599: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 6600: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 6601: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 6602: $link.
6603: '<label><input type="checkbox" name="scantronformat_del"'.
6604: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 6605: '<td><span class="LC_nobreak"> '.
6606: &mt('Replace:').'</span><br />';
1.46 raeburn 6607: }
6608: }
6609: if (keys(%error) == 0) {
6610: if ($switchserver) {
6611: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6612: } else {
1.65 raeburn 6613: $datatable .='<span class="LC_nobreak"> '.
6614: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 6615: }
6616: }
6617: $datatable .= '</td></tr>';
6618: $$rowtotal ++;
6619: return $datatable;
6620: }
6621:
6622: sub legacy_scantronformat {
6623: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
6624: my ($url,$error);
6625: my @statinfo = &Apache::lonnet::stat_file($newurl);
6626: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
6627: (my $result,$url) =
6628: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
6629: '','',$newfile);
6630: if ($result ne 'ok') {
1.130 raeburn 6631: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 6632: }
6633: }
6634: return ($url,$error);
6635: }
1.43 raeburn 6636:
1.160.6.97 raeburn 6637: sub print_scantronconfig {
6638: my ($dom,$settings,$rowtotal) = @_;
6639: my $itemcount = 2;
6640: my $is_checked = ' checked="checked"';
6641: my %optionson = (
6642: hdr => ' checked="checked"',
6643: pad => ' checked="checked"',
6644: rem => ' checked="checked"',
6645: );
6646: my %optionsoff = (
6647: hdr => '',
6648: pad => '',
6649: rem => '',
6650: );
6651: my $currcsvsty = 'none';
6652: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
6653: my @fields = &scantroncsv_fields();
6654: my %titles = &scantronconfig_titles();
6655: if (ref($settings) eq 'HASH') {
6656: if (ref($settings->{config}) eq 'HASH') {
6657: if ($settings->{config}->{dat}) {
6658: $checked{'dat'} = $is_checked;
6659: }
6660: if (ref($settings->{config}->{csv}) eq 'HASH') {
6661: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
6662: %csvfields = %{$settings->{config}->{csv}->{fields}};
6663: if (keys(%csvfields) > 0) {
6664: $checked{'csv'} = $is_checked;
6665: $currcsvsty = 'block';
6666: }
6667: }
6668: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
6669: %csvoptions = %{$settings->{config}->{csv}->{options}};
6670: foreach my $option (keys(%optionson)) {
6671: unless ($csvoptions{$option}) {
6672: $optionsoff{$option} = $optionson{$option};
6673: $optionson{$option} = '';
6674: }
6675: }
6676: }
6677: }
6678: } else {
6679: $checked{'dat'} = $is_checked;
6680: }
6681: } else {
6682: $checked{'dat'} = $is_checked;
6683: }
6684: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
6685: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6686: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
6687: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
6688: foreach my $item ('dat','csv') {
6689: my $id;
6690: if ($item eq 'csv') {
6691: $id = 'id="scantronconfcsv" ';
6692: }
6693: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
6694: $titles{$item}.'</label>'.(' 'x3);
6695: if ($item eq 'csv') {
6696: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
6697: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
6698: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
6699: foreach my $col (@fields) {
6700: my $selnone;
6701: if ($csvfields{$col} eq '') {
6702: $selnone = ' selected="selected"';
6703: }
6704: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
6705: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
6706: '<option value=""'.$selnone.'></option>';
6707: for (my $i=0; $i<20; $i++) {
6708: my $shown = $i+1;
6709: my $sel;
6710: unless ($selnone) {
6711: if (exists($csvfields{$col})) {
6712: if ($csvfields{$col} == $i) {
6713: $sel = ' selected="selected"';
6714: }
6715: }
6716: }
6717: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
6718: }
6719: $datatable .= '</select></td></tr>';
6720: }
6721: $datatable .= '</table></fieldset>'.
6722: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
6723: '<legend>'.&mt('CSV Options').'</legend>';
6724: foreach my $option ('hdr','pad','rem') {
6725: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
6726: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
6727: &mt('Yes').'</label>'.(' 'x2)."\n".
6728: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
6729: }
6730: $datatable .= '</fieldset>';
6731: $itemcount ++;
6732: }
6733: }
6734: $datatable .= '</td></tr>';
6735: $$rowtotal ++;
6736: return $datatable;
6737: }
6738:
6739: sub scantronconfig_titles {
6740: return &Apache::lonlocal::texthash(
6741: dat => 'Standard format (.dat)',
6742: csv => 'Comma separated values (.csv)',
6743: hdr => 'Remove first line in file (contains column titles)',
6744: pad => 'Prepend 0s to PaperID',
6745: rem => 'Remove leading spaces (except Question Response columns)',
6746: CODE => 'CODE',
6747: ID => 'Student ID',
6748: PaperID => 'Paper ID',
6749: FirstName => 'First Name',
6750: LastName => 'Last Name',
6751: FirstQuestion => 'First Question Response',
6752: Section => 'Section',
6753: );
6754: }
6755:
6756: sub scantroncsv_fields {
6757: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
6758: }
6759:
1.49 raeburn 6760: sub print_coursecategories {
1.57 raeburn 6761: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
6762: my $datatable;
6763: if ($position eq 'top') {
1.160.6.42 raeburn 6764: my (%checked);
6765: my @catitems = ('unauth','auth');
6766: my @cattypes = ('std','domonly','codesrch','none');
6767: $checked{'unauth'} = 'std';
6768: $checked{'auth'} = 'std';
6769: if (ref($settings) eq 'HASH') {
6770: foreach my $type (@cattypes) {
6771: if ($type eq $settings->{'unauth'}) {
6772: $checked{'unauth'} = $type;
6773: }
6774: if ($type eq $settings->{'auth'}) {
6775: $checked{'auth'} = $type;
6776: }
6777: }
6778: }
6779: my %lt = &Apache::lonlocal::texthash (
6780: unauth => 'Catalog type for unauthenticated users',
6781: auth => 'Catalog type for authenticated users',
6782: none => 'No catalog',
6783: std => 'Standard catalog',
6784: domonly => 'Domain-only catalog',
6785: codesrch => "Code search form",
6786: );
6787: my $itemcount = 0;
6788: foreach my $item (@catitems) {
6789: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6790: $datatable .= '<tr '.$css_class.'>'.
6791: '<td>'.$lt{$item}.'</td>'.
6792: '<td class="LC_right_item"><span class="LC_nobreak">';
6793: foreach my $type (@cattypes) {
6794: my $ischecked;
6795: if ($checked{$item} eq $type) {
6796: $ischecked=' checked="checked"';
6797: }
6798: $datatable .= '<label>'.
6799: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
6800: ' />'.$lt{$type}.'</label> ';
6801: }
1.160.6.87 raeburn 6802: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 6803: $itemcount ++;
6804: }
6805: $$rowtotal += $itemcount;
6806: } elsif ($position eq 'middle') {
1.57 raeburn 6807: my $toggle_cats_crs = ' ';
6808: my $toggle_cats_dom = ' checked="checked" ';
6809: my $can_cat_crs = ' ';
6810: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 6811: my $toggle_catscomm_comm = ' ';
6812: my $toggle_catscomm_dom = ' checked="checked" ';
6813: my $can_catcomm_comm = ' ';
6814: my $can_catcomm_dom = ' checked="checked" ';
6815:
1.57 raeburn 6816: if (ref($settings) eq 'HASH') {
6817: if ($settings->{'togglecats'} eq 'crs') {
6818: $toggle_cats_crs = $toggle_cats_dom;
6819: $toggle_cats_dom = ' ';
6820: }
6821: if ($settings->{'categorize'} eq 'crs') {
6822: $can_cat_crs = $can_cat_dom;
6823: $can_cat_dom = ' ';
6824: }
1.120 raeburn 6825: if ($settings->{'togglecatscomm'} eq 'comm') {
6826: $toggle_catscomm_comm = $toggle_catscomm_dom;
6827: $toggle_catscomm_dom = ' ';
6828: }
6829: if ($settings->{'categorizecomm'} eq 'comm') {
6830: $can_catcomm_comm = $can_catcomm_dom;
6831: $can_catcomm_dom = ' ';
6832: }
1.57 raeburn 6833: }
6834: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 6835: togglecats => 'Show/Hide a course in catalog',
6836: togglecatscomm => 'Show/Hide a community in catalog',
6837: categorize => 'Assign a category to a course',
6838: categorizecomm => 'Assign a category to a community',
1.57 raeburn 6839: );
6840: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 6841: dom => 'Set in Domain',
6842: crs => 'Set in Course',
6843: comm => 'Set in Community',
1.57 raeburn 6844: );
6845: $datatable = '<tr class="LC_odd_row">'.
6846: '<td>'.$title{'togglecats'}.'</td>'.
6847: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6848: '<input type="radio" name="togglecats"'.
6849: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6850: '<label><input type="radio" name="togglecats"'.
6851: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
6852: '</tr><tr>'.
6853: '<td>'.$title{'categorize'}.'</td>'.
6854: '<td class="LC_right_item"><span class="LC_nobreak">'.
6855: '<label><input type="radio" name="categorize"'.
6856: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6857: '<label><input type="radio" name="categorize"'.
6858: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 6859: '</tr><tr class="LC_odd_row">'.
6860: '<td>'.$title{'togglecatscomm'}.'</td>'.
6861: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6862: '<input type="radio" name="togglecatscomm"'.
6863: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6864: '<label><input type="radio" name="togglecatscomm"'.
6865: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
6866: '</tr><tr>'.
6867: '<td>'.$title{'categorizecomm'}.'</td>'.
6868: '<td class="LC_right_item"><span class="LC_nobreak">'.
6869: '<label><input type="radio" name="categorizecomm"'.
6870: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6871: '<label><input type="radio" name="categorizecomm"'.
6872: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 6873: '</tr>';
1.120 raeburn 6874: $$rowtotal += 4;
1.57 raeburn 6875: } else {
6876: my $css_class;
6877: my $itemcount = 1;
6878: my $cathash;
6879: if (ref($settings) eq 'HASH') {
6880: $cathash = $settings->{'cats'};
6881: }
6882: if (ref($cathash) eq 'HASH') {
6883: my (@cats,@trails,%allitems,%idx,@jsarray);
6884: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
6885: \%allitems,\%idx,\@jsarray);
6886: my $maxdepth = scalar(@cats);
6887: my $colattrib = '';
6888: if ($maxdepth > 2) {
6889: $colattrib = ' colspan="2" ';
6890: }
6891: my @path;
6892: if (@cats > 0) {
6893: if (ref($cats[0]) eq 'ARRAY') {
6894: my $numtop = @{$cats[0]};
6895: my $maxnum = $numtop;
1.120 raeburn 6896: my %default_names = (
6897: instcode => &mt('Official courses'),
6898: communities => &mt('Communities'),
6899: );
6900:
6901: if ((!grep(/^instcode$/,@{$cats[0]})) ||
6902: ($cathash->{'instcode::0'} eq '') ||
6903: (!grep(/^communities$/,@{$cats[0]})) ||
6904: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 6905: $maxnum ++;
6906: }
6907: my $lastidx;
6908: for (my $i=0; $i<$numtop; $i++) {
6909: my $parent = $cats[0][$i];
6910: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6911: my $item = &escape($parent).'::0';
6912: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
6913: $lastidx = $idx{$item};
6914: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6915: .'<select name="'.$item.'"'.$chgstr.'>';
6916: for (my $k=0; $k<=$maxnum; $k++) {
6917: my $vpos = $k+1;
6918: my $selstr;
6919: if ($k == $i) {
6920: $selstr = ' selected="selected" ';
6921: }
6922: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6923: }
1.160.6.29 raeburn 6924: $datatable .= '</select></span></td><td>';
1.120 raeburn 6925: if ($parent eq 'instcode' || $parent eq 'communities') {
6926: $datatable .= '<span class="LC_nobreak">'
6927: .$default_names{$parent}.'</span>';
6928: if ($parent eq 'instcode') {
6929: $datatable .= '<br /><span class="LC_nobreak">('
6930: .&mt('with institutional codes')
6931: .')</span></td><td'.$colattrib.'>';
6932: } else {
6933: $datatable .= '<table><tr><td>';
6934: }
6935: $datatable .= '<span class="LC_nobreak">'
6936: .'<label><input type="radio" name="'
6937: .$parent.'" value="1" checked="checked" />'
6938: .&mt('Display').'</label>';
6939: if ($parent eq 'instcode') {
6940: $datatable .= ' ';
6941: } else {
6942: $datatable .= '</span></td></tr><tr><td>'
6943: .'<span class="LC_nobreak">';
6944: }
6945: $datatable .= '<label><input type="radio" name="'
6946: .$parent.'" value="0" />'
6947: .&mt('Do not display').'</label></span>';
6948: if ($parent eq 'communities') {
6949: $datatable .= '</td></tr></table>';
6950: }
6951: $datatable .= '</td>';
1.57 raeburn 6952: } else {
6953: $datatable .= $parent
1.160.6.29 raeburn 6954: .' <span class="LC_nobreak"><label>'
6955: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6956: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6957: }
6958: my $depth = 1;
6959: push(@path,$parent);
6960: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6961: pop(@path);
6962: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6963: $itemcount ++;
6964: }
1.48 raeburn 6965: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6966: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6967: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6968: for (my $k=0; $k<=$maxnum; $k++) {
6969: my $vpos = $k+1;
6970: my $selstr;
1.57 raeburn 6971: if ($k == $numtop) {
1.48 raeburn 6972: $selstr = ' selected="selected" ';
6973: }
6974: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6975: }
1.59 bisitz 6976: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6977: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6978: .'</tr>'."\n";
1.48 raeburn 6979: $itemcount ++;
1.120 raeburn 6980: foreach my $default ('instcode','communities') {
6981: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6982: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6983: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6984: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6985: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6986: for (my $k=0; $k<=$maxnum; $k++) {
6987: my $vpos = $k+1;
6988: my $selstr;
6989: if ($k == $maxnum) {
6990: $selstr = ' selected="selected" ';
6991: }
6992: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6993: }
1.120 raeburn 6994: $datatable .= '</select></span></td>'.
6995: '<td><span class="LC_nobreak">'.
6996: $default_names{$default}.'</span>';
6997: if ($default eq 'instcode') {
6998: $datatable .= '<br /><span class="LC_nobreak">('
6999: .&mt('with institutional codes').')</span>';
7000: }
7001: $datatable .= '</td>'
7002: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
7003: .&mt('Display').'</label> '
7004: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
7005: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 7006: }
7007: }
7008: }
1.57 raeburn 7009: } else {
7010: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 7011: }
7012: } else {
1.160.6.87 raeburn 7013: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 7014: .&initialize_categories($itemcount);
1.48 raeburn 7015: }
1.57 raeburn 7016: $$rowtotal += $itemcount;
1.48 raeburn 7017: }
7018: return $datatable;
7019: }
7020:
1.69 raeburn 7021: sub print_serverstatuses {
7022: my ($dom,$settings,$rowtotal) = @_;
7023: my $datatable;
7024: my @pages = &serverstatus_pages();
7025: my (%namedaccess,%machineaccess);
7026: foreach my $type (@pages) {
7027: $namedaccess{$type} = '';
7028: $machineaccess{$type}= '';
7029: }
7030: if (ref($settings) eq 'HASH') {
7031: foreach my $type (@pages) {
7032: if (exists($settings->{$type})) {
7033: if (ref($settings->{$type}) eq 'HASH') {
7034: foreach my $key (keys(%{$settings->{$type}})) {
7035: if ($key eq 'namedusers') {
7036: $namedaccess{$type} = $settings->{$type}->{$key};
7037: } elsif ($key eq 'machines') {
7038: $machineaccess{$type} = $settings->{$type}->{$key};
7039: }
7040: }
7041: }
7042: }
7043: }
7044: }
1.81 raeburn 7045: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7046: my $rownum = 0;
7047: my $css_class;
7048: foreach my $type (@pages) {
7049: $rownum ++;
7050: $css_class = $rownum%2?' class="LC_odd_row"':'';
7051: $datatable .= '<tr'.$css_class.'>'.
7052: '<td><span class="LC_nobreak">'.
7053: $titles->{$type}.'</span></td>'.
7054: '<td class="LC_left_item">'.
7055: '<input type="text" name="'.$type.'_namedusers" '.
7056: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
7057: '<td class="LC_right_item">'.
7058: '<span class="LC_nobreak">'.
7059: '<input type="text" name="'.$type.'_machines" '.
7060: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 7061: '</span></td></tr>'."\n";
1.69 raeburn 7062: }
7063: $$rowtotal += $rownum;
7064: return $datatable;
7065: }
7066:
7067: sub serverstatus_pages {
7068: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 7069: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 7070: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 7071: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 7072: }
7073:
1.160.6.40 raeburn 7074: sub defaults_javascript {
7075: my ($settings) = @_;
1.160.6.98! raeburn 7076: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 7077: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
7078: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
7079: if ($maxnum eq '') {
7080: $maxnum = 0;
7081: }
7082: $maxnum ++;
1.160.6.51 raeburn 7083: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 7084: return <<"ENDSCRIPT";
7085: <script type="text/javascript">
7086: // <![CDATA[
7087: function reorderTypes(form,caller) {
7088: var changedVal;
7089: $jstext
7090: var newpos = 'addinststatus_pos';
7091: var current = new Array;
7092: var maxh = $maxnum;
7093: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7094: var oldVal;
7095: if (caller == newpos) {
7096: changedVal = newitemVal;
7097: } else {
7098: var curritem = 'inststatus_pos_'+caller;
7099: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
7100: current[newitemVal] = newpos;
7101: }
7102: for (var i=0; i<inststatuses.length; i++) {
7103: if (inststatuses[i] != caller) {
7104: var elementName = 'inststatus_pos_'+inststatuses[i];
7105: if (form.elements[elementName]) {
7106: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7107: current[currVal] = elementName;
7108: }
7109: }
7110: }
7111: for (var j=0; j<maxh; j++) {
7112: if (current[j] == undefined) {
7113: oldVal = j;
7114: }
7115: }
7116: if (oldVal < changedVal) {
7117: for (var k=oldVal+1; k<=changedVal ; k++) {
7118: var elementName = current[k];
7119: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7120: }
7121: } else {
7122: for (var k=changedVal; k<oldVal; k++) {
7123: var elementName = current[k];
7124: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7125: }
7126: }
7127: return;
7128: }
7129:
7130: // ]]>
7131: </script>
7132:
7133: ENDSCRIPT
7134: }
7135: }
7136:
1.160.6.98! raeburn 7137: sub passwords_javascript {
! 7138: my $intauthcheck = &mt('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.');
! 7139: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
! 7140: &js_escape(\$intauthcheck);
! 7141: &js_escape(\$intauthcost);
! 7142: my $intauthjs = <<"ENDSCRIPT";
! 7143:
! 7144: function warnIntAuth(field) {
! 7145: if (field.name == 'intauth_check') {
! 7146: if (field.value == '2') {
! 7147: alert('$intauthcheck');
! 7148: }
! 7149: }
! 7150: if (field.name == 'intauth_cost') {
! 7151: field.value.replace(/\s/g,'');
! 7152: if (field.value != '') {
! 7153: var regexdigit=/^\\d+\$/;
! 7154: if (!regexdigit.test(field.value)) {
! 7155: alert('$intauthcost');
! 7156: }
! 7157: }
! 7158: }
! 7159: return;
! 7160: }
! 7161:
! 7162: ENDSCRIPT
! 7163: return &Apache::lonhtmlcommon::scripttag($intauthjs);
! 7164: }
! 7165:
1.49 raeburn 7166: sub coursecategories_javascript {
7167: my ($settings) = @_;
1.57 raeburn 7168: my ($output,$jstext,$cathash);
1.49 raeburn 7169: if (ref($settings) eq 'HASH') {
1.57 raeburn 7170: $cathash = $settings->{'cats'};
7171: }
7172: if (ref($cathash) eq 'HASH') {
1.49 raeburn 7173: my (@cats,@jsarray,%idx);
1.57 raeburn 7174: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 7175: if (@jsarray > 0) {
7176: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
7177: for (my $i=0; $i<@jsarray; $i++) {
7178: if (ref($jsarray[$i]) eq 'ARRAY') {
7179: my $catstr = join('","',@{$jsarray[$i]});
7180: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
7181: }
7182: }
7183: }
7184: } else {
7185: $jstext = ' var categories = Array(1);'."\n".
7186: ' categories[0] = Array("instcode_pos");'."\n";
7187: }
1.160.6.42 raeburn 7188: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
7189: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 7190: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
7191: &js_escape(\$instcode_reserved);
7192: &js_escape(\$communities_reserved);
7193: &js_escape(\$choose_again);
1.49 raeburn 7194: $output = <<"ENDSCRIPT";
7195: <script type="text/javascript">
1.109 raeburn 7196: // <![CDATA[
1.49 raeburn 7197: function reorderCats(form,parent,item,idx) {
7198: var changedVal;
7199: $jstext
7200: var newpos = 'addcategory_pos';
7201: if (parent == '') {
7202: var has_instcode = 0;
7203: var maxtop = categories[idx].length;
7204: for (var j=0; j<maxtop; j++) {
7205: if (categories[idx][j] == 'instcode::0') {
7206: has_instcode == 1;
7207: }
7208: }
7209: if (has_instcode == 0) {
7210: categories[idx][maxtop] = 'instcode_pos';
7211: }
7212: } else {
7213: newpos += '_'+parent;
7214: }
7215: var maxh = 1 + categories[idx].length;
7216: var current = new Array;
7217: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7218: if (item == newpos) {
7219: changedVal = newitemVal;
7220: } else {
7221: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
7222: current[newitemVal] = newpos;
7223: }
7224: for (var i=0; i<categories[idx].length; i++) {
7225: var elementName = categories[idx][i];
7226: if (elementName != item) {
7227: if (form.elements[elementName]) {
7228: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7229: current[currVal] = elementName;
7230: }
7231: }
7232: }
7233: var oldVal;
7234: for (var j=0; j<maxh; j++) {
7235: if (current[j] == undefined) {
7236: oldVal = j;
7237: }
7238: }
7239: if (oldVal < changedVal) {
7240: for (var k=oldVal+1; k<=changedVal ; k++) {
7241: var elementName = current[k];
7242: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7243: }
7244: } else {
7245: for (var k=changedVal; k<oldVal; k++) {
7246: var elementName = current[k];
7247: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7248: }
7249: }
7250: return;
7251: }
1.120 raeburn 7252:
7253: function categoryCheck(form) {
7254: if (form.elements['addcategory_name'].value == 'instcode') {
7255: alert('$instcode_reserved\\n$choose_again');
7256: return false;
7257: }
7258: if (form.elements['addcategory_name'].value == 'communities') {
7259: alert('$communities_reserved\\n$choose_again');
7260: return false;
7261: }
7262: return true;
7263: }
7264:
1.109 raeburn 7265: // ]]>
1.49 raeburn 7266: </script>
7267:
7268: ENDSCRIPT
7269: return $output;
7270: }
7271:
1.48 raeburn 7272: sub initialize_categories {
7273: my ($itemcount) = @_;
1.120 raeburn 7274: my ($datatable,$css_class,$chgstr);
7275: my %default_names = (
7276: instcode => 'Official courses (with institutional codes)',
7277: communities => 'Communities',
7278: );
7279: my $select0 = ' selected="selected"';
7280: my $select1 = '';
7281: foreach my $default ('instcode','communities') {
7282: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 7283: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 7284: if ($default eq 'communities') {
7285: $select1 = $select0;
7286: $select0 = '';
7287: }
7288: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7289: .'<select name="'.$default.'_pos">'
7290: .'<option value="0"'.$select0.'>1</option>'
7291: .'<option value="1"'.$select1.'>2</option>'
7292: .'<option value="2">3</option></select> '
7293: .$default_names{$default}
7294: .'</span></td><td><span class="LC_nobreak">'
7295: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
7296: .&mt('Display').'</label> <label>'
7297: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 7298: .'</label></span></td></tr>';
1.120 raeburn 7299: $itemcount ++;
7300: }
1.48 raeburn 7301: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 7302: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 7303: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 7304: .'<select name="addcategory_pos"'.$chgstr.'>'
7305: .'<option value="0">1</option>'
7306: .'<option value="1">2</option>'
7307: .'<option value="2" selected="selected">3</option></select> '
1.160.6.87 raeburn 7308: .&mt('Add category').'</span></td><tda<span class="LC_nobreak">>'.&mt('Name:')
7309: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
7310: .'</td></tr>';
1.48 raeburn 7311: return $datatable;
7312: }
7313:
7314: sub build_category_rows {
1.49 raeburn 7315: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
7316: my ($text,$name,$item,$chgstr);
1.48 raeburn 7317: if (ref($cats) eq 'ARRAY') {
7318: my $maxdepth = scalar(@{$cats});
7319: if (ref($cats->[$depth]) eq 'HASH') {
7320: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
7321: my $numchildren = @{$cats->[$depth]{$parent}};
7322: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 7323: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 7324: my ($idxnum,$parent_name,$parent_item);
7325: my $higher = $depth - 1;
7326: if ($higher == 0) {
7327: $parent_name = &escape($parent).'::'.$higher;
7328: } else {
7329: if (ref($path) eq 'ARRAY') {
7330: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7331: }
7332: }
7333: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 7334: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 7335: if ($j < $numchildren) {
1.48 raeburn 7336: $name = $cats->[$depth]{$parent}[$j];
7337: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 7338: $idxnum = $idx->{$item};
7339: } else {
7340: $name = $parent_name;
7341: $item = $parent_item;
1.48 raeburn 7342: }
1.49 raeburn 7343: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
7344: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 7345: for (my $i=0; $i<=$numchildren; $i++) {
7346: my $vpos = $i+1;
7347: my $selstr;
7348: if ($j == $i) {
7349: $selstr = ' selected="selected" ';
7350: }
7351: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
7352: }
7353: $text .= '</select> ';
7354: if ($j < $numchildren) {
7355: my $deeper = $depth+1;
7356: $text .= $name.' '
7357: .'<label><input type="checkbox" name="deletecategory" value="'
7358: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
7359: if(ref($path) eq 'ARRAY') {
7360: push(@{$path},$name);
1.49 raeburn 7361: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 7362: pop(@{$path});
7363: }
7364: } else {
1.160.6.87 raeburn 7365: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 7366: if ($j == $numchildren) {
7367: $text .= $name;
7368: } else {
7369: $text .= $item;
7370: }
7371: $text .= '" value="" />';
7372: }
7373: $text .= '</td></tr>';
7374: }
7375: $text .= '</table></td>';
7376: } else {
7377: my $higher = $depth-1;
7378: if ($higher == 0) {
7379: $name = &escape($parent).'::'.$higher;
7380: } else {
7381: if (ref($path) eq 'ARRAY') {
7382: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7383: }
7384: }
7385: my $colspan;
7386: if ($parent ne 'instcode') {
7387: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 7388: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 7389: }
7390: }
7391: }
7392: }
7393: return $text;
7394: }
7395:
1.33 raeburn 7396: sub modifiable_userdata_row {
1.160.6.93 raeburn 7397: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
7398: $rowid,$customcss,$rowstyle) = @_;
1.160.6.35 raeburn 7399: my ($role,$rolename,$statustype);
7400: $role = $item;
1.160.6.34 raeburn 7401: if ($context eq 'cancreate') {
1.160.6.93 raeburn 7402: if ($item =~ /^(emailusername)_(.+)$/) {
7403: $role = $1;
7404: $statustype = $2;
1.160.6.35 raeburn 7405: if (ref($usertypes) eq 'HASH') {
7406: if ($usertypes->{$statustype}) {
7407: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
7408: } else {
7409: $rolename = &mt('Data provided by user');
7410: }
7411: }
1.160.6.34 raeburn 7412: }
7413: } elsif ($context eq 'selfcreate') {
1.63 raeburn 7414: if (ref($usertypes) eq 'HASH') {
7415: $rolename = $usertypes->{$role};
7416: } else {
7417: $rolename = $role;
7418: }
1.33 raeburn 7419: } else {
1.63 raeburn 7420: if ($role eq 'cr') {
7421: $rolename = &mt('Custom role');
7422: } else {
7423: $rolename = &Apache::lonnet::plaintext($role);
7424: }
1.33 raeburn 7425: }
1.160.6.34 raeburn 7426: my (@fields,%fieldtitles);
7427: if (ref($fieldsref) eq 'ARRAY') {
7428: @fields = @{$fieldsref};
7429: } else {
7430: @fields = ('lastname','firstname','middlename','generation',
7431: 'permanentemail','id');
7432: }
7433: if ((ref($titlesref) eq 'HASH')) {
7434: %fieldtitles = %{$titlesref};
7435: } else {
7436: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7437: }
1.33 raeburn 7438: my $output;
1.160.6.93 raeburn 7439: my $css_class;
7440: if ($rowcount%2) {
7441: $css_class = 'LC_odd_row';
7442: }
7443: if ($customcss) {
7444: $css_class .= " $customcss";
7445: }
7446: $css_class =~ s/^\s+//;
7447: if ($css_class) {
7448: $css_class = ' class="'.$css_class.'"';
7449: }
7450: if ($rowstyle) {
7451: $css_class .= ' style="'.$rowstyle.'"';
7452: }
7453: if ($rowid) {
7454: $rowid = ' id="'.$rowid.'"';
7455: }
7456:
7457: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 7458: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
7459: '<td class="LC_left_item" colspan="2"><table>';
7460: my $rem;
7461: my %checks;
7462: if (ref($settings) eq 'HASH') {
7463: if (ref($settings->{$context}) eq 'HASH') {
7464: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 7465: my $hashref = $settings->{$context}->{$role};
7466: if ($role eq 'emailusername') {
7467: if ($statustype) {
7468: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
7469: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 7470: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 7471: foreach my $field (@fields) {
7472: if ($hashref->{$field}) {
7473: $checks{$field} = $hashref->{$field};
7474: }
7475: }
7476: }
7477: }
7478: }
7479: } else {
7480: if (ref($hashref) eq 'HASH') {
7481: foreach my $field (@fields) {
7482: if ($hashref->{$field}) {
7483: $checks{$field} = ' checked="checked" ';
7484: }
7485: }
1.33 raeburn 7486: }
7487: }
7488: }
7489: }
7490: }
1.160.6.93 raeburn 7491:
7492: my $total = scalar(@fields);
7493: for (my $i=0; $i<$total; $i++) {
7494: $rem = $i%($numinrow);
1.33 raeburn 7495: if ($rem == 0) {
7496: if ($i > 0) {
7497: $output .= '</tr>';
7498: }
7499: $output .= '<tr>';
7500: }
7501: my $check = ' ';
1.160.6.35 raeburn 7502: unless ($role eq 'emailusername') {
7503: if (exists($checks{$fields[$i]})) {
1.160.6.98! raeburn 7504: $check = $checks{$fields[$i]};
1.160.6.35 raeburn 7505: } else {
7506: if ($role eq 'st') {
7507: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 7508: $check = ' checked="checked" ';
1.160.6.35 raeburn 7509: }
1.33 raeburn 7510: }
7511: }
7512: }
7513: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 7514: '<span class="LC_nobreak">';
7515: if ($role eq 'emailusername') {
7516: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
7517: $checks{$fields[$i]} = 'omit';
7518: }
7519: foreach my $option ('required','optional','omit') {
7520: my $checked='';
7521: if ($checks{$fields[$i]} eq $option) {
7522: $checked='checked="checked" ';
7523: }
7524: $output .= '<label>'.
7525: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
7526: &mt($option).'</label>'.(' ' x2);
7527: }
7528: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
7529: } else {
7530: $output .= '<label>'.
7531: '<input type="checkbox" name="canmodify_'.$role.'" '.
7532: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
7533: '</label>';
7534: }
7535: $output .= '</span></td>';
1.33 raeburn 7536: }
1.160.6.93 raeburn 7537: $rem = $total%$numinrow;
7538: my $colsleft;
7539: if ($rem) {
7540: $colsleft = $numinrow - $rem;
7541: }
7542: if ($colsleft > 1) {
1.33 raeburn 7543: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7544: ' </td>';
7545: } elsif ($colsleft == 1) {
7546: $output .= '<td class="LC_left_item"> </td>';
7547: }
7548: $output .= '</tr></table></td></tr>';
7549: return $output;
7550: }
1.28 raeburn 7551:
1.93 raeburn 7552: sub insttypes_row {
1.160.6.93 raeburn 7553: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
7554: $customcss,$rowstyle) = @_;
1.93 raeburn 7555: my %lt = &Apache::lonlocal::texthash (
7556: cansearch => 'Users allowed to search',
7557: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 7558: lockablenames => 'User preference to lock name',
1.160.6.93 raeburn 7559: selfassign => 'Self-reportable affiliations',
1.93 raeburn 7560: );
7561: my $showdom;
7562: if ($context eq 'cansearch') {
7563: $showdom = ' ('.$dom.')';
7564: }
1.160.6.5 raeburn 7565: my $class = 'LC_left_item';
7566: if ($context eq 'statustocreate') {
7567: $class = 'LC_right_item';
7568: }
1.160.6.93 raeburn 7569: my $css_class;
7570: if ($$rowtotal%2) {
7571: $css_class = 'LC_odd_row';
7572: }
7573: if ($customcss) {
7574: $css_class .= ' '.$customcss;
7575: }
7576: $css_class =~ s/^\s+//;
7577: if ($css_class) {
7578: $css_class = ' class="'.$css_class.'"';
7579: }
7580: if ($rowstyle) {
7581: $css_class .= ' style="'.$rowstyle.'"';
7582: }
7583: if ($onclick) {
7584: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 7585: }
7586: my $output = '<tr'.$css_class.'>'.
7587: '<td>'.$lt{$context}.$showdom.
7588: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 7589: my $rem;
7590: if (ref($types) eq 'ARRAY') {
7591: for (my $i=0; $i<@{$types}; $i++) {
7592: if (defined($usertypes->{$types->[$i]})) {
7593: my $rem = $i%($numinrow);
7594: if ($rem == 0) {
7595: if ($i > 0) {
7596: $output .= '</tr>';
7597: }
7598: $output .= '<tr>';
1.23 raeburn 7599: }
1.26 raeburn 7600: my $check = ' ';
1.99 raeburn 7601: if (ref($settings) eq 'HASH') {
7602: if (ref($settings->{$context}) eq 'ARRAY') {
7603: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
7604: $check = ' checked="checked" ';
7605: }
7606: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7607: $check = ' checked="checked" ';
7608: }
1.23 raeburn 7609: }
1.26 raeburn 7610: $output .= '<td class="LC_left_item">'.
7611: '<span class="LC_nobreak"><label>'.
1.93 raeburn 7612: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 7613: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
1.26 raeburn 7614: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 7615: }
7616: }
1.26 raeburn 7617: $rem = @{$types}%($numinrow);
1.23 raeburn 7618: }
7619: my $colsleft = $numinrow - $rem;
1.160.6.87 raeburn 7620: if ($rem == 0) {
1.131 raeburn 7621: $output .= '<tr>';
7622: }
1.23 raeburn 7623: if ($colsleft > 1) {
1.25 raeburn 7624: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 7625: } else {
1.25 raeburn 7626: $output .= '<td class="LC_left_item">';
1.23 raeburn 7627: }
7628: my $defcheck = ' ';
1.99 raeburn 7629: if (ref($settings) eq 'HASH') {
7630: if (ref($settings->{$context}) eq 'ARRAY') {
7631: if (grep(/^default$/,@{$settings->{$context}})) {
7632: $defcheck = ' checked="checked" ';
7633: }
7634: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7635: $defcheck = ' checked="checked" ';
7636: }
1.23 raeburn 7637: }
1.25 raeburn 7638: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 7639: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 7640: 'value="default"'.$defcheck.$onclick.'/>'.
1.25 raeburn 7641: $othertitle.'</label></span></td>'.
7642: '</tr></table></td></tr>';
7643: return $output;
1.23 raeburn 7644: }
7645:
7646: sub sorted_searchtitles {
7647: my %searchtitles = &Apache::lonlocal::texthash(
7648: 'uname' => 'username',
7649: 'lastname' => 'last name',
7650: 'lastfirst' => 'last name, first name',
7651: );
7652: my @titleorder = ('uname','lastname','lastfirst');
7653: return (\%searchtitles,\@titleorder);
7654: }
7655:
1.25 raeburn 7656: sub sorted_searchtypes {
7657: my %srchtypes_desc = (
7658: exact => 'is exact match',
7659: contains => 'contains ..',
7660: begins => 'begins with ..',
7661: );
7662: my @srchtypeorder = ('exact','begins','contains');
7663: return (\%srchtypes_desc,\@srchtypeorder);
7664: }
7665:
1.3 raeburn 7666: sub usertype_update_row {
7667: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
7668: my $datatable;
7669: my $numinrow = 4;
7670: foreach my $type (@{$types}) {
7671: if (defined($usertypes->{$type})) {
7672: $$rownums ++;
7673: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
7674: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
7675: '</td><td class="LC_left_item"><table>';
7676: for (my $i=0; $i<@{$fields}; $i++) {
7677: my $rem = $i%($numinrow);
7678: if ($rem == 0) {
7679: if ($i > 0) {
7680: $datatable .= '</tr>';
7681: }
7682: $datatable .= '<tr>';
7683: }
7684: my $check = ' ';
1.39 raeburn 7685: if (ref($settings) eq 'HASH') {
7686: if (ref($settings->{'fields'}) eq 'HASH') {
7687: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
7688: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
7689: $check = ' checked="checked" ';
7690: }
1.3 raeburn 7691: }
7692: }
7693: }
7694:
7695: if ($i == @{$fields}-1) {
7696: my $colsleft = $numinrow - $rem;
7697: if ($colsleft > 1) {
7698: $datatable .= '<td colspan="'.$colsleft.'">';
7699: } else {
7700: $datatable .= '<td>';
7701: }
7702: } else {
7703: $datatable .= '<td>';
7704: }
1.8 raeburn 7705: $datatable .= '<span class="LC_nobreak"><label>'.
7706: '<input type="checkbox" name="updateable_'.$type.
7707: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
7708: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 7709: }
7710: $datatable .= '</tr></table></td></tr>';
7711: }
7712: }
7713: return $datatable;
1.1 raeburn 7714: }
7715:
7716: sub modify_login {
1.160.6.24 raeburn 7717: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 7718: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
7719: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
7720: %title = ( coursecatalog => 'Display course catalog',
7721: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 7722: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 7723: newuser => 'Link for visitors to create a user account',
7724: loginheader => 'Log-in box header');
7725: @offon = ('off','on');
1.112 raeburn 7726: if (ref($domconfig{login}) eq 'HASH') {
7727: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
7728: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
7729: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
7730: }
7731: }
7732: }
1.9 raeburn 7733: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
7734: \%domconfig,\%loginhash);
1.160.6.14 raeburn 7735: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7736: foreach my $item (@toggles) {
7737: $loginhash{login}{$item} = $env{'form.'.$item};
7738: }
1.41 raeburn 7739: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 7740: if (ref($colchanges{'login'}) eq 'HASH') {
7741: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
7742: \%loginhash);
7743: }
1.110 raeburn 7744:
1.149 raeburn 7745: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 7746: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 7747: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 7748: if (keys(%servers) > 1) {
7749: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 7750: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
7751: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
7752: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
7753: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
7754: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
7755: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7756: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7757: $changes{'loginvia'}{$lonhost} = 1;
7758: } else {
7759: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
7760: $changes{'loginvia'}{$lonhost} = 1;
7761: }
7762: } else {
7763: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7764: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7765: $changes{'loginvia'}{$lonhost} = 1;
7766: }
7767: }
7768: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
7769: foreach my $item (@loginvia_attribs) {
7770: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
7771: }
7772: } else {
7773: foreach my $item (@loginvia_attribs) {
7774: my $new = $env{'form.'.$lonhost.'_'.$item};
7775: if (($item eq 'serverpath') && ($new eq 'custom')) {
7776: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
7777: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7778: $new = '/';
7779: }
7780: }
7781: if (($item eq 'custompath') &&
7782: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7783: $new = '';
7784: }
7785: if ($new ne $curr_loginvia{$lonhost}{$item}) {
7786: $changes{'loginvia'}{$lonhost} = 1;
7787: }
7788: if ($item eq 'exempt') {
1.160.6.56 raeburn 7789: $new = &check_exempt_addresses($new);
1.128 raeburn 7790: }
7791: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7792: }
7793: }
1.112 raeburn 7794: } else {
1.128 raeburn 7795: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7796: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 7797: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 7798: foreach my $item (@loginvia_attribs) {
7799: my $new = $env{'form.'.$lonhost.'_'.$item};
7800: if (($item eq 'serverpath') && ($new eq 'custom')) {
7801: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7802: $new = '/';
7803: }
7804: }
7805: if (($item eq 'custompath') &&
7806: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7807: $new = '';
7808: }
7809: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7810: }
1.110 raeburn 7811: }
7812: }
7813: }
7814: }
1.119 raeburn 7815:
1.160.6.5 raeburn 7816: my $servadm = $r->dir_config('lonAdmEMail');
7817: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
7818: if (ref($domconfig{'login'}) eq 'HASH') {
7819: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
7820: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
7821: if ($lang eq 'nolang') {
7822: push(@currlangs,$lang);
7823: } elsif (defined($langchoices{$lang})) {
7824: push(@currlangs,$lang);
7825: } else {
7826: next;
7827: }
7828: }
7829: }
7830: }
7831: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
7832: if (@currlangs > 0) {
7833: foreach my $lang (@currlangs) {
7834: if (grep(/^\Q$lang\E$/,@delurls)) {
7835: $changes{'helpurl'}{$lang} = 1;
7836: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
7837: $changes{'helpurl'}{$lang} = 1;
7838: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
7839: push(@newlangs,$lang);
7840: } else {
7841: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7842: }
7843: }
7844: }
7845: unless (grep(/^nolang$/,@currlangs)) {
7846: if ($env{'form.loginhelpurl_nolang.filename'}) {
7847: $changes{'helpurl'}{'nolang'} = 1;
7848: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
7849: push(@newlangs,'nolang');
7850: }
7851: }
7852: if ($env{'form.loginhelpurl_add_lang'}) {
7853: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
7854: ($env{'form.loginhelpurl_add_file.filename'})) {
7855: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
7856: $addedfile = $env{'form.loginhelpurl_add_lang'};
7857: }
7858: }
7859: if ((@newlangs > 0) || ($addedfile)) {
7860: my $error;
7861: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7862: if ($configuserok eq 'ok') {
7863: if ($switchserver) {
7864: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7865: } elsif ($author_ok eq 'ok') {
7866: my @allnew = @newlangs;
7867: if ($addedfile ne '') {
7868: push(@allnew,$addedfile);
7869: }
7870: foreach my $lang (@allnew) {
7871: my $formelem = 'loginhelpurl_'.$lang;
7872: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
7873: $formelem = 'loginhelpurl_add_file';
7874: }
7875: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7876: "help/$lang",'','',$newfile{$lang});
7877: if ($result eq 'ok') {
7878: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
7879: $changes{'helpurl'}{$lang} = 1;
7880: } else {
7881: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
7882: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7883: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
7884: (!grep(/^\Q$lang\E$/,@delurls))) {
7885: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7886: }
7887: }
7888: }
7889: } else {
7890: $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);
7891: }
7892: } else {
7893: $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);
7894: }
7895: if ($error) {
7896: &Apache::lonnet::logthis($error);
7897: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7898: }
7899: }
1.160.6.56 raeburn 7900:
7901: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
7902: if (ref($domconfig{'login'}) eq 'HASH') {
7903: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
7904: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
7905: if ($domservers{$lonhost}) {
7906: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7907: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 7908: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 7909: }
7910: }
7911: }
7912: }
7913: }
7914: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
7915: foreach my $lonhost (sort(keys(%domservers))) {
7916: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7917: $changes{'headtag'}{$lonhost} = 1;
7918: } else {
7919: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
7920: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
7921: }
7922: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
7923: push(@newhosts,$lonhost);
7924: } elsif ($currheadtagurls{$lonhost}) {
7925: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
7926: if ($currexempt{$lonhost}) {
7927: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
7928: $changes{'headtag'}{$lonhost} = 1;
7929: }
7930: } elsif ($possexempt{$lonhost}) {
7931: $changes{'headtag'}{$lonhost} = 1;
7932: }
7933: if ($possexempt{$lonhost}) {
7934: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7935: }
7936: }
7937: }
7938: }
7939: if (@newhosts) {
7940: my $error;
7941: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7942: if ($configuserok eq 'ok') {
7943: if ($switchserver) {
7944: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
7945: } elsif ($author_ok eq 'ok') {
7946: foreach my $lonhost (@newhosts) {
7947: my $formelem = 'loginheadtag_'.$lonhost;
7948: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7949: "login/headtag/$lonhost",'','',
7950: $env{'form.loginheadtag_'.$lonhost.'.filename'});
7951: if ($result eq 'ok') {
7952: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
7953: $changes{'headtag'}{$lonhost} = 1;
7954: if ($possexempt{$lonhost}) {
7955: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7956: }
7957: } else {
7958: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7959: $newheadtagurls{$lonhost},$result);
7960: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7961: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7962: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7963: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7964: }
7965: }
7966: }
7967: } else {
7968: $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);
7969: }
7970: } else {
7971: $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);
7972: }
7973: if ($error) {
7974: &Apache::lonnet::logthis($error);
7975: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7976: }
7977: }
1.160.6.5 raeburn 7978: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
7979:
7980: my $defaulthelpfile = '/adm/loginproblems.html';
7981: my $defaulttext = &mt('Default in use');
7982:
1.1 raeburn 7983: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7984: $dom);
7985: if ($putresult eq 'ok') {
1.160.6.14 raeburn 7986: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7987: my %defaultchecked = (
7988: 'coursecatalog' => 'on',
1.160.6.14 raeburn 7989: 'helpdesk' => 'on',
1.42 raeburn 7990: 'adminmail' => 'off',
1.43 raeburn 7991: 'newuser' => 'off',
1.42 raeburn 7992: );
1.55 raeburn 7993: if (ref($domconfig{'login'}) eq 'HASH') {
7994: foreach my $item (@toggles) {
7995: if ($defaultchecked{$item} eq 'on') {
7996: if (($domconfig{'login'}{$item} eq '0') &&
7997: ($env{'form.'.$item} eq '1')) {
7998: $changes{$item} = 1;
7999: } elsif (($domconfig{'login'}{$item} eq '' ||
8000: $domconfig{'login'}{$item} eq '1') &&
8001: ($env{'form.'.$item} eq '0')) {
8002: $changes{$item} = 1;
8003: }
8004: } elsif ($defaultchecked{$item} eq 'off') {
8005: if (($domconfig{'login'}{$item} eq '1') &&
8006: ($env{'form.'.$item} eq '0')) {
8007: $changes{$item} = 1;
8008: } elsif (($domconfig{'login'}{$item} eq '' ||
8009: $domconfig{'login'}{$item} eq '0') &&
8010: ($env{'form.'.$item} eq '1')) {
8011: $changes{$item} = 1;
8012: }
1.42 raeburn 8013: }
8014: }
1.41 raeburn 8015: }
1.6 raeburn 8016: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 8017: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8018: if (ref($lastactref) eq 'HASH') {
8019: $lastactref->{'domainconfig'} = 1;
8020: }
1.1 raeburn 8021: $resulttext = &mt('Changes made:').'<ul>';
8022: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 8023: if ($item eq 'loginvia') {
1.112 raeburn 8024: if (ref($changes{$item}) eq 'HASH') {
8025: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
8026: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 8027: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
8028: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
8029: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
8030: $protocol = 'http' if ($protocol ne 'https');
8031: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
8032:
8033: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
8034: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
8035: } else {
8036: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
8037: }
8038: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
8039: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
8040: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
8041: }
8042: $resulttext .= '</li>';
8043: } else {
8044: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
8045: }
1.112 raeburn 8046: } else {
1.128 raeburn 8047: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 8048: }
8049: }
1.128 raeburn 8050: $resulttext .= '</ul></li>';
1.112 raeburn 8051: }
1.160.6.5 raeburn 8052: } elsif ($item eq 'helpurl') {
8053: if (ref($changes{$item}) eq 'HASH') {
8054: foreach my $lang (sort(keys(%{$changes{$item}}))) {
8055: if (grep(/^\Q$lang\E$/,@delurls)) {
8056: my ($chg,$link);
8057: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
8058: if ($lang eq 'nolang') {
8059: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
8060: } else {
8061: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
8062: }
8063: $resulttext .= '<li>'.$chg.'</li>';
8064: } else {
8065: my $chg;
8066: if ($lang eq 'nolang') {
8067: $chg = &mt('custom log-in help file for no preferred language');
8068: } else {
8069: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
8070: }
8071: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
8072: $loginhash{'login'}{'helpurl'}{$lang}.
8073: '?inhibitmenu=yes',$chg,600,500).
8074: '</li>';
8075: }
8076: }
8077: }
1.160.6.56 raeburn 8078: } elsif ($item eq 'headtag') {
8079: if (ref($changes{$item}) eq 'HASH') {
8080: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
8081: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8082: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
8083: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8084: $resulttext .= '<li><a href="'.
8085: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
8086: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
8087: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
8088: if ($possexempt{$lonhost}) {
8089: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
8090: } else {
8091: $resulttext .= &mt('included for any client IP');
8092: }
8093: $resulttext .= '</li>';
8094: }
8095: }
8096: }
1.160.6.5 raeburn 8097: } elsif ($item eq 'captcha') {
8098: if (ref($loginhash{'login'}) eq 'HASH') {
8099: my $chgtxt;
8100: if ($loginhash{'login'}{$item} eq 'notused') {
8101: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
8102: } else {
8103: my %captchas = &captcha_phrases();
8104: if ($captchas{$loginhash{'login'}{$item}}) {
8105: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
8106: } else {
8107: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
8108: }
8109: }
8110: $resulttext .= '<li>'.$chgtxt.'</li>';
8111: }
8112: } elsif ($item eq 'recaptchakeys') {
8113: if (ref($loginhash{'login'}) eq 'HASH') {
8114: my ($privkey,$pubkey);
8115: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
8116: $pubkey = $loginhash{'login'}{$item}{'public'};
8117: $privkey = $loginhash{'login'}{$item}{'private'};
8118: }
8119: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
8120: if (!$pubkey) {
8121: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
8122: } else {
8123: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8124: }
8125: if (!$privkey) {
8126: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
8127: } else {
1.160.6.53 raeburn 8128: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 8129: }
8130: $chgtxt .= '</ul>';
8131: $resulttext .= '<li>'.$chgtxt.'</li>';
8132: }
1.160.6.69 raeburn 8133: } elsif ($item eq 'recaptchaversion') {
8134: if (ref($loginhash{'login'}) eq 'HASH') {
8135: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
8136: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
8137: '</li>';
8138: }
8139: }
1.41 raeburn 8140: } else {
8141: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
8142: }
1.1 raeburn 8143: }
1.6 raeburn 8144: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 8145: } else {
8146: $resulttext = &mt('No changes made to log-in page settings');
8147: }
8148: } else {
1.11 albertel 8149: $resulttext = '<span class="LC_error">'.
8150: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8151: }
1.6 raeburn 8152: if ($errors) {
1.9 raeburn 8153: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 8154: $errors.'</ul>';
8155: }
8156: return $resulttext;
8157: }
8158:
1.160.6.56 raeburn 8159: sub check_exempt_addresses {
8160: my ($iplist) = @_;
8161: $iplist =~ s/^\s+//;
8162: $iplist =~ s/\s+$//;
8163: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
8164: my (@okips,$new);
8165: foreach my $ip (@poss_ips) {
8166: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
8167: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
8168: push(@okips,$ip);
8169: }
8170: }
8171: }
8172: if (@okips > 0) {
8173: $new = join(',',@okips);
8174: } else {
8175: $new = '';
8176: }
8177: return $new;
8178: }
8179:
1.6 raeburn 8180: sub color_font_choices {
8181: my %choices =
8182: &Apache::lonlocal::texthash (
8183: img => "Header",
8184: bgs => "Background colors",
8185: links => "Link colors",
1.55 raeburn 8186: images => "Images",
1.6 raeburn 8187: font => "Font color",
1.160.6.22 raeburn 8188: fontmenu => "Font menu",
1.76 raeburn 8189: pgbg => "Page",
1.6 raeburn 8190: tabbg => "Header",
8191: sidebg => "Border",
8192: link => "Link",
8193: alink => "Active link",
8194: vlink => "Visited link",
8195: );
8196: return %choices;
8197: }
8198:
8199: sub modify_rolecolors {
1.160.6.24 raeburn 8200: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 8201: my ($resulttext,%rolehash);
8202: $rolehash{'rolecolors'} = {};
1.55 raeburn 8203: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
8204: if ($domconfig{'rolecolors'} eq '') {
8205: $domconfig{'rolecolors'} = {};
8206: }
8207: }
1.9 raeburn 8208: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 8209: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
8210: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
8211: $dom);
8212: if ($putresult eq 'ok') {
8213: if (keys(%changes) > 0) {
1.41 raeburn 8214: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8215: if (ref($lastactref) eq 'HASH') {
8216: $lastactref->{'domainconfig'} = 1;
8217: }
1.6 raeburn 8218: $resulttext = &display_colorchgs($dom,\%changes,$roles,
8219: $rolehash{'rolecolors'});
8220: } else {
8221: $resulttext = &mt('No changes made to default color schemes');
8222: }
8223: } else {
1.11 albertel 8224: $resulttext = '<span class="LC_error">'.
8225: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 8226: }
8227: if ($errors) {
8228: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8229: $errors.'</ul>';
8230: }
8231: return $resulttext;
8232: }
8233:
8234: sub modify_colors {
1.9 raeburn 8235: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 8236: my (%changes,%choices);
1.51 raeburn 8237: my @bgs;
1.6 raeburn 8238: my @links = ('link','alink','vlink');
1.41 raeburn 8239: my @logintext;
1.6 raeburn 8240: my @images;
8241: my $servadm = $r->dir_config('lonAdmEMail');
8242: my $errors;
1.160.6.22 raeburn 8243: my %defaults;
1.6 raeburn 8244: foreach my $role (@{$roles}) {
8245: if ($role eq 'login') {
1.12 raeburn 8246: %choices = &login_choices();
1.41 raeburn 8247: @logintext = ('textcol','bgcol');
1.12 raeburn 8248: } else {
8249: %choices = &color_font_choices();
8250: }
8251: if ($role eq 'login') {
1.41 raeburn 8252: @images = ('img','logo','domlogo','login');
1.51 raeburn 8253: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 8254: } else {
8255: @images = ('img');
1.160.6.22 raeburn 8256: @bgs = ('pgbg','tabbg','sidebg');
8257: }
8258: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
8259: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
8260: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
8261: }
8262: if ($role eq 'login') {
8263: foreach my $item (@logintext) {
1.160.6.39 raeburn 8264: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8265: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8266: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8267: }
8268: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 8269: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8270: }
8271: }
8272: } else {
1.160.6.39 raeburn 8273: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
8274: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
8275: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
8276: }
8277: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 8278: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
8279: }
1.6 raeburn 8280: }
1.160.6.22 raeburn 8281: foreach my $item (@bgs) {
1.160.6.39 raeburn 8282: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8283: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8284: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8285: }
8286: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 8287: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8288: }
8289: }
8290: foreach my $item (@links) {
1.160.6.39 raeburn 8291: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8292: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8293: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8294: }
8295: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 8296: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8297: }
1.6 raeburn 8298: }
1.46 raeburn 8299: my ($configuserok,$author_ok,$switchserver) =
8300: &config_check($dom,$confname,$servadm);
1.9 raeburn 8301: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 8302: if (ref($domconfig->{$role}) ne 'HASH') {
8303: $domconfig->{$role} = {};
8304: }
1.8 raeburn 8305: foreach my $img (@images) {
1.70 raeburn 8306: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
8307: if (defined($env{'form.login_showlogo_'.$img})) {
8308: $confhash->{$role}{'showlogo'}{$img} = 1;
8309: } else {
8310: $confhash->{$role}{'showlogo'}{$img} = 0;
8311: }
8312: }
1.18 albertel 8313: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
8314: && !defined($domconfig->{$role}{$img})
8315: && !$env{'form.'.$role.'_del_'.$img}
8316: && $env{'form.'.$role.'_import_'.$img}) {
8317: # import the old configured image from the .tab setting
8318: # if they haven't provided a new one
8319: $domconfig->{$role}{$img} =
8320: $env{'form.'.$role.'_import_'.$img};
8321: }
1.6 raeburn 8322: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 8323: my $error;
1.6 raeburn 8324: if ($configuserok eq 'ok') {
1.9 raeburn 8325: if ($switchserver) {
1.12 raeburn 8326: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 8327: } else {
8328: if ($author_ok eq 'ok') {
8329: my ($result,$logourl) =
8330: &publishlogo($r,'upload',$role.'_'.$img,
8331: $dom,$confname,$img,$width,$height);
8332: if ($result eq 'ok') {
8333: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 8334: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8335: } else {
1.12 raeburn 8336: $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 8337: }
8338: } else {
1.46 raeburn 8339: $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 8340: }
8341: }
8342: } else {
1.46 raeburn 8343: $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 8344: }
8345: if ($error) {
1.8 raeburn 8346: &Apache::lonnet::logthis($error);
1.11 albertel 8347: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 8348: }
8349: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 8350: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
8351: my $error;
8352: if ($configuserok eq 'ok') {
8353: # is confname an author?
8354: if ($switchserver eq '') {
8355: if ($author_ok eq 'ok') {
8356: my ($result,$logourl) =
8357: &publishlogo($r,'copy',$domconfig->{$role}{$img},
8358: $dom,$confname,$img,$width,$height);
8359: if ($result eq 'ok') {
8360: $confhash->{$role}{$img} = $logourl;
1.18 albertel 8361: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8362: }
8363: }
8364: }
8365: }
1.6 raeburn 8366: }
8367: }
8368: }
8369: if (ref($domconfig) eq 'HASH') {
8370: if (ref($domconfig->{$role}) eq 'HASH') {
8371: foreach my $img (@images) {
8372: if ($domconfig->{$role}{$img} ne '') {
8373: if ($env{'form.'.$role.'_del_'.$img}) {
8374: $confhash->{$role}{$img} = '';
1.12 raeburn 8375: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8376: } else {
1.9 raeburn 8377: if ($confhash->{$role}{$img} eq '') {
8378: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
8379: }
1.6 raeburn 8380: }
8381: } else {
8382: if ($env{'form.'.$role.'_del_'.$img}) {
8383: $confhash->{$role}{$img} = '';
1.12 raeburn 8384: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8385: }
8386: }
1.70 raeburn 8387: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
8388: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
8389: if ($confhash->{$role}{'showlogo'}{$img} ne
8390: $domconfig->{$role}{'showlogo'}{$img}) {
8391: $changes{$role}{'showlogo'}{$img} = 1;
8392: }
8393: } else {
8394: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8395: $changes{$role}{'showlogo'}{$img} = 1;
8396: }
8397: }
8398: }
8399: }
1.6 raeburn 8400: if ($domconfig->{$role}{'font'} ne '') {
8401: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
8402: $changes{$role}{'font'} = 1;
8403: }
8404: } else {
8405: if ($confhash->{$role}{'font'}) {
8406: $changes{$role}{'font'} = 1;
8407: }
8408: }
1.107 raeburn 8409: if ($role ne 'login') {
8410: if ($domconfig->{$role}{'fontmenu'} ne '') {
8411: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
8412: $changes{$role}{'fontmenu'} = 1;
8413: }
8414: } else {
8415: if ($confhash->{$role}{'fontmenu'}) {
8416: $changes{$role}{'fontmenu'} = 1;
8417: }
1.97 tempelho 8418: }
8419: }
1.6 raeburn 8420: foreach my $item (@bgs) {
8421: if ($domconfig->{$role}{$item} ne '') {
8422: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8423: $changes{$role}{'bgs'}{$item} = 1;
8424: }
8425: } else {
8426: if ($confhash->{$role}{$item}) {
8427: $changes{$role}{'bgs'}{$item} = 1;
8428: }
8429: }
8430: }
8431: foreach my $item (@links) {
8432: if ($domconfig->{$role}{$item} ne '') {
8433: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8434: $changes{$role}{'links'}{$item} = 1;
8435: }
8436: } else {
8437: if ($confhash->{$role}{$item}) {
8438: $changes{$role}{'links'}{$item} = 1;
8439: }
8440: }
8441: }
1.41 raeburn 8442: foreach my $item (@logintext) {
8443: if ($domconfig->{$role}{$item} ne '') {
8444: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8445: $changes{$role}{'logintext'}{$item} = 1;
8446: }
8447: } else {
8448: if ($confhash->{$role}{$item}) {
8449: $changes{$role}{'logintext'}{$item} = 1;
8450: }
8451: }
8452: }
1.6 raeburn 8453: } else {
8454: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8455: \@logintext,$confhash,\%changes);
1.6 raeburn 8456: }
8457: } else {
8458: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8459: \@logintext,$confhash,\%changes);
1.6 raeburn 8460: }
8461: }
8462: return ($errors,%changes);
8463: }
8464:
1.46 raeburn 8465: sub config_check {
8466: my ($dom,$confname,$servadm) = @_;
8467: my ($configuserok,$author_ok,$switchserver,%currroles);
8468: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8469: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8470: $confname,$servadm);
8471: if ($configuserok eq 'ok') {
8472: $switchserver = &check_switchserver($dom,$confname);
8473: if ($switchserver eq '') {
8474: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8475: }
8476: }
8477: return ($configuserok,$author_ok,$switchserver);
8478: }
8479:
1.6 raeburn 8480: sub default_change_checker {
1.41 raeburn 8481: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 8482: foreach my $item (@{$links}) {
8483: if ($confhash->{$role}{$item}) {
8484: $changes->{$role}{'links'}{$item} = 1;
8485: }
8486: }
8487: foreach my $item (@{$bgs}) {
8488: if ($confhash->{$role}{$item}) {
8489: $changes->{$role}{'bgs'}{$item} = 1;
8490: }
8491: }
1.41 raeburn 8492: foreach my $item (@{$logintext}) {
8493: if ($confhash->{$role}{$item}) {
8494: $changes->{$role}{'logintext'}{$item} = 1;
8495: }
8496: }
1.6 raeburn 8497: foreach my $img (@{$images}) {
8498: if ($env{'form.'.$role.'_del_'.$img}) {
8499: $confhash->{$role}{$img} = '';
1.12 raeburn 8500: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 8501: }
1.70 raeburn 8502: if ($role eq 'login') {
8503: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8504: $changes->{$role}{'showlogo'}{$img} = 1;
8505: }
8506: }
1.6 raeburn 8507: }
8508: if ($confhash->{$role}{'font'}) {
8509: $changes->{$role}{'font'} = 1;
8510: }
1.48 raeburn 8511: }
1.6 raeburn 8512:
8513: sub display_colorchgs {
8514: my ($dom,$changes,$roles,$confhash) = @_;
8515: my (%choices,$resulttext);
8516: if (!grep(/^login$/,@{$roles})) {
8517: $resulttext = &mt('Changes made:').'<br />';
8518: }
8519: foreach my $role (@{$roles}) {
8520: if ($role eq 'login') {
8521: %choices = &login_choices();
8522: } else {
8523: %choices = &color_font_choices();
8524: }
8525: if (ref($changes->{$role}) eq 'HASH') {
8526: if ($role ne 'login') {
8527: $resulttext .= '<h4>'.&mt($role).'</h4>';
8528: }
8529: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8530: if ($role ne 'login') {
8531: $resulttext .= '<ul>';
8532: }
8533: if (ref($changes->{$role}{$key}) eq 'HASH') {
8534: if ($role ne 'login') {
8535: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
8536: }
8537: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 8538: if (($role eq 'login') && ($key eq 'showlogo')) {
8539: if ($confhash->{$role}{$key}{$item}) {
8540: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
8541: } else {
8542: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
8543: }
8544: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 8545: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
8546: } else {
1.12 raeburn 8547: my $newitem = $confhash->{$role}{$item};
8548: if ($key eq 'images') {
8549: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
8550: }
8551: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 8552: }
8553: }
8554: if ($role ne 'login') {
8555: $resulttext .= '</ul></li>';
8556: }
8557: } else {
8558: if ($confhash->{$role}{$key} eq '') {
8559: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
8560: } else {
8561: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8562: }
8563: }
8564: if ($role ne 'login') {
8565: $resulttext .= '</ul>';
8566: }
8567: }
8568: }
8569: }
1.3 raeburn 8570: return $resulttext;
1.1 raeburn 8571: }
8572:
1.9 raeburn 8573: sub thumb_dimensions {
8574: return ('200','50');
8575: }
8576:
1.16 raeburn 8577: sub check_dimensions {
8578: my ($inputfile) = @_;
8579: my ($fullwidth,$fullheight);
8580: if ($inputfile =~ m|^[/\w.\-]+$|) {
8581: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8582: my $imageinfo = <PIPE>;
8583: if (!close(PIPE)) {
8584: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8585: }
8586: chomp($imageinfo);
8587: my ($fullsize) =
1.21 raeburn 8588: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 8589: if ($fullsize) {
8590: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8591: }
8592: }
8593: }
8594: return ($fullwidth,$fullheight);
8595: }
8596:
1.9 raeburn 8597: sub check_configuser {
8598: my ($uhome,$dom,$confname,$servadm) = @_;
8599: my ($configuserok,%currroles);
8600: if ($uhome eq 'no_host') {
8601: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98! raeburn 8602: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 8603: $configuserok =
8604: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8605: $configpass,'','','','','',undef,$servadm);
8606: } else {
8607: $configuserok = 'ok';
8608: %currroles =
8609: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
8610: }
8611: return ($configuserok,%currroles);
8612: }
8613:
8614: sub check_authorstatus {
8615: my ($dom,$confname,%currroles) = @_;
8616: my $author_ok;
1.40 raeburn 8617: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 8618: my $start = time;
8619: my $end = 0;
8620: $author_ok =
8621: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 8622: 'au',$end,$start,'','','domconfig');
1.9 raeburn 8623: } else {
8624: $author_ok = 'ok';
8625: }
8626: return $author_ok;
8627: }
8628:
8629: sub publishlogo {
1.46 raeburn 8630: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 8631: my ($output,$fname,$logourl);
8632: if ($action eq 'upload') {
8633: $fname=$env{'form.'.$formname.'.filename'};
8634: chop($env{'form.'.$formname});
8635: } else {
8636: ($fname) = ($formname =~ /([^\/]+)$/);
8637: }
1.46 raeburn 8638: if ($savefileas ne '') {
8639: $fname = $savefileas;
8640: }
1.9 raeburn 8641: $fname=&Apache::lonnet::clean_filename($fname);
8642: # See if there is anything left
8643: unless ($fname) { return ('error: no uploaded file'); }
8644: $fname="$subdir/$fname";
1.160.6.5 raeburn 8645: my $docroot=$r->dir_config('lonDocRoot');
8646: my $filepath="$docroot/priv";
8647: my $relpath = "$dom/$confname";
1.9 raeburn 8648: my ($fnamepath,$file,$fetchthumb);
8649: $file=$fname;
8650: if ($fname=~m|/|) {
8651: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
8652: }
1.160.6.26 raeburn 8653: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 8654: my $count;
1.160.6.5 raeburn 8655: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 8656: $filepath.="/$parts[$count]";
8657: if ((-e $filepath)!=1) {
8658: mkdir($filepath,02770);
8659: }
8660: }
8661: # Check for bad extension and disallow upload
8662: if ($file=~/\.(\w+)$/ &&
8663: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8664: $output =
1.160.6.25 raeburn 8665: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 8666: } elsif ($file=~/\.(\w+)$/ &&
8667: !defined(&Apache::loncommon::fileembstyle($1))) {
8668: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8669: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 8670: $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 8671: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 8672: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 8673: } else {
8674: my $source = $filepath.'/'.$file;
8675: my $logfile;
1.160.6.88 raeburn 8676: if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 8677: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 8678: }
8679: print $logfile
8680: "\n================= Publish ".localtime()." ================\n".
8681: $env{'user.name'}.':'.$env{'user.domain'}."\n";
8682: # Save the file
1.160.6.88 raeburn 8683: if (!open(FH,">",$source)) {
1.9 raeburn 8684: &Apache::lonnet::logthis('Failed to create '.$source);
8685: return (&mt('Failed to create file'));
8686: }
8687: if ($action eq 'upload') {
8688: if (!print FH ($env{'form.'.$formname})) {
8689: &Apache::lonnet::logthis('Failed to write to '.$source);
8690: return (&mt('Failed to write file'));
8691: }
8692: } else {
8693: my $original = &Apache::lonnet::filelocation('',$formname);
8694: if(!copy($original,$source)) {
8695: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
8696: return (&mt('Failed to write file'));
8697: }
8698: }
8699: close(FH);
8700: chmod(0660, $source); # Permissions to rw-rw---.
8701:
8702: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
8703: my $copyfile=$targetdir.'/'.$file;
8704:
8705: my @parts=split(/\//,$targetdir);
8706: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
8707: for (my $count=5;$count<=$#parts;$count++) {
8708: $path.="/$parts[$count]";
8709: if (!-e $path) {
8710: print $logfile "\nCreating directory ".$path;
8711: mkdir($path,02770);
8712: }
8713: }
8714: my $versionresult;
8715: if (-e $copyfile) {
8716: $versionresult = &logo_versioning($targetdir,$file,$logfile);
8717: } else {
8718: $versionresult = 'ok';
8719: }
8720: if ($versionresult eq 'ok') {
8721: if (copy($source,$copyfile)) {
8722: print $logfile "\nCopied original source to ".$copyfile."\n";
8723: $output = 'ok';
8724: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 8725: push(@{$modified_urls},[$copyfile,$source]);
8726: my $metaoutput =
8727: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
8728: unless ($registered_cleanup) {
8729: my $handlers = $r->get_handlers('PerlCleanupHandler');
8730: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8731: $registered_cleanup=1;
8732: }
1.9 raeburn 8733: } else {
8734: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
8735: $output = &mt('Failed to copy file to RES space').", $!";
8736: }
8737: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
8738: my $inputfile = $filepath.'/'.$file;
8739: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 8740: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
8741: if ($fullwidth ne '' && $fullheight ne '') {
8742: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
8743: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88 raeburn 8744: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
8745: system({$args[0]} @args);
1.16 raeburn 8746: chmod(0660, $filepath.'/tn-'.$file);
8747: if (-e $outfile) {
8748: my $copyfile=$targetdir.'/tn-'.$file;
8749: if (copy($outfile,$copyfile)) {
8750: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 8751: my $thumb_metaoutput =
8752: &write_metadata($dom,$confname,$formname,
8753: $targetdir,'tn-'.$file,$logfile);
8754: push(@{$modified_urls},[$copyfile,$outfile]);
8755: unless ($registered_cleanup) {
8756: my $handlers = $r->get_handlers('PerlCleanupHandler');
8757: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8758: $registered_cleanup=1;
8759: }
1.16 raeburn 8760: } else {
8761: print $logfile "\nUnable to write ".$copyfile.
8762: ':'.$!."\n";
8763: }
8764: }
1.9 raeburn 8765: }
8766: }
8767: }
8768: } else {
8769: $output = $versionresult;
8770: }
8771: }
8772: return ($output,$logourl);
8773: }
8774:
8775: sub logo_versioning {
8776: my ($targetdir,$file,$logfile) = @_;
8777: my $target = $targetdir.'/'.$file;
8778: my ($maxversion,$fn,$extn,$output);
8779: $maxversion = 0;
8780: if ($file =~ /^(.+)\.(\w+)$/) {
8781: $fn=$1;
8782: $extn=$2;
8783: }
8784: opendir(DIR,$targetdir);
8785: while (my $filename=readdir(DIR)) {
8786: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
8787: $maxversion=($1>$maxversion)?$1:$maxversion;
8788: }
8789: }
8790: $maxversion++;
8791: print $logfile "\nCreating old version ".$maxversion."\n";
8792: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
8793: if (copy($target,$copyfile)) {
8794: print $logfile "Copied old target to ".$copyfile."\n";
8795: $copyfile=$copyfile.'.meta';
8796: if (copy($target.'.meta',$copyfile)) {
8797: print $logfile "Copied old target metadata to ".$copyfile."\n";
8798: $output = 'ok';
8799: } else {
8800: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
8801: $output = &mt('Failed to copy old meta').", $!, ";
8802: }
8803: } else {
8804: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
8805: $output = &mt('Failed to copy old target').", $!, ";
8806: }
8807: return $output;
8808: }
8809:
8810: sub write_metadata {
8811: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
8812: my (%metadatafields,%metadatakeys,$output);
8813: $metadatafields{'title'}=$formname;
8814: $metadatafields{'creationdate'}=time;
8815: $metadatafields{'lastrevisiondate'}=time;
8816: $metadatafields{'copyright'}='public';
8817: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
8818: $env{'user.domain'};
8819: $metadatafields{'authorspace'}=$confname.':'.$dom;
8820: $metadatafields{'domain'}=$dom;
8821: {
8822: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
8823: my $mfh;
1.160.6.88 raeburn 8824: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 8825: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 8826: unless ($_=~/\./) {
8827: my $unikey=$_;
8828: $unikey=~/^([A-Za-z]+)/;
8829: my $tag=$1;
8830: $tag=~tr/A-Z/a-z/;
8831: print $mfh "\n\<$tag";
8832: foreach (split(/\,/,$metadatakeys{$unikey})) {
8833: my $value=$metadatafields{$unikey.'.'.$_};
8834: $value=~s/\"/\'\'/g;
8835: print $mfh ' '.$_.'="'.$value.'"';
8836: }
8837: print $mfh '>'.
8838: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
8839: .'</'.$tag.'>';
8840: }
8841: }
8842: $output = 'ok';
8843: print $logfile "\nWrote metadata";
8844: close($mfh);
8845: } else {
8846: print $logfile "\nFailed to open metadata file";
1.9 raeburn 8847: $output = &mt('Could not write metadata');
8848: }
8849: }
1.155 raeburn 8850: return $output;
8851: }
8852:
8853: sub notifysubscribed {
8854: foreach my $targetsource (@{$modified_urls}){
8855: next unless (ref($targetsource) eq 'ARRAY');
8856: my ($target,$source)=@{$targetsource};
8857: if ($source ne '') {
1.160.6.88 raeburn 8858: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 8859: print $logfh "\nCleanup phase: Notifications\n";
8860: my @subscribed=&subscribed_hosts($target);
8861: foreach my $subhost (@subscribed) {
8862: print $logfh "\nNotifying host ".$subhost.':';
8863: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
8864: print $logfh $reply;
8865: }
8866: my @subscribedmeta=&subscribed_hosts("$target.meta");
8867: foreach my $subhost (@subscribedmeta) {
8868: print $logfh "\nNotifying host for metadata only ".$subhost.':';
8869: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
8870: $subhost);
8871: print $logfh $reply;
8872: }
8873: print $logfh "\n============ Done ============\n";
1.160 raeburn 8874: close($logfh);
1.155 raeburn 8875: }
8876: }
8877: }
8878: return OK;
8879: }
8880:
8881: sub subscribed_hosts {
8882: my ($target) = @_;
8883: my @subscribed;
1.160.6.88 raeburn 8884: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 8885: while (my $subline=<$fh>) {
8886: if ($subline =~ /^($match_lonid):/) {
8887: my $host = $1;
8888: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
8889: unless (grep(/^\Q$host\E$/,@subscribed)) {
8890: push(@subscribed,$host);
8891: }
8892: }
8893: }
8894: }
8895: }
8896: return @subscribed;
1.9 raeburn 8897: }
8898:
8899: sub check_switchserver {
8900: my ($dom,$confname) = @_;
8901: my ($allowed,$switchserver);
8902: my $home = &Apache::lonnet::homeserver($confname,$dom);
8903: if ($home eq 'no_host') {
8904: $home = &Apache::lonnet::domain($dom,'primary');
8905: }
8906: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 8907: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
8908: if (!$allowed) {
1.160.6.11 raeburn 8909: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 8910: }
8911: return $switchserver;
8912: }
8913:
1.1 raeburn 8914: sub modify_quotas {
1.160.6.30 raeburn 8915: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 8916: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 8917: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 8918: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
8919: $validationfieldsref);
1.86 raeburn 8920: if ($action eq 'quotas') {
8921: $context = 'tools';
1.160.6.26 raeburn 8922: } else {
1.86 raeburn 8923: $context = $action;
8924: }
8925: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 8926: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 8927: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 8928: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
8929: %titles = &courserequest_titles();
8930: $toolregexp = join('|',@usertools);
8931: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 8932: $confname = $dom.'-domainconfig';
8933: my $servadm = $r->dir_config('lonAdmEMail');
8934: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 8935: ($validationitemsref,$validationnamesref,$validationfieldsref) =
8936: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 8937: } elsif ($context eq 'requestauthor') {
8938: @usertools = ('author');
8939: %titles = &authorrequest_titles();
1.86 raeburn 8940: } else {
1.160.6.4 raeburn 8941: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 8942: %titles = &tool_titles();
1.86 raeburn 8943: }
1.160.6.27 raeburn 8944: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 8945: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8946: foreach my $key (keys(%env)) {
1.101 raeburn 8947: if ($context eq 'requestcourses') {
8948: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
8949: my $item = $1;
8950: my $type = $2;
8951: if ($type =~ /^limit_(.+)/) {
8952: $limithash{$item}{$1} = $env{$key};
8953: } else {
8954: $confhash{$item}{$type} = $env{$key};
8955: }
8956: }
1.160.6.5 raeburn 8957: } elsif ($context eq 'requestauthor') {
8958: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8959: $confhash{$1} = $env{$key};
8960: }
1.101 raeburn 8961: } else {
1.86 raeburn 8962: if ($key =~ /^form\.quota_(.+)$/) {
8963: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 8964: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8965: $confhash{'authorquota'}{$1} = $env{$key};
8966: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8967: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8968: }
1.72 raeburn 8969: }
8970: }
1.160.6.5 raeburn 8971: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 8972: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8973: @approvalnotify = sort(@approvalnotify);
8974: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 8975: my @crstypes = ('official','unofficial','community','textbook');
8976: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8977: foreach my $type (@hasuniquecode) {
8978: if (grep(/^\Q$type\E$/,@crstypes)) {
8979: $confhash{'uniquecode'}{$type} = 1;
8980: }
8981: }
1.160.6.46 raeburn 8982: my (%newbook,%allpos);
1.160.6.30 raeburn 8983: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8984: foreach my $type ('textbooks','templates') {
8985: @{$allpos{$type}} = ();
8986: my $invalid;
8987: if ($type eq 'textbooks') {
8988: $invalid = &mt('Invalid LON-CAPA course for textbook');
8989: } else {
8990: $invalid = &mt('Invalid LON-CAPA course for template');
8991: }
8992: if ($env{'form.'.$type.'_addbook'}) {
8993: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8994: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8995: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8996: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8997: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8998: } else {
8999: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
9000: my $position = $env{'form.'.$type.'_addbook_pos'};
9001: $position =~ s/\D+//g;
9002: if ($position ne '') {
9003: $allpos{$type}[$position] = $newbook{$type};
9004: }
1.160.6.30 raeburn 9005: }
1.160.6.46 raeburn 9006: } else {
9007: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 9008: }
9009: }
1.160.6.46 raeburn 9010: }
1.160.6.30 raeburn 9011: }
1.102 raeburn 9012: if (ref($domconfig{$action}) eq 'HASH') {
9013: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
9014: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
9015: $changes{'notify'}{'approval'} = 1;
9016: }
9017: } else {
1.144 raeburn 9018: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9019: $changes{'notify'}{'approval'} = 1;
9020: }
9021: }
1.160.6.30 raeburn 9022: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
9023: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9024: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
9025: unless ($confhash{'uniquecode'}{$crstype}) {
9026: $changes{'uniquecode'} = 1;
9027: }
9028: }
9029: unless ($changes{'uniquecode'}) {
9030: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
9031: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
9032: $changes{'uniquecode'} = 1;
9033: }
9034: }
9035: }
9036: } else {
9037: $changes{'uniquecode'} = 1;
9038: }
9039: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
9040: $changes{'uniquecode'} = 1;
9041: }
9042: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 9043: foreach my $type ('textbooks','templates') {
9044: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9045: my %deletions;
9046: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
9047: if (@todelete) {
9048: map { $deletions{$_} = 1; } @todelete;
9049: }
9050: my %imgdeletions;
9051: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
9052: if (@todeleteimages) {
9053: map { $imgdeletions{$_} = 1; } @todeleteimages;
9054: }
9055: my $maxnum = $env{'form.'.$type.'_maxnum'};
9056: for (my $i=0; $i<=$maxnum; $i++) {
9057: my $itemid = $env{'form.'.$type.'_id_'.$i};
9058: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
9059: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
9060: if ($deletions{$key}) {
9061: if ($domconfig{$action}{$type}{$key}{'image'}) {
9062: #FIXME need to obsolete item in RES space
9063: }
9064: next;
9065: } else {
9066: my $newpos = $env{'form.'.$itemid};
9067: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 9068: foreach my $item ('subject','title','publisher','author') {
9069: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9070: ($type eq 'templates'));
1.160.6.46 raeburn 9071: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
9072: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
9073: $changes{$type}{$key} = 1;
9074: }
9075: }
9076: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 9077: }
1.160.6.46 raeburn 9078: if ($imgdeletions{$key}) {
9079: $changes{$type}{$key} = 1;
9080: #FIXME need to obsolete item in RES space
9081: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
9082: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 9083: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
9084: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
9085: } else {
9086: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
9087: $cdom,$cnum,$type,$configuserok,
9088: $switchserver,$author_ok);
9089: if ($imgurl) {
9090: $confhash{$type}{$key}{'image'} = $imgurl;
9091: $changes{$type}{$key} = 1;
9092: }
9093: if ($error) {
9094: &Apache::lonnet::logthis($error);
9095: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9096: }
1.160.6.46 raeburn 9097: }
9098: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
9099: $confhash{$type}{$key}{'image'} =
9100: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 9101: }
9102: }
9103: }
9104: }
9105: }
9106: }
1.102 raeburn 9107: } else {
1.144 raeburn 9108: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9109: $changes{'notify'}{'approval'} = 1;
9110: }
1.160.6.30 raeburn 9111: if (ref($confhash{'uniquecode'} eq 'HASH')) {
9112: $changes{'uniquecode'} = 1;
9113: }
9114: }
9115: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 9116: foreach my $type ('textbooks','templates') {
9117: if ($newbook{$type}) {
9118: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 9119: foreach my $item ('subject','title','publisher','author') {
9120: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9121: ($type eq 'template'));
1.160.6.46 raeburn 9122: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
9123: if ($env{'form.'.$type.'_addbook_'.$item}) {
9124: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
9125: }
9126: }
9127: if ($type eq 'textbooks') {
9128: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
9129: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 9130: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
9131: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
9132: } else {
9133: my ($imageurl,$error) =
9134: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
9135: $configuserok,$switchserver,$author_ok);
9136: if ($imageurl) {
9137: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
9138: }
9139: if ($error) {
9140: &Apache::lonnet::logthis($error);
9141: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9142: }
1.160.6.46 raeburn 9143: }
9144: }
1.160.6.30 raeburn 9145: }
9146: }
1.160.6.46 raeburn 9147: if (@{$allpos{$type}} > 0) {
9148: my $idx = 0;
9149: foreach my $item (@{$allpos{$type}}) {
9150: if ($item ne '') {
9151: $confhash{$type}{$item}{'order'} = $idx;
9152: if (ref($domconfig{$action}) eq 'HASH') {
9153: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9154: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
9155: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
9156: $changes{$type}{$item} = 1;
9157: }
1.160.6.30 raeburn 9158: }
9159: }
9160: }
1.160.6.46 raeburn 9161: $idx ++;
1.160.6.30 raeburn 9162: }
9163: }
9164: }
9165: }
1.160.6.39 raeburn 9166: if (ref($validationitemsref) eq 'ARRAY') {
9167: foreach my $item (@{$validationitemsref}) {
9168: if ($item eq 'fields') {
9169: my @changed;
9170: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
9171: if (@{$confhash{'validation'}{$item}} > 0) {
9172: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
9173: }
1.160.6.65 raeburn 9174: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9175: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9176: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
9177: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
9178: $domconfig{'requestcourses'}{'validation'}{$item});
9179: } else {
9180: @changed = @{$confhash{'validation'}{$item}};
9181: }
1.160.6.39 raeburn 9182: } else {
9183: @changed = @{$confhash{'validation'}{$item}};
9184: }
9185: } else {
9186: @changed = @{$confhash{'validation'}{$item}};
9187: }
9188: if (@changed) {
9189: if ($confhash{'validation'}{$item}) {
9190: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
9191: } else {
9192: $changes{'validation'}{$item} = &mt('None');
9193: }
9194: }
9195: } else {
9196: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
9197: if ($item eq 'markup') {
9198: if ($env{'form.requestcourses_validation_'.$item}) {
9199: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
9200: }
9201: }
1.160.6.65 raeburn 9202: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9203: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9204: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
9205: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9206: }
9207: } else {
9208: if ($confhash{'validation'}{$item} ne '') {
9209: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9210: }
1.160.6.39 raeburn 9211: }
9212: } else {
9213: if ($confhash{'validation'}{$item} ne '') {
9214: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9215: }
9216: }
9217: }
9218: }
9219: }
9220: if ($env{'form.validationdc'}) {
9221: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 9222: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 9223: if (exists($domcoords{$newval})) {
9224: $confhash{'validation'}{'dc'} = $newval;
9225: }
9226: }
9227: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 9228: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9229: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9230: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9231: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
9232: if ($confhash{'validation'}{'dc'} eq '') {
9233: $changes{'validation'}{'dc'} = &mt('None');
9234: } else {
9235: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9236: }
1.160.6.39 raeburn 9237: }
1.160.6.65 raeburn 9238: } elsif ($confhash{'validation'}{'dc'} ne '') {
9239: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 9240: }
9241: } elsif ($confhash{'validation'}{'dc'} ne '') {
9242: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9243: }
9244: } elsif ($confhash{'validation'}{'dc'} ne '') {
9245: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9246: }
1.160.6.65 raeburn 9247: } else {
9248: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9249: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9250: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9251: $changes{'validation'}{'dc'} = &mt('None');
9252: }
9253: }
1.160.6.39 raeburn 9254: }
9255: }
1.102 raeburn 9256: }
9257: } else {
1.86 raeburn 9258: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 9259: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 9260: }
1.72 raeburn 9261: foreach my $item (@usertools) {
9262: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 9263: my $unset;
1.101 raeburn 9264: if ($context eq 'requestcourses') {
1.104 raeburn 9265: $unset = '0';
9266: if ($type eq '_LC_adv') {
9267: $unset = '';
9268: }
1.101 raeburn 9269: if ($confhash{$item}{$type} eq 'autolimit') {
9270: $confhash{$item}{$type} .= '=';
9271: unless ($limithash{$item}{$type} =~ /\D/) {
9272: $confhash{$item}{$type} .= $limithash{$item}{$type};
9273: }
9274: }
1.160.6.5 raeburn 9275: } elsif ($context eq 'requestauthor') {
9276: $unset = '0';
9277: if ($type eq '_LC_adv') {
9278: $unset = '';
9279: }
1.72 raeburn 9280: } else {
1.101 raeburn 9281: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
9282: $confhash{$item}{$type} = 1;
9283: } else {
9284: $confhash{$item}{$type} = 0;
9285: }
1.72 raeburn 9286: }
1.86 raeburn 9287: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 9288: if ($action eq 'requestauthor') {
9289: if ($domconfig{$action}{$type} ne $confhash{$type}) {
9290: $changes{$type} = 1;
9291: }
9292: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 9293: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
9294: $changes{$item}{$type} = 1;
9295: }
9296: } else {
9297: if ($context eq 'requestcourses') {
1.104 raeburn 9298: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 9299: $changes{$item}{$type} = 1;
9300: }
9301: } else {
9302: if (!$confhash{$item}{$type}) {
9303: $changes{$item}{$type} = 1;
9304: }
9305: }
9306: }
9307: } else {
9308: if ($context eq 'requestcourses') {
1.104 raeburn 9309: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 9310: $changes{$item}{$type} = 1;
9311: }
1.160.6.5 raeburn 9312: } elsif ($context eq 'requestauthor') {
9313: if ($confhash{$type} ne $unset) {
9314: $changes{$type} = 1;
9315: }
1.72 raeburn 9316: } else {
9317: if (!$confhash{$item}{$type}) {
9318: $changes{$item}{$type} = 1;
9319: }
9320: }
9321: }
1.1 raeburn 9322: }
9323: }
1.160.6.5 raeburn 9324: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 9325: if (ref($domconfig{'quotas'}) eq 'HASH') {
9326: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9327: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
9328: if (exists($confhash{'defaultquota'}{$key})) {
9329: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
9330: $changes{'defaultquota'}{$key} = 1;
9331: }
9332: } else {
9333: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 9334: }
9335: }
1.86 raeburn 9336: } else {
9337: foreach my $key (keys(%{$domconfig{'quotas'}})) {
9338: if (exists($confhash{'defaultquota'}{$key})) {
9339: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
9340: $changes{'defaultquota'}{$key} = 1;
9341: }
9342: } else {
9343: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 9344: }
1.1 raeburn 9345: }
9346: }
1.160.6.20 raeburn 9347: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9348: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
9349: if (exists($confhash{'authorquota'}{$key})) {
9350: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
9351: $changes{'authorquota'}{$key} = 1;
9352: }
9353: } else {
9354: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
9355: }
9356: }
9357: }
1.1 raeburn 9358: }
1.86 raeburn 9359: if (ref($confhash{'defaultquota'}) eq 'HASH') {
9360: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
9361: if (ref($domconfig{'quotas'}) eq 'HASH') {
9362: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9363: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
9364: $changes{'defaultquota'}{$key} = 1;
9365: }
9366: } else {
9367: if (!exists($domconfig{'quotas'}{$key})) {
9368: $changes{'defaultquota'}{$key} = 1;
9369: }
1.72 raeburn 9370: }
9371: } else {
1.86 raeburn 9372: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 9373: }
1.1 raeburn 9374: }
9375: }
1.160.6.20 raeburn 9376: if (ref($confhash{'authorquota'}) eq 'HASH') {
9377: foreach my $key (keys(%{$confhash{'authorquota'}})) {
9378: if (ref($domconfig{'quotas'}) eq 'HASH') {
9379: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9380: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
9381: $changes{'authorquota'}{$key} = 1;
9382: }
9383: } else {
9384: $changes{'authorquota'}{$key} = 1;
9385: }
9386: } else {
9387: $changes{'authorquota'}{$key} = 1;
9388: }
9389: }
9390: }
1.1 raeburn 9391: }
1.72 raeburn 9392:
1.160.6.5 raeburn 9393: if ($context eq 'requestauthor') {
9394: $domdefaults{'requestauthor'} = \%confhash;
9395: } else {
9396: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 9397: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 9398: $domdefaults{$key} = $confhash{$key};
9399: }
1.160.6.5 raeburn 9400: }
1.72 raeburn 9401: }
1.160.6.5 raeburn 9402:
1.1 raeburn 9403: my %quotahash = (
1.86 raeburn 9404: $action => { %confhash }
1.1 raeburn 9405: );
9406: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
9407: $dom);
9408: if ($putresult eq 'ok') {
9409: if (keys(%changes) > 0) {
1.72 raeburn 9410: my $cachetime = 24*60*60;
9411: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 9412: if (ref($lastactref) eq 'HASH') {
9413: $lastactref->{'domdefaults'} = 1;
9414: }
1.1 raeburn 9415: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 9416: unless (($context eq 'requestcourses') ||
9417: ($context eq 'requestauthor')) {
1.86 raeburn 9418: if (ref($changes{'defaultquota'}) eq 'HASH') {
9419: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
9420: foreach my $type (@{$types},'default') {
9421: if (defined($changes{'defaultquota'}{$type})) {
9422: my $typetitle = $usertypes->{$type};
9423: if ($type eq 'default') {
9424: $typetitle = $othertitle;
9425: }
1.160.6.28 raeburn 9426: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 9427: }
9428: }
1.86 raeburn 9429: $resulttext .= '</ul></li>';
1.72 raeburn 9430: }
1.160.6.20 raeburn 9431: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 9432: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 9433: foreach my $type (@{$types},'default') {
9434: if (defined($changes{'authorquota'}{$type})) {
9435: my $typetitle = $usertypes->{$type};
9436: if ($type eq 'default') {
9437: $typetitle = $othertitle;
9438: }
1.160.6.28 raeburn 9439: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 9440: }
9441: }
9442: $resulttext .= '</ul></li>';
9443: }
1.72 raeburn 9444: }
1.80 raeburn 9445: my %newenv;
1.72 raeburn 9446: foreach my $item (@usertools) {
1.160.6.5 raeburn 9447: my (%haschgs,%inconf);
9448: if ($context eq 'requestauthor') {
9449: %haschgs = %changes;
9450: %inconf = %confhash;
9451: } else {
9452: if (ref($changes{$item}) eq 'HASH') {
9453: %haschgs = %{$changes{$item}};
9454: }
9455: if (ref($confhash{$item}) eq 'HASH') {
9456: %inconf = %{$confhash{$item}};
9457: }
9458: }
9459: if (keys(%haschgs) > 0) {
1.80 raeburn 9460: my $newacc =
9461: &Apache::lonnet::usertools_access($env{'user.name'},
9462: $env{'user.domain'},
1.86 raeburn 9463: $item,'reload',$context);
1.160.6.5 raeburn 9464: if (($context eq 'requestcourses') ||
9465: ($context eq 'requestauthor')) {
1.108 raeburn 9466: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9467: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 9468: }
9469: } else {
9470: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9471: $newenv{'environment.availabletools.'.$item} = $newacc;
9472: }
1.80 raeburn 9473: }
1.160.6.5 raeburn 9474: unless ($context eq 'requestauthor') {
9475: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9476: }
1.72 raeburn 9477: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 9478: if ($haschgs{$type}) {
1.72 raeburn 9479: my $typetitle = $usertypes->{$type};
9480: if ($type eq 'default') {
9481: $typetitle = $othertitle;
9482: } elsif ($type eq '_LC_adv') {
9483: $typetitle = 'LON-CAPA Advanced Users';
9484: }
1.160.6.5 raeburn 9485: if ($inconf{$type}) {
1.101 raeburn 9486: if ($context eq 'requestcourses') {
9487: my $cond;
1.160.6.5 raeburn 9488: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 9489: if ($1 eq '') {
9490: $cond = &mt('(Automatic processing of any request).');
9491: } else {
9492: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9493: }
9494: } else {
1.160.6.5 raeburn 9495: $cond = $conditions{$inconf{$type}};
1.101 raeburn 9496: }
9497: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 9498: } elsif ($context eq 'requestauthor') {
9499: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9500: $titles{$inconf{$type}},$typetitle);
9501:
1.101 raeburn 9502: } else {
9503: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9504: }
1.72 raeburn 9505: } else {
1.104 raeburn 9506: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 9507: if ($inconf{$type} eq '0') {
1.104 raeburn 9508: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9509: } else {
9510: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9511: }
9512: } else {
9513: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9514: }
1.72 raeburn 9515: }
9516: }
1.26 raeburn 9517: }
1.160.6.5 raeburn 9518: unless ($context eq 'requestauthor') {
9519: $resulttext .= '</ul></li>';
9520: }
1.26 raeburn 9521: }
1.1 raeburn 9522: }
1.160.6.5 raeburn 9523: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 9524: if (ref($changes{'notify'}) eq 'HASH') {
9525: if ($changes{'notify'}{'approval'}) {
9526: if (ref($confhash{'notify'}) eq 'HASH') {
9527: if ($confhash{'notify'}{'approval'}) {
9528: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9529: } else {
1.160.6.5 raeburn 9530: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 9531: }
9532: }
9533: }
9534: }
9535: }
1.160.6.30 raeburn 9536: if ($action eq 'requestcourses') {
9537: my @offon = ('off','on');
9538: if ($changes{'uniquecode'}) {
9539: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9540: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
9541: $resulttext .= '<li>'.
9542: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
9543: '</li>';
9544: } else {
9545: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
9546: '</li>';
9547: }
9548: }
1.160.6.46 raeburn 9549: foreach my $type ('textbooks','templates') {
9550: if (ref($changes{$type}) eq 'HASH') {
9551: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
9552: foreach my $key (sort(keys(%{$changes{$type}}))) {
9553: my %coursehash = &Apache::lonnet::coursedescription($key);
9554: my $coursetitle = $coursehash{'description'};
9555: my $position = $confhash{$type}{$key}{'order'} + 1;
9556: $resulttext .= '<li>';
1.160.6.47 raeburn 9557: foreach my $item ('subject','title','publisher','author') {
9558: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9559: ($type eq 'templates'));
1.160.6.46 raeburn 9560: my $name = $item.':';
9561: $name =~ s/^(\w)/\U$1/;
9562: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9563: }
9564: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9565: if ($type eq 'textbooks') {
9566: if ($confhash{$type}{$key}{'image'}) {
9567: $resulttext .= ' '.&mt('Image: [_1]',
9568: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9569: ' alt="Textbook cover" />').'<br />';
9570: }
9571: }
9572: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 9573: }
1.160.6.46 raeburn 9574: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 9575: }
9576: }
1.160.6.39 raeburn 9577: if (ref($changes{'validation'}) eq 'HASH') {
9578: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9579: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9580: foreach my $item (@{$validationitemsref}) {
9581: if (exists($changes{'validation'}{$item})) {
9582: if ($item eq 'markup') {
9583: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9584: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9585: } else {
9586: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9587: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9588: }
9589: }
9590: }
9591: if (exists($changes{'validation'}{'dc'})) {
9592: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9593: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9594: }
9595: }
9596: }
1.160.6.30 raeburn 9597: }
1.1 raeburn 9598: $resulttext .= '</ul>';
1.80 raeburn 9599: if (keys(%newenv)) {
9600: &Apache::lonnet::appenv(\%newenv);
9601: }
1.1 raeburn 9602: } else {
1.86 raeburn 9603: if ($context eq 'requestcourses') {
9604: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 9605: } elsif ($context eq 'requestauthor') {
9606: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 9607: } else {
1.90 weissno 9608: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 9609: }
1.1 raeburn 9610: }
9611: } else {
1.11 albertel 9612: $resulttext = '<span class="LC_error">'.
9613: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9614: }
1.160.6.30 raeburn 9615: if ($errors) {
9616: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
9617: '<ul>'.$errors.'</ul></p>';
9618: }
1.3 raeburn 9619: return $resulttext;
1.1 raeburn 9620: }
9621:
1.160.6.30 raeburn 9622: sub process_textbook_image {
1.160.6.46 raeburn 9623: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 9624: my $filename = $env{'form.'.$caller.'.filename'};
9625: my ($error,$url);
9626: my ($width,$height) = (50,50);
9627: if ($configuserok eq 'ok') {
9628: if ($switchserver) {
9629: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
9630: $switchserver);
9631: } elsif ($author_ok eq 'ok') {
9632: my ($result,$imageurl) =
9633: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88 raeburn 9634: "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 9635: if ($result eq 'ok') {
9636: $url = $imageurl;
9637: } else {
9638: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9639: }
9640: } else {
9641: $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);
9642: }
9643: } else {
9644: $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);
9645: }
9646: return ($url,$error);
9647: }
9648:
1.3 raeburn 9649: sub modify_autoenroll {
1.160.6.24 raeburn 9650: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 9651: my ($resulttext,%changes);
9652: my %currautoenroll;
9653: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
9654: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
9655: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
9656: }
9657: }
9658: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
9659: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 9660: sender => 'Sender for notification messages',
1.160.6.68 raeburn 9661: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
9662: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 9663: my @offon = ('off','on');
1.17 raeburn 9664: my $sender_uname = $env{'form.sender_uname'};
9665: my $sender_domain = $env{'form.sender_domain'};
9666: if ($sender_domain eq '') {
9667: $sender_uname = '';
9668: } elsif ($sender_uname eq '') {
9669: $sender_domain = '';
9670: }
1.129 raeburn 9671: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 9672: my $failsafe = $env{'form.autoenroll_failsafe'};
9673: $failsafe =~ s{^\s+|\s+$}{}g;
9674: if ($failsafe =~ /\D/) {
9675: undef($failsafe);
9676: }
1.1 raeburn 9677: my %autoenrollhash = (
1.129 raeburn 9678: autoenroll => { 'run' => $env{'form.autoenroll_run'},
9679: 'sender_uname' => $sender_uname,
9680: 'sender_domain' => $sender_domain,
9681: 'co-owners' => $coowners,
1.160.6.68 raeburn 9682: 'autofailsafe' => $failsafe,
1.1 raeburn 9683: }
9684: );
1.4 raeburn 9685: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
9686: $dom);
1.1 raeburn 9687: if ($putresult eq 'ok') {
9688: if (exists($currautoenroll{'run'})) {
9689: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
9690: $changes{'run'} = 1;
9691: }
9692: } elsif ($autorun) {
9693: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 9694: $changes{'run'} = 1;
1.1 raeburn 9695: }
9696: }
1.17 raeburn 9697: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 9698: $changes{'sender'} = 1;
9699: }
1.17 raeburn 9700: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 9701: $changes{'sender'} = 1;
9702: }
1.129 raeburn 9703: if ($currautoenroll{'co-owners'} ne '') {
9704: if ($currautoenroll{'co-owners'} ne $coowners) {
9705: $changes{'coowners'} = 1;
9706: }
9707: } elsif ($coowners) {
9708: $changes{'coowners'} = 1;
1.160.6.68 raeburn 9709: }
9710: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
9711: $changes{'autofailsafe'} = 1;
9712: }
1.1 raeburn 9713: if (keys(%changes) > 0) {
9714: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 9715: if ($changes{'run'}) {
1.1 raeburn 9716: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
9717: }
9718: if ($changes{'sender'}) {
1.17 raeburn 9719: if ($sender_uname eq '' || $sender_domain eq '') {
9720: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
9721: } else {
9722: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
9723: }
1.1 raeburn 9724: }
1.129 raeburn 9725: if ($changes{'coowners'}) {
9726: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
9727: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9728: if (ref($lastactref) eq 'HASH') {
9729: $lastactref->{'domainconfig'} = 1;
9730: }
1.129 raeburn 9731: }
1.160.6.68 raeburn 9732: if ($changes{'autofailsafe'}) {
9733: if ($failsafe ne '') {
1.160.6.82 raeburn 9734: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68 raeburn 9735: } else {
1.160.6.82 raeburn 9736: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68 raeburn 9737: }
9738: &Apache::lonnet::get_domain_defaults($dom,1);
9739: if (ref($lastactref) eq 'HASH') {
9740: $lastactref->{'domdefaults'} = 1;
9741: }
9742: }
1.1 raeburn 9743: $resulttext .= '</ul>';
9744: } else {
9745: $resulttext = &mt('No changes made to auto-enrollment settings');
9746: }
9747: } else {
1.11 albertel 9748: $resulttext = '<span class="LC_error">'.
9749: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9750: }
1.3 raeburn 9751: return $resulttext;
1.1 raeburn 9752: }
9753:
9754: sub modify_autoupdate {
1.3 raeburn 9755: my ($dom,%domconfig) = @_;
1.1 raeburn 9756: my ($resulttext,%currautoupdate,%fields,%changes);
9757: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
9758: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
9759: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
9760: }
9761: }
9762: my @offon = ('off','on');
9763: my %title = &Apache::lonlocal::texthash (
9764: run => 'Auto-update:',
9765: classlists => 'Updates to user information in classlists?'
9766: );
1.44 raeburn 9767: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9768: my %fieldtitles = &Apache::lonlocal::texthash (
9769: id => 'Student/Employee ID',
1.20 raeburn 9770: permanentemail => 'E-mail address',
1.1 raeburn 9771: lastname => 'Last Name',
9772: firstname => 'First Name',
9773: middlename => 'Middle Name',
1.132 raeburn 9774: generation => 'Generation',
1.1 raeburn 9775: );
1.142 raeburn 9776: $othertitle = &mt('All users');
1.1 raeburn 9777: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 9778: $othertitle = &mt('Other users');
1.1 raeburn 9779: }
9780: foreach my $key (keys(%env)) {
9781: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 9782: my ($usertype,$item) = ($1,$2);
9783: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
9784: if ($usertype eq 'default') {
9785: push(@{$fields{$1}},$2);
9786: } elsif (ref($types) eq 'ARRAY') {
9787: if (grep(/^\Q$usertype\E$/,@{$types})) {
9788: push(@{$fields{$1}},$2);
9789: }
9790: }
9791: }
1.1 raeburn 9792: }
9793: }
1.131 raeburn 9794: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
9795: @lockablenames = sort(@lockablenames);
9796: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
9797: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9798: if (@changed) {
9799: $changes{'lockablenames'} = 1;
9800: }
9801: } else {
9802: if (@lockablenames) {
9803: $changes{'lockablenames'} = 1;
9804: }
9805: }
1.1 raeburn 9806: my %updatehash = (
9807: autoupdate => { run => $env{'form.autoupdate_run'},
9808: classlists => $env{'form.classlists'},
9809: fields => {%fields},
1.131 raeburn 9810: lockablenames => \@lockablenames,
1.1 raeburn 9811: }
9812: );
9813: foreach my $key (keys(%currautoupdate)) {
9814: if (($key eq 'run') || ($key eq 'classlists')) {
9815: if (exists($updatehash{autoupdate}{$key})) {
9816: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
9817: $changes{$key} = 1;
9818: }
9819: }
9820: } elsif ($key eq 'fields') {
9821: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 9822: foreach my $item (@{$types},'default') {
1.1 raeburn 9823: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
9824: my $change = 0;
9825: foreach my $type (@{$currautoupdate{$key}{$item}}) {
9826: if (!exists($fields{$item})) {
9827: $change = 1;
1.132 raeburn 9828: last;
1.1 raeburn 9829: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 9830: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 9831: $change = 1;
1.132 raeburn 9832: last;
1.1 raeburn 9833: }
9834: }
9835: }
9836: if ($change) {
9837: push(@{$changes{$key}},$item);
9838: }
1.26 raeburn 9839: }
1.1 raeburn 9840: }
9841: }
1.131 raeburn 9842: } elsif ($key eq 'lockablenames') {
9843: if (ref($currautoupdate{$key}) eq 'ARRAY') {
9844: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9845: if (@changed) {
9846: $changes{'lockablenames'} = 1;
9847: }
9848: } else {
9849: if (@lockablenames) {
9850: $changes{'lockablenames'} = 1;
9851: }
9852: }
9853: }
9854: }
9855: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
9856: if (@lockablenames) {
9857: $changes{'lockablenames'} = 1;
1.1 raeburn 9858: }
9859: }
1.26 raeburn 9860: foreach my $item (@{$types},'default') {
9861: if (defined($fields{$item})) {
9862: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 9863: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
9864: my $change = 0;
9865: if (ref($fields{$item}) eq 'ARRAY') {
9866: foreach my $type (@{$fields{$item}}) {
9867: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
9868: $change = 1;
9869: last;
9870: }
9871: }
9872: }
9873: if ($change) {
9874: push(@{$changes{'fields'}},$item);
9875: }
9876: } else {
1.26 raeburn 9877: push(@{$changes{'fields'}},$item);
9878: }
9879: } else {
9880: push(@{$changes{'fields'}},$item);
1.1 raeburn 9881: }
9882: }
9883: }
9884: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
9885: $dom);
9886: if ($putresult eq 'ok') {
9887: if (keys(%changes) > 0) {
9888: $resulttext = &mt('Changes made:').'<ul>';
9889: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 9890: if ($key eq 'lockablenames') {
9891: $resulttext .= '<li>';
9892: if (@lockablenames) {
9893: $usertypes->{'default'} = $othertitle;
9894: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
9895: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
9896: } else {
9897: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
9898: }
9899: $resulttext .= '</li>';
9900: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 9901: foreach my $item (@{$changes{$key}}) {
9902: my @newvalues;
9903: foreach my $type (@{$fields{$item}}) {
9904: push(@newvalues,$fieldtitles{$type});
9905: }
1.3 raeburn 9906: my $newvaluestr;
9907: if (@newvalues > 0) {
9908: $newvaluestr = join(', ',@newvalues);
9909: } else {
9910: $newvaluestr = &mt('none');
1.6 raeburn 9911: }
1.1 raeburn 9912: if ($item eq 'default') {
1.26 raeburn 9913: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 9914: } else {
1.26 raeburn 9915: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 9916: }
9917: }
9918: } else {
9919: my $newvalue;
9920: if ($key eq 'run') {
9921: $newvalue = $offon[$env{'form.autoupdate_run'}];
9922: } else {
9923: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 9924: }
1.1 raeburn 9925: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
9926: }
9927: }
9928: $resulttext .= '</ul>';
9929: } else {
1.3 raeburn 9930: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 9931: }
9932: } else {
1.11 albertel 9933: $resulttext = '<span class="LC_error">'.
9934: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9935: }
1.3 raeburn 9936: return $resulttext;
1.1 raeburn 9937: }
9938:
1.125 raeburn 9939: sub modify_autocreate {
9940: my ($dom,%domconfig) = @_;
9941: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
9942: if (ref($domconfig{'autocreate'}) eq 'HASH') {
9943: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
9944: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
9945: }
9946: }
9947: my %title= ( xml => 'Auto-creation of courses in XML course description files',
9948: req => 'Auto-creation of validated requests for official courses',
9949: xmldc => 'Identity of course creator of courses from XML files',
9950: );
9951: my @types = ('xml','req');
9952: foreach my $item (@types) {
9953: $newvals{$item} = $env{'form.autocreate_'.$item};
9954: $newvals{$item} =~ s/\D//g;
9955: $newvals{$item} = 0 if ($newvals{$item} eq '');
9956: }
9957: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 9958: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 9959: unless (exists($domcoords{$newvals{'xmldc'}})) {
9960: $newvals{'xmldc'} = '';
9961: }
9962: %autocreatehash = (
9963: autocreate => { xml => $newvals{'xml'},
9964: req => $newvals{'req'},
9965: }
9966: );
9967: if ($newvals{'xmldc'} ne '') {
9968: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
9969: }
9970: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
9971: $dom);
9972: if ($putresult eq 'ok') {
9973: my @items = @types;
9974: if ($newvals{'xml'}) {
9975: push(@items,'xmldc');
9976: }
9977: foreach my $item (@items) {
9978: if (exists($currautocreate{$item})) {
9979: if ($currautocreate{$item} ne $newvals{$item}) {
9980: $changes{$item} = 1;
9981: }
9982: } elsif ($newvals{$item}) {
9983: $changes{$item} = 1;
9984: }
9985: }
9986: if (keys(%changes) > 0) {
9987: my @offon = ('off','on');
9988: $resulttext = &mt('Changes made:').'<ul>';
9989: foreach my $item (@types) {
9990: if ($changes{$item}) {
9991: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 9992: $resulttext .= '<li>'.
9993: &mt("$title{$item} set to [_1]$newtxt [_2]",
9994: '<b>','</b>').
9995: '</li>';
1.125 raeburn 9996: }
9997: }
9998: if ($changes{'xmldc'}) {
9999: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
10000: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 10001: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 10002: }
10003: $resulttext .= '</ul>';
10004: } else {
10005: $resulttext = &mt('No changes made to auto-creation settings');
10006: }
10007: } else {
10008: $resulttext = '<span class="LC_error">'.
10009: &mt('An error occurred: [_1]',$putresult).'</span>';
10010: }
10011: return $resulttext;
10012: }
10013:
1.23 raeburn 10014: sub modify_directorysrch {
1.160.6.81 raeburn 10015: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 10016: my ($resulttext,%changes);
10017: my %currdirsrch;
10018: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10019: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
10020: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
10021: }
10022: }
1.160.6.72 raeburn 10023: my %title = ( available => 'Institutional directory search available',
10024: localonly => 'Other domains can search institution',
10025: lcavailable => 'LON-CAPA directory search available',
10026: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 10027: searchby => 'Search types',
10028: searchtypes => 'Search latitude');
10029: my @offon = ('off','on');
1.24 raeburn 10030: my @otherdoms = ('Yes','No');
1.23 raeburn 10031:
1.25 raeburn 10032: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 10033: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
10034: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
10035:
1.44 raeburn 10036: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 10037: if (keys(%{$usertypes}) == 0) {
10038: @cansearch = ('default');
10039: } else {
10040: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
10041: foreach my $type (@{$currdirsrch{'cansearch'}}) {
10042: if (!grep(/^\Q$type\E$/,@cansearch)) {
10043: push(@{$changes{'cansearch'}},$type);
10044: }
1.23 raeburn 10045: }
1.26 raeburn 10046: foreach my $type (@cansearch) {
10047: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
10048: push(@{$changes{'cansearch'}},$type);
10049: }
1.23 raeburn 10050: }
1.26 raeburn 10051: } else {
10052: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 10053: }
10054: }
10055:
10056: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
10057: foreach my $by (@{$currdirsrch{'searchby'}}) {
10058: if (!grep(/^\Q$by\E$/,@searchby)) {
10059: push(@{$changes{'searchby'}},$by);
10060: }
10061: }
10062: foreach my $by (@searchby) {
10063: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
10064: push(@{$changes{'searchby'}},$by);
10065: }
10066: }
10067: } else {
10068: push(@{$changes{'searchby'}},@searchby);
10069: }
1.25 raeburn 10070:
10071: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
10072: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
10073: if (!grep(/^\Q$type\E$/,@searchtypes)) {
10074: push(@{$changes{'searchtypes'}},$type);
10075: }
10076: }
10077: foreach my $type (@searchtypes) {
10078: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
10079: push(@{$changes{'searchtypes'}},$type);
10080: }
10081: }
10082: } else {
10083: if (exists($currdirsrch{'searchtypes'})) {
10084: foreach my $type (@searchtypes) {
10085: if ($type ne $currdirsrch{'searchtypes'}) {
10086: push(@{$changes{'searchtypes'}},$type);
10087: }
10088: }
10089: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
10090: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
10091: }
10092: } else {
10093: push(@{$changes{'searchtypes'}},@searchtypes);
10094: }
10095: }
10096:
1.23 raeburn 10097: my %dirsrch_hash = (
10098: directorysrch => { available => $env{'form.dirsrch_available'},
10099: cansearch => \@cansearch,
1.160.6.72 raeburn 10100: localonly => $env{'form.dirsrch_instlocalonly'},
10101: lclocalonly => $env{'form.dirsrch_domlocalonly'},
10102: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 10103: searchby => \@searchby,
1.25 raeburn 10104: searchtypes => \@searchtypes,
1.23 raeburn 10105: }
10106: );
10107: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
10108: $dom);
10109: if ($putresult eq 'ok') {
10110: if (exists($currdirsrch{'available'})) {
10111: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
10112: $changes{'available'} = 1;
10113: }
10114: } else {
10115: if ($env{'form.dirsrch_available'} eq '1') {
10116: $changes{'available'} = 1;
10117: }
10118: }
1.160.6.72 raeburn 10119: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 10120: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
10121: $changes{'lcavailable'} = 1;
10122: }
1.24 raeburn 10123: } else {
1.160.6.72 raeburn 10124: if ($env{'form.dirsrch_lcavailable'} eq '1') {
10125: $changes{'lcavailable'} = 1;
10126: }
10127: }
10128: if (exists($currdirsrch{'localonly'})) {
10129: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 10130: $changes{'localonly'} = 1;
10131: }
1.160.6.72 raeburn 10132: } else {
10133: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
10134: $changes{'localonly'} = 1;
10135: }
10136: }
10137: if (exists($currdirsrch{'lclocalonly'})) {
10138: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
10139: $changes{'lclocalonly'} = 1;
10140: }
10141: } else {
10142: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
10143: $changes{'lclocalonly'} = 1;
10144: }
1.24 raeburn 10145: }
1.23 raeburn 10146: if (keys(%changes) > 0) {
10147: $resulttext = &mt('Changes made:').'<ul>';
10148: if ($changes{'available'}) {
10149: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
10150: }
1.160.6.72 raeburn 10151: if ($changes{'lcavailable'}) {
10152: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
10153: }
1.24 raeburn 10154: if ($changes{'localonly'}) {
1.160.6.72 raeburn 10155: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
10156: }
10157: if ($changes{'lclocalonly'}) {
10158: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 10159: }
1.23 raeburn 10160: if (ref($changes{'cansearch'}) eq 'ARRAY') {
10161: my $chgtext;
1.26 raeburn 10162: if (ref($usertypes) eq 'HASH') {
10163: if (keys(%{$usertypes}) > 0) {
10164: foreach my $type (@{$types}) {
10165: if (grep(/^\Q$type\E$/,@cansearch)) {
10166: $chgtext .= $usertypes->{$type}.'; ';
10167: }
10168: }
10169: if (grep(/^default$/,@cansearch)) {
10170: $chgtext .= $othertitle;
10171: } else {
10172: $chgtext =~ s/\; $//;
10173: }
1.160.6.13 raeburn 10174: $resulttext .=
10175: '<li>'.
10176: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
10177: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
10178: '</li>';
1.23 raeburn 10179: }
10180: }
10181: }
10182: if (ref($changes{'searchby'}) eq 'ARRAY') {
10183: my ($searchtitles,$titleorder) = &sorted_searchtitles();
10184: my $chgtext;
10185: foreach my $type (@{$titleorder}) {
10186: if (grep(/^\Q$type\E$/,@searchby)) {
10187: if (defined($searchtitles->{$type})) {
10188: $chgtext .= $searchtitles->{$type}.'; ';
10189: }
10190: }
10191: }
10192: $chgtext =~ s/\; $//;
10193: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
10194: }
1.25 raeburn 10195: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
10196: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
10197: my $chgtext;
10198: foreach my $type (@{$srchtypeorder}) {
10199: if (grep(/^\Q$type\E$/,@searchtypes)) {
10200: if (defined($srchtypes_desc->{$type})) {
10201: $chgtext .= $srchtypes_desc->{$type}.'; ';
10202: }
10203: }
10204: }
10205: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 10206: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 10207: }
10208: $resulttext .= '</ul>';
1.160.6.81 raeburn 10209: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
10210: if (ref($lastactref) eq 'HASH') {
10211: $lastactref->{'directorysrch'} = 1;
10212: }
1.23 raeburn 10213: } else {
1.160.6.72 raeburn 10214: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 10215: }
10216: } else {
10217: $resulttext = '<span class="LC_error">'.
1.27 raeburn 10218: &mt('An error occurred: [_1]',$putresult).'</span>';
10219: }
10220: return $resulttext;
10221: }
10222:
1.28 raeburn 10223: sub modify_contacts {
1.160.6.24 raeburn 10224: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 10225: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
10226: if (ref($domconfig{'contacts'}) eq 'HASH') {
10227: foreach my $key (keys(%{$domconfig{'contacts'}})) {
10228: $currsetting{$key} = $domconfig{'contacts'}{$key};
10229: }
10230: }
1.160.6.78 raeburn 10231: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 10232: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 10233: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 10234: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.23 raeburn 10235: my @toggles = ('reporterrors','reportupdates');
1.160.6.78 raeburn 10236: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 10237: foreach my $type (@mailings) {
10238: @{$newsetting{$type}} =
10239: &Apache::loncommon::get_env_multiple('form.'.$type);
10240: foreach my $item (@contacts) {
10241: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
10242: $contacts_hash{contacts}{$type}{$item} = 1;
10243: } else {
10244: $contacts_hash{contacts}{$type}{$item} = 0;
10245: }
1.160.6.78 raeburn 10246: }
1.28 raeburn 10247: $others{$type} = $env{'form.'.$type.'_others'};
10248: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 10249: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10250: $bcc{$type} = $env{'form.'.$type.'_bcc'};
10251: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 10252: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
10253: $includestr{$type} = $env{'form.'.$type.'_includestr'};
10254: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
10255: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
10256: }
1.134 raeburn 10257: }
1.28 raeburn 10258: }
10259: foreach my $item (@contacts) {
10260: $to{$item} = $env{'form.'.$item};
10261: $contacts_hash{'contacts'}{$item} = $to{$item};
10262: }
1.160.6.23 raeburn 10263: foreach my $item (@toggles) {
10264: if ($env{'form.'.$item} =~ /^(0|1)$/) {
10265: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
10266: }
10267: }
1.160.6.78 raeburn 10268: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
10269: foreach my $field (@{$fields}) {
10270: if (ref($possoptions->{$field}) eq 'ARRAY') {
10271: my $value = $env{'form.helpform_'.$field};
10272: $value =~ s/^\s+|\s+$//g;
10273: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
10274: $contacts_hash{contacts}{'helpform'}{$field} = $value;
10275: if ($field eq 'screenshot') {
10276: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
10277: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
10278: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
10279: }
10280: }
10281: }
10282: }
10283: }
10284: }
1.28 raeburn 10285: if (keys(%currsetting) > 0) {
10286: foreach my $item (@contacts) {
10287: if ($to{$item} ne $currsetting{$item}) {
10288: $changes{$item} = 1;
10289: }
10290: }
10291: foreach my $type (@mailings) {
10292: foreach my $item (@contacts) {
10293: if (ref($currsetting{$type}) eq 'HASH') {
10294: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
10295: push(@{$changes{$type}},$item);
10296: }
10297: } else {
10298: push(@{$changes{$type}},@{$newsetting{$type}});
10299: }
10300: }
10301: if ($others{$type} ne $currsetting{$type}{'others'}) {
10302: push(@{$changes{$type}},'others');
10303: }
1.160.6.78 raeburn 10304: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10305: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
10306: push(@{$changes{$type}},'bcc');
10307: }
1.160.6.78 raeburn 10308: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
10309: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
10310: push(@{$changes{$type}},'include');
10311: }
10312: }
10313: }
10314: if (ref($fields) eq 'ARRAY') {
10315: if (ref($currsetting{'helpform'}) eq 'HASH') {
10316: foreach my $field (@{$fields}) {
10317: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
10318: push(@{$changes{'helpform'}},$field);
10319: }
10320: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10321: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
10322: push(@{$changes{'helpform'}},'maxsize');
10323: }
10324: }
10325: }
10326: } else {
10327: foreach my $field (@{$fields}) {
10328: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10329: push(@{$changes{'helpform'}},$field);
10330: }
10331: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10332: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10333: push(@{$changes{'helpform'}},'maxsize');
10334: }
10335: }
10336: }
1.134 raeburn 10337: }
1.28 raeburn 10338: }
10339: } else {
10340: my %default;
10341: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
10342: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
10343: $default{'errormail'} = 'adminemail';
10344: $default{'packagesmail'} = 'adminemail';
10345: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 10346: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 10347: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 10348: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 10349: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 10350: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 10351: foreach my $item (@contacts) {
10352: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 10353: $changes{$item} = 1;
1.160.6.23 raeburn 10354: }
1.28 raeburn 10355: }
10356: foreach my $type (@mailings) {
10357: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
10358: push(@{$changes{$type}},@{$newsetting{$type}});
10359: }
10360: if ($others{$type} ne '') {
10361: push(@{$changes{$type}},'others');
1.134 raeburn 10362: }
1.160.6.78 raeburn 10363: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10364: if ($bcc{$type} ne '') {
10365: push(@{$changes{$type}},'bcc');
10366: }
1.160.6.78 raeburn 10367: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
10368: push(@{$changes{$type}},'include');
10369: }
10370: }
10371: }
10372: if (ref($fields) eq 'ARRAY') {
10373: foreach my $field (@{$fields}) {
10374: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10375: push(@{$changes{'helpform'}},$field);
10376: }
10377: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10378: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10379: push(@{$changes{'helpform'}},'maxsize');
10380: }
10381: }
1.134 raeburn 10382: }
1.28 raeburn 10383: }
10384: }
1.160.6.23 raeburn 10385: foreach my $item (@toggles) {
10386: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
10387: $changes{$item} = 1;
10388: } elsif ((!$env{'form.'.$item}) &&
10389: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
10390: $changes{$item} = 1;
10391: }
10392: }
1.28 raeburn 10393: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
10394: $dom);
10395: if ($putresult eq 'ok') {
10396: if (keys(%changes) > 0) {
1.160.6.24 raeburn 10397: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10398: if (ref($lastactref) eq 'HASH') {
10399: $lastactref->{'domainconfig'} = 1;
10400: }
1.28 raeburn 10401: my ($titles,$short_titles) = &contact_titles();
10402: $resulttext = &mt('Changes made:').'<ul>';
10403: foreach my $item (@contacts) {
10404: if ($changes{$item}) {
10405: $resulttext .= '<li>'.$titles->{$item}.
10406: &mt(' set to: ').
10407: '<span class="LC_cusr_emph">'.
10408: $to{$item}.'</span></li>';
10409: }
10410: }
10411: foreach my $type (@mailings) {
10412: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 10413: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
10414: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
10415: } else {
10416: $resulttext .= '<li>'.$titles->{$type}.': ';
10417: }
1.28 raeburn 10418: my @text;
10419: foreach my $item (@{$newsetting{$type}}) {
10420: push(@text,$short_titles->{$item});
10421: }
10422: if ($others{$type} ne '') {
10423: push(@text,$others{$type});
10424: }
1.160.6.78 raeburn 10425: if (@text) {
10426: $resulttext .= '<span class="LC_cusr_emph">'.
10427: join(', ',@text).'</span>';
10428: }
10429: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10430: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 10431: my $bcctext;
10432: if (@text) {
10433: $bcctext = ' '.&mt('with Bcc to');
10434: } else {
10435: $bcctext = '(Bcc)';
10436: }
10437: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
10438: } elsif (!@text) {
10439: $resulttext .= &mt('No one');
1.134 raeburn 10440: }
1.160.6.78 raeburn 10441: if ($includestr{$type} ne '') {
10442: if ($includeloc{$type} eq 'b') {
10443: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
10444: } elsif ($includeloc{$type} eq 's') {
10445: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
10446: }
10447: }
10448: } elsif (!@text) {
10449: $resulttext .= &mt('No recipients');
1.134 raeburn 10450: }
10451: $resulttext .= '</li>';
1.28 raeburn 10452: }
10453: }
1.160.6.23 raeburn 10454: my @offon = ('off','on');
10455: if ($changes{'reporterrors'}) {
10456: $resulttext .= '<li>'.
10457: &mt('E-mail error reports to [_1] set to "'.
10458: $offon[$env{'form.reporterrors'}].'".',
10459: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10460: &mt('LON-CAPA core group - MSU'),600,500)).
10461: '</li>';
10462: }
10463: if ($changes{'reportupdates'}) {
10464: $resulttext .= '<li>'.
10465: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
10466: $offon[$env{'form.reportupdates'}].'".',
10467: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10468: &mt('LON-CAPA core group - MSU'),600,500)).
10469: '</li>';
10470: }
1.160.6.78 raeburn 10471: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
10472: my (@optional,@required,@unused,$maxsizechg);
10473: foreach my $field (@{$changes{'helpform'}}) {
10474: if ($field eq 'maxsize') {
10475: $maxsizechg = 1;
10476: next;
10477: }
10478: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
10479: push(@optional,$field);
10480: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
10481: push(@unused,$field);
10482: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
10483: push(@required,$field);
10484: }
10485: }
10486: if (@optional) {
10487: $resulttext .= '<li>'.
10488: &mt('Help form fields changed to "Optional": [_1].',
10489: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
10490: '</li>';
10491: }
10492: if (@required) {
10493: $resulttext .= '<li>'.
10494: &mt('Help form fields changed to "Required": [_1].',
10495: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
10496: '</li>';
10497: }
10498: if (@unused) {
10499: $resulttext .= '<li>'.
10500: &mt('Help form fields changed to "Not shown": [_1].',
10501: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
10502: '</li>';
10503: }
10504: if ($maxsizechg) {
10505: $resulttext .= '<li>'.
10506: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
10507: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
10508: '</li>';
10509:
10510: }
10511: }
1.28 raeburn 10512: $resulttext .= '</ul>';
10513: } else {
1.160.6.78 raeburn 10514: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 10515: }
10516: } else {
10517: $resulttext = '<span class="LC_error">'.
10518: &mt('An error occurred: [_1].',$putresult).'</span>';
10519: }
10520: return $resulttext;
10521: }
10522:
1.160.6.98! raeburn 10523: sub modify_passwords {
! 10524: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
! 10525: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
! 10526: $updatedefaults,$updateconf);
! 10527: my $customfn = 'resetpw.html';
! 10528: if (ref($domconfig{'passwords'}) eq 'HASH') {
! 10529: %current = %{$domconfig{'passwords'}};
! 10530: }
! 10531: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
! 10532: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
! 10533: if (ref($types) eq 'ARRAY') {
! 10534: @oktypes = @{$types};
! 10535: }
! 10536: push(@oktypes,'default');
! 10537:
! 10538: my %titles = &Apache::lonlocal::texthash (
! 10539: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
! 10540: intauth_check => 'Check bcrypt cost if authenticated',
! 10541: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
! 10542: permanent => 'Permanent e-mail address',
! 10543: critical => 'Critical notification address',
! 10544: notify => 'Notification address',
! 10545: min => 'Minimum password length',
! 10546: max => 'Maximum password length',
! 10547: chars => 'Required characters',
! 10548: numsaved => 'Number of previous passwords to save',
! 10549: reset => 'Resetting Forgotten Password',
! 10550: intauth => 'Encryption of Stored Passwords (Internal Auth)',
! 10551: rules => 'Rules for LON-CAPA Passwords',
! 10552: crsownerchg => 'Course Owner Changing Student Passwords',
! 10553: username => 'Username',
! 10554: email => 'E-mail address',
! 10555: );
! 10556:
! 10557: #
! 10558: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
! 10559: #
! 10560: my (%curr_defaults,%save_defaults);
! 10561: if (ref($domconfig{'defaults'}) eq 'HASH') {
! 10562: foreach my $key (keys(%{$domconfig{'defaults'}})) {
! 10563: if ($key =~ /^intauth_(cost|check|switch)$/) {
! 10564: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
! 10565: } else {
! 10566: $save_defaults{$key} = $domconfig{'defaults'}{$key};
! 10567: }
! 10568: }
! 10569: }
! 10570: my %staticdefaults = (
! 10571: 'resetlink' => 2,
! 10572: 'resetcase' => \@oktypes,
! 10573: 'resetprelink' => 'both',
! 10574: 'resetemail' => ['critical','notify','permanent'],
! 10575: 'intauth_cost' => 10,
! 10576: 'intauth_check' => 0,
! 10577: 'intauth_switch' => 0,
! 10578: 'min' => 7,
! 10579: );
! 10580: foreach my $type (@oktypes) {
! 10581: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
! 10582: }
! 10583: my $linklife = $env{'form.passwords_link'};
! 10584: $linklife =~ s/^\s+|\s+$//g;
! 10585: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
! 10586: $newvalues{'resetlink'} = $linklife;
! 10587: if ($current{'resetlink'}) {
! 10588: if ($current{'resetlink'} ne $linklife) {
! 10589: $changes{'reset'} = 1;
! 10590: }
! 10591: } elsif (!exists($domconfig{passwords})) {
! 10592: if ($staticdefaults{'resetlink'} ne $linklife) {
! 10593: $changes{'reset'} = 1;
! 10594: }
! 10595: }
! 10596: } elsif ($current{'resetlink'}) {
! 10597: $changes{'reset'} = 1;
! 10598: }
! 10599: my @casesens;
! 10600: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
! 10601: foreach my $case (sort(@posscase)) {
! 10602: if (grep(/^\Q$case\E$/,@oktypes)) {
! 10603: push(@casesens,$case);
! 10604: }
! 10605: }
! 10606: $newvalues{'resetcase'} = \@casesens;
! 10607: if (ref($current{'resetcase'}) eq 'ARRAY') {
! 10608: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
! 10609: if (@diffs > 0) {
! 10610: $changes{'reset'} = 1;
! 10611: }
! 10612: } elsif (!exists($domconfig{passwords})) {
! 10613: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
! 10614: if (@diffs > 0) {
! 10615: $changes{'reset'} = 1;
! 10616: }
! 10617: }
! 10618: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
! 10619: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
! 10620: if (exists($current{'resetprelink'})) {
! 10621: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
! 10622: $changes{'reset'} = 1;
! 10623: }
! 10624: } elsif (!exists($domconfig{passwords})) {
! 10625: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
! 10626: $changes{'reset'} = 1;
! 10627: }
! 10628: }
! 10629: } elsif ($current{'resetprelink'}) {
! 10630: $changes{'reset'} = 1;
! 10631: }
! 10632: foreach my $type (@oktypes) {
! 10633: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
! 10634: my @postlink;
! 10635: foreach my $item (sort(@possplink)) {
! 10636: if ($item =~ /^(email|username)$/) {
! 10637: push(@postlink,$item);
! 10638: }
! 10639: }
! 10640: $newvalues{'resetpostlink'}{$type} = \@postlink;
! 10641: unless ($changes{'reset'}) {
! 10642: if (ref($current{'resetpostlink'}) eq 'HASH') {
! 10643: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
! 10644: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
! 10645: if (@diffs > 0) {
! 10646: $changes{'reset'} = 1;
! 10647: }
! 10648: } else {
! 10649: $changes{'reset'} = 1;
! 10650: }
! 10651: } elsif (!exists($domconfig{passwords})) {
! 10652: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
! 10653: if (@diffs > 0) {
! 10654: $changes{'reset'} = 1;
! 10655: }
! 10656: }
! 10657: }
! 10658: }
! 10659: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
! 10660: my @resetemail;
! 10661: foreach my $item (sort(@possemailsrc)) {
! 10662: if ($item =~ /^(permanent|critical|notify)$/) {
! 10663: push(@resetemail,$item);
! 10664: }
! 10665: }
! 10666: $newvalues{'resetemail'} = \@resetemail;
! 10667: unless ($changes{'reset'}) {
! 10668: if (ref($current{'resetemail'}) eq 'ARRAY') {
! 10669: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
! 10670: if (@diffs > 0) {
! 10671: $changes{'reset'} = 1;
! 10672: }
! 10673: } elsif (!exists($domconfig{passwords})) {
! 10674: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
! 10675: if (@diffs > 0) {
! 10676: $changes{'reset'} = 1;
! 10677: }
! 10678: }
! 10679: }
! 10680: if ($env{'form.passwords_stdtext'} == 0) {
! 10681: $newvalues{'resetremove'} = 1;
! 10682: unless ($current{'resetremove'}) {
! 10683: $changes{'reset'} = 1;
! 10684: }
! 10685: } elsif ($current{'resetremove'}) {
! 10686: $changes{'reset'} = 1;
! 10687: }
! 10688: if ($env{'form.passwords_customfile.filename'} ne '') {
! 10689: my $servadm = $r->dir_config('lonAdmEMail');
! 10690: my $servadm = $r->dir_config('lonAdmEMail');
! 10691: my ($configuserok,$author_ok,$switchserver) =
! 10692: &config_check($dom,$confname,$servadm);
! 10693: my $error;
! 10694: if ($configuserok eq 'ok') {
! 10695: if ($switchserver) {
! 10696: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
! 10697: } else {
! 10698: if ($author_ok eq 'ok') {
! 10699: my ($result,$customurl) =
! 10700: &publishlogo($r,'upload','passwords_customfile',$dom,
! 10701: $confname,'customtext/resetpw','','',$customfn);
! 10702: if ($result eq 'ok') {
! 10703: $newvalues{'resetcustom'} = $customurl;
! 10704: $changes{'reset'} = 1;
! 10705: } else {
! 10706: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
! 10707: }
! 10708: } else {
! 10709: $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);
! 10710: }
! 10711: }
! 10712: } else {
! 10713: $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);
! 10714: }
! 10715: if ($error) {
! 10716: &Apache::lonnet::logthis($error);
! 10717: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
! 10718: }
! 10719: } elsif ($current{'resetcustom'}) {
! 10720: if ($env{'form.passwords_custom_del'}) {
! 10721: $changes{'reset'} = 1;
! 10722: } else {
! 10723: $newvalues{'resetcustom'} = $current{'resetcustom'};
! 10724: }
! 10725: }
! 10726: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
! 10727: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
! 10728: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
! 10729: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
! 10730: $changes{'intauth'} = 1;
! 10731: }
! 10732: } else {
! 10733: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
! 10734: }
! 10735: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
! 10736: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
! 10737: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
! 10738: $changes{'intauth'} = 1;
! 10739: }
! 10740: } else {
! 10741: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
! 10742: }
! 10743: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
! 10744: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
! 10745: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
! 10746: $changes{'intauth'} = 1;
! 10747: }
! 10748: } else {
! 10749: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
! 10750: }
! 10751: foreach my $item ('cost','check','switch') {
! 10752: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
! 10753: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
! 10754: $updatedefaults = 1;
! 10755: }
! 10756: }
! 10757: foreach my $rule ('min','max','numsaved') {
! 10758: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
! 10759: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
! 10760: $newvalues{$rule} = $env{'form.passwords_'.$rule};
! 10761: if (exists($current{$rule})) {
! 10762: if ($newvalues{$rule} ne $current{$rule}) {
! 10763: $changes{'rules'} = 1;
! 10764: }
! 10765: } elsif ($rule eq 'min') {
! 10766: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
! 10767: $changes{'rules'} = 1;
! 10768: }
! 10769: }
! 10770: } elsif (exists($current{$rule})) {
! 10771: $changes{'rules'} = 1;
! 10772: }
! 10773: }
! 10774: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
! 10775: my @chars;
! 10776: foreach my $item (sort(@posschars)) {
! 10777: if ($item =~ /^(uc|lc|num|spec)$/) {
! 10778: push(@chars,$item);
! 10779: }
! 10780: }
! 10781: $newvalues{'chars'} = \@chars;
! 10782: unless ($changes{'rules'}) {
! 10783: if (ref($current{'chars'}) eq 'ARRAY') {
! 10784: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
! 10785: if (@diffs > 0) {
! 10786: $changes{'rules'} = 1;
! 10787: }
! 10788: } else {
! 10789: if (@chars > 0) {
! 10790: $changes{'rules'} = 1;
! 10791: }
! 10792: }
! 10793: }
! 10794: my %crsownerchg = (
! 10795: by => [],
! 10796: for => [],
! 10797: );
! 10798: foreach my $item ('by','for') {
! 10799: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
! 10800: foreach my $type (sort(@posstypes)) {
! 10801: if (grep(/^\Q$type\E$/,@oktypes)) {
! 10802: push(@{$crsownerchg{$item}},$type);
! 10803: }
! 10804: }
! 10805: }
! 10806: $newvalues{'crsownerchg'} = \%crsownerchg;
! 10807: if (ref($current{'crsownerchg'}) eq 'HASH') {
! 10808: foreach my $item ('by','for') {
! 10809: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
! 10810: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
! 10811: if (@diffs > 0) {
! 10812: $changes{'crsownerchg'} = 1;
! 10813: last;
! 10814: }
! 10815: }
! 10816: }
! 10817: } elsif (!exists($domconfig{passwords})) {
! 10818: foreach my $item ('by','for') {
! 10819: if (@{$crsownerchg{$item}} > 0) {
! 10820: $changes{'crsownerchg'} = 1;
! 10821: last;
! 10822: }
! 10823: }
! 10824: }
! 10825:
! 10826: my %confighash = (
! 10827: defaults => \%save_defaults,
! 10828: passwords => \%newvalues,
! 10829: );
! 10830: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
! 10831:
! 10832: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
! 10833: if ($putresult eq 'ok') {
! 10834: if (keys(%changes) > 0) {
! 10835: $resulttext = &mt('Changes made: ').'<ul>';
! 10836: foreach my $key ('reset','intauth','rules','crsownerchg') {
! 10837: if ($changes{$key}) {
! 10838: unless ($key eq 'intauth') {
! 10839: $updateconf = 1;
! 10840: }
! 10841: $resulttext .= '<li>'.$titles{$key}.':<ul>';
! 10842: if ($key eq 'reset') {
! 10843: if ($confighash{'passwords'}{'captcha'} eq 'original') {
! 10844: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
! 10845: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
! 10846: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
! 10847: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />'.
! 10848: &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchapub'}).'</br>'.
! 10849: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchapriv'}).'</li>';
! 10850: } else {
! 10851: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
! 10852: }
! 10853: if ($confighash{'passwords'}{'resetlink'}) {
! 10854: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
! 10855: } else {
! 10856: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
! 10857: &mt('Will default to 2 hours').'</li>';
! 10858: }
! 10859: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
! 10860: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
! 10861: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
! 10862: } else {
! 10863: my $casesens;
! 10864: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
! 10865: if ($type eq 'default') {
! 10866: $casesens .= $othertitle.', ';
! 10867: } elsif ($usertypes->{$type} ne '') {
! 10868: $casesens .= $usertypes->{$type}.', ';
! 10869: }
! 10870: }
! 10871: $casesens =~ s/\Q, \E$//;
! 10872: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
! 10873: }
! 10874: } else {
! 10875: $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>';
! 10876: }
! 10877: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
! 10878: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
! 10879: } else {
! 10880: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
! 10881: }
! 10882: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
! 10883: my $output;
! 10884: if (ref($types) eq 'ARRAY') {
! 10885: foreach my $type (@{$types}) {
! 10886: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
! 10887: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
! 10888: $output .= $usertypes->{$type}.' -- '.&mt('none');
! 10889: } else {
! 10890: $output .= $usertypes->{$type}.' -- '.
! 10891: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
! 10892: }
! 10893: }
! 10894: }
! 10895: }
! 10896: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
! 10897: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
! 10898: $output .= $othertitle.' -- '.&mt('none');
! 10899: } else {
! 10900: $output .= $othertitle.' -- '.
! 10901: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
! 10902: }
! 10903: }
! 10904: if ($output) {
! 10905: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
! 10906: } else {
! 10907: $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>';
! 10908: }
! 10909: } else {
! 10910: $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>';
! 10911: }
! 10912: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
! 10913: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
! 10914: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
! 10915: } else {
! 10916: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
! 10917: }
! 10918: } else {
! 10919: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA usedfor verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
! 10920: }
! 10921: if ($confighash{'passwords'}{'resetremove'}) {
! 10922: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
! 10923: } else {
! 10924: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
! 10925: }
! 10926: if ($confighash{'passwords'}{'resetcustom'}) {
! 10927: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
! 10928: $titles{custom},600,500);
! 10929: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes [_1]',$customlink).'</li>';
! 10930: } else {
! 10931: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
! 10932: }
! 10933: } elsif ($key eq 'intauth') {
! 10934: foreach my $item ('cost','switch','check') {
! 10935: my $value = $save_defaults{$key.'_'.$item};
! 10936: if ($item eq 'switch') {
! 10937: my %optiondesc = &Apache::lonlocal::texthash (
! 10938: 0 => 'No',
! 10939: 1 => 'Yes',
! 10940: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
! 10941: );
! 10942: if ($value =~ /^(0|1|2)$/) {
! 10943: $value = $optiondesc{$value};
! 10944: } else {
! 10945: $value = &mt('none -- defaults to No');
! 10946: }
! 10947: } elsif ($item eq 'check') {
! 10948: my %optiondesc = &Apache::lonlocal::texthash (
! 10949: 0 => 'No',
! 10950: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
! 10951: 2 => 'Yes, disallow login if stored cost is less than domain default',
! 10952: );
! 10953: if ($value =~ /^(0|1|2)$/) {
! 10954: $value = $optiondesc{$value};
! 10955: } else {
! 10956: $value = &mt('none -- defaults to No');
! 10957: }
! 10958: }
! 10959: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
! 10960: }
! 10961: } elsif ($key eq 'rules') {
! 10962: foreach my $rule ('min','max','numsaved') {
! 10963: if ($confighash{'passwords'}{$rule} eq '') {
! 10964: if ($rule eq 'min') {
! 10965: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
! 10966: ' '.&mt('Default of 7 will be used').'</li>';
! 10967: } else {
! 10968: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
! 10969: }
! 10970: } else {
! 10971: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
! 10972: }
! 10973: }
! 10974: } elsif ($key eq 'crsownerchg') {
! 10975: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
! 10976: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
! 10977: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
! 10978: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
! 10979: } else {
! 10980: my %crsownerstr;
! 10981: foreach my $item ('by','for') {
! 10982: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
! 10983: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
! 10984: if ($type eq 'default') {
! 10985: $crsownerstr{$item} .= $othertitle.', ';
! 10986: } elsif ($usertypes->{$type} ne '') {
! 10987: $crsownerstr{$item} .= $usertypes->{$type}.', ';
! 10988: }
! 10989: }
! 10990: $crsownerstr{$item} =~ s/\Q, \E$//;
! 10991: }
! 10992: }
! 10993: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
! 10994: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
! 10995: }
! 10996: } else {
! 10997: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
! 10998: }
! 10999: }
! 11000: $resulttext .= '</ul></li>';
! 11001: }
! 11002: }
! 11003: $resulttext .= '</ul>';
! 11004: } else {
! 11005: $resulttext = &mt('No changes made to password settings');
! 11006: }
! 11007: my $cachetime = 24*60*60;
! 11008: if ($updatedefaults) {
! 11009: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
! 11010: if (ref($lastactref) eq 'HASH') {
! 11011: $lastactref->{'domdefaults'} = 1;
! 11012: }
! 11013: }
! 11014: if ($updateconf) {
! 11015: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
! 11016: if (ref($lastactref) eq 'HASH') {
! 11017: $lastactref->{'passwdconf'} = 1;
! 11018: }
! 11019: }
! 11020: } else {
! 11021: $resulttext = '<span class="LC_error">'.
! 11022: &mt('An error occurred: [_1]',$putresult).'</span>';
! 11023: }
! 11024: if ($errors) {
! 11025: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
! 11026: $errors.'</ul></p>';
! 11027: }
! 11028: return $resulttext;
! 11029: }
! 11030:
1.28 raeburn 11031: sub modify_usercreation {
1.27 raeburn 11032: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 11033: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 11034: my $warningmsg;
1.27 raeburn 11035: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11036: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 11037: if ($key eq 'cancreate') {
11038: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11039: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 11040: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 11041: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 11042: } else {
11043: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 11044: }
1.50 raeburn 11045: }
1.43 raeburn 11046: }
1.160.6.34 raeburn 11047: } elsif ($key eq 'email_rule') {
11048: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11049: } else {
11050: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 11051: }
11052: }
1.34 raeburn 11053: }
1.160.6.34 raeburn 11054: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
11055: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
11056: my @contexts = ('author','course','requestcrs');
11057: foreach my $item(@contexts) {
11058: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 11059: }
1.34 raeburn 11060: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11061: foreach my $item (@contexts) {
1.160.6.34 raeburn 11062: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
11063: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 11064: }
1.27 raeburn 11065: }
1.34 raeburn 11066: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
11067: foreach my $item (@contexts) {
1.43 raeburn 11068: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 11069: if ($cancreate{$item} ne 'any') {
11070: push(@{$changes{'cancreate'}},$item);
11071: }
11072: } else {
11073: if ($cancreate{$item} ne 'none') {
11074: push(@{$changes{'cancreate'}},$item);
11075: }
1.27 raeburn 11076: }
11077: }
11078: } else {
1.43 raeburn 11079: foreach my $item (@contexts) {
1.34 raeburn 11080: push(@{$changes{'cancreate'}},$item);
11081: }
1.27 raeburn 11082: }
1.34 raeburn 11083:
1.27 raeburn 11084: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
11085: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
11086: if (!grep(/^\Q$type\E$/,@username_rule)) {
11087: push(@{$changes{'username_rule'}},$type);
11088: }
11089: }
11090: foreach my $type (@username_rule) {
11091: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
11092: push(@{$changes{'username_rule'}},$type);
11093: }
11094: }
11095: } else {
11096: push(@{$changes{'username_rule'}},@username_rule);
11097: }
11098:
1.32 raeburn 11099: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
11100: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
11101: if (!grep(/^\Q$type\E$/,@id_rule)) {
11102: push(@{$changes{'id_rule'}},$type);
11103: }
11104: }
11105: foreach my $type (@id_rule) {
11106: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
11107: push(@{$changes{'id_rule'}},$type);
11108: }
11109: }
11110: } else {
11111: push(@{$changes{'id_rule'}},@id_rule);
11112: }
11113:
1.43 raeburn 11114: my @authen_contexts = ('author','course','domain');
1.28 raeburn 11115: my @authtypes = ('int','krb4','krb5','loc');
11116: my %authhash;
1.43 raeburn 11117: foreach my $item (@authen_contexts) {
1.28 raeburn 11118: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
11119: foreach my $auth (@authtypes) {
11120: if (grep(/^\Q$auth\E$/,@authallowed)) {
11121: $authhash{$item}{$auth} = 1;
11122: } else {
11123: $authhash{$item}{$auth} = 0;
11124: }
11125: }
11126: }
11127: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 11128: foreach my $item (@authen_contexts) {
1.28 raeburn 11129: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
11130: foreach my $auth (@authtypes) {
11131: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
11132: push(@{$changes{'authtypes'}},$item);
11133: last;
11134: }
11135: }
11136: }
11137: }
11138: } else {
1.43 raeburn 11139: foreach my $item (@authen_contexts) {
1.28 raeburn 11140: push(@{$changes{'authtypes'}},$item);
11141: }
11142: }
11143:
1.160.6.34 raeburn 11144: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
11145: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
11146: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
11147: $save_usercreate{'id_rule'} = \@id_rule;
11148: $save_usercreate{'username_rule'} = \@username_rule,
11149: $save_usercreate{'authtypes'} = \%authhash;
11150:
1.27 raeburn 11151: my %usercreation_hash = (
1.160.6.34 raeburn 11152: usercreation => \%save_usercreate,
11153: );
1.27 raeburn 11154:
11155: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
11156: $dom);
1.50 raeburn 11157:
1.160.6.34 raeburn 11158: if ($putresult eq 'ok') {
11159: if (keys(%changes) > 0) {
11160: $resulttext = &mt('Changes made:').'<ul>';
11161: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11162: my %lt = &usercreation_types();
11163: foreach my $type (@{$changes{'cancreate'}}) {
11164: my $chgtext = $lt{$type}.', ';
11165: if ($cancreate{$type} eq 'none') {
11166: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
11167: } elsif ($cancreate{$type} eq 'any') {
11168: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
11169: } elsif ($cancreate{$type} eq 'official') {
11170: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
11171: } elsif ($cancreate{$type} eq 'unofficial') {
11172: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
11173: }
11174: $resulttext .= '<li>'.$chgtext.'</li>';
11175: }
11176: }
11177: if (ref($changes{'username_rule'}) eq 'ARRAY') {
11178: my ($rules,$ruleorder) =
11179: &Apache::lonnet::inst_userrules($dom,'username');
11180: my $chgtext = '<ul>';
11181: foreach my $type (@username_rule) {
11182: if (ref($rules->{$type}) eq 'HASH') {
11183: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
11184: }
11185: }
11186: $chgtext .= '</ul>';
11187: if (@username_rule > 0) {
11188: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11189: } else {
11190: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
11191: }
11192: }
11193: if (ref($changes{'id_rule'}) eq 'ARRAY') {
11194: my ($idrules,$idruleorder) =
11195: &Apache::lonnet::inst_userrules($dom,'id');
11196: my $chgtext = '<ul>';
11197: foreach my $type (@id_rule) {
11198: if (ref($idrules->{$type}) eq 'HASH') {
11199: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
11200: }
11201: }
11202: $chgtext .= '</ul>';
11203: if (@id_rule > 0) {
11204: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11205: } else {
11206: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
11207: }
11208: }
11209: my %authname = &authtype_names();
11210: my %context_title = &context_names();
11211: if (ref($changes{'authtypes'}) eq 'ARRAY') {
11212: my $chgtext = '<ul>';
11213: foreach my $type (@{$changes{'authtypes'}}) {
11214: my @allowed;
11215: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
11216: foreach my $auth (@authtypes) {
11217: if ($authhash{$type}{$auth}) {
11218: push(@allowed,$authname{$auth});
11219: }
11220: }
11221: if (@allowed > 0) {
11222: $chgtext .= join(', ',@allowed).'</li>';
11223: } else {
11224: $chgtext .= &mt('none').'</li>';
11225: }
11226: }
11227: $chgtext .= '</ul>';
11228: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
11229: $resulttext .= '</li>';
11230: }
11231: $resulttext .= '</ul>';
11232: } else {
11233: $resulttext = &mt('No changes made to user creation settings');
11234: }
11235: } else {
11236: $resulttext = '<span class="LC_error">'.
11237: &mt('An error occurred: [_1]',$putresult).'</span>';
11238: }
11239: if ($warningmsg ne '') {
11240: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11241: }
11242: return $resulttext;
11243: }
11244:
11245: sub modify_selfcreation {
1.160.6.93 raeburn 11246: my ($dom,$lastactref,%domconfig) = @_;
11247: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
11248: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
11249: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11250: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
11251: if (ref($typesref) eq 'ARRAY') {
11252: @types = @{$typesref};
11253: }
11254: if (ref($usertypesref) eq 'HASH') {
11255: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 11256: }
1.160.6.93 raeburn 11257: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 11258: #
11259: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
11260: #
11261: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11262: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
11263: if ($key eq 'cancreate') {
11264: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11265: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
11266: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 11267: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
11268: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
11269: ($item eq 'emailusername') || ($item eq 'shibenv') ||
11270: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
11271: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 11272: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11273: } else {
11274: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11275: }
11276: }
11277: }
11278: } elsif ($key eq 'email_rule') {
11279: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11280: } else {
11281: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11282: }
11283: }
11284: }
11285: #
11286: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
11287: #
11288: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11289: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
11290: if ($key eq 'selfcreate') {
11291: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
11292: } else {
11293: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
11294: }
11295: }
11296: }
1.160.6.93 raeburn 11297: #
11298: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
11299: #
11300: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11301: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
11302: if ($key eq 'inststatusguest') {
11303: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
11304: } else {
11305: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
11306: }
11307: }
11308: }
1.160.6.34 raeburn 11309:
11310: my @contexts = ('selfcreate');
11311: @{$cancreate{'selfcreate'}} = ();
11312: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 11313: if (@types) {
11314: @{$cancreate{'statustocreate'}} = ();
11315: }
1.160.6.40 raeburn 11316: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 11317: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 11318: %{$cancreate{'emailverified'}} = ();
11319: %{$cancreate{'emailoptions'}} = ();
11320: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 11321: my %selfcreatetypes = (
11322: sso => 'users authenticated by institutional single sign on',
11323: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 11324: email => 'users verified by e-mail',
1.50 raeburn 11325: );
1.160.6.34 raeburn 11326: #
11327: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
11328: # is permitted.
11329: #
1.160.6.40 raeburn 11330:
1.160.6.93 raeburn 11331: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 11332:
1.160.6.93 raeburn 11333: my (@statuses,%email_rule);
1.160.6.35 raeburn 11334: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 11335: if ($item eq 'email') {
1.160.6.40 raeburn 11336: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 11337: if (@types) {
11338: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
11339: foreach my $status (@poss_statuses) {
11340: if (grep(/^\Q$status\E$/,(@types,'default'))) {
11341: push(@statuses,$status);
11342: }
11343: }
11344: $save_inststatus{'inststatusguest'} = \@statuses;
11345: } else {
11346: push(@statuses,'default');
11347: }
11348: if (@statuses) {
11349: my %curr_rule;
11350: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
11351: foreach my $type (@statuses) {
11352: $curr_rule{$type} = $curr_usercreation{'email_rule'};
11353: }
11354: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
11355: foreach my $type (@statuses) {
11356: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
11357: }
11358: }
11359: push(@{$cancreate{'selfcreate'}},'email');
11360: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
11361: my %curremaildom;
11362: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
11363: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
11364: }
11365: foreach my $type (@statuses) {
11366: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
11367: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
11368: }
11369: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
11370: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
11371: }
11372: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
11373: #
11374: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
11375: #
11376: my $chosen = $1;
11377: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
11378: my $emaildom;
11379: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
11380: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
11381: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
11382: if (ref($curremaildom{$type}) eq 'HASH') {
11383: if (exists($curremaildom{$type}{$chosen})) {
11384: if ($curremaildom{$type}{$chosen} ne $emaildom) {
11385: push(@{$changes{'cancreate'}},'emaildomain');
11386: }
11387: } elsif ($emaildom ne '') {
11388: push(@{$changes{'cancreate'}},'emaildomain');
11389: }
11390: } elsif ($emaildom ne '') {
11391: push(@{$changes{'cancreate'}},'emaildomain');
11392: }
11393: }
11394: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
11395: } elsif ($chosen eq 'custom') {
11396: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
11397: $email_rule{$type} = [];
11398: if (ref($emailrules) eq 'HASH') {
11399: foreach my $rule (@possemail_rules) {
11400: if (exists($emailrules->{$rule})) {
11401: push(@{$email_rule{$type}},$rule);
11402: }
11403: }
11404: }
11405: if (@{$email_rule{$type}}) {
11406: $cancreate{'emailoptions'}{$type} = 'custom';
11407: if (ref($curr_rule{$type}) eq 'ARRAY') {
11408: if (@{$curr_rule{$type}} > 0) {
11409: foreach my $rule (@{$curr_rule{$type}}) {
11410: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
11411: push(@{$changes{'email_rule'}},$type);
11412: }
11413: }
11414: }
11415: foreach my $type (@{$email_rule{$type}}) {
11416: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
11417: push(@{$changes{'email_rule'}},$type);
11418: }
11419: }
11420: } else {
11421: push(@{$changes{'email_rule'}},$type);
11422: }
11423: }
11424: } else {
11425: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
11426: }
11427: }
11428: }
11429: if (@types) {
11430: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
11431: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
11432: if (@changed) {
11433: push(@{$changes{'inststatus'}},'inststatusguest');
11434: }
11435: } else {
11436: push(@{$changes{'inststatus'}},'inststatusguest');
11437: }
11438: }
11439: } else {
11440: delete($env{'form.cancreate_email'});
11441: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
11442: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
11443: push(@{$changes{'inststatus'}},'inststatusguest');
11444: }
11445: }
11446: }
11447: } else {
11448: $save_inststatus{'inststatusguest'} = [];
11449: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
11450: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
11451: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 11452: }
11453: }
1.160.6.34 raeburn 11454: }
11455: } else {
11456: if ($env{'form.cancreate_'.$item}) {
11457: push(@{$cancreate{'selfcreate'}},$item);
11458: }
11459: }
11460: }
1.160.6.93 raeburn 11461: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 11462: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
11463: #
1.160.6.35 raeburn 11464: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
11465: # 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 11466: #
1.160.6.40 raeburn 11467:
1.160.6.48 raeburn 11468: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 11469: push(@contexts,'emailusername');
1.160.6.93 raeburn 11470: if (@statuses) {
11471: foreach my $type (@statuses) {
1.160.6.35 raeburn 11472: if (ref($infofields) eq 'ARRAY') {
11473: foreach my $field (@{$infofields}) {
11474: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
11475: $cancreate{'emailusername'}{$type}{$field} = $1;
11476: }
11477: }
1.160.6.34 raeburn 11478: }
11479: }
11480: }
11481: #
11482: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 11483: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 11484: #
11485:
11486: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
11487: @approvalnotify = sort(@approvalnotify);
11488: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
11489: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11490: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
11491: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
11492: push(@{$changes{'cancreate'}},'notify');
11493: }
11494: } else {
11495: if ($cancreate{'notify'}{'approval'}) {
11496: push(@{$changes{'cancreate'}},'notify');
11497: }
11498: }
11499: } elsif ($cancreate{'notify'}{'approval'}) {
11500: push(@{$changes{'cancreate'}},'notify');
11501: }
11502:
11503: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
11504: }
11505: #
1.160.6.40 raeburn 11506: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 11507: # institutional log-in.
11508: #
11509: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
11510: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
11511: ($domdefaults{'auth_def'} eq 'localauth'))) {
11512: $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.').' '.
11513: &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.');
11514: }
11515: }
11516: my @fields = ('lastname','firstname','middlename','generation',
11517: 'permanentemail','id');
1.160.6.44 raeburn 11518: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 11519: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11520: #
11521: # Where usernames may created for institutional log-in and/or institutional single sign on:
11522: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
11523: # may self-create accounts
11524: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
11525: # which the user may supply, if institutional data is unavailable.
11526: #
11527: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 11528: if (@types) {
11529: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
11530: push(@contexts,'statustocreate');
11531: foreach my $type (@types) {
1.160.6.34 raeburn 11532: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
11533: foreach my $field (@fields) {
11534: if (grep(/^\Q$field\E$/,@modifiable)) {
11535: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
11536: } else {
11537: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
11538: }
11539: }
11540: }
11541: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 11542: foreach my $type (@types) {
1.160.6.34 raeburn 11543: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
11544: foreach my $field (@fields) {
11545: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
11546: $curr_usermodify{'selfcreate'}{$type}{$field}) {
11547: push(@{$changes{'selfcreate'}},$type);
11548: last;
11549: }
11550: }
11551: }
11552: }
11553: } else {
1.160.6.93 raeburn 11554: foreach my $type (@types) {
1.160.6.34 raeburn 11555: push(@{$changes{'selfcreate'}},$type);
11556: }
11557: }
11558: }
1.160.6.44 raeburn 11559: foreach my $field (@shibfields) {
11560: if ($env{'form.shibenv_'.$field} ne '') {
11561: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
11562: }
11563: }
11564: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11565: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
11566: foreach my $field (@shibfields) {
11567: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
11568: push(@{$changes{'cancreate'}},'shibenv');
11569: }
11570: }
11571: } else {
11572: foreach my $field (@shibfields) {
11573: if ($env{'form.shibenv_'.$field}) {
11574: push(@{$changes{'cancreate'}},'shibenv');
11575: last;
11576: }
11577: }
11578: }
11579: }
1.160.6.34 raeburn 11580: }
11581: foreach my $item (@contexts) {
11582: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
11583: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
11584: if (ref($cancreate{$item}) eq 'ARRAY') {
11585: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
11586: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11587: push(@{$changes{'cancreate'}},$item);
11588: }
11589: }
11590: }
11591: }
11592: if (ref($cancreate{$item}) eq 'ARRAY') {
11593: foreach my $type (@{$cancreate{$item}}) {
11594: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
11595: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11596: push(@{$changes{'cancreate'}},$item);
11597: }
11598: }
11599: }
11600: }
11601: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
11602: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 11603: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
11604: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
11605: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
11606: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 11607: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11608: push(@{$changes{'cancreate'}},$item);
11609: }
11610: }
11611: }
1.160.6.93 raeburn 11612: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
11613: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 11614: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11615: push(@{$changes{'cancreate'}},$item);
11616: }
1.160.6.34 raeburn 11617: }
11618: }
11619: }
1.160.6.93 raeburn 11620: foreach my $type (keys(%{$cancreate{$item}})) {
11621: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11622: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11623: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
11624: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 11625: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11626: push(@{$changes{'cancreate'}},$item);
11627: }
11628: }
11629: } else {
11630: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11631: push(@{$changes{'cancreate'}},$item);
11632: }
11633: }
11634: }
1.160.6.93 raeburn 11635: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
11636: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 11637: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11638: push(@{$changes{'cancreate'}},$item);
11639: }
1.160.6.34 raeburn 11640: }
11641: }
11642: }
11643: }
11644: } elsif ($curr_usercreation{'cancreate'}{$item}) {
11645: if (ref($cancreate{$item}) eq 'ARRAY') {
11646: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
11647: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11648: push(@{$changes{'cancreate'}},$item);
11649: }
11650: }
1.160.6.93 raeburn 11651: }
11652: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
11653: if (ref($cancreate{$item}) eq 'HASH') {
11654: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11655: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 11656: }
11657: }
11658: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 11659: if (ref($cancreate{$item}) eq 'HASH') {
11660: foreach my $type (keys(%{$cancreate{$item}})) {
11661: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11662: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11663: if ($cancreate{$item}{$type}{$field}) {
11664: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11665: push(@{$changes{'cancreate'}},$item);
11666: }
11667: last;
11668: }
11669: }
11670: }
11671: }
1.160.6.34 raeburn 11672: }
11673: }
11674: }
11675: #
11676: # Populate %save_usercreate hash with updates to self-creation configuration.
11677: #
11678: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
11679: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 11680: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 11681: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
11682: if (ref($cancreate{'notify'}) eq 'HASH') {
11683: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
11684: }
1.160.6.40 raeburn 11685: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
11686: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
11687: }
1.160.6.93 raeburn 11688: if (ref($cancreate{'emailverified'}) eq 'HASH') {
11689: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
11690: }
11691: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
11692: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
11693: }
11694: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
11695: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
11696: }
1.160.6.34 raeburn 11697: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11698: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
11699: }
1.160.6.44 raeburn 11700: if (ref($cancreate{'shibenv'}) eq 'HASH') {
11701: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
11702: }
1.160.6.34 raeburn 11703: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 11704: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 11705:
11706: my %userconfig_hash = (
11707: usercreation => \%save_usercreate,
11708: usermodification => \%save_usermodify,
1.160.6.93 raeburn 11709: inststatus => \%save_inststatus,
1.160.6.34 raeburn 11710: );
1.160.6.93 raeburn 11711:
1.160.6.34 raeburn 11712: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
11713: $dom);
11714: #
1.160.6.93 raeburn 11715: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 11716: #
1.27 raeburn 11717: if ($putresult eq 'ok') {
11718: if (keys(%changes) > 0) {
11719: $resulttext = &mt('Changes made:').'<ul>';
11720: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 11721: my %lt = &selfcreation_types();
1.34 raeburn 11722: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 11723: my $chgtext = '';
1.45 raeburn 11724: if ($type eq 'selfcreate') {
1.50 raeburn 11725: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 11726: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 11727: } else {
1.160.6.34 raeburn 11728: $chgtext .= &mt('Self-creation of a new account is permitted for:').
11729: '<ul>';
1.50 raeburn 11730: foreach my $case (@{$cancreate{$type}}) {
11731: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
11732: }
11733: $chgtext .= '</ul>';
1.100 raeburn 11734: if (ref($cancreate{$type}) eq 'ARRAY') {
11735: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
11736: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11737: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 11738: $chgtext .= '<span class="LC_warning">'.
11739: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
11740: '</span><br />';
1.100 raeburn 11741: }
11742: }
11743: }
1.160.6.93 raeburn 11744: if (grep(/^email$/,@{$cancreate{$type}})) {
11745: if (!@statuses) {
11746: $chgtext .= '<span class="LC_warning">'.
11747: &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.").
11748: '</span><br />';
11749:
11750: }
11751: }
1.100 raeburn 11752: }
1.43 raeburn 11753: }
1.160.6.44 raeburn 11754: } elsif ($type eq 'shibenv') {
11755: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 11756: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 11757: } else {
11758: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
11759: '<ul>';
11760: foreach my $field (@shibfields) {
11761: next if ($cancreate{$type}{$field} eq '');
11762: if ($field eq 'inststatus') {
11763: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
11764: } else {
11765: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
11766: }
11767: }
11768: $chgtext .= '</ul>';
1.160.6.93 raeburn 11769: }
1.93 raeburn 11770: } elsif ($type eq 'statustocreate') {
1.96 raeburn 11771: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
11772: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
11773: if (@{$cancreate{'selfcreate'}} > 0) {
11774: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 11775: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 11776: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 11777: $chgtext .= '<br />'.
11778: '<span class="LC_warning">'.
11779: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11780: '</span>';
11781: }
1.160.6.93 raeburn 11782: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 11783: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 11784: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
11785: } else {
11786: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
11787: }
11788: $chgtext .= '<ul>';
11789: foreach my $case (@{$cancreate{$type}}) {
11790: if ($case eq 'default') {
11791: $chgtext .= '<li>'.$othertitle.'</li>';
11792: } else {
1.160.6.93 raeburn 11793: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 11794: }
11795: }
1.100 raeburn 11796: $chgtext .= '</ul>';
11797: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 11798: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 11799: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
11800: '</span>';
1.100 raeburn 11801: }
11802: }
11803: } else {
11804: if (@{$cancreate{$type}} == 0) {
11805: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
11806: } else {
11807: $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 11808: }
11809: }
1.160.6.93 raeburn 11810: $chgtext .= '<br />';
1.93 raeburn 11811: }
1.160.6.40 raeburn 11812: } elsif ($type eq 'selfcreateprocessing') {
11813: my %choices = &Apache::lonlocal::texthash (
11814: automatic => 'Automatic approval',
11815: approval => 'Queued for approval',
11816: );
1.160.6.93 raeburn 11817: if (@types) {
11818: if (@statuses) {
11819: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
11820: '<ul>';
11821: foreach my $status (@statuses) {
11822: if ($status eq 'default') {
11823: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
11824: } else {
11825: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
11826: }
11827: }
11828: $chgtext .= '</ul>';
11829: }
11830: } else {
11831: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
11832: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
11833: }
11834: } elsif ($type eq 'emailverified') {
11835: my %options = &Apache::lonlocal::texthash (
11836: all => 'Same as e-mail',
11837: first => 'Omit @domain',
11838: free => 'Free to choose',
11839: );
11840: if (@types) {
11841: if (@statuses) {
11842: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
11843: '<ul>';
11844: foreach my $status (@statuses) {
11845: if ($status eq 'default') {
11846: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
11847: } else {
11848: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
11849: }
11850: }
11851: $chgtext .= '</ul>';
11852: }
1.160.6.40 raeburn 11853: } else {
1.160.6.93 raeburn 11854: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
11855: $options{$cancreate{'emailverified'}{'default'}});
11856: }
11857: } elsif ($type eq 'emailoptions') {
11858: my %options = &Apache::lonlocal::texthash (
11859: any => 'Any e-mail',
11860: inst => 'Institutional only',
11861: noninst => 'Non-institutional only',
11862: custom => 'Custom restrictions',
11863: );
11864: if (@types) {
11865: if (@statuses) {
11866: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
11867: '<ul>';
11868: foreach my $status (@statuses) {
11869: if ($type eq 'default') {
11870: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
11871: } else {
11872: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
11873: }
11874: }
11875: $chgtext .= '</ul>';
11876: }
11877: } else {
11878: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
11879: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
11880: } else {
11881: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
11882: $options{$cancreate{'emailoptions'}{'default'}});
11883: }
11884: }
11885: } elsif ($type eq 'emaildomain') {
11886: my $output;
11887: if (@statuses) {
11888: foreach my $type (@statuses) {
11889: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
11890: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
11891: if ($type eq 'default') {
11892: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
11893: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
11894: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
11895: } else {
11896: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
11897: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
11898: }
11899: } else {
11900: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
11901: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
11902: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
11903: } else {
11904: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
11905: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
11906: }
11907: }
11908: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
11909: if ($type eq 'default') {
11910: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
11911: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
11912: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
11913: } else {
11914: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
11915: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
11916: }
11917: } else {
11918: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
11919: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
11920: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
11921: } else {
11922: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
11923: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
11924: }
11925: }
11926: }
11927: }
11928: }
11929: }
11930: if ($output ne '') {
11931: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
11932: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 11933: }
1.160.6.5 raeburn 11934: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 11935: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 11936: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
11937: } else {
11938: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 11939: if ($captchas{$savecaptcha{$type}}) {
11940: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 11941: } else {
11942: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
11943: }
11944: }
11945: } elsif ($type eq 'recaptchakeys') {
11946: my ($privkey,$pubkey);
1.160.6.34 raeburn 11947: if (ref($savecaptcha{$type}) eq 'HASH') {
11948: $pubkey = $savecaptcha{$type}{'public'};
11949: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 11950: }
11951: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
11952: if (!$pubkey) {
11953: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
11954: } else {
11955: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11956: }
11957: if (!$privkey) {
11958: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
11959: } else {
11960: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
11961: }
11962: $chgtext .= '</ul>';
1.160.6.69 raeburn 11963: } elsif ($type eq 'recaptchaversion') {
11964: if ($savecaptcha{'captcha'} eq 'recaptcha') {
11965: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
11966: }
1.160.6.34 raeburn 11967: } elsif ($type eq 'emailusername') {
11968: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 11969: if (@statuses) {
11970: foreach my $type (@statuses) {
1.160.6.35 raeburn 11971: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
11972: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 11973: $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 11974: '<ul>';
11975: foreach my $field (@{$infofields}) {
11976: if ($cancreate{'emailusername'}{$type}{$field}) {
11977: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
11978: }
11979: }
1.160.6.50 raeburn 11980: $chgtext .= '</ul>';
11981: } else {
1.160.6.93 raeburn 11982: $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 11983: }
11984: } else {
1.160.6.93 raeburn 11985: $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 11986: }
11987: }
11988: }
11989: }
11990: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 11991: my $numapprove = 0;
1.160.6.34 raeburn 11992: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11993: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
11994: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 11995: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
11996: $numapprove ++;
1.160.6.34 raeburn 11997: }
11998: }
1.43 raeburn 11999: }
1.160.6.93 raeburn 12000: unless ($numapprove) {
12001: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
12002: }
1.34 raeburn 12003: }
1.160.6.34 raeburn 12004: if ($chgtext) {
12005: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 12006: }
12007: }
12008: }
1.160.6.93 raeburn 12009: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 12010: my ($emailrules,$emailruleorder) =
12011: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 12012: foreach my $type (@{$changes{'email_rule'}}) {
12013: if (ref($email_rule{$type}) eq 'ARRAY') {
12014: my $chgtext = '<ul>';
12015: foreach my $rule (@{$email_rule{$type}}) {
12016: if (ref($emailrules->{$rule}) eq 'HASH') {
12017: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
12018: }
12019: }
12020: $chgtext .= '</ul>';
12021: my $typename;
12022: if (@types) {
12023: if ($type eq 'default') {
12024: $typename = $othertitle;
12025: } else {
12026: $typename = $usertypes{$type};
12027: }
12028: $chgtext .= &mt('(Affiliation: [_1])',$typename);
12029: }
12030: if (@{$email_rule{$type}} > 0) {
12031: $resulttext .= '<li>'.
12032: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
12033: $usertypes{$type}).
12034: $chgtext.
12035: '</li>';
12036: } else {
12037: $resulttext .= '<li>'.
12038: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
12039: '</li>'.
12040: &mt('(Affiliation: [_1])',$typename);
12041: }
1.43 raeburn 12042: }
12043: }
1.160.6.93 raeburn 12044: }
12045: if (ref($changes{'inststatus'}) eq 'ARRAY') {
12046: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
12047: if (@{$save_inststatus{'inststatusguest'}} > 0) {
12048: my $chgtext = '<ul>';
12049: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
12050: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
12051: }
12052: $chgtext .= '</ul>';
12053: $resulttext .= '<li>'.
12054: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
12055: $chgtext.
12056: '</li>';
12057: } else {
12058: $resulttext .= '<li>'.
12059: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
12060: '</li>';
12061: }
1.43 raeburn 12062: }
12063: }
1.160.6.34 raeburn 12064: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
12065: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
12066: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12067: foreach my $type (@{$changes{'selfcreate'}}) {
12068: my $typename = $type;
1.160.6.93 raeburn 12069: if (keys(%usertypes) > 0) {
12070: if ($usertypes{$type} ne '') {
12071: $typename = $usertypes{$type};
1.28 raeburn 12072: }
12073: }
1.160.6.34 raeburn 12074: my @modifiable;
12075: $resulttext .= '<li>'.
12076: &mt('Self-creation of account by users with status: [_1]',
12077: '<span class="LC_cusr_emph">'.$typename.'</span>').
12078: ' - '.&mt('modifiable fields (if institutional data blank): ');
12079: foreach my $field (@fields) {
12080: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
12081: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
12082: }
12083: }
12084: if (@modifiable > 0) {
12085: $resulttext .= join(', ',@modifiable);
1.43 raeburn 12086: } else {
1.160.6.34 raeburn 12087: $resulttext .= &mt('none');
1.43 raeburn 12088: }
1.160.6.34 raeburn 12089: $resulttext .= '</li>';
1.28 raeburn 12090: }
1.160.6.34 raeburn 12091: $resulttext .= '</ul></li>';
1.28 raeburn 12092: }
1.27 raeburn 12093: $resulttext .= '</ul>';
1.160.6.93 raeburn 12094: my $cachetime = 24*60*60;
12095: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
12096: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12097: if (ref($lastactref) eq 'HASH') {
12098: $lastactref->{'domdefaults'} = 1;
12099: }
1.27 raeburn 12100: } else {
1.160.6.34 raeburn 12101: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 12102: }
12103: } else {
12104: $resulttext = '<span class="LC_error">'.
1.23 raeburn 12105: &mt('An error occurred: [_1]',$putresult).'</span>';
12106: }
1.43 raeburn 12107: if ($warningmsg ne '') {
12108: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
12109: }
1.23 raeburn 12110: return $resulttext;
12111: }
12112:
1.160.6.5 raeburn 12113: sub process_captcha {
12114: my ($container,$changes,$newsettings,$current) = @_;
12115: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
12116: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
12117: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
12118: $newsettings->{'captcha'} = 'original';
12119: }
12120: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
12121: if ($container eq 'cancreate') {
12122: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12123: push(@{$changes->{'cancreate'}},'captcha');
12124: } elsif (!defined($changes->{'cancreate'})) {
12125: $changes->{'cancreate'} = ['captcha'];
12126: }
12127: } else {
12128: $changes->{'captcha'} = 1;
12129: }
12130: }
1.160.6.69 raeburn 12131: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 12132: if ($newsettings->{'captcha'} eq 'recaptcha') {
12133: $newpub = $env{'form.'.$container.'_recaptchapub'};
12134: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 12135: $newpub =~ s/[^\w\-]//g;
12136: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 12137: $newsettings->{'recaptchakeys'} = {
12138: public => $newpub,
12139: private => $newpriv,
12140: };
1.160.6.69 raeburn 12141: $newversion = $env{'form.'.$container.'_recaptchaversion'};
12142: $newversion =~ s/\D//g;
12143: if ($newversion ne '2') {
12144: $newversion = 1;
12145: }
12146: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 12147: }
12148: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
12149: $currpub = $current->{'recaptchakeys'}{'public'};
12150: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 12151: unless ($newsettings->{'captcha'} eq 'recaptcha') {
12152: $newsettings->{'recaptchakeys'} = {
12153: public => '',
12154: private => '',
12155: }
12156: }
1.160.6.5 raeburn 12157: }
1.160.6.69 raeburn 12158: if ($current->{'captcha'} eq 'recaptcha') {
12159: $currversion = $current->{'recaptchaversion'};
12160: if ($currversion ne '2') {
12161: $currversion = 1;
12162: }
12163: }
12164: if ($currversion ne $newversion) {
12165: if ($container eq 'cancreate') {
12166: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12167: push(@{$changes->{'cancreate'}},'recaptchaversion');
12168: } elsif (!defined($changes->{'cancreate'})) {
12169: $changes->{'cancreate'} = ['recaptchaversion'];
12170: }
12171: } else {
12172: $changes->{'recaptchaversion'} = 1;
12173: }
12174: }
1.160.6.5 raeburn 12175: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
12176: if ($container eq 'cancreate') {
12177: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12178: push(@{$changes->{'cancreate'}},'recaptchakeys');
12179: } elsif (!defined($changes->{'cancreate'})) {
12180: $changes->{'cancreate'} = ['recaptchakeys'];
12181: }
12182: } else {
12183: $changes->{'recaptchakeys'} = 1;
12184: }
12185: }
12186: return;
12187: }
12188:
1.33 raeburn 12189: sub modify_usermodification {
12190: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 12191: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 12192: if (ref($domconfig{'usermodification'}) eq 'HASH') {
12193: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 12194: if ($key eq 'selfcreate') {
12195: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
12196: } else {
12197: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
12198: }
1.33 raeburn 12199: }
12200: }
1.160.6.34 raeburn 12201: my @contexts = ('author','course');
1.33 raeburn 12202: my %context_title = (
12203: author => 'In author context',
12204: course => 'In course context',
12205: );
12206: my @fields = ('lastname','firstname','middlename','generation',
12207: 'permanentemail','id');
12208: my %roles = (
12209: author => ['ca','aa'],
12210: course => ['st','ep','ta','in','cr'],
12211: );
12212: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12213: foreach my $context (@contexts) {
12214: foreach my $role (@{$roles{$context}}) {
12215: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
12216: foreach my $item (@fields) {
12217: if (grep(/^\Q$item\E$/,@modifiable)) {
12218: $modifyhash{$context}{$role}{$item} = 1;
12219: } else {
12220: $modifyhash{$context}{$role}{$item} = 0;
12221: }
12222: }
12223: }
12224: if (ref($curr_usermodification{$context}) eq 'HASH') {
12225: foreach my $role (@{$roles{$context}}) {
12226: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
12227: foreach my $field (@fields) {
12228: if ($modifyhash{$context}{$role}{$field} ne
12229: $curr_usermodification{$context}{$role}{$field}) {
12230: push(@{$changes{$context}},$role);
12231: last;
12232: }
12233: }
12234: }
12235: }
12236: } else {
12237: foreach my $context (@contexts) {
12238: foreach my $role (@{$roles{$context}}) {
12239: push(@{$changes{$context}},$role);
12240: }
12241: }
12242: }
12243: }
12244: my %usermodification_hash = (
12245: usermodification => \%modifyhash,
12246: );
12247: my $putresult = &Apache::lonnet::put_dom('configuration',
12248: \%usermodification_hash,$dom);
12249: if ($putresult eq 'ok') {
12250: if (keys(%changes) > 0) {
12251: $resulttext = &mt('Changes made: ').'<ul>';
12252: foreach my $context (@contexts) {
12253: if (ref($changes{$context}) eq 'ARRAY') {
12254: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
12255: if (ref($changes{$context}) eq 'ARRAY') {
12256: foreach my $role (@{$changes{$context}}) {
12257: my $rolename;
1.160.6.34 raeburn 12258: if ($role eq 'cr') {
12259: $rolename = &mt('Custom');
1.33 raeburn 12260: } else {
1.160.6.34 raeburn 12261: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 12262: }
12263: my @modifiable;
1.160.6.34 raeburn 12264: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 12265: foreach my $field (@fields) {
12266: if ($modifyhash{$context}{$role}{$field}) {
12267: push(@modifiable,$fieldtitles{$field});
12268: }
12269: }
12270: if (@modifiable > 0) {
12271: $resulttext .= join(', ',@modifiable);
12272: } else {
12273: $resulttext .= &mt('none');
12274: }
12275: $resulttext .= '</li>';
12276: }
12277: $resulttext .= '</ul></li>';
12278: }
12279: }
12280: }
12281: $resulttext .= '</ul>';
12282: } else {
12283: $resulttext = &mt('No changes made to user modification settings');
12284: }
12285: } else {
12286: $resulttext = '<span class="LC_error">'.
12287: &mt('An error occurred: [_1]',$putresult).'</span>';
12288: }
12289: return $resulttext;
12290: }
12291:
1.43 raeburn 12292: sub modify_defaults {
1.160.6.27 raeburn 12293: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 12294: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 12295: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 12296: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98! raeburn 12297: 'portal_def');
1.43 raeburn 12298: my @authtypes = ('internal','krb4','krb5','localauth');
12299: foreach my $item (@items) {
12300: $newvalues{$item} = $env{'form.'.$item};
12301: if ($item eq 'auth_def') {
12302: if ($newvalues{$item} ne '') {
12303: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
12304: push(@errors,$item);
12305: }
12306: }
12307: } elsif ($item eq 'lang_def') {
12308: if ($newvalues{$item} ne '') {
12309: if ($newvalues{$item} =~ /^(\w+)/) {
12310: my $langcode = $1;
1.103 raeburn 12311: if ($langcode ne 'x_chef') {
12312: if (code2language($langcode) eq '') {
12313: push(@errors,$item);
12314: }
1.43 raeburn 12315: }
12316: } else {
12317: push(@errors,$item);
12318: }
12319: }
1.54 raeburn 12320: } elsif ($item eq 'timezone_def') {
12321: if ($newvalues{$item} ne '') {
1.62 raeburn 12322: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 12323: push(@errors,$item);
12324: }
12325: }
1.68 raeburn 12326: } elsif ($item eq 'datelocale_def') {
12327: if ($newvalues{$item} ne '') {
12328: my @datelocale_ids = DateTime::Locale->ids();
12329: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
12330: push(@errors,$item);
12331: }
12332: }
1.141 raeburn 12333: } elsif ($item eq 'portal_def') {
12334: if ($newvalues{$item} ne '') {
12335: 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])\/?$/) {
12336: push(@errors,$item);
12337: }
12338: }
1.43 raeburn 12339: }
12340: if (grep(/^\Q$item\E$/,@errors)) {
12341: $newvalues{$item} = $domdefaults{$item};
12342: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
12343: $changes{$item} = 1;
12344: }
1.72 raeburn 12345: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 12346: }
1.160.6.98! raeburn 12347: my %staticdefaults = (
! 12348: 'intauth_cost' => 10,
! 12349: 'intauth_check' => 0,
! 12350: 'intauth_switch' => 0,
! 12351: );
! 12352: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
! 12353: if (exists($domdefaults{$item})) {
! 12354: $newvalues{$item} = $domdefaults{$item};
! 12355: } else {
! 12356: $newvalues{$item} = $staticdefaults{$item};
! 12357: }
! 12358: }
1.43 raeburn 12359: my %defaults_hash = (
1.72 raeburn 12360: defaults => \%newvalues,
12361: );
1.43 raeburn 12362: my $title = &defaults_titles();
1.160.6.40 raeburn 12363:
12364: my $currinststatus;
12365: if (ref($domconfig{'inststatus'}) eq 'HASH') {
12366: $currinststatus = $domconfig{'inststatus'};
12367: } else {
12368: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12369: $currinststatus = {
12370: inststatustypes => $usertypes,
12371: inststatusorder => $types,
12372: inststatusguest => [],
12373: };
12374: }
12375: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
12376: my @allpos;
12377: my %alltypes;
1.160.6.93 raeburn 12378: my @inststatusguest;
12379: if (ref($currinststatus) eq 'HASH') {
12380: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
12381: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
12382: unless (grep(/^\Q$type\E$/,@todelete)) {
12383: push(@inststatusguest,$type);
12384: }
12385: }
12386: }
12387: }
12388: my ($currtitles,$currorder);
1.160.6.40 raeburn 12389: if (ref($currinststatus) eq 'HASH') {
12390: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
12391: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
12392: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
12393: if ($currinststatus->{inststatustypes}->{$type} ne '') {
12394: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
12395: }
12396: }
12397: unless (grep(/^\Q$type\E$/,@todelete)) {
12398: my $position = $env{'form.inststatus_pos_'.$type};
12399: $position =~ s/\D+//g;
12400: $allpos[$position] = $type;
12401: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
12402: $alltypes{$type} =~ s/`//g;
12403: }
12404: }
12405: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
12406: $currtitles =~ s/,$//;
12407: }
12408: }
12409: if ($env{'form.addinststatus'}) {
12410: my $newtype = $env{'form.addinststatus'};
12411: $newtype =~ s/\W//g;
12412: unless (exists($alltypes{$newtype})) {
12413: $alltypes{$newtype} = $env{'form.addinststatus_title'};
12414: $alltypes{$newtype} =~ s/`//g;
12415: my $position = $env{'form.addinststatus_pos'};
12416: $position =~ s/\D+//g;
12417: if ($position ne '') {
12418: $allpos[$position] = $newtype;
12419: }
12420: }
12421: }
1.160.6.93 raeburn 12422: my @orderedstatus;
1.160.6.40 raeburn 12423: foreach my $type (@allpos) {
12424: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
12425: push(@orderedstatus,$type);
12426: }
12427: }
12428: foreach my $type (keys(%alltypes)) {
12429: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
12430: delete($alltypes{$type});
12431: }
12432: }
12433: $defaults_hash{'inststatus'} = {
12434: inststatustypes => \%alltypes,
12435: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 12436: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 12437: };
12438: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
12439: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
12440: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
12441: }
12442: }
12443: if ($currorder ne join(',',@orderedstatus)) {
12444: $changes{'inststatus'}{'inststatusorder'} = 1;
12445: }
12446: my $newtitles;
12447: foreach my $item (@orderedstatus) {
12448: $newtitles .= $alltypes{$item}.',';
12449: }
12450: $newtitles =~ s/,$//;
12451: if ($currtitles ne $newtitles) {
12452: $changes{'inststatus'}{'inststatustypes'} = 1;
12453: }
1.43 raeburn 12454: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
12455: $dom);
12456: if ($putresult eq 'ok') {
12457: if (keys(%changes) > 0) {
12458: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 12459: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 12460: 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";
12461: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 12462: if ($item eq 'inststatus') {
12463: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 12464: if (@orderedstatus) {
1.160.6.40 raeburn 12465: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
12466: foreach my $type (@orderedstatus) {
12467: $resulttext .= $alltypes{$type}.', ';
12468: }
12469: $resulttext =~ s/, $//;
12470: $resulttext .= '</li>';
1.160.6.93 raeburn 12471: } else {
12472: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 12473: }
12474: }
12475: } else {
12476: my $value = $env{'form.'.$item};
12477: if ($value eq '') {
12478: $value = &mt('none');
12479: } elsif ($item eq 'auth_def') {
12480: my %authnames = &authtype_names();
12481: my %shortauth = (
12482: internal => 'int',
12483: krb4 => 'krb4',
12484: krb5 => 'krb5',
12485: localauth => 'loc',
12486: );
12487: $value = $authnames{$shortauth{$value}};
12488: }
12489: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
12490: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 12491: }
12492: }
12493: $resulttext .= '</ul>';
12494: $mailmsgtext .= "\n";
12495: my $cachetime = 24*60*60;
1.72 raeburn 12496: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 12497: if (ref($lastactref) eq 'HASH') {
12498: $lastactref->{'domdefaults'} = 1;
12499: }
1.68 raeburn 12500: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 12501: my $notify = 1;
12502: if (ref($domconfig{'contacts'}) eq 'HASH') {
12503: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
12504: $notify = 0;
12505: }
12506: }
12507: if ($notify) {
12508: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
12509: "LON-CAPA Domain Settings Change - $dom",
12510: $mailmsgtext);
12511: }
1.54 raeburn 12512: }
1.43 raeburn 12513: } else {
1.54 raeburn 12514: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 12515: }
12516: } else {
12517: $resulttext = '<span class="LC_error">'.
12518: &mt('An error occurred: [_1]',$putresult).'</span>';
12519: }
12520: if (@errors > 0) {
12521: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
12522: foreach my $item (@errors) {
12523: $resulttext .= ' "'.$title->{$item}.'",';
12524: }
12525: $resulttext =~ s/,$//;
12526: }
12527: return $resulttext;
12528: }
12529:
1.46 raeburn 12530: sub modify_scantron {
1.160.6.24 raeburn 12531: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 12532: my ($resulttext,%confhash,%changes,$errors);
12533: my $custom = 'custom.tab';
12534: my $default = 'default.tab';
12535: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 12536: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 12537: &config_check($dom,$confname,$servadm);
12538: if ($env{'form.scantronformat.filename'} ne '') {
12539: my $error;
12540: if ($configuserok eq 'ok') {
12541: if ($switchserver) {
1.130 raeburn 12542: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 12543: } else {
12544: if ($author_ok eq 'ok') {
12545: my ($result,$scantronurl) =
12546: &publishlogo($r,'upload','scantronformat',$dom,
12547: $confname,'scantron','','',$custom);
12548: if ($result eq 'ok') {
12549: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 12550: $changes{'scantronformat'} = 1;
1.46 raeburn 12551: } else {
12552: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
12553: }
12554: } else {
12555: $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);
12556: }
12557: }
12558: } else {
12559: $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);
12560: }
12561: if ($error) {
12562: &Apache::lonnet::logthis($error);
12563: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12564: }
12565: }
1.48 raeburn 12566: if (ref($domconfig{'scantron'}) eq 'HASH') {
12567: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
12568: if ($env{'form.scantronformat_del'}) {
12569: $confhash{'scantron'}{'scantronformat'} = '';
12570: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 12571: } else {
12572: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
12573: }
12574: }
12575: }
12576: my @options = ('hdr','pad','rem');
12577: my @fields = &scantroncsv_fields();
12578: my %titles = &scantronconfig_titles();
12579: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
12580: my ($newdat,$currdat,%newcol,%currcol);
12581: if (grep(/^dat$/,@formats)) {
12582: $confhash{'scantron'}{config}{dat} = 1;
12583: $newdat = 1;
12584: } else {
12585: $newdat = 0;
12586: }
12587: if (grep(/^csv$/,@formats)) {
12588: my %bynum;
12589: foreach my $field (@fields) {
12590: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
12591: my $posscol = $1;
12592: if (($posscol < 20) && (!$bynum{$posscol})) {
12593: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
12594: $bynum{$posscol} = $field;
12595: $newcol{$field} = $posscol;
12596: }
12597: }
12598: }
12599: if (keys(%newcol)) {
12600: foreach my $option (@options) {
12601: if ($env{'form.scantroncsv_'.$option}) {
12602: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
12603: }
12604: }
12605: }
12606: }
12607: $currdat = 1;
12608: if (ref($domconfig{'scantron'}) eq 'HASH') {
12609: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
12610: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
12611: $currdat = 0;
12612: }
12613: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
12614: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
12615: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
12616: }
12617: }
12618: }
12619: }
12620: if ($currdat != $newdat) {
12621: $changes{'config'} = 1;
12622: } else {
12623: foreach my $field (@fields) {
12624: if ($currcol{$field} ne '') {
12625: if ($currcol{$field} ne $newcol{$field}) {
12626: $changes{'config'} = 1;
12627: last;
12628: }
12629: } elsif ($newcol{$field} ne '') {
12630: $changes{'config'} = 1;
12631: last;
1.46 raeburn 12632: }
12633: }
12634: }
12635: if (keys(%confhash) > 0) {
12636: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
12637: $dom);
12638: if ($putresult eq 'ok') {
12639: if (keys(%changes) > 0) {
1.48 raeburn 12640: if (ref($confhash{'scantron'}) eq 'HASH') {
12641: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 12642: if ($changes{'scantronformat'}) {
12643: if ($confhash{'scantron'}{'scantronformat'} eq '') {
12644: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
12645: } else {
12646: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
12647: }
12648: }
12649: if ($changes{'config'}) {
12650: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
12651: if ($confhash{'scantron'}{'config'}{'dat'}) {
12652: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
12653: }
12654: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
12655: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
12656: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
12657: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
12658: foreach my $field (@fields) {
12659: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
12660: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
12661: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
12662: }
12663: }
12664: $resulttext .= '</ul></li>';
12665: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
12666: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
12667: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
12668: foreach my $option (@options) {
12669: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
12670: $resulttext .= '<li>'.$titles{$option}.'</li>';
12671: }
12672: }
12673: $resulttext .= '</ul></li>';
12674: }
12675: }
12676: }
12677: }
12678: }
12679: } else {
12680: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
12681: }
1.46 raeburn 12682: }
1.48 raeburn 12683: $resulttext .= '</ul>';
12684: } else {
1.130 raeburn 12685: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 12686: }
12687: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 12688: if (ref($lastactref) eq 'HASH') {
12689: $lastactref->{'domainconfig'} = 1;
12690: }
1.46 raeburn 12691: } else {
1.160.6.97 raeburn 12692: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 12693: }
12694: } else {
12695: $resulttext = '<span class="LC_error">'.
12696: &mt('An error occurred: [_1]',$putresult).'</span>';
12697: }
12698: } else {
1.160.6.97 raeburn 12699: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 12700: }
12701: if ($errors) {
12702: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12703: $errors.'</ul>';
12704: }
12705: return $resulttext;
12706: }
12707:
1.48 raeburn 12708: sub modify_coursecategories {
1.160.6.43 raeburn 12709: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 12710: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
12711: $cathash);
1.48 raeburn 12712: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 12713: my @catitems = ('unauth','auth');
12714: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 12715: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 12716: $cathash = $domconfig{'coursecategories'}{'cats'};
12717: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
12718: $changes{'togglecats'} = 1;
12719: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
12720: }
12721: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
12722: $changes{'categorize'} = 1;
12723: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
12724: }
1.120 raeburn 12725: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
12726: $changes{'togglecatscomm'} = 1;
12727: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
12728: }
12729: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
12730: $changes{'categorizecomm'} = 1;
12731: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
12732: }
1.160.6.42 raeburn 12733: foreach my $item (@catitems) {
12734: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12735: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
12736: $changes{$item} = 1;
12737: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12738: }
12739: }
12740: }
1.57 raeburn 12741: } else {
12742: $changes{'togglecats'} = 1;
12743: $changes{'categorize'} = 1;
1.124 raeburn 12744: $changes{'togglecatscomm'} = 1;
12745: $changes{'categorizecomm'} = 1;
1.87 raeburn 12746: $domconfig{'coursecategories'} = {
12747: togglecats => $env{'form.togglecats'},
12748: categorize => $env{'form.categorize'},
1.124 raeburn 12749: togglecatscomm => $env{'form.togglecatscomm'},
12750: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 12751: };
1.160.6.42 raeburn 12752: foreach my $item (@catitems) {
12753: if ($env{'form.coursecat_'.$item} ne 'std') {
12754: $changes{$item} = 1;
12755: }
12756: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12757: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12758: }
12759: }
1.57 raeburn 12760: }
12761: if (ref($cathash) eq 'HASH') {
12762: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 12763: push (@deletecategory,'instcode::0');
12764: }
1.120 raeburn 12765: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
12766: push(@deletecategory,'communities::0');
12767: }
1.48 raeburn 12768: }
1.57 raeburn 12769: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
12770: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12771: if (@deletecategory > 0) {
12772: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 12773: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 12774: foreach my $item (@deletecategory) {
1.57 raeburn 12775: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
12776: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 12777: $deletions{$item} = 1;
1.57 raeburn 12778: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 12779: }
12780: }
12781: }
1.57 raeburn 12782: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 12783: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 12784: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 12785: $reorderings{$item} = 1;
1.57 raeburn 12786: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 12787: }
12788: if ($env{'form.addcategory_name_'.$item} ne '') {
12789: my $newcat = $env{'form.addcategory_name_'.$item};
12790: my $newdepth = $depth+1;
12791: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12792: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 12793: $adds{$newitem} = 1;
12794: }
12795: if ($env{'form.subcat_'.$item} ne '') {
12796: my $newcat = $env{'form.subcat_'.$item};
12797: my $newdepth = $depth+1;
12798: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12799: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 12800: $adds{$newitem} = 1;
12801: }
12802: }
12803: }
12804: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 12805: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12806: my $newitem = 'instcode::0';
1.57 raeburn 12807: if ($cathash->{$newitem} eq '') {
12808: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12809: $adds{$newitem} = 1;
12810: }
12811: } else {
12812: my $newitem = 'instcode::0';
1.57 raeburn 12813: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12814: $adds{$newitem} = 1;
12815: }
12816: }
1.120 raeburn 12817: if ($env{'form.communities'} eq '1') {
12818: if (ref($cathash) eq 'HASH') {
12819: my $newitem = 'communities::0';
12820: if ($cathash->{$newitem} eq '') {
12821: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12822: $adds{$newitem} = 1;
12823: }
12824: } else {
12825: my $newitem = 'communities::0';
12826: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12827: $adds{$newitem} = 1;
12828: }
12829: }
1.48 raeburn 12830: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 12831: if (($env{'form.addcategory_name'} ne 'instcode') &&
12832: ($env{'form.addcategory_name'} ne 'communities')) {
12833: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
12834: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
12835: $adds{$newitem} = 1;
12836: }
1.48 raeburn 12837: }
1.57 raeburn 12838: my $putresult;
1.48 raeburn 12839: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12840: if (keys(%deletions) > 0) {
12841: foreach my $key (keys(%deletions)) {
12842: if ($predelallitems{$key} ne '') {
12843: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
12844: }
12845: }
12846: }
12847: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 12848: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 12849: if (ref($chkcats[0]) eq 'ARRAY') {
12850: my $depth = 0;
12851: my $chg = 0;
12852: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
12853: my $name = $chkcats[0][$i];
12854: my $item;
12855: if ($name eq '') {
12856: $chg ++;
12857: } else {
12858: $item = &escape($name).'::0';
12859: if ($chg) {
1.57 raeburn 12860: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 12861: }
12862: $depth ++;
1.57 raeburn 12863: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 12864: $depth --;
12865: }
12866: }
12867: }
1.57 raeburn 12868: }
12869: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12870: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 12871: if ($putresult eq 'ok') {
1.57 raeburn 12872: my %title = (
1.120 raeburn 12873: togglecats => 'Show/Hide a course in catalog',
12874: categorize => 'Assign a category to a course',
12875: togglecatscomm => 'Show/Hide a community in catalog',
12876: categorizecomm => 'Assign a category to a community',
1.57 raeburn 12877: );
12878: my %level = (
1.120 raeburn 12879: dom => 'set in Domain ("Modify Course/Community")',
12880: crs => 'set in Course ("Course Configuration")',
12881: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 12882: none => 'No catalog',
12883: std => 'Standard catalog',
12884: domonly => 'Domain-only catalog',
12885: codesrch => 'Code search form',
1.57 raeburn 12886: );
1.48 raeburn 12887: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 12888: if ($changes{'togglecats'}) {
12889: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
12890: }
12891: if ($changes{'categorize'}) {
12892: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 12893: }
1.120 raeburn 12894: if ($changes{'togglecatscomm'}) {
12895: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
12896: }
12897: if ($changes{'categorizecomm'}) {
12898: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
12899: }
1.160.6.42 raeburn 12900: if ($changes{'unauth'}) {
12901: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
12902: }
12903: if ($changes{'auth'}) {
12904: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
12905: }
1.57 raeburn 12906: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12907: my $cathash;
12908: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
12909: $cathash = $domconfig{'coursecategories'}{'cats'};
12910: } else {
12911: $cathash = {};
12912: }
12913: my (@cats,@trails,%allitems);
12914: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
12915: if (keys(%deletions) > 0) {
12916: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
12917: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
12918: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
12919: }
12920: $resulttext .= '</ul></li>';
12921: }
12922: if (keys(%reorderings) > 0) {
12923: my %sort_by_trail;
12924: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
12925: foreach my $key (keys(%reorderings)) {
12926: if ($allitems{$key} ne '') {
12927: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12928: }
1.48 raeburn 12929: }
1.57 raeburn 12930: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12931: $resulttext .= '<li>'.$trails[$trail].'</li>';
12932: }
12933: $resulttext .= '</ul></li>';
1.48 raeburn 12934: }
1.57 raeburn 12935: if (keys(%adds) > 0) {
12936: my %sort_by_trail;
12937: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
12938: foreach my $key (keys(%adds)) {
12939: if ($allitems{$key} ne '') {
12940: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12941: }
12942: }
12943: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12944: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 12945: }
1.57 raeburn 12946: $resulttext .= '</ul></li>';
1.48 raeburn 12947: }
1.160.6.92 raeburn 12948: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
12949: if (ref($lastactref) eq 'HASH') {
12950: $lastactref->{'cats'} = 1;
12951: }
1.48 raeburn 12952: }
12953: $resulttext .= '</ul>';
1.160.6.43 raeburn 12954: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 12955: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12956: if ($changes{'auth'}) {
12957: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
12958: }
12959: if ($changes{'unauth'}) {
12960: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
12961: }
12962: my $cachetime = 24*60*60;
12963: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 12964: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 12965: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 12966: }
12967: }
1.48 raeburn 12968: } else {
12969: $resulttext = '<span class="LC_error">'.
1.57 raeburn 12970: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 12971: }
12972: } else {
1.120 raeburn 12973: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 12974: }
12975: return $resulttext;
12976: }
12977:
1.69 raeburn 12978: sub modify_serverstatuses {
12979: my ($dom,%domconfig) = @_;
12980: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
12981: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
12982: %currserverstatus = %{$domconfig{'serverstatuses'}};
12983: }
12984: my @pages = &serverstatus_pages();
12985: foreach my $type (@pages) {
12986: $newserverstatus{$type}{'namedusers'} = '';
12987: $newserverstatus{$type}{'machines'} = '';
12988: if (defined($env{'form.'.$type.'_namedusers'})) {
12989: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
12990: my @okusers;
12991: foreach my $user (@users) {
12992: my ($uname,$udom) = split(/:/,$user);
12993: if (($udom =~ /^$match_domain$/) &&
12994: (&Apache::lonnet::domain($udom)) &&
12995: ($uname =~ /^$match_username$/)) {
12996: if (!grep(/^\Q$user\E/,@okusers)) {
12997: push(@okusers,$user);
12998: }
12999: }
13000: }
13001: if (@okusers > 0) {
13002: @okusers = sort(@okusers);
13003: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
13004: }
13005: }
13006: if (defined($env{'form.'.$type.'_machines'})) {
13007: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
13008: my @okmachines;
13009: foreach my $ip (@machines) {
13010: my @parts = split(/\./,$ip);
13011: next if (@parts < 4);
13012: my $badip = 0;
13013: for (my $i=0; $i<4; $i++) {
13014: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
13015: $badip = 1;
13016: last;
13017: }
13018: }
13019: if (!$badip) {
13020: push(@okmachines,$ip);
13021: }
13022: }
13023: @okmachines = sort(@okmachines);
13024: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
13025: }
13026: }
13027: my %serverstatushash = (
13028: serverstatuses => \%newserverstatus,
13029: );
13030: foreach my $type (@pages) {
1.83 raeburn 13031: foreach my $setting ('namedusers','machines') {
1.84 raeburn 13032: my (@current,@new);
1.83 raeburn 13033: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 13034: if ($currserverstatus{$type}{$setting} ne '') {
13035: @current = split(/,/,$currserverstatus{$type}{$setting});
13036: }
13037: }
13038: if ($newserverstatus{$type}{$setting} ne '') {
13039: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 13040: }
13041: if (@current > 0) {
13042: if (@new > 0) {
13043: foreach my $item (@current) {
13044: if (!grep(/^\Q$item\E$/,@new)) {
13045: $changes{$type}{$setting} = 1;
1.82 raeburn 13046: last;
13047: }
13048: }
1.84 raeburn 13049: foreach my $item (@new) {
13050: if (!grep(/^\Q$item\E$/,@current)) {
13051: $changes{$type}{$setting} = 1;
13052: last;
1.82 raeburn 13053: }
13054: }
13055: } else {
1.83 raeburn 13056: $changes{$type}{$setting} = 1;
1.69 raeburn 13057: }
1.83 raeburn 13058: } elsif (@new > 0) {
13059: $changes{$type}{$setting} = 1;
1.69 raeburn 13060: }
13061: }
13062: }
13063: if (keys(%changes) > 0) {
1.81 raeburn 13064: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 13065: my $putresult = &Apache::lonnet::put_dom('configuration',
13066: \%serverstatushash,$dom);
13067: if ($putresult eq 'ok') {
13068: $resulttext .= &mt('Changes made:').'<ul>';
13069: foreach my $type (@pages) {
1.84 raeburn 13070: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 13071: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 13072: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 13073: if ($newserverstatus{$type}{'namedusers'} eq '') {
13074: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
13075: } else {
13076: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
13077: }
1.84 raeburn 13078: }
13079: if ($changes{$type}{'machines'}) {
1.69 raeburn 13080: if ($newserverstatus{$type}{'machines'} eq '') {
13081: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
13082: } else {
13083: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
13084: }
13085:
13086: }
13087: $resulttext .= '</ul></li>';
13088: }
13089: }
13090: $resulttext .= '</ul>';
13091: } else {
13092: $resulttext = '<span class="LC_error">'.
13093: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
13094:
13095: }
13096: } else {
13097: $resulttext = &mt('No changes made to access to server status pages');
13098: }
13099: return $resulttext;
13100: }
13101:
1.118 jms 13102: sub modify_helpsettings {
1.160.6.77 raeburn 13103: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 13104: my ($resulttext,$errors,%changes,%helphash);
13105: my %defaultchecked = ('submitbugs' => 'on');
13106: my @offon = ('off','on');
1.118 jms 13107: my @toggles = ('submitbugs');
1.160.6.77 raeburn 13108: my %current = ('submitbugs' => '',
13109: 'adhoc' => {},
13110: );
1.118 jms 13111: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 13112: %current = %{$domconfig{'helpsettings'}};
13113: }
1.160.6.77 raeburn 13114: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 13115: foreach my $item (@toggles) {
13116: if ($defaultchecked{$item} eq 'on') {
13117: if ($current{$item} eq '') {
13118: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 13119: $changes{$item} = 1;
13120: }
1.160.6.73 raeburn 13121: } elsif ($current{$item} ne $env{'form.'.$item}) {
13122: $changes{$item} = 1;
13123: }
13124: } elsif ($defaultchecked{$item} eq 'off') {
13125: if ($current{$item} eq '') {
13126: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 13127: $changes{$item} = 1;
13128: }
1.160.6.73 raeburn 13129: } elsif ($current{$item} ne $env{'form.'.$item}) {
13130: $changes{$item} = 1;
13131: }
13132: }
13133: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
13134: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
13135: }
13136: }
1.160.6.77 raeburn 13137: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 13138: my $confname = $dom.'-domainconfig';
13139: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 13140: my (@allpos,%newsettings,%changedprivs,$newrole);
13141: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 13142: my @accesstypes = ('all','dh','da','none','status','inc','exc');
13143: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 13144: my %lt = &Apache::lonlocal::texthash(
13145: s => 'system',
13146: d => 'domain',
13147: order => 'Display order',
13148: access => 'Role usage',
1.160.6.79 raeburn 13149: all => 'All with domain helpdesk or helpdesk assistant role',
13150: dh => 'All with domain helpdesk role',
13151: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 13152: none => 'None',
13153: status => 'Determined based on institutional status',
13154: inc => 'Include all, but exclude specific personnel',
13155: exc => 'Exclude all, but include specific personnel',
13156: );
13157: for (my $num=0; $num<=$maxnum; $num++) {
13158: my ($prefix,$identifier,$rolename,%curr);
13159: if ($num == $maxnum) {
13160: next unless ($env{'form.newcusthelp'} == $maxnum);
13161: $identifier = 'custhelp'.$num;
13162: $prefix = 'helproles_'.$num;
13163: $rolename = $env{'form.custhelpname'.$num};
13164: $rolename=~s/[^A-Za-z0-9]//gs;
13165: next if ($rolename eq '');
13166: next if (exists($existing{'rolesdef_'.$rolename}));
13167: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
13168: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
13169: $newprivs{'c'},$confname,$dom);
13170: if ($result ne 'ok') {
13171: $errors .= '<li><span class="LC_error">'.
13172: &mt('An error occurred storing the new custom role: [_1]',
13173: $result).'</span></li>';
13174: next;
13175: } else {
13176: $changedprivs{$rolename} = \%newprivs;
13177: $newrole = $rolename;
13178: }
13179: } else {
13180: $prefix = 'helproles_'.$num;
13181: $rolename = $env{'form.'.$prefix};
13182: next if ($rolename eq '');
13183: next unless (exists($existing{'rolesdef_'.$rolename}));
13184: $identifier = 'custhelp'.$num;
13185: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
13186: my %currprivs;
13187: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
13188: split(/\_/,$existing{'rolesdef_'.$rolename});
13189: foreach my $level ('c','d','s') {
13190: if ($newprivs{$level} ne $currprivs{$level}) {
13191: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
13192: $newprivs{'c'},$confname,$dom);
13193: if ($result ne 'ok') {
13194: $errors .= '<li><span class="LC_error">'.
13195: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
13196: $rolename,$result).'</span></li>';
13197: } else {
13198: $changedprivs{$rolename} = \%newprivs;
13199: }
13200: last;
13201: }
13202: }
13203: if (ref($current{'adhoc'}) eq 'HASH') {
13204: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
13205: %curr = %{$current{'adhoc'}{$rolename}};
13206: }
13207: }
13208: }
13209: my $newpos = $env{'form.'.$prefix.'_pos'};
13210: $newpos =~ s/\D+//g;
13211: $allpos[$newpos] = $rolename;
13212: my $newdesc = $env{'form.'.$prefix.'_desc'};
13213: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
13214: if ($curr{'desc'}) {
13215: if ($curr{'desc'} ne $newdesc) {
13216: $changes{'customrole'}{$rolename}{'desc'} = 1;
13217: $newsettings{$rolename}{'desc'} = $newdesc;
13218: }
13219: } elsif ($newdesc ne '') {
13220: $changes{'customrole'}{$rolename}{'desc'} = 1;
13221: $newsettings{$rolename}{'desc'} = $newdesc;
13222: }
13223: my $access = $env{'form.'.$prefix.'_access'};
13224: if (grep(/^\Q$access\E$/,@accesstypes)) {
13225: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
13226: if ($access eq 'status') {
13227: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
13228: if (scalar(@statuses) == 0) {
13229: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
13230: } else {
13231: my (@shownstatus,$numtypes);
13232: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
13233: if (ref($types) eq 'ARRAY') {
13234: $numtypes = scalar(@{$types});
13235: foreach my $type (sort(@statuses)) {
13236: if ($type eq 'default') {
13237: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
13238: } elsif (grep(/^\Q$type\E$/,@{$types})) {
13239: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
13240: push(@shownstatus,$usertypes->{$type});
13241: }
1.160.6.73 raeburn 13242: }
13243: }
1.160.6.77 raeburn 13244: if (grep(/^default$/,@statuses)) {
13245: push(@shownstatus,$othertitle);
13246: }
13247: if (scalar(@shownstatus) == 1+$numtypes) {
13248: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
13249: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
13250: } else {
13251: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
13252: if (ref($curr{'status'}) eq 'ARRAY') {
13253: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
13254: if (@diffs) {
13255: $changes{'customrole'}{$rolename}{$access} = 1;
13256: }
13257: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13258: $changes{'customrole'}{$rolename}{$access} = 1;
13259: }
13260: }
13261: }
13262: } elsif (($access eq 'inc') || ($access eq 'exc')) {
13263: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
13264: my @newspecstaff;
13265: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
13266: foreach my $person (sort(@personnel)) {
13267: if ($domhelpdesk{$person}) {
13268: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
13269: }
13270: }
13271: if (ref($curr{$access}) eq 'ARRAY') {
13272: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
13273: if (@diffs) {
13274: $changes{'customrole'}{$rolename}{$access} = 1;
13275: }
13276: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13277: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 13278: }
1.160.6.77 raeburn 13279: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13280: my ($uname,$udom) = split(/:/,$person);
13281: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
13282: }
13283: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 13284: }
1.160.6.77 raeburn 13285: } else {
13286: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
13287: }
13288: unless ($curr{'access'} eq $access) {
13289: $changes{'customrole'}{$rolename}{'access'} = 1;
13290: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 13291: }
13292: }
1.160.6.77 raeburn 13293: if (@allpos > 0) {
13294: my $idx = 0;
13295: foreach my $rolename (@allpos) {
13296: if ($rolename ne '') {
13297: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
13298: if (ref($current{'adhoc'}) eq 'HASH') {
13299: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
13300: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
13301: $changes{'customrole'}{$rolename}{'order'} = 1;
13302: $newsettings{$rolename}{'order'} = $idx+1;
13303: }
13304: }
1.160.6.73 raeburn 13305: }
1.160.6.77 raeburn 13306: $idx ++;
1.122 jms 13307: }
13308: }
1.118 jms 13309: }
1.123 jms 13310: my $putresult;
13311: if (keys(%changes) > 0) {
1.160.6.5 raeburn 13312: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
13313: if ($putresult eq 'ok') {
1.160.6.77 raeburn 13314: if (ref($helphash{'helpsettings'}) eq 'HASH') {
13315: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
13316: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
13317: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
13318: }
13319: }
13320: my $cachetime = 24*60*60;
13321: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13322: if (ref($lastactref) eq 'HASH') {
13323: $lastactref->{'domdefaults'} = 1;
13324: }
13325: } else {
13326: $errors .= '<li><span class="LC_error">'.
13327: &mt('An error occurred storing the settings: [_1]',
13328: $putresult).'</span></li>';
13329: }
13330: }
13331: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
13332: $resulttext = &mt('Changes made:').'<ul>';
13333: my (%shownprivs,@levelorder);
13334: @levelorder = ('c','d','s');
13335: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 13336: foreach my $item (sort(keys(%changes))) {
13337: if ($item eq 'submitbugs') {
13338: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
13339: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
13340: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 13341: } elsif ($item eq 'customrole') {
13342: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 13343: my @keyorder = ('order','desc','access','status','exc','inc');
13344: my %keytext = &Apache::lonlocal::texthash(
13345: order => 'Order',
13346: desc => 'Role description',
13347: access => 'Role usage',
1.160.6.83 raeburn 13348: status => 'Allowed institutional types',
1.160.6.77 raeburn 13349: exc => 'Allowed personnel',
13350: inc => 'Disallowed personnel',
13351: );
1.160.6.73 raeburn 13352: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 13353: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
13354: if ($role eq $newrole) {
13355: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
13356: $role).'<ul>';
13357: } else {
13358: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
13359: $role).'<ul>';
13360: }
13361: foreach my $key (@keyorder) {
13362: if ($changes{'customrole'}{$role}{$key}) {
13363: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
13364: $keytext{$key},$newsettings{$role}{$key}).
13365: '</li>';
13366: }
13367: }
13368: if (ref($changedprivs{$role}) eq 'HASH') {
13369: $shownprivs{$role} = 1;
13370: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
13371: foreach my $level (@levelorder) {
13372: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13373: next if ($item eq '');
13374: my ($priv) = split(/\&/,$item,2);
13375: if (&Apache::lonnet::plaintext($priv)) {
13376: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13377: unless ($level eq 'c') {
13378: $resulttext .= ' ('.$lt{$level}.')';
13379: }
13380: $resulttext .= '</li>';
13381: }
13382: }
13383: }
13384: $resulttext .= '</ul>';
13385: }
13386: $resulttext .= '</ul></li>';
13387: }
1.160.6.73 raeburn 13388: }
13389: }
1.160.6.5 raeburn 13390: }
13391: }
13392: }
1.160.6.77 raeburn 13393: if (keys(%changedprivs)) {
13394: foreach my $role (sort(keys(%changedprivs))) {
13395: unless ($shownprivs{$role}) {
13396: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
13397: $role).'<ul>'.
13398: '<li>'.&mt('Privileges set to :').'<ul>';
13399: foreach my $level (@levelorder) {
13400: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13401: next if ($item eq '');
13402: my ($priv) = split(/\&/,$item,2);
13403: if (&Apache::lonnet::plaintext($priv)) {
13404: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13405: unless ($level eq 'c') {
13406: $resulttext .= ' ('.$lt{$level}.')';
13407: }
13408: $resulttext .= '</li>';
13409: }
13410: }
13411: }
13412: $resulttext .= '</ul></li></ul></li>';
13413: }
13414: }
13415: }
13416: $resulttext .= '</ul>';
13417: } else {
13418: $resulttext = &mt('No changes made to help settings');
1.118 jms 13419: }
13420: if ($errors) {
1.160.6.5 raeburn 13421: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 13422: $errors.'</ul>';
1.118 jms 13423: }
13424: return $resulttext;
13425: }
13426:
1.121 raeburn 13427: sub modify_coursedefaults {
1.160.6.27 raeburn 13428: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 13429: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 13430: my %defaultchecked = (
13431: 'uselcmath' => 'on',
13432: 'usejsme' => 'on'
13433: );
13434: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 13435: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 13436: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
13437: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 13438: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 13439: my %staticdefaults = (
13440: anonsurvey_threshold => 10,
13441: uploadquota => 500,
1.160.6.57 raeburn 13442: postsubmit => 60,
1.160.6.70 raeburn 13443: mysqltables => 172800,
1.160.6.21 raeburn 13444: );
1.160.6.90 raeburn 13445: my %texoptions = (
13446: MathJax => 'MathJax',
13447: mimetex => &mt('Convert to Images'),
13448: tth => &mt('TeX to HTML'),
13449: );
1.121 raeburn 13450: $defaultshash{'coursedefaults'} = {};
13451:
13452: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
13453: if ($domconfig{'coursedefaults'} eq '') {
13454: $domconfig{'coursedefaults'} = {};
13455: }
13456: }
13457:
13458: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
13459: foreach my $item (@toggles) {
13460: if ($defaultchecked{$item} eq 'on') {
13461: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13462: ($env{'form.'.$item} eq '0')) {
13463: $changes{$item} = 1;
1.160.6.16 raeburn 13464: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 13465: $changes{$item} = 1;
13466: }
13467: } elsif ($defaultchecked{$item} eq 'off') {
13468: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13469: ($env{'form.'.$item} eq '1')) {
13470: $changes{$item} = 1;
13471: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
13472: $changes{$item} = 1;
13473: }
13474: }
13475: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
13476: }
1.160.6.21 raeburn 13477: foreach my $item (@numbers) {
13478: my ($currdef,$newdef);
1.160.6.26 raeburn 13479: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 13480: if ($item eq 'anonsurvey_threshold') {
13481: $currdef = $domconfig{'coursedefaults'}{$item};
13482: $newdef =~ s/\D//g;
13483: if ($newdef eq '' || $newdef < 1) {
13484: $newdef = 1;
13485: }
13486: $defaultshash{'coursedefaults'}{$item} = $newdef;
13487: } else {
1.160.6.70 raeburn 13488: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
13489: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
13490: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 13491: }
13492: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 13493: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 13494: }
13495: if ($currdef ne $newdef) {
13496: if ($item eq 'anonsurvey_threshold') {
13497: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
13498: $changes{$item} = 1;
13499: }
1.160.6.70 raeburn 13500: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
13501: my $setting = $1;
13502: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
13503: $changes{$setting} = 1;
1.160.6.21 raeburn 13504: }
13505: }
1.139 raeburn 13506: }
13507: }
1.160.6.90 raeburn 13508: my $texengine;
13509: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
13510: $texengine = $env{'form.texengine'};
13511: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
13512: if ($currdef eq '') {
13513: unless ($texengine eq $Apache::lonnet::deftex) {
13514: $changes{'texengine'} = 1;
13515: }
13516: } elsif ($currdef ne $texengine) {
13517: $changes{'texengine'} = 1;
13518: }
13519: }
13520: if ($texengine ne '') {
13521: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
13522: }
1.160.6.64 raeburn 13523: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
13524: my @currclonecode;
13525: if (ref($currclone) eq 'HASH') {
13526: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
13527: @currclonecode = @{$currclone->{'instcode'}};
13528: }
13529: }
13530: my $newclone;
13531: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
13532: $newclone = $env{'form.canclone'};
13533: }
13534: if ($newclone eq 'instcode') {
13535: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
13536: my (%codedefaults,@code_order,@clonecode);
13537: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
13538: \@code_order);
13539: foreach my $item (@code_order) {
13540: if (grep(/^\Q$item\E$/,@newcodes)) {
13541: push(@clonecode,$item);
13542: }
13543: }
13544: if (@clonecode) {
13545: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
13546: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
13547: if (@diffs) {
13548: $changes{'canclone'} = 1;
13549: }
13550: } else {
13551: $newclone eq '';
13552: }
13553: } elsif ($newclone ne '') {
13554: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
13555: }
13556: if ($newclone ne $currclone) {
13557: $changes{'canclone'} = 1;
13558: }
1.160.6.57 raeburn 13559: my %credits;
13560: foreach my $type (@types) {
13561: unless ($type eq 'community') {
13562: $credits{$type} = $env{'form.'.$type.'_credits'};
13563: $credits{$type} =~ s/[^\d.]+//g;
13564: }
13565: }
13566: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
13567: ($env{'form.coursecredits'} eq '1')) {
13568: $changes{'coursecredits'} = 1;
13569: foreach my $type (keys(%credits)) {
13570: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13571: }
13572: } else {
13573: if ($env{'form.coursecredits'} eq '1') {
13574: foreach my $type (@types) {
13575: unless ($type eq 'community') {
13576: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
13577: $changes{'coursecredits'} = 1;
13578: }
13579: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13580: }
13581: }
13582: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13583: foreach my $type (@types) {
13584: unless ($type eq 'community') {
13585: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
13586: $changes{'coursecredits'} = 1;
13587: last;
13588: }
13589: }
13590: }
13591: }
13592: }
13593: if ($env{'form.postsubmit'} eq '1') {
13594: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
13595: my %currtimeout;
13596: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13597: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
13598: $changes{'postsubmit'} = 1;
13599: }
13600: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13601: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
13602: }
13603: } else {
13604: $changes{'postsubmit'} = 1;
13605: }
13606: foreach my $type (@types) {
13607: my $timeout = $env{'form.'.$type.'_timeout'};
13608: $timeout =~ s/\D//g;
13609: if ($timeout == $staticdefaults{'postsubmit'}) {
13610: $timeout = '';
13611: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
13612: $timeout = '0';
13613: }
13614: unless ($timeout eq '') {
13615: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
13616: }
13617: if (exists($currtimeout{$type})) {
13618: if ($timeout ne $currtimeout{$type}) {
13619: $changes{'postsubmit'} = 1;
13620: }
13621: } elsif ($timeout ne '') {
13622: $changes{'postsubmit'} = 1;
13623: }
13624: }
13625: } else {
13626: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
13627: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13628: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
13629: $changes{'postsubmit'} = 1;
13630: }
13631: } else {
13632: $changes{'postsubmit'} = 1;
13633: }
1.160.6.16 raeburn 13634: }
1.121 raeburn 13635: }
13636: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13637: $dom);
13638: if ($putresult eq 'ok') {
13639: if (keys(%changes) > 0) {
1.160.6.27 raeburn 13640: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 13641: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 13642: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.90 raeburn 13643: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
13644: foreach my $item ('uselcmath','usejsme','texengine') {
1.160.6.57 raeburn 13645: if ($changes{$item}) {
13646: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
13647: }
1.160.6.16 raeburn 13648: }
13649: if ($changes{'coursecredits'}) {
13650: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 13651: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
13652: $domdefaults{$type.'credits'} =
13653: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
13654: }
13655: }
13656: }
13657: if ($changes{'postsubmit'}) {
13658: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13659: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
13660: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13661: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
13662: $domdefaults{$type.'postsubtimeout'} =
13663: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13664: }
13665: }
1.160.6.16 raeburn 13666: }
13667: }
1.160.6.21 raeburn 13668: if ($changes{'uploadquota'}) {
13669: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13670: foreach my $type (@types) {
13671: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
13672: }
13673: }
13674: }
1.160.6.64 raeburn 13675: if ($changes{'canclone'}) {
13676: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13677: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13678: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
13679: if (@clonecodes) {
13680: $domdefaults{'canclone'} = join('+',@clonecodes);
13681: }
13682: }
13683: } else {
13684: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
13685: }
13686: }
1.121 raeburn 13687: my $cachetime = 24*60*60;
13688: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 13689: if (ref($lastactref) eq 'HASH') {
13690: $lastactref->{'domdefaults'} = 1;
13691: }
1.121 raeburn 13692: }
13693: $resulttext = &mt('Changes made:').'<ul>';
13694: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 13695: if ($item eq 'uselcmath') {
1.121 raeburn 13696: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 13697: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 13698: } else {
1.160.6.57 raeburn 13699: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
13700: }
13701: } elsif ($item eq 'usejsme') {
13702: if ($env{'form.'.$item} eq '1') {
13703: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
13704: } else {
13705: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 13706: }
1.160.6.90 raeburn 13707: } elsif ($item eq 'texengine') {
13708: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
13709: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
13710: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
13711: }
1.139 raeburn 13712: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 13713: $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 13714: } elsif ($item eq 'uploadquota') {
13715: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13716: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
13717: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
13718: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 13719: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
13720:
1.160.6.21 raeburn 13721: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
13722: '</ul>'.
13723: '</li>';
13724: } else {
13725: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
13726: }
1.160.6.70 raeburn 13727: } elsif ($item eq 'mysqltables') {
13728: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
13729: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
13730: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
13731: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
13732: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
13733: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
13734: '</ul>'.
13735: '</li>';
13736: } else {
13737: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
13738: }
1.160.6.57 raeburn 13739: } elsif ($item eq 'postsubmit') {
13740: if ($domdefaults{'postsubmit'} eq 'off') {
13741: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
13742: } else {
13743: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
13744: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13745: $resulttext .= &mt('durations:').'<ul>';
13746: foreach my $type (@types) {
13747: $resulttext .= '<li>';
13748: my $timeout;
13749: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13750: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13751: }
13752: my $display;
13753: if ($timeout eq '0') {
13754: $display = &mt('unlimited');
13755: } elsif ($timeout eq '') {
13756: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
13757: } else {
13758: $display = &mt('[quant,_1,second]',$timeout);
13759: }
13760: if ($type eq 'community') {
13761: $resulttext .= &mt('Communities');
13762: } elsif ($type eq 'official') {
13763: $resulttext .= &mt('Official courses');
13764: } elsif ($type eq 'unofficial') {
13765: $resulttext .= &mt('Unofficial courses');
13766: } elsif ($type eq 'textbook') {
13767: $resulttext .= &mt('Textbook courses');
13768: }
13769: $resulttext .= ' -- '.$display.'</li>';
13770: }
13771: $resulttext .= '</ul>';
13772: }
13773: $resulttext .= '</li>';
13774: }
1.160.6.16 raeburn 13775: } elsif ($item eq 'coursecredits') {
13776: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13777: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 13778: ($domdefaults{'unofficialcredits'} eq '') &&
13779: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 13780: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13781: } else {
13782: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
13783: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
13784: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 13785: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 13786: '</ul>'.
13787: '</li>';
13788: }
13789: } else {
13790: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13791: }
1.160.6.64 raeburn 13792: } elsif ($item eq 'canclone') {
13793: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13794: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13795: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
13796: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
13797: }
13798: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
13799: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
13800: } else {
13801: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
13802: }
1.140 raeburn 13803: }
1.121 raeburn 13804: }
13805: $resulttext .= '</ul>';
13806: } else {
13807: $resulttext = &mt('No changes made to course defaults');
13808: }
13809: } else {
13810: $resulttext = '<span class="LC_error">'.
13811: &mt('An error occurred: [_1]',$putresult).'</span>';
13812: }
13813: return $resulttext;
13814: }
13815:
1.160.6.37 raeburn 13816: sub modify_selfenrollment {
13817: my ($dom,$lastactref,%domconfig) = @_;
13818: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
13819: my @types = ('official','unofficial','community','textbook');
13820: my %titles = &tool_titles();
13821: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
13822: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
13823: $ordered{'default'} = ['types','registered','approval','limit'];
13824:
13825: my (%roles,%shown,%toplevel);
13826: $roles{'0'} = &Apache::lonnet::plaintext('dc');
13827:
13828: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
13829: if ($domconfig{'selfenrollment'} eq '') {
13830: $domconfig{'selfenrollment'} = {};
13831: }
13832: }
13833: %toplevel = (
13834: admin => 'Configuration Rights',
13835: default => 'Default settings',
13836: validation => 'Validation of self-enrollment requests',
13837: );
13838: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
13839:
13840: if (ref($ordered{'admin'}) eq 'ARRAY') {
13841: foreach my $item (@{$ordered{'admin'}}) {
13842: foreach my $type (@types) {
13843: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
13844: $selfenrollhash{'admin'}{$type}{$item} = 1;
13845: } else {
13846: $selfenrollhash{'admin'}{$type}{$item} = 0;
13847: }
13848: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
13849: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
13850: if ($selfenrollhash{'admin'}{$type}{$item} ne
13851: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
13852: push(@{$changes{'admin'}{$type}},$item);
13853: }
13854: } else {
13855: if (!$selfenrollhash{'admin'}{$type}{$item}) {
13856: push(@{$changes{'admin'}{$type}},$item);
13857: }
13858: }
13859: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
13860: push(@{$changes{'admin'}{$type}},$item);
13861: }
13862: }
13863: }
13864: }
13865:
13866: foreach my $item (@{$ordered{'default'}}) {
13867: foreach my $type (@types) {
13868: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
13869: if ($item eq 'types') {
13870: unless (($value eq 'all') || ($value eq 'dom')) {
13871: $value = '';
13872: }
13873: } elsif ($item eq 'registered') {
13874: unless ($value eq '1') {
13875: $value = 0;
13876: }
13877: } elsif ($item eq 'approval') {
13878: unless ($value =~ /^[012]$/) {
13879: $value = 0;
13880: }
13881: } else {
13882: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13883: $value = 'none';
13884: }
13885: }
13886: $selfenrollhash{'default'}{$type}{$item} = $value;
13887: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
13888: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13889: if ($selfenrollhash{'default'}{$type}{$item} ne
13890: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
13891: push(@{$changes{'default'}{$type}},$item);
13892: }
13893: } else {
13894: push(@{$changes{'default'}{$type}},$item);
13895: }
13896: } else {
13897: push(@{$changes{'default'}{$type}},$item);
13898: }
13899: if ($item eq 'limit') {
13900: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13901: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
13902: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
13903: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
13904: }
13905: } else {
13906: $selfenrollhash{'default'}{$type}{'cap'} = '';
13907: }
13908: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13909: if ($selfenrollhash{'default'}{$type}{'cap'} ne
13910: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
13911: push(@{$changes{'default'}{$type}},'cap');
13912: }
13913: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
13914: push(@{$changes{'default'}{$type}},'cap');
13915: }
13916: }
13917: }
13918: }
13919:
13920: foreach my $item (@{$itemsref}) {
13921: if ($item eq 'fields') {
13922: my @changed;
13923: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
13924: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
13925: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
13926: }
13927: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13928: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
13929: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
13930: $domconfig{'selfenrollment'}{'validation'}{$item});
13931: } else {
13932: @changed = @{$selfenrollhash{'validation'}{$item}};
13933: }
13934: } else {
13935: @changed = @{$selfenrollhash{'validation'}{$item}};
13936: }
13937: if (@changed) {
13938: if ($selfenrollhash{'validation'}{$item}) {
13939: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
13940: } else {
13941: $changes{'validation'}{$item} = &mt('None');
13942: }
13943: }
13944: } else {
13945: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
13946: if ($item eq 'markup') {
13947: if ($env{'form.selfenroll_validation_'.$item}) {
13948: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13949: }
13950: }
13951: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13952: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
13953: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
13954: }
13955: }
13956: }
13957: }
13958:
13959: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
13960: $dom);
13961: if ($putresult eq 'ok') {
13962: if (keys(%changes) > 0) {
13963: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13964: $resulttext = &mt('Changes made:').'<ul>';
13965: foreach my $key ('admin','default','validation') {
13966: if (ref($changes{$key}) eq 'HASH') {
13967: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
13968: if ($key eq 'validation') {
13969: foreach my $item (@{$itemsref}) {
13970: if (exists($changes{$key}{$item})) {
13971: if ($item eq 'markup') {
13972: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13973: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
13974: } else {
13975: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13976: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
13977: }
13978: }
13979: }
13980: } else {
13981: foreach my $type (@types) {
13982: if ($type eq 'community') {
13983: $roles{'1'} = &mt('Community personnel');
13984: } else {
13985: $roles{'1'} = &mt('Course personnel');
13986: }
13987: if (ref($changes{$key}{$type}) eq 'ARRAY') {
13988: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13989: if ($key eq 'admin') {
13990: my @mgrdc = ();
13991: if (ref($ordered{$key}) eq 'ARRAY') {
13992: foreach my $item (@{$ordered{'admin'}}) {
13993: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13994: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
13995: push(@mgrdc,$item);
13996: }
13997: }
13998: }
13999: if (@mgrdc) {
14000: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
14001: } else {
14002: delete($domdefaults{$type.'selfenrolladmdc'});
14003: }
14004: }
14005: } else {
14006: if (ref($ordered{$key}) eq 'ARRAY') {
14007: foreach my $item (@{$ordered{$key}}) {
14008: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
14009: $domdefaults{$type.'selfenroll'.$item} =
14010: $selfenrollhash{$key}{$type}{$item};
14011: }
14012: }
14013: }
14014: }
14015: }
14016: $resulttext .= '<li>'.$titles{$type}.'<ul>';
14017: foreach my $item (@{$ordered{$key}}) {
14018: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
14019: $resulttext .= '<li>';
14020: if ($key eq 'admin') {
14021: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
14022: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
14023: } else {
14024: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
14025: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
14026: }
14027: $resulttext .= '</li>';
14028: }
14029: }
14030: $resulttext .= '</ul></li>';
14031: }
14032: }
14033: $resulttext .= '</ul></li>';
14034: }
14035: }
1.160.6.93 raeburn 14036: }
14037: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
14038: my $cachetime = 24*60*60;
14039: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14040: if (ref($lastactref) eq 'HASH') {
14041: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 14042: }
14043: }
14044: $resulttext .= '</ul>';
14045: } else {
14046: $resulttext = &mt('No changes made to self-enrollment settings');
14047: }
14048: } else {
14049: $resulttext = '<span class="LC_error">'.
14050: &mt('An error occurred: [_1]',$putresult).'</span>';
14051: }
14052: return $resulttext;
14053: }
14054:
1.137 raeburn 14055: sub modify_usersessions {
1.160.6.27 raeburn 14056: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 14057: my @hostingtypes = ('version','excludedomain','includedomain');
14058: my @offloadtypes = ('primary','default');
14059: my %types = (
14060: remote => \@hostingtypes,
14061: hosted => \@hostingtypes,
14062: spares => \@offloadtypes,
14063: );
14064: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 14065: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 14066: my (%by_ip,%by_location,@intdoms);
14067: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
14068: my @locations = sort(keys(%by_location));
1.137 raeburn 14069: my (%defaultshash,%changes);
14070: foreach my $prefix (@prefixes) {
14071: $defaultshash{'usersessions'}{$prefix} = {};
14072: }
1.160.6.27 raeburn 14073: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 14074: my $resulttext;
1.138 raeburn 14075: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 14076: foreach my $prefix (@prefixes) {
1.145 raeburn 14077: next if ($prefix eq 'spares');
14078: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 14079: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14080: if ($type eq 'version') {
14081: my $value = $env{'form.'.$prefix.'_'.$type};
14082: my $okvalue;
14083: if ($value ne '') {
14084: if (grep(/^\Q$value\E$/,@lcversions)) {
14085: $okvalue = $value;
14086: }
14087: }
14088: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14089: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
14090: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
14091: if ($inuse == 0) {
14092: $changes{$prefix}{$type} = 1;
14093: } else {
14094: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
14095: $changes{$prefix}{$type} = 1;
14096: }
14097: if ($okvalue ne '') {
14098: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14099: }
14100: }
14101: } else {
14102: if (($inuse == 1) && ($okvalue ne '')) {
14103: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14104: $changes{$prefix}{$type} = 1;
14105: }
14106: }
14107: } else {
14108: if (($inuse == 1) && ($okvalue ne '')) {
14109: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14110: $changes{$prefix}{$type} = 1;
14111: }
14112: }
14113: } else {
14114: if (($inuse == 1) && ($okvalue ne '')) {
14115: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14116: $changes{$prefix}{$type} = 1;
14117: }
14118: }
14119: } else {
14120: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14121: my @okvals;
14122: foreach my $val (@vals) {
1.138 raeburn 14123: if ($val =~ /:/) {
14124: my @items = split(/:/,$val);
14125: foreach my $item (@items) {
14126: if (ref($by_location{$item}) eq 'ARRAY') {
14127: push(@okvals,$item);
14128: }
14129: }
14130: } else {
14131: if (ref($by_location{$val}) eq 'ARRAY') {
14132: push(@okvals,$val);
14133: }
1.137 raeburn 14134: }
14135: }
14136: @okvals = sort(@okvals);
14137: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14138: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
14139: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
14140: if ($inuse == 0) {
14141: $changes{$prefix}{$type} = 1;
14142: } else {
14143: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14144: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
14145: if (@changed > 0) {
14146: $changes{$prefix}{$type} = 1;
14147: }
14148: }
14149: } else {
14150: if ($inuse == 1) {
14151: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14152: $changes{$prefix}{$type} = 1;
14153: }
14154: }
14155: } else {
14156: if ($inuse == 1) {
14157: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14158: $changes{$prefix}{$type} = 1;
14159: }
14160: }
14161: } else {
14162: if ($inuse == 1) {
14163: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14164: $changes{$prefix}{$type} = 1;
14165: }
14166: }
14167: }
14168: }
14169: }
1.145 raeburn 14170:
14171: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 14172: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 14173: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
14174: my $savespares;
14175:
14176: foreach my $lonhost (sort(keys(%servers))) {
14177: my $serverhomeID =
14178: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 14179: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 14180: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
14181: my %spareschg;
14182: foreach my $type (@{$types{'spares'}}) {
14183: my @okspares;
14184: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
14185: foreach my $server (@checked) {
1.152 raeburn 14186: if (&Apache::lonnet::hostname($server) ne '') {
14187: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
14188: unless (grep(/^\Q$server\E$/,@okspares)) {
14189: push(@okspares,$server);
14190: }
1.145 raeburn 14191: }
14192: }
14193: }
14194: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
14195: my $newspare;
1.152 raeburn 14196: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
14197: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 14198: $newspare = $new;
14199: }
14200: }
1.152 raeburn 14201: my @spares;
14202: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
14203: @spares = sort(@okspares,$newspare);
14204: } else {
14205: @spares = sort(@okspares);
14206: }
14207: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 14208: if (ref($spareid{$lonhost}) eq 'HASH') {
14209: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 14210: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 14211: if (@diffs > 0) {
14212: $spareschg{$type} = 1;
14213: }
14214: }
14215: }
14216: }
14217: if (keys(%spareschg) > 0) {
14218: $changes{'spares'}{$lonhost} = \%spareschg;
14219: }
14220: }
1.160.6.61 raeburn 14221: $defaultshash{'usersessions'}{'offloadnow'} = {};
14222: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
14223: my @okoffload;
14224: if (@offloadnow) {
14225: foreach my $server (@offloadnow) {
14226: if (&Apache::lonnet::hostname($server) ne '') {
14227: unless (grep(/^\Q$server\E$/,@okoffload)) {
14228: push(@okoffload,$server);
14229: }
14230: }
14231: }
14232: if (@okoffload) {
14233: foreach my $lonhost (@okoffload) {
14234: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
14235: }
14236: }
14237: }
1.145 raeburn 14238: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14239: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
14240: if (ref($changes{'spares'}) eq 'HASH') {
14241: if (keys(%{$changes{'spares'}}) > 0) {
14242: $savespares = 1;
14243: }
14244: }
14245: } else {
14246: $savespares = 1;
14247: }
1.160.6.61 raeburn 14248: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
14249: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
14250: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
14251: $changes{'offloadnow'} = 1;
14252: last;
14253: }
14254: }
14255: unless ($changes{'offloadnow'}) {
14256: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
14257: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
14258: $changes{'offloadnow'} = 1;
14259: last;
14260: }
14261: }
14262: }
14263: } elsif (@okoffload) {
14264: $changes{'offloadnow'} = 1;
14265: }
14266: } elsif (@okoffload) {
14267: $changes{'offloadnow'} = 1;
1.145 raeburn 14268: }
1.147 raeburn 14269: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
14270: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 14271: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14272: $dom);
14273: if ($putresult eq 'ok') {
14274: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
14275: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
14276: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
14277: }
14278: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
14279: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
14280: }
1.160.6.61 raeburn 14281: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
14282: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
14283: }
1.137 raeburn 14284: }
14285: my $cachetime = 24*60*60;
14286: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 14287: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 14288: if (ref($lastactref) eq 'HASH') {
14289: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 14290: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 14291: }
1.147 raeburn 14292: if (keys(%changes) > 0) {
14293: my %lt = &usersession_titles();
14294: $resulttext = &mt('Changes made:').'<ul>';
14295: foreach my $prefix (@prefixes) {
14296: if (ref($changes{$prefix}) eq 'HASH') {
14297: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
14298: if ($prefix eq 'spares') {
14299: if (ref($changes{$prefix}) eq 'HASH') {
14300: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
14301: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 14302: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 14303: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
14304: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 14305: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
14306: foreach my $type (@{$types{$prefix}}) {
14307: if ($changes{$prefix}{$lonhost}{$type}) {
14308: my $offloadto = &mt('None');
14309: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
14310: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
14311: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
14312: }
1.145 raeburn 14313: }
1.147 raeburn 14314: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 14315: }
1.137 raeburn 14316: }
14317: }
1.147 raeburn 14318: $resulttext .= '</li>';
1.137 raeburn 14319: }
14320: }
1.147 raeburn 14321: } else {
14322: foreach my $type (@{$types{$prefix}}) {
14323: if (defined($changes{$prefix}{$type})) {
14324: my $newvalue;
14325: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
14326: if (ref($defaultshash{'usersessions'}{$prefix})) {
14327: if ($type eq 'version') {
14328: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
14329: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
14330: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
14331: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
14332: }
1.145 raeburn 14333: }
14334: }
14335: }
1.147 raeburn 14336: if ($newvalue eq '') {
14337: if ($type eq 'version') {
14338: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
14339: } else {
14340: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
14341: }
1.145 raeburn 14342: } else {
1.147 raeburn 14343: if ($type eq 'version') {
14344: $newvalue .= ' '.&mt('(or later)');
14345: }
14346: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 14347: }
1.137 raeburn 14348: }
14349: }
14350: }
1.147 raeburn 14351: $resulttext .= '</ul>';
1.137 raeburn 14352: }
14353: }
1.160.6.61 raeburn 14354: if ($changes{'offloadnow'}) {
14355: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
14356: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
14357: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
14358: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
14359: $resulttext .= '<li>'.$lonhost.'</li>';
14360: }
14361: $resulttext .= '</ul>';
14362: } else {
14363: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
14364: }
14365: } else {
14366: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
14367: }
14368: }
1.147 raeburn 14369: $resulttext .= '</ul>';
14370: } else {
14371: $resulttext = $nochgmsg;
1.137 raeburn 14372: }
14373: } else {
14374: $resulttext = '<span class="LC_error">'.
14375: &mt('An error occurred: [_1]',$putresult).'</span>';
14376: }
14377: } else {
1.147 raeburn 14378: $resulttext = $nochgmsg;
1.137 raeburn 14379: }
14380: return $resulttext;
14381: }
14382:
1.150 raeburn 14383: sub modify_loadbalancing {
14384: my ($dom,%domconfig) = @_;
14385: my $primary_id = &Apache::lonnet::domain($dom,'primary');
14386: my $intdom = &Apache::lonnet::internet_dom($primary_id);
14387: my ($othertitle,$usertypes,$types) =
14388: &Apache::loncommon::sorted_inst_types($dom);
14389: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 14390: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 14391: my @sparestypes = ('primary','default');
14392: my %typetitles = &sparestype_titles();
14393: my $resulttext;
1.160.6.94 raeburn 14394: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 14395: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14396: %existing = %{$domconfig{'loadbalancing'}};
14397: }
14398: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 14399: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 14400: my ($saveloadbalancing,%defaultshash,%changes);
14401: my ($alltypes,$othertypes,$titles) =
14402: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
14403: my %ruletitles = &offloadtype_text();
14404: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
14405: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
14406: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
14407: if ($balancer eq '') {
14408: next;
14409: }
14410: if (!exists($servers{$balancer})) {
14411: if (exists($currbalancer{$balancer})) {
14412: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 14413: }
1.160.6.7 raeburn 14414: next;
14415: }
14416: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
14417: push(@{$changes{'delete'}},$balancer);
14418: next;
14419: }
14420: if (!exists($currbalancer{$balancer})) {
14421: push(@{$changes{'add'}},$balancer);
14422: }
14423: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
14424: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
14425: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
14426: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14427: $saveloadbalancing = 1;
14428: }
14429: foreach my $sparetype (@sparestypes) {
14430: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
14431: my @offloadto;
14432: foreach my $target (@targets) {
14433: if (($servers{$target}) && ($target ne $balancer)) {
14434: if ($sparetype eq 'default') {
14435: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
14436: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 14437: }
14438: }
1.160.6.7 raeburn 14439: unless(grep(/^\Q$target\E$/,@offloadto)) {
14440: push(@offloadto,$target);
14441: }
1.150 raeburn 14442: }
14443: }
1.160.6.76 raeburn 14444: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
14445: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
14446: push(@offloadto,$balancer);
14447: }
14448: }
14449: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 14450: }
1.160.6.94 raeburn 14451: if ($env{'form.loadbalancing_cookie_'.$i}) {
14452: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
14453: if (exists($currbalancer{$balancer})) {
14454: unless ($currcookies{$balancer}) {
14455: $changes{'curr'}{$balancer}{'cookie'} = 1;
14456: }
14457: }
14458: } elsif (exists($currbalancer{$balancer})) {
14459: if ($currcookies{$balancer}) {
14460: $changes{'curr'}{$balancer}{'cookie'} = 1;
14461: }
14462: }
1.160.6.7 raeburn 14463: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 14464: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 14465: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
14466: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 14467: if (@targetdiffs > 0) {
1.160.6.7 raeburn 14468: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14469: }
1.160.6.7 raeburn 14470: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14471: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14472: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14473: }
14474: }
14475: }
14476: } else {
1.160.6.7 raeburn 14477: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
14478: foreach my $sparetype (@sparestypes) {
14479: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14480: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14481: $changes{'curr'}{$balancer}{'targets'} = 1;
14482: }
1.150 raeburn 14483: }
14484: }
1.160.6.7 raeburn 14485: }
1.150 raeburn 14486: }
14487: my $ishomedom;
1.160.6.7 raeburn 14488: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
14489: $ishomedom = 1;
1.150 raeburn 14490: }
14491: if (ref($alltypes) eq 'ARRAY') {
14492: foreach my $type (@{$alltypes}) {
14493: my $rule;
1.160.6.7 raeburn 14494: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 14495: (!$ishomedom)) {
1.160.6.7 raeburn 14496: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
14497: }
14498: if ($rule eq 'specific') {
1.160.6.55 raeburn 14499: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
14500: if (exists($servers{$specifiedhost})) {
14501: $rule = $specifiedhost;
14502: }
1.150 raeburn 14503: }
1.160.6.7 raeburn 14504: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
14505: if (ref($currrules{$balancer}) eq 'HASH') {
14506: if ($rule ne $currrules{$balancer}{$type}) {
14507: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14508: }
14509: } elsif ($rule ne '') {
1.160.6.7 raeburn 14510: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14511: }
14512: }
14513: }
1.160.6.7 raeburn 14514: }
14515: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
14516: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
14517: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
14518: $defaultshash{'loadbalancing'} = {};
14519: }
14520: my $putresult = &Apache::lonnet::put_dom('configuration',
14521: \%defaultshash,$dom);
14522: if ($putresult eq 'ok') {
14523: if (keys(%changes) > 0) {
1.160.6.54 raeburn 14524: my %toupdate;
1.160.6.7 raeburn 14525: if (ref($changes{'delete'}) eq 'ARRAY') {
14526: foreach my $balancer (sort(@{$changes{'delete'}})) {
14527: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 14528: $toupdate{$balancer} = 1;
1.150 raeburn 14529: }
1.160.6.7 raeburn 14530: }
14531: if (ref($changes{'add'}) eq 'ARRAY') {
14532: foreach my $balancer (sort(@{$changes{'add'}})) {
14533: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 14534: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 14535: }
14536: }
14537: if (ref($changes{'curr'}) eq 'HASH') {
14538: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 14539: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 14540: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
14541: if ($changes{'curr'}{$balancer}{'targets'}) {
14542: my %offloadstr;
14543: foreach my $sparetype (@sparestypes) {
14544: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14545: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14546: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14547: }
14548: }
1.150 raeburn 14549: }
1.160.6.7 raeburn 14550: if (keys(%offloadstr) == 0) {
14551: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 14552: } else {
1.160.6.7 raeburn 14553: my $showoffload;
14554: foreach my $sparetype (@sparestypes) {
14555: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
14556: if (defined($offloadstr{$sparetype})) {
14557: $showoffload .= $offloadstr{$sparetype};
14558: } else {
14559: $showoffload .= &mt('None');
14560: }
14561: $showoffload .= (' 'x3);
14562: }
14563: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 14564: }
14565: }
14566: }
1.160.6.7 raeburn 14567: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
14568: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
14569: foreach my $type (@{$alltypes}) {
14570: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
14571: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14572: my $balancetext;
14573: if ($rule eq '') {
14574: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 14575: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 14576: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
14577: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 14578: foreach my $sparetype (@sparestypes) {
14579: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14580: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14581: }
14582: }
1.160.6.55 raeburn 14583: foreach my $item (@{$alltypes}) {
14584: next if ($item =~ /^_LC_ipchange/);
14585: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
14586: if ($hasrule eq 'homeserver') {
14587: map { $toupdate{$_} = 1; } (keys(%libraryservers));
14588: } else {
14589: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
14590: if ($servers{$hasrule}) {
14591: $toupdate{$hasrule} = 1;
14592: }
14593: }
14594: }
14595: }
14596: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
14597: $balancetext = $ruletitles{$rule};
14598: } else {
14599: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14600: $balancetext = $ruletitles{'particular'}.' '.$receiver;
14601: if ($receiver) {
14602: $toupdate{$receiver};
14603: }
14604: }
14605: } else {
14606: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 14607: }
1.160.6.7 raeburn 14608: } else {
14609: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
14610: }
1.160.6.26 raeburn 14611: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 14612: }
14613: }
14614: }
14615: }
1.160.6.94 raeburn 14616: if ($changes{'curr'}{$balancer}{'cookie'}) {
14617: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
14618: $balancer).'</li>';
14619: }
1.160.6.54 raeburn 14620: if (keys(%toupdate)) {
14621: my %thismachine;
14622: my $updatedhere;
14623: my $cachetime = 60*60*24;
14624: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
14625: foreach my $lonhost (keys(%toupdate)) {
14626: if ($thismachine{$lonhost}) {
14627: unless ($updatedhere) {
14628: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
14629: $defaultshash{'loadbalancing'},
14630: $cachetime);
14631: $updatedhere = 1;
14632: }
14633: } else {
14634: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
14635: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
14636: }
14637: }
14638: }
1.150 raeburn 14639: }
1.160.6.7 raeburn 14640: }
14641: if ($resulttext ne '') {
14642: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 14643: } else {
14644: $resulttext = $nochgmsg;
14645: }
14646: } else {
1.160.6.7 raeburn 14647: $resulttext = $nochgmsg;
1.150 raeburn 14648: }
14649: } else {
1.160.6.7 raeburn 14650: $resulttext = '<span class="LC_error">'.
14651: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 14652: }
14653: } else {
1.160.6.7 raeburn 14654: $resulttext = $nochgmsg;
1.150 raeburn 14655: }
14656: return $resulttext;
14657: }
14658:
1.48 raeburn 14659: sub recurse_check {
14660: my ($chkcats,$categories,$depth,$name) = @_;
14661: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
14662: my $chg = 0;
14663: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
14664: my $category = $chkcats->[$depth]{$name}[$j];
14665: my $item;
14666: if ($category eq '') {
14667: $chg ++;
14668: } else {
14669: my $deeper = $depth + 1;
14670: $item = &escape($category).':'.&escape($name).':'.$depth;
14671: if ($chg) {
14672: $categories->{$item} -= $chg;
14673: }
14674: &recurse_check($chkcats,$categories,$deeper,$category);
14675: $deeper --;
14676: }
14677: }
14678: }
14679: return;
14680: }
14681:
14682: sub recurse_cat_deletes {
14683: my ($item,$coursecategories,$deletions) = @_;
14684: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14685: my $subdepth = $depth + 1;
14686: if (ref($coursecategories) eq 'HASH') {
14687: foreach my $subitem (keys(%{$coursecategories})) {
14688: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
14689: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
14690: delete($coursecategories->{$subitem});
14691: $deletions->{$subitem} = 1;
14692: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 14693: }
1.48 raeburn 14694: }
14695: }
14696: return;
14697: }
14698:
1.125 raeburn 14699: sub active_dc_picker {
1.160.6.16 raeburn 14700: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 14701: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 14702: my @domcoord = keys(%domcoords);
14703: if (keys(%currhash)) {
14704: foreach my $dc (keys(%currhash)) {
14705: unless (exists($domcoords{$dc})) {
14706: push(@domcoord,$dc);
14707: }
14708: }
14709: }
14710: @domcoord = sort(@domcoord);
14711: my $numdcs = scalar(@domcoord);
14712: my $rows = 0;
14713: my $table;
1.125 raeburn 14714: if ($numdcs > 1) {
1.160.6.16 raeburn 14715: $table = '<table>';
14716: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 14717: my $rem = $i%($numinrow);
14718: if ($rem == 0) {
14719: if ($i > 0) {
1.160.6.16 raeburn 14720: $table .= '</tr>';
1.125 raeburn 14721: }
1.160.6.16 raeburn 14722: $table .= '<tr>';
14723: $rows ++;
1.125 raeburn 14724: }
1.160.6.16 raeburn 14725: my $check = '';
14726: if ($inputtype eq 'radio') {
14727: if (keys(%currhash) == 0) {
14728: if (!$i) {
14729: $check = ' checked="checked"';
14730: }
14731: } elsif (exists($currhash{$domcoord[$i]})) {
14732: $check = ' checked="checked"';
14733: }
14734: } else {
14735: if (exists($currhash{$domcoord[$i]})) {
14736: $check = ' checked="checked"';
1.125 raeburn 14737: }
14738: }
1.160.6.16 raeburn 14739: if ($i == @domcoord - 1) {
1.125 raeburn 14740: my $colsleft = $numinrow - $rem;
14741: if ($colsleft > 1) {
1.160.6.16 raeburn 14742: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 14743: } else {
1.160.6.16 raeburn 14744: $table .= '<td class="LC_left_item">';
1.125 raeburn 14745: }
14746: } else {
1.160.6.16 raeburn 14747: $table .= '<td class="LC_left_item">';
14748: }
14749: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
14750: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
14751: $table .= '<span class="LC_nobreak"><label>'.
14752: '<input type="'.$inputtype.'" name="'.$name.'"'.
14753: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
14754: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 14755: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 14756: }
1.160.6.33 raeburn 14757: $table .= '</label></span></td>';
1.125 raeburn 14758: }
1.160.6.16 raeburn 14759: $table .= '</tr></table>';
14760: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 14761: my ($dcname,$dcdom) = split(':',$domcoord[0]);
14762: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 14763: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 14764: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 14765: if ($user ne $dcname.':'.$dcdom) {
14766: $table .= ' ('.$dcname.':'.$dcdom.')';
14767: }
1.160.6.16 raeburn 14768: } else {
14769: my $check;
14770: if (exists($currhash{$domcoord[0]})) {
14771: $check = ' checked="checked"';
14772: }
1.160.6.50 raeburn 14773: $table = '<span class="LC_nobreak"><label>'.
14774: '<input type="checkbox" name="'.$name.'" '.
14775: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 14776: if ($user ne $dcname.':'.$dcdom) {
14777: $table .= ' ('.$dcname.':'.$dcdom.')';
14778: }
14779: $table .= '</label></span>';
1.160.6.16 raeburn 14780: $rows ++;
14781: }
1.125 raeburn 14782: }
1.160.6.16 raeburn 14783: return ($numdcs,$table,$rows);
1.125 raeburn 14784: }
14785:
1.137 raeburn 14786: sub usersession_titles {
14787: return &Apache::lonlocal::texthash(
14788: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
14789: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 14790: spares => 'Servers offloaded to, when busy',
1.137 raeburn 14791: version => 'LON-CAPA version requirement',
1.138 raeburn 14792: excludedomain => 'Allow all, but exclude specific domains',
14793: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 14794: primary => 'Primary (checked first)',
1.154 raeburn 14795: default => 'Default',
1.137 raeburn 14796: );
14797: }
14798:
1.152 raeburn 14799: sub id_for_thisdom {
14800: my (%servers) = @_;
14801: my %altids;
14802: foreach my $server (keys(%servers)) {
14803: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
14804: if ($serverhome ne $server) {
14805: $altids{$serverhome} = $server;
14806: }
14807: }
14808: return %altids;
14809: }
14810:
1.150 raeburn 14811: sub count_servers {
14812: my ($currbalancer,%servers) = @_;
14813: my (@spares,$numspares);
14814: foreach my $lonhost (sort(keys(%servers))) {
14815: next if ($currbalancer eq $lonhost);
14816: push(@spares,$lonhost);
14817: }
14818: if ($currbalancer) {
14819: $numspares = scalar(@spares);
14820: } else {
14821: $numspares = scalar(@spares) - 1;
14822: }
14823: return ($numspares,@spares);
14824: }
14825:
14826: sub lonbalance_targets_js {
1.160.6.7 raeburn 14827: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 14828: my $select = &mt('Select');
14829: my ($alltargets,$allishome,$allinsttypes,@alltypes);
14830: if (ref($servers) eq 'HASH') {
14831: $alltargets = join("','",sort(keys(%{$servers})));
14832: my @homedoms;
14833: foreach my $server (sort(keys(%{$servers}))) {
14834: if (&Apache::lonnet::host_domain($server) eq $dom) {
14835: push(@homedoms,'1');
14836: } else {
14837: push(@homedoms,'0');
14838: }
14839: }
14840: $allishome = join("','",@homedoms);
14841: }
14842: if (ref($types) eq 'ARRAY') {
14843: if (@{$types} > 0) {
14844: @alltypes = @{$types};
14845: }
14846: }
14847: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
14848: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 14849: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 14850: if (ref($settings) eq 'HASH') {
14851: %existing = %{$settings};
14852: }
14853: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 14854: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 14855: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 14856: return <<"END";
14857:
14858: <script type="text/javascript">
14859: // <![CDATA[
14860:
1.160.6.7 raeburn 14861: currBalancers = new Array('$balancers');
14862:
14863: function toggleTargets(balnum) {
14864: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14865: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
14866: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
14867: var prevbalancer = prevhostitem.value;
14868: var baltotal = document.getElementById('loadbalancing_total').value;
14869: prevhostitem.value = balancer;
14870: if (prevbalancer != '') {
14871: var prevIdx = currBalancers.indexOf(prevbalancer);
14872: if (prevIdx != -1) {
14873: currBalancers.splice(prevIdx,1);
14874: }
14875: }
1.150 raeburn 14876: if (balancer == '') {
1.160.6.7 raeburn 14877: hideSpares(balnum);
1.150 raeburn 14878: } else {
1.160.6.7 raeburn 14879: var currIdx = currBalancers.indexOf(balancer);
14880: if (currIdx == -1) {
14881: currBalancers.push(balancer);
14882: }
1.150 raeburn 14883: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 14884: var ishomedom = homedoms[lonhostitem.selectedIndex];
14885: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 14886: }
1.160.6.7 raeburn 14887: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 14888: return;
14889: }
14890:
1.160.6.7 raeburn 14891: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 14892: var alltargets = new Array('$alltargets');
14893: var insttypes = new Array('$allinsttypes');
1.151 raeburn 14894: var offloadtypes = new Array('primary','default');
14895:
1.160.6.7 raeburn 14896: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
14897: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 14898:
1.151 raeburn 14899: for (var i=0; i<offloadtypes.length; i++) {
14900: var count = 0;
14901: for (var j=0; j<alltargets.length; j++) {
14902: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 14903: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
14904: item.value = alltargets[j];
14905: item.style.textAlign='left';
14906: item.style.textFace='normal';
14907: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
14908: if (currBalancers.indexOf(alltargets[j]) == -1) {
14909: item.disabled = '';
14910: } else {
14911: item.disabled = 'disabled';
14912: item.checked = false;
14913: }
1.151 raeburn 14914: count ++;
14915: }
1.150 raeburn 14916: }
14917: }
1.151 raeburn 14918: for (var k=0; k<insttypes.length; k++) {
14919: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 14920: if (ishomedom == 1) {
1.160.6.7 raeburn 14921: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14922: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14923: } else {
1.160.6.7 raeburn 14924: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14925: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 14926: }
14927: } else {
1.160.6.7 raeburn 14928: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14929: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14930: }
1.151 raeburn 14931: if ((insttypes[k] != '_LC_external') &&
14932: ((insttypes[k] != '_LC_internetdom') ||
14933: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 14934: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
14935: item.options.length = 0;
14936: item.options[0] = new Option("","",true,true);
14937: var idx = 0;
1.151 raeburn 14938: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 14939: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
14940: idx ++;
14941: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 14942: }
14943: }
14944: }
14945: }
14946: return;
14947: }
14948:
1.160.6.7 raeburn 14949: function hideSpares(balnum) {
1.150 raeburn 14950: var alltargets = new Array('$alltargets');
14951: var insttypes = new Array('$allinsttypes');
14952: var offloadtypes = new Array('primary','default');
14953:
1.160.6.7 raeburn 14954: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
14955: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 14956:
14957: var total = alltargets.length - 1;
14958: for (var i=0; i<offloadtypes; i++) {
14959: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 14960: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
14961: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
14962: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 14963: }
1.150 raeburn 14964: }
14965: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 14966: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14967: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 14968: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 14969: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
14970: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 14971: }
14972: }
14973: return;
14974: }
14975:
1.160.6.7 raeburn 14976: function checkOffloads(item,balnum,type) {
1.150 raeburn 14977: var alltargets = new Array('$alltargets');
14978: var offloadtypes = new Array('primary','default');
14979: if (item.checked) {
14980: var total = alltargets.length - 1;
14981: var other;
14982: if (type == offloadtypes[0]) {
1.151 raeburn 14983: other = offloadtypes[1];
1.150 raeburn 14984: } else {
1.151 raeburn 14985: other = offloadtypes[0];
1.150 raeburn 14986: }
14987: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 14988: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 14989: if (server == item.value) {
1.160.6.7 raeburn 14990: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
14991: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 14992: }
14993: }
14994: }
14995: }
14996: return;
14997: }
14998:
1.160.6.7 raeburn 14999: function singleServerToggle(balnum,type) {
15000: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 15001: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 15002: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
15003: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 15004:
15005: } else {
1.160.6.7 raeburn 15006: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
15007: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 15008: }
15009: return;
15010: }
15011:
1.160.6.7 raeburn 15012: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 15013: if (type == '_LC_external') {
1.160.6.26 raeburn 15014: return;
1.150 raeburn 15015: }
1.160.6.7 raeburn 15016: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 15017: for (var i=0; i<typesRules.length; i++) {
15018: if (formname.elements[typesRules[i]].checked) {
15019: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 15020: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
15021: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 15022: } else {
1.160.6.7 raeburn 15023: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
15024: }
15025: }
15026: }
15027: return;
15028: }
15029:
15030: function balancerDeleteChange(balnum) {
15031: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
15032: var baltotal = document.getElementById('loadbalancing_total').value;
15033: var addtarget;
15034: var removetarget;
15035: var action = 'delete';
15036: if (document.getElementById('loadbalancing_delete_'+balnum)) {
15037: var lonhost = hostitem.value;
15038: var currIdx = currBalancers.indexOf(lonhost);
15039: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
15040: if (currIdx != -1) {
15041: currBalancers.splice(currIdx,1);
15042: }
15043: addtarget = lonhost;
15044: } else {
15045: if (currIdx == -1) {
15046: currBalancers.push(lonhost);
15047: }
15048: removetarget = lonhost;
15049: action = 'undelete';
15050: }
15051: balancerChange(balnum,baltotal,action,addtarget,removetarget);
15052: }
15053: return;
15054: }
15055:
15056: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
15057: if (baltotal > 1) {
15058: var offloadtypes = new Array('primary','default');
15059: var alltargets = new Array('$alltargets');
15060: var insttypes = new Array('$allinsttypes');
15061: for (var i=0; i<baltotal; i++) {
15062: if (i != balnum) {
15063: for (var j=0; j<offloadtypes.length; j++) {
15064: var total = alltargets.length - 1;
15065: for (var k=0; k<total; k++) {
15066: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
15067: var server = serveritem.value;
15068: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
15069: if (server == addtarget) {
15070: serveritem.disabled = '';
15071: }
15072: }
15073: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
15074: if (server == removetarget) {
15075: serveritem.disabled = 'disabled';
15076: serveritem.checked = false;
15077: }
15078: }
15079: }
15080: }
15081: for (var j=0; j<insttypes.length; j++) {
15082: if (insttypes[j] != '_LC_external') {
15083: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
15084: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
15085: var currSel = singleserver.selectedIndex;
15086: var currVal = singleserver.options[currSel].value;
15087: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
15088: var numoptions = singleserver.options.length;
15089: var needsnew = 1;
15090: for (var k=0; k<numoptions; k++) {
15091: if (singleserver.options[k] == addtarget) {
15092: needsnew = 0;
15093: break;
15094: }
15095: }
15096: if (needsnew == 1) {
15097: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
15098: }
15099: }
15100: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
15101: singleserver.options.length = 0;
15102: if ((currVal) && (currVal != removetarget)) {
15103: singleserver.options[0] = new Option("","",false,false);
15104: } else {
15105: singleserver.options[0] = new Option("","",true,true);
15106: }
15107: var idx = 0;
15108: for (var m=0; m<alltargets.length; m++) {
15109: if (currBalancers.indexOf(alltargets[m]) == -1) {
15110: idx ++;
15111: if (currVal == alltargets[m]) {
15112: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
15113: } else {
15114: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
15115: }
15116: }
15117: }
15118: }
15119: }
15120: }
15121: }
1.150 raeburn 15122: }
15123: }
15124: }
15125: return;
15126: }
15127:
1.152 raeburn 15128: // ]]>
15129: </script>
15130:
15131: END
15132: }
15133:
15134: sub new_spares_js {
15135: my @sparestypes = ('primary','default');
15136: my $types = join("','",@sparestypes);
15137: my $select = &mt('Select');
15138: return <<"END";
15139:
15140: <script type="text/javascript">
15141: // <![CDATA[
15142:
15143: function updateNewSpares(formname,lonhost) {
15144: var types = new Array('$types');
15145: var include = new Array();
15146: var exclude = new Array();
15147: for (var i=0; i<types.length; i++) {
15148: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
15149: for (var j=0; j<spareboxes.length; j++) {
15150: if (formname.elements[spareboxes[j]].checked) {
15151: exclude.push(formname.elements[spareboxes[j]].value);
15152: } else {
15153: include.push(formname.elements[spareboxes[j]].value);
15154: }
15155: }
15156: }
15157: for (var i=0; i<types.length; i++) {
15158: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
15159: var selIdx = newSpare.selectedIndex;
15160: var currnew = newSpare.options[selIdx].value;
15161: var okSpares = new Array();
15162: for (var j=0; j<newSpare.options.length; j++) {
15163: var possible = newSpare.options[j].value;
15164: if (possible != '') {
15165: if (exclude.indexOf(possible) == -1) {
15166: okSpares.push(possible);
15167: } else {
15168: if (currnew == possible) {
15169: selIdx = 0;
15170: }
15171: }
15172: }
15173: }
15174: for (var k=0; k<include.length; k++) {
15175: if (okSpares.indexOf(include[k]) == -1) {
15176: okSpares.push(include[k]);
15177: }
15178: }
15179: okSpares.sort();
15180: newSpare.options.length = 0;
15181: if (selIdx == 0) {
15182: newSpare.options[0] = new Option("$select","",true,true);
15183: } else {
15184: newSpare.options[0] = new Option("$select","",false,false);
15185: }
15186: for (var m=0; m<okSpares.length; m++) {
15187: var idx = m+1;
15188: var selThis = 0;
15189: if (selIdx != 0) {
15190: if (okSpares[m] == currnew) {
15191: selThis = 1;
15192: }
15193: }
15194: if (selThis == 1) {
15195: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
15196: } else {
15197: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
15198: }
15199: }
15200: }
15201: return;
15202: }
15203:
15204: function checkNewSpares(lonhost,type) {
15205: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
15206: var chosen = newSpare.options[newSpare.selectedIndex].value;
15207: if (chosen != '') {
15208: var othertype;
15209: var othernewSpare;
15210: if (type == 'primary') {
15211: othernewSpare = document.getElementById('newspare_default_'+lonhost);
15212: }
15213: if (type == 'default') {
15214: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
15215: }
15216: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
15217: othernewSpare.selectedIndex = 0;
15218: }
15219: }
15220: return;
15221: }
15222:
15223: // ]]>
15224: </script>
15225:
15226: END
15227:
15228: }
15229:
15230: sub common_domprefs_js {
15231: return <<"END";
15232:
15233: <script type="text/javascript">
15234: // <![CDATA[
15235:
1.150 raeburn 15236: function getIndicesByName(formname,item) {
1.152 raeburn 15237: var group = new Array();
1.150 raeburn 15238: for (var i=0;i<formname.elements.length;i++) {
15239: if (formname.elements[i].name == item) {
1.152 raeburn 15240: group.push(formname.elements[i].id);
1.150 raeburn 15241: }
15242: }
1.152 raeburn 15243: return group;
1.150 raeburn 15244: }
15245:
15246: // ]]>
15247: </script>
15248:
15249: END
1.152 raeburn 15250:
1.150 raeburn 15251: }
15252:
1.160.6.5 raeburn 15253: sub recaptcha_js {
15254: my %lt = &captcha_phrases();
15255: return <<"END";
15256:
15257: <script type="text/javascript">
15258: // <![CDATA[
15259:
15260: function updateCaptcha(caller,context) {
15261: var privitem;
15262: var pubitem;
15263: var privtext;
15264: var pubtext;
1.160.6.69 raeburn 15265: var versionitem;
15266: var versiontext;
1.160.6.5 raeburn 15267: if (document.getElementById(context+'_recaptchapub')) {
15268: pubitem = document.getElementById(context+'_recaptchapub');
15269: } else {
15270: return;
15271: }
15272: if (document.getElementById(context+'_recaptchapriv')) {
15273: privitem = document.getElementById(context+'_recaptchapriv');
15274: } else {
15275: return;
15276: }
15277: if (document.getElementById(context+'_recaptchapubtxt')) {
15278: pubtext = document.getElementById(context+'_recaptchapubtxt');
15279: } else {
15280: return;
15281: }
15282: if (document.getElementById(context+'_recaptchaprivtxt')) {
15283: privtext = document.getElementById(context+'_recaptchaprivtxt');
15284: } else {
15285: return;
15286: }
1.160.6.69 raeburn 15287: if (document.getElementById(context+'_recaptchaversion')) {
15288: versionitem = document.getElementById(context+'_recaptchaversion');
15289: } else {
15290: return;
15291: }
15292: if (document.getElementById(context+'_recaptchavertxt')) {
15293: versiontext = document.getElementById(context+'_recaptchavertxt');
15294: } else {
15295: return;
15296: }
1.160.6.5 raeburn 15297: if (caller.checked) {
15298: if (caller.value == 'recaptcha') {
15299: pubitem.type = 'text';
15300: privitem.type = 'text';
15301: pubitem.size = '40';
15302: privitem.size = '40';
15303: pubtext.innerHTML = "$lt{'pub'}";
15304: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 15305: versionitem.type = 'text';
15306: versionitem.size = '3';
15307: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 15308: } else {
15309: pubitem.type = 'hidden';
15310: privitem.type = 'hidden';
1.160.6.69 raeburn 15311: versionitem.type = 'hidden';
1.160.6.5 raeburn 15312: pubtext.innerHTML = '';
15313: privtext.innerHTML = '';
1.160.6.69 raeburn 15314: versiontext.innerHTML = '';
1.160.6.5 raeburn 15315: }
15316: }
15317: return;
15318: }
15319:
15320: // ]]>
15321: </script>
15322:
15323: END
15324:
15325: }
15326:
1.160.6.40 raeburn 15327: sub toggle_display_js {
1.160.6.16 raeburn 15328: return <<"END";
15329:
15330: <script type="text/javascript">
15331: // <![CDATA[
15332:
1.160.6.40 raeburn 15333: function toggleDisplay(domForm,caller) {
15334: if (document.getElementById(caller)) {
15335: var divitem = document.getElementById(caller);
15336: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 15337: var checkval = 1;
15338: var dispval = 'block';
1.160.6.93 raeburn 15339: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 15340: if (caller == 'emailoptions') {
15341: optionsElement = domForm.cancreate_email;
15342: }
1.160.6.57 raeburn 15343: if (caller == 'studentsubmission') {
15344: optionsElement = domForm.postsubmit;
15345: }
1.160.6.64 raeburn 15346: if (caller == 'cloneinstcode') {
15347: optionsElement = domForm.canclone;
15348: checkval = 'instcode';
15349: }
1.160.6.93 raeburn 15350: if (selfcreateRegExp.test(caller)) {
15351: optionsElement = domForm.elements[caller];
15352: checkval = 'other';
15353: dispval = 'inline'
15354: }
1.160.6.40 raeburn 15355: if (optionsElement.length) {
1.160.6.16 raeburn 15356: var currval;
1.160.6.40 raeburn 15357: for (var i=0; i<optionsElement.length; i++) {
15358: if (optionsElement[i].checked) {
15359: currval = optionsElement[i].value;
1.160.6.16 raeburn 15360: }
15361: }
1.160.6.64 raeburn 15362: if (currval == checkval) {
15363: divitem.style.display = dispval;
1.160.6.16 raeburn 15364: } else {
1.160.6.40 raeburn 15365: divitem.style.display = 'none';
1.160.6.16 raeburn 15366: }
15367: }
15368: }
15369: return;
15370: }
15371:
15372: // ]]>
15373: </script>
15374:
15375: END
15376:
15377: }
15378:
1.160.6.5 raeburn 15379: sub captcha_phrases {
15380: return &Apache::lonlocal::texthash (
15381: priv => 'Private key',
15382: pub => 'Public key',
15383: original => 'original (CAPTCHA)',
15384: recaptcha => 'successor (ReCAPTCHA)',
15385: notused => 'unused',
1.160.6.69 raeburn 15386: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 15387: );
15388: }
15389:
1.160.6.24 raeburn 15390: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 15391: my ($dom,$cachekeys) = @_;
15392: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 15393: my %servers = &Apache::lonnet::internet_dom_servers($dom);
15394: my %thismachine;
15395: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.98! raeburn 15396: my @posscached = ('domainconfig','domdefaults','usersessions',
! 15397: 'directorysrch','passwdconf','cats');
1.160.6.61 raeburn 15398: if (keys(%servers)) {
1.160.6.24 raeburn 15399: foreach my $server (keys(%servers)) {
15400: next if ($thismachine{$server});
1.160.6.27 raeburn 15401: my @cached;
15402: foreach my $name (@posscached) {
15403: if ($cachekeys->{$name}) {
15404: push(@cached,&escape($name).':'.&escape($dom));
15405: }
15406: }
15407: if (@cached) {
15408: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
15409: }
1.160.6.24 raeburn 15410: }
15411: }
15412: return;
15413: }
15414:
1.3 raeburn 15415: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>