Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.107
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.107! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.106 2021/01/01 15:33:55 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',},
1.160.6.107! raeburn 338: {col1 => 'Nightly status check e-mail',
! 339: col2 => 'Settings',},
1.160.6.78 raeburn 340: {col1 => 'Ask helpdesk form settings',
341: col2 => 'Value',},],
1.160.6.37 raeburn 342: print => \&print_contacts,
343: modify => \&modify_contacts,
1.30 raeburn 344: },
345: 'usercreation' =>
346: { text => 'User creation',
1.67 raeburn 347: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 348: header => [{col1 => 'Format rule type',
349: col2 => 'Format rules in force'},
1.34 raeburn 350: {col1 => 'User account creation',
351: col2 => 'Usernames which may be created',},
1.30 raeburn 352: {col1 => 'Context',
1.43 raeburn 353: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 354: print => \&print_usercreation,
355: modify => \&modify_usercreation,
1.30 raeburn 356: },
1.160.6.34 raeburn 357: 'selfcreation' =>
358: { text => 'Users self-creating accounts',
359: help => 'Domain_Configuration_Self_Creation',
360: header => [{col1 => 'Self-creation with institutional username',
361: col2 => 'Enabled?'},
362: {col1 => 'Institutional user type (login/SSO self-creation)',
363: col2 => 'Information user can enter'},
1.160.6.93 raeburn 364: {col1 => 'Self-creation with e-mail verification',
1.160.6.34 raeburn 365: col2 => 'Settings'}],
1.160.6.37 raeburn 366: print => \&print_selfcreation,
367: modify => \&modify_selfcreation,
1.160.6.34 raeburn 368: },
1.69 raeburn 369: 'usermodification' =>
1.33 raeburn 370: { text => 'User modification',
1.67 raeburn 371: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 372: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 373: col2 => 'User information updatable in author context'},
1.33 raeburn 374: {col1 => 'Target user has role',
1.160.6.35 raeburn 375: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 376: print => \&print_usermodification,
377: modify => \&modify_usermodification,
1.33 raeburn 378: },
1.69 raeburn 379: 'scantron' =>
1.160.6.97 raeburn 380: { text => 'Bubblesheet format',
1.67 raeburn 381: help => 'Domain_Configuration_Scantron_Format',
1.160.6.97 raeburn 382: header => [ {col1 => 'Bubblesheet format file',
383: col2 => ''},
384: {col1 => 'Bubblesheet data upload formats',
385: col2 => 'Settings'}],
1.160.6.37 raeburn 386: print => \&print_scantron,
387: modify => \&modify_scantron,
1.46 raeburn 388: },
1.86 raeburn 389: 'requestcourses' =>
390: {text => 'Request creation of courses',
391: help => 'Domain_Configuration_Request_Courses',
392: header => [{col1 => 'User affiliation',
1.102 raeburn 393: col2 => 'Availability/Processing of requests',},
394: {col1 => 'Setting',
1.160.6.30 raeburn 395: col2 => 'Value'},
396: {col1 => 'Available textbooks',
1.160.6.39 raeburn 397: col2 => ''},
1.160.6.46 raeburn 398: {col1 => 'Available templates',
399: col2 => ''},
1.160.6.39 raeburn 400: {col1 => 'Validation (not official courses)',
401: col2 => 'Value'},],
1.160.6.37 raeburn 402: print => \&print_quotas,
403: modify => \&modify_quotas,
1.86 raeburn 404: },
1.160.6.5 raeburn 405: 'requestauthor' =>
1.160.6.34 raeburn 406: {text => 'Request Authoring Space',
1.160.6.5 raeburn 407: help => 'Domain_Configuration_Request_Author',
408: header => [{col1 => 'User affiliation',
409: col2 => 'Availability/Processing of requests',},
410: {col1 => 'Setting',
411: col2 => 'Value'}],
1.160.6.37 raeburn 412: print => \&print_quotas,
413: modify => \&modify_quotas,
1.160.6.5 raeburn 414: },
1.69 raeburn 415: 'coursecategories' =>
1.120 raeburn 416: { text => 'Cataloging of courses/communities',
1.67 raeburn 417: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 418: header => [{col1 => 'Catalog type/availability',
419: col2 => '',},
420: {col1 => 'Category settings for standard catalog',
1.57 raeburn 421: col2 => '',},
422: {col1 => 'Categories',
423: col2 => '',
424: }],
1.160.6.37 raeburn 425: print => \&print_coursecategories,
426: modify => \&modify_coursecategories,
1.69 raeburn 427: },
428: 'serverstatuses' =>
1.77 raeburn 429: {text => 'Access to server status pages',
1.69 raeburn 430: help => 'Domain_Configuration_Server_Status',
431: header => [{col1 => 'Status Page',
432: col2 => 'Other named users',
433: col3 => 'Specific IPs',
434: }],
1.160.6.37 raeburn 435: print => \&print_serverstatuses,
436: modify => \&modify_serverstatuses,
1.69 raeburn 437: },
1.160.6.73 raeburn 438: 'helpsettings' =>
439: {text => 'Support settings',
440: help => 'Domain_Configuration_Help_Settings',
441: header => [{col1 => 'Help Page Settings (logged-in users)',
442: col2 => 'Value'},
443: {col1 => 'Helpdesk Roles',
444: col2 => 'Settings'},],
445: print => \&print_helpsettings,
446: modify => \&modify_helpsettings,
447: },
1.160.6.39 raeburn 448: 'coursedefaults' =>
1.160.6.16 raeburn 449: {text => 'Course/Community defaults',
450: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 451: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
452: col2 => 'Value',},
453: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 454: col2 => 'Value',},],
1.160.6.37 raeburn 455: print => \&print_coursedefaults,
456: modify => \&modify_coursedefaults,
457: },
1.160.6.39 raeburn 458: 'selfenrollment' =>
1.160.6.37 raeburn 459: {text => 'Self-enrollment in Course/Community',
460: help => 'Domain_Configuration_Selfenrollment',
461: header => [{col1 => 'Configuration Rights',
462: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
463: {col1 => 'Defaults',
464: col2 => 'Value'},
465: {col1 => 'Self-enrollment validation (optional)',
466: col2 => 'Value'},],
467: print => \&print_selfenrollment,
468: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 469: },
1.141 raeburn 470: 'usersessions' =>
1.145 raeburn 471: {text => 'User session hosting/offloading',
1.137 raeburn 472: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 473: header => [{col1 => 'Domain server',
474: col2 => 'Servers to offload sessions to when busy'},
475: {col1 => 'Hosting of users from other domains',
1.137 raeburn 476: col2 => 'Rules'},
477: {col1 => "Hosting domain's own users elsewhere",
478: col2 => 'Rules'}],
1.160.6.37 raeburn 479: print => \&print_usersessions,
480: modify => \&modify_usersessions,
1.137 raeburn 481: },
1.160.6.78 raeburn 482: 'loadbalancing' =>
1.160.6.7 raeburn 483: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 484: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 485: header => [{col1 => 'Balancers',
1.150 raeburn 486: col2 => 'Default destinations',
1.160.6.13 raeburn 487: col3 => 'User affiliation',
1.150 raeburn 488: col4 => 'Overrides'},
489: ],
1.160.6.37 raeburn 490: print => \&print_loadbalancing,
491: modify => \&modify_loadbalancing,
1.150 raeburn 492: },
1.3 raeburn 493: );
1.110 raeburn 494: if (keys(%servers) > 1) {
495: $prefs{'login'} = { text => 'Log-in page options',
496: help => 'Domain_Configuration_Login_Page',
497: header => [{col1 => 'Log-in Service',
498: col2 => 'Server Setting',},
499: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 500: col2 => ''},
501: {col1 => 'Log-in Help',
1.160.6.56 raeburn 502: col2 => 'Value'},
503: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 504: col2 => 'Value'}],
1.160.6.37 raeburn 505: print => \&print_login,
506: modify => \&modify_login,
1.110 raeburn 507: };
508: }
1.160.6.13 raeburn 509:
1.6 raeburn 510: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 511: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 512: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 513: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 514: text=>"Settings to display/modify"});
1.9 raeburn 515: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 516:
1.3 raeburn 517: if ($phase eq 'process') {
1.160.6.27 raeburn 518: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
519: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 520: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 521: $r->rflush();
1.160.6.27 raeburn 522: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 523: }
1.30 raeburn 524: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 525: my $js = &recaptcha_js().
1.160.6.40 raeburn 526: &toggle_display_js();
1.160.6.7 raeburn 527: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 528: my ($othertitle,$usertypes,$types) =
529: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 530: $js .= &lonbalance_targets_js($dom,$types,\%servers,
531: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 532: &new_spares_js().
533: &common_domprefs_js().
534: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 535: }
1.160.6.30 raeburn 536: if (grep(/^requestcourses$/,@actions)) {
537: my $javascript_validations;
538: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
539: $js .= <<END;
540: <script type="text/javascript">
541: $javascript_validations
542: </script>
543: $coursebrowserjs
544: END
545: }
1.160.6.93 raeburn 546: if (grep(/^selfcreation$/,@actions)) {
547: $js .= &selfcreate_javascript();
548: }
1.160.6.78 raeburn 549: if (grep(/^contacts$/,@actions)) {
550: $js .= &contacts_javascript();
551: }
1.160.6.97 raeburn 552: if (grep(/^scantron$/,@actions)) {
553: $js .= &scantron_javascript();
554: }
1.150 raeburn 555: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 556: } else {
1.160.6.11 raeburn 557: # check if domconfig user exists for the domain.
558: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 559: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 560: &config_check($dom,$confname,$servadm);
561: unless ($configuserok eq 'ok') {
562: &Apache::lonconfigsettings::print_header($r,$phase,$context);
563: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
564: $confname).
565: '<br />'
566: );
567: if ($switchserver) {
568: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
569: '<br />'.
570: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
571: '<br />'.
572: &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).
573: '<br />'.
574: &mt('To do that now, use the following link: [_1]',$switchserver)
575: );
576: } else {
577: $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.').
578: '<br />'.
579: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
580: );
581: }
582: $r->print(&Apache::loncommon::end_page());
583: return OK;
584: }
1.21 raeburn 585: if (keys(%domconfig) == 0) {
586: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 587: my @ids=&Apache::lonnet::current_machine_ids();
588: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 589: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 590: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 591: my $custom_img_count = 0;
592: foreach my $img (@loginimages) {
593: if ($designhash{$dom.'.login.'.$img} ne '') {
594: $custom_img_count ++;
595: }
596: }
597: foreach my $role (@roles) {
598: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
599: $custom_img_count ++;
600: }
601: }
602: if ($custom_img_count > 0) {
1.94 raeburn 603: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 604: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 605: $r->print(
606: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
607: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
608: &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 />'.
609: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
610: if ($switch_server) {
1.30 raeburn 611: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 612: }
1.91 raeburn 613: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 614: return OK;
615: }
616: }
617: }
1.91 raeburn 618: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 619: }
620: return OK;
621: }
622:
623: sub process_changes {
1.160.6.24 raeburn 624: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 625: my %domconfig;
626: if (ref($values) eq 'HASH') {
627: %domconfig = %{$values};
628: }
1.3 raeburn 629: my $output;
630: if ($action eq 'login') {
1.160.6.24 raeburn 631: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 632: } elsif ($action eq 'rolecolors') {
1.9 raeburn 633: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 634: $lastactref,%domconfig);
1.3 raeburn 635: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 636: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 637: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 638: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 639: } elsif ($action eq 'autoupdate') {
640: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 641: } elsif ($action eq 'autocreate') {
642: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 643: } elsif ($action eq 'directorysrch') {
1.160.6.81 raeburn 644: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 645: } elsif ($action eq 'usercreation') {
1.28 raeburn 646: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 647: } elsif ($action eq 'selfcreation') {
1.160.6.93 raeburn 648: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 649: } elsif ($action eq 'usermodification') {
650: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 651: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 652: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 653: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 654: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 655: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 656: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 657: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 658: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 659: } elsif ($action eq 'serverstatuses') {
660: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 661: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 662: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 663: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 664: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 665: } elsif ($action eq 'helpsettings') {
1.160.6.77 raeburn 666: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16 raeburn 667: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 668: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 669: } elsif ($action eq 'selfenrollment') {
670: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 671: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 672: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 673: } elsif ($action eq 'loadbalancing') {
674: $output = &modify_loadbalancing($dom,%domconfig);
1.160.6.98 raeburn 675: } elsif ($action eq 'passwords') {
676: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.3 raeburn 677: }
678: return $output;
679: }
680:
681: sub print_config_box {
1.9 raeburn 682: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 683: my $rowtotal = 0;
1.49 raeburn 684: my $output;
685: if ($action eq 'coursecategories') {
686: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 687: } elsif ($action eq 'defaults') {
688: $output = &defaults_javascript($settings);
1.160.6.98 raeburn 689: } elsif ($action eq 'passwords') {
690: $output = &passwords_javascript();
1.160.6.73 raeburn 691: } elsif ($action eq 'helpsettings') {
692: my (%privs,%levelscurrent);
693: my %full=();
694: my %levels=(
695: course => {},
696: domain => {},
697: system => {},
698: );
699: my $context = 'domain';
700: my $crstype = 'Course';
701: my $formname = 'display';
702: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
703: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
704: $output =
705: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
706: \@templateroles);
1.91 raeburn 707: }
1.160.6.40 raeburn 708: $output .=
1.30 raeburn 709: '<table class="LC_nested_outer">
1.3 raeburn 710: <tr>
1.66 raeburn 711: <th align="left" valign="middle"><span class="LC_nobreak">'.
712: &mt($item->{text}).' '.
713: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
714: '</tr>';
1.30 raeburn 715: $rowtotal ++;
1.110 raeburn 716: my $numheaders = 1;
717: if (ref($item->{'header'}) eq 'ARRAY') {
718: $numheaders = scalar(@{$item->{'header'}});
719: }
720: if ($numheaders > 1) {
1.64 raeburn 721: my $colspan = '';
1.145 raeburn 722: my $rightcolspan = '';
1.160.6.104 raeburn 723: my $leftnobr = '';
1.160.6.42 raeburn 724: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 725: ($action eq 'directorysrch') ||
1.160.6.56 raeburn 726: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 727: $colspan = ' colspan="2"';
728: }
1.145 raeburn 729: if ($action eq 'usersessions') {
730: $rightcolspan = ' colspan="3"';
731: }
1.160.6.104 raeburn 732: if ($action eq 'passwords') {
733: $leftnobr = ' LC_nobreak';
734: }
1.30 raeburn 735: $output .= '
1.3 raeburn 736: <tr>
737: <td>
738: <table class="LC_nested">
739: <tr class="LC_info_row">
1.160.6.104 raeburn 740: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 741: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 742: </tr>';
1.69 raeburn 743: $rowtotal ++;
1.160.6.37 raeburn 744: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 745: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 746: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.78 raeburn 747: ($action eq 'helpsettings') || ($action eq 'contacts')) {
1.160.6.37 raeburn 748: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.160.6.98 raeburn 749: } elsif ($action eq 'passwords') {
750: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 751: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 752: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.160.6.97 raeburn 753: } elsif ($action eq 'scantron') {
754: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 755: } elsif ($action eq 'login') {
1.160.6.56 raeburn 756: if ($numheaders == 4) {
1.160.6.5 raeburn 757: $colspan = ' colspan="2"';
758: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
759: } else {
760: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
761: }
1.160.6.37 raeburn 762: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 763: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 764: } elsif ($action eq 'rolecolors') {
1.30 raeburn 765: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 766: }
1.30 raeburn 767: $output .= '
1.6 raeburn 768: </table>
769: </td>
770: </tr>
771: <tr>
772: <td>
773: <table class="LC_nested">
774: <tr class="LC_info_row">
1.160.6.37 raeburn 775: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 776: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 777: </tr>';
778: $rowtotal ++;
1.160.6.37 raeburn 779: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
780: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 781: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.98 raeburn 782: ($action eq 'contacts') || ($action eq 'passwords')) {
1.160.6.42 raeburn 783: if ($action eq 'coursecategories') {
784: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
785: $colspan = ' colspan="2"';
1.160.6.98 raeburn 786: } elsif ($action eq 'passwords') {
787: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.160.6.42 raeburn 788: } else {
789: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
790: }
791: $output .= '
1.63 raeburn 792: </table>
793: </td>
794: </tr>
795: <tr>
796: <td>
797: <table class="LC_nested">
798: <tr class="LC_info_row">
1.160.6.104 raeburn 799: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 800: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 801: </tr>'."\n";
802: if ($action eq 'coursecategories') {
803: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.160.6.107! raeburn 804: } elsif ($action eq 'contacts') || ($action eq 'passwords')) {
! 805: if ($action eq 'passwords') {
! 806: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
! 807: } else {
! 808: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
! 809: }
! 810: $output .= '
1.160.6.98 raeburn 811: </tr>
812: </table>
813: </td>
814: </tr>
815: <tr>
816: <td>
817: <table class="LC_nested">
818: <tr class="LC_info_row">
819: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.160.6.107! raeburn 820: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
! 821: if ($action eq 'passwords') {
! 822: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
! 823: } else {
! 824: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
! 825: }
! 826: $output .= '
1.160.6.98 raeburn 827: </table>
828: </td>
829: </tr>
830: <tr>';
1.160.6.42 raeburn 831: } else {
832: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
833: }
1.63 raeburn 834: $rowtotal ++;
1.160.6.57 raeburn 835: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 836: ($action eq 'defaults') || ($action eq 'directorysrch') ||
837: ($action eq 'helpsettings')) {
1.160.6.37 raeburn 838: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.160.6.97 raeburn 839: } elsif ($action eq 'scantron') {
840: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 841: } elsif ($action eq 'login') {
1.160.6.56 raeburn 842: if ($numheaders == 4) {
1.160.6.5 raeburn 843: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
844: </table>
845: </td>
846: </tr>
847: <tr>
848: <td>
849: <table class="LC_nested">
850: <tr class="LC_info_row">
851: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 852: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 853: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
854: $rowtotal ++;
855: } else {
856: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
857: }
1.160.6.56 raeburn 858: $output .= '
859: </table>
860: </td>
861: </tr>
862: <tr>
863: <td>
864: <table class="LC_nested">
865: <tr class="LC_info_row">';
866: if ($numheaders == 4) {
867: $output .= '
868: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
869: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
870: </tr>';
871: } else {
872: $output .= '
873: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
874: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
875: </tr>';
876: }
877: $rowtotal ++;
878: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 879: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 880: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
881: $rowtotal ++;
882: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 883: </table>
884: </td>
885: </tr>
886: <tr>
887: <td>
888: <table class="LC_nested">
889: <tr class="LC_info_row">
890: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
891: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 892: &textbookcourses_javascript($settings).
893: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
894: </table>
895: </td>
896: </tr>
897: <tr>
898: <td>
899: <table class="LC_nested">
900: <tr class="LC_info_row">
901: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
902: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
903: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 904: </table>
905: </td>
906: </tr>
907: <tr>
908: <td>
909: <table class="LC_nested">
910: <tr class="LC_info_row">
1.160.6.46 raeburn 911: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
912: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 913: </tr>'.
914: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 915: } elsif ($action eq 'requestauthor') {
916: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 917: $rowtotal ++;
1.122 jms 918: } elsif ($action eq 'rolecolors') {
1.30 raeburn 919: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 920: </table>
921: </td>
922: </tr>
923: <tr>
924: <td>
925: <table class="LC_nested">
926: <tr class="LC_info_row">
1.69 raeburn 927: <td class="LC_left_item"'.$colspan.' valign="top">'.
928: &mt($item->{'header'}->[2]->{'col1'}).'</td>
929: <td class="LC_right_item" valign="top">'.
930: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 931: </tr>'.
1.30 raeburn 932: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 933: </table>
934: </td>
935: </tr>
936: <tr>
937: <td>
938: <table class="LC_nested">
939: <tr class="LC_info_row">
1.59 bisitz 940: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
941: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 942: </tr>'.
1.30 raeburn 943: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
944: $rowtotal += 2;
1.6 raeburn 945: }
1.3 raeburn 946: } else {
1.30 raeburn 947: $output .= '
1.3 raeburn 948: <tr>
949: <td>
950: <table class="LC_nested">
1.30 raeburn 951: <tr class="LC_info_row">';
1.160.6.72 raeburn 952: if ($action eq 'login') {
1.30 raeburn 953: $output .= '
1.59 bisitz 954: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 955: } elsif ($action eq 'serverstatuses') {
956: $output .= '
957: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
958: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
959:
1.6 raeburn 960: } else {
1.30 raeburn 961: $output .= '
1.69 raeburn 962: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
963: }
1.72 raeburn 964: if (defined($item->{'header'}->[0]->{'col3'})) {
965: $output .= '<td class="LC_left_item" valign="top">'.
966: &mt($item->{'header'}->[0]->{'col2'});
967: if ($action eq 'serverstatuses') {
968: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
969: }
1.69 raeburn 970: } else {
971: $output .= '<td class="LC_right_item" valign="top">'.
972: &mt($item->{'header'}->[0]->{'col2'});
973: }
974: $output .= '</td>';
975: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 976: if (defined($item->{'header'}->[0]->{'col4'})) {
977: $output .= '<td class="LC_left_item" valign="top">'.
978: &mt($item->{'header'}->[0]->{'col3'});
979: } else {
980: $output .= '<td class="LC_right_item" valign="top">'.
981: &mt($item->{'header'}->[0]->{'col3'});
982: }
1.69 raeburn 983: if ($action eq 'serverstatuses') {
984: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
985: }
986: $output .= '</td>';
1.6 raeburn 987: }
1.150 raeburn 988: if ($item->{'header'}->[0]->{'col4'}) {
989: $output .= '<td class="LC_right_item" valign="top">'.
990: &mt($item->{'header'}->[0]->{'col4'});
991: }
1.69 raeburn 992: $output .= '</tr>';
1.48 raeburn 993: $rowtotal ++;
1.160.6.5 raeburn 994: if ($action eq 'quotas') {
1.86 raeburn 995: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 996: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.78 raeburn 997: ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.160.6.37 raeburn 998: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 999: }
1.3 raeburn 1000: }
1.30 raeburn 1001: $output .= '
1.3 raeburn 1002: </table>
1003: </td>
1004: </tr>
1.30 raeburn 1005: </table><br />';
1006: return ($output,$rowtotal);
1.1 raeburn 1007: }
1008:
1.3 raeburn 1009: sub print_login {
1.160.6.5 raeburn 1010: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1011: my ($css_class,$datatable);
1.6 raeburn 1012: my %choices = &login_choices();
1.110 raeburn 1013:
1.160.6.5 raeburn 1014: if ($caller eq 'service') {
1.149 raeburn 1015: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1016: my $choice = $choices{'disallowlogin'};
1017: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1018: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 1019: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1020: '<th>'.$choices{'server'}.'</th>'.
1021: '<th>'.$choices{'serverpath'}.'</th>'.
1022: '<th>'.$choices{'custompath'}.'</th>'.
1023: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1024: my %disallowed;
1025: if (ref($settings) eq 'HASH') {
1026: if (ref($settings->{'loginvia'}) eq 'HASH') {
1027: %disallowed = %{$settings->{'loginvia'}};
1028: }
1029: }
1030: foreach my $lonhost (sort(keys(%servers))) {
1031: my $direct = 'selected="selected"';
1.128 raeburn 1032: if (ref($disallowed{$lonhost}) eq 'HASH') {
1033: if ($disallowed{$lonhost}{'server'} ne '') {
1034: $direct = '';
1035: }
1.110 raeburn 1036: }
1.115 raeburn 1037: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1038: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1039: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1040: '</option>';
1.160.6.13 raeburn 1041: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1042: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1043: my $selected = '';
1.128 raeburn 1044: if (ref($disallowed{$lonhost}) eq 'HASH') {
1045: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1046: $selected = 'selected="selected"';
1047: }
1.110 raeburn 1048: }
1049: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1050: $servers{$hostid}.'</option>';
1051: }
1.128 raeburn 1052: $datatable .= '</select></td>'.
1053: '<td><select name="'.$lonhost.'_serverpath">';
1054: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1055: my $pathname = $path;
1056: if ($path eq 'custom') {
1057: $pathname = &mt('Custom Path').' ->';
1058: }
1059: my $selected = '';
1060: if (ref($disallowed{$lonhost}) eq 'HASH') {
1061: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1062: $selected = 'selected="selected"';
1063: }
1064: } elsif ($path eq '') {
1065: $selected = 'selected="selected"';
1066: }
1067: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1068: }
1069: $datatable .= '</select></td>';
1070: my ($custom,$exempt);
1071: if (ref($disallowed{$lonhost}) eq 'HASH') {
1072: $custom = $disallowed{$lonhost}{'custompath'};
1073: $exempt = $disallowed{$lonhost}{'exempt'};
1074: }
1075: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1076: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1077: '</tr>';
1.110 raeburn 1078: }
1079: $datatable .= '</table></td></tr>';
1080: return $datatable;
1.160.6.5 raeburn 1081: } elsif ($caller eq 'page') {
1082: my %defaultchecked = (
1083: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1084: 'helpdesk' => 'on',
1.160.6.5 raeburn 1085: 'adminmail' => 'off',
1086: 'newuser' => 'off',
1087: );
1.160.6.14 raeburn 1088: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1089: my (%checkedon,%checkedoff);
1.42 raeburn 1090: foreach my $item (@toggles) {
1.160.6.5 raeburn 1091: if ($defaultchecked{$item} eq 'on') {
1092: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1093: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1094: } elsif ($defaultchecked{$item} eq 'off') {
1095: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1096: $checkedon{$item} = ' ';
1097: }
1.1 raeburn 1098: }
1.160.6.5 raeburn 1099: my @images = ('img','logo','domlogo','login');
1100: my @logintext = ('textcol','bgcol');
1101: my @bgs = ('pgbg','mainbg','sidebg');
1102: my @links = ('link','alink','vlink');
1103: my %designhash = &Apache::loncommon::get_domainconf($dom);
1104: my %defaultdesign = %Apache::loncommon::defaultdesign;
1105: my (%is_custom,%designs);
1106: my %defaults = (
1107: font => $defaultdesign{'login.font'},
1108: );
1.6 raeburn 1109: foreach my $item (@images) {
1.160.6.5 raeburn 1110: $defaults{$item} = $defaultdesign{'login.'.$item};
1111: $defaults{'showlogo'}{$item} = 1;
1112: }
1113: foreach my $item (@bgs) {
1114: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1115: }
1.41 raeburn 1116: foreach my $item (@logintext) {
1.160.6.5 raeburn 1117: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1118: }
1.160.6.5 raeburn 1119: foreach my $item (@links) {
1120: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1121: }
1.160.6.5 raeburn 1122: if (ref($settings) eq 'HASH') {
1123: foreach my $item (@toggles) {
1124: if ($settings->{$item} eq '1') {
1125: $checkedon{$item} = ' checked="checked" ';
1126: $checkedoff{$item} = ' ';
1127: } elsif ($settings->{$item} eq '0') {
1128: $checkedoff{$item} = ' checked="checked" ';
1129: $checkedon{$item} = ' ';
1130: }
1.6 raeburn 1131: }
1.160.6.5 raeburn 1132: foreach my $item (@images) {
1133: if (defined($settings->{$item})) {
1134: $designs{$item} = $settings->{$item};
1135: $is_custom{$item} = 1;
1136: }
1137: if (defined($settings->{'showlogo'}{$item})) {
1138: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1139: }
1140: }
1141: foreach my $item (@logintext) {
1142: if ($settings->{$item} ne '') {
1143: $designs{'logintext'}{$item} = $settings->{$item};
1144: $is_custom{$item} = 1;
1145: }
1146: }
1147: if ($settings->{'font'} ne '') {
1148: $designs{'font'} = $settings->{'font'};
1149: $is_custom{'font'} = 1;
1150: }
1151: foreach my $item (@bgs) {
1152: if ($settings->{$item} ne '') {
1153: $designs{'bgs'}{$item} = $settings->{$item};
1154: $is_custom{$item} = 1;
1155: }
1156: }
1157: foreach my $item (@links) {
1158: if ($settings->{$item} ne '') {
1159: $designs{'links'}{$item} = $settings->{$item};
1160: $is_custom{$item} = 1;
1161: }
1162: }
1163: } else {
1164: if ($designhash{$dom.'.login.font'} ne '') {
1165: $designs{'font'} = $designhash{$dom.'.login.font'};
1166: $is_custom{'font'} = 1;
1167: }
1168: foreach my $item (@images) {
1169: if ($designhash{$dom.'.login.'.$item} ne '') {
1170: $designs{$item} = $designhash{$dom.'.login.'.$item};
1171: $is_custom{$item} = 1;
1172: }
1173: }
1174: foreach my $item (@bgs) {
1175: if ($designhash{$dom.'.login.'.$item} ne '') {
1176: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1177: $is_custom{$item} = 1;
1178: }
1179: }
1180: foreach my $item (@links) {
1181: if ($designhash{$dom.'.login.'.$item} ne '') {
1182: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1183: $is_custom{$item} = 1;
1184: }
1.6 raeburn 1185: }
1186: }
1.160.6.5 raeburn 1187: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1188: logo => 'Institution Logo',
1189: domlogo => 'Domain Logo',
1190: login => 'Login box');
1191: my $itemcount = 1;
1192: foreach my $item (@toggles) {
1193: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1194: $datatable .=
1195: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1196: '</td><td>'.
1197: '<span class="LC_nobreak"><label><input type="radio" name="'.
1198: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1199: '</label> <label><input type="radio" name="'.$item.'"'.
1200: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1201: '</tr>';
1202: $itemcount ++;
1.6 raeburn 1203: }
1.160.6.5 raeburn 1204: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1205: $datatable .= '</tr></table></td></tr>';
1206: } elsif ($caller eq 'help') {
1207: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1208: my $switchserver = &check_switchserver($dom,$confname);
1209: my $itemcount = 1;
1210: $defaulturl = '/adm/loginproblems.html';
1211: $defaulttype = 'default';
1212: %lt = &Apache::lonlocal::texthash (
1213: del => 'Delete?',
1214: rep => 'Replace:',
1215: upl => 'Upload:',
1216: default => 'Default',
1217: custom => 'Custom',
1218: );
1219: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1220: my @currlangs;
1221: if (ref($settings) eq 'HASH') {
1222: if (ref($settings->{'helpurl'}) eq 'HASH') {
1223: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1224: next if ($settings->{'helpurl'}{$key} eq '');
1225: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1226: $type{$key} = 'custom';
1227: unless ($key eq 'nolang') {
1228: push(@currlangs,$key);
1229: }
1230: }
1231: } elsif ($settings->{'helpurl'} ne '') {
1232: $type{'nolang'} = 'custom';
1233: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1234: }
1235: }
1.160.6.5 raeburn 1236: foreach my $lang ('nolang',sort(@currlangs)) {
1237: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1238: $datatable .= '<tr'.$css_class.'>';
1239: if ($url{$lang} eq '') {
1240: $url{$lang} = $defaulturl;
1241: }
1242: if ($type{$lang} eq '') {
1243: $type{$lang} = $defaulttype;
1244: }
1245: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1246: if ($lang eq 'nolang') {
1247: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1248: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1249: } else {
1250: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1251: $langchoices{$lang},
1252: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1253: }
1254: $datatable .= '</span></td>'."\n".
1255: '<td class="LC_left_item">';
1256: if ($type{$lang} eq 'custom') {
1257: $datatable .= '<span class="LC_nobreak"><label>'.
1258: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1259: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1260: } else {
1261: $datatable .= $lt{'upl'};
1262: }
1263: $datatable .='<br />';
1264: if ($switchserver) {
1265: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1266: } else {
1267: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1268: }
1.160.6.5 raeburn 1269: $datatable .= '</td></tr>';
1270: $itemcount ++;
1.6 raeburn 1271: }
1.160.6.5 raeburn 1272: my @addlangs;
1273: foreach my $lang (sort(keys(%langchoices))) {
1274: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1275: push(@addlangs,$lang);
1276: }
1277: if (@addlangs > 0) {
1278: my %toadd;
1279: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1280: $toadd{''} = &mt('Select');
1281: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1282: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1283: &mt('Add log-in help page for a specific language:').' '.
1284: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1285: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1286: if ($switchserver) {
1287: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1288: } else {
1289: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1290: }
1.160.6.5 raeburn 1291: $datatable .= '</td></tr>';
1292: $itemcount ++;
1.6 raeburn 1293: }
1.160.6.5 raeburn 1294: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1295: } elsif ($caller eq 'headtag') {
1296: my %domservers = &Apache::lonnet::get_servers($dom);
1297: my $choice = $choices{'headtag'};
1298: $css_class = ' class="LC_odd_row"';
1299: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1300: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1301: '<th>'.$choices{'current'}.'</th>'.
1302: '<th>'.$choices{'action'}.'</th>'.
1303: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1304: my (%currurls,%currexempt);
1305: if (ref($settings) eq 'HASH') {
1306: if (ref($settings->{'headtag'}) eq 'HASH') {
1307: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1308: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1309: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1310: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1311: }
1312: }
1313: }
1314: }
1315: my %lt = &Apache::lonlocal::texthash(
1316: del => 'Delete?',
1317: rep => 'Replace:',
1318: upl => 'Upload:',
1319: curr => 'View contents',
1320: none => 'None',
1321: );
1322: my $switchserver = &check_switchserver($dom,$confname);
1323: foreach my $lonhost (sort(keys(%domservers))) {
1324: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1325: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1326: if ($currurls{$lonhost}) {
1327: $datatable .= '<td class="LC_right_item"><a href="'.
1328: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1329: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1330: '">'.$lt{'curr'}.'</a></td>'.
1331: '<td><span class="LC_nobreak"><label>'.
1332: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1333: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1334: } else {
1335: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1336: }
1337: $datatable .='<br />';
1338: if ($switchserver) {
1339: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1340: } else {
1341: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1342: }
1.160.6.87 raeburn 1343: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56 raeburn 1344: }
1345: $datatable .= '</table></td></tr>';
1.1 raeburn 1346: }
1.6 raeburn 1347: return $datatable;
1348: }
1349:
1350: sub login_choices {
1351: my %choices =
1352: &Apache::lonlocal::texthash (
1.116 bisitz 1353: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1354: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1355: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1356: disallowlogin => "Login page requests redirected",
1357: hostid => "Server",
1.128 raeburn 1358: server => "Redirect to:",
1359: serverpath => "Path",
1360: custompath => "Custom",
1361: exempt => "Exempt IP(s)",
1.110 raeburn 1362: directlogin => "No redirect",
1363: newuser => "Link to create a user account",
1364: img => "Header",
1365: logo => "Main Logo",
1366: domlogo => "Domain Logo",
1367: login => "Log-in Header",
1368: textcol => "Text color",
1369: bgcol => "Box color",
1370: bgs => "Background colors",
1371: links => "Link colors",
1372: font => "Font color",
1373: pgbg => "Header",
1374: mainbg => "Page",
1375: sidebg => "Login box",
1376: link => "Link",
1377: alink => "Active link",
1378: vlink => "Visited link",
1.160.6.56 raeburn 1379: headtag => "Custom markup",
1380: action => "Action",
1381: current => "Current",
1.6 raeburn 1382: );
1383: return %choices;
1384: }
1385:
1386: sub print_rolecolors {
1.30 raeburn 1387: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1388: my %choices = &color_font_choices();
1389: my @bgs = ('pgbg','tabbg','sidebg');
1390: my @links = ('link','alink','vlink');
1391: my @images = ('img');
1392: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1393: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1394: my %defaultdesign = %Apache::loncommon::defaultdesign;
1395: my (%is_custom,%designs);
1.160.6.22 raeburn 1396: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1397: if (ref($settings) eq 'HASH') {
1398: if (ref($settings->{$role}) eq 'HASH') {
1399: if ($settings->{$role}->{'img'} ne '') {
1400: $designs{'img'} = $settings->{$role}->{'img'};
1401: $is_custom{'img'} = 1;
1402: }
1403: if ($settings->{$role}->{'font'} ne '') {
1404: $designs{'font'} = $settings->{$role}->{'font'};
1405: $is_custom{'font'} = 1;
1406: }
1.97 tempelho 1407: if ($settings->{$role}->{'fontmenu'} ne '') {
1408: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1409: $is_custom{'fontmenu'} = 1;
1410: }
1.6 raeburn 1411: foreach my $item (@bgs) {
1412: if ($settings->{$role}->{$item} ne '') {
1413: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1414: $is_custom{$item} = 1;
1415: }
1416: }
1417: foreach my $item (@links) {
1418: if ($settings->{$role}->{$item} ne '') {
1419: $designs{'links'}{$item} = $settings->{$role}->{$item};
1420: $is_custom{$item} = 1;
1421: }
1422: }
1423: }
1424: } else {
1425: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1426: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1427: $is_custom{'img'} = 1;
1428: }
1.97 tempelho 1429: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1430: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1431: $is_custom{'fontmenu'} = 1;
1432: }
1.6 raeburn 1433: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1434: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1435: $is_custom{'font'} = 1;
1436: }
1437: foreach my $item (@bgs) {
1438: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1439: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1440: $is_custom{$item} = 1;
1441:
1442: }
1443: }
1444: foreach my $item (@links) {
1445: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1446: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1447: $is_custom{$item} = 1;
1448: }
1449: }
1450: }
1451: my $itemcount = 1;
1.30 raeburn 1452: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1453: $datatable .= '</tr></table></td></tr>';
1454: return $datatable;
1455: }
1456:
1.160.6.22 raeburn 1457: sub role_defaults {
1458: my ($role,$bgs,$links,$images,$logintext) = @_;
1459: my %defaults;
1460: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1461: return %defaults;
1462: }
1463: my %defaultdesign = %Apache::loncommon::defaultdesign;
1464: if ($role eq 'login') {
1465: %defaults = (
1466: font => $defaultdesign{$role.'.font'},
1467: );
1468: if (ref($logintext) eq 'ARRAY') {
1469: foreach my $item (@{$logintext}) {
1470: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1471: }
1472: }
1473: foreach my $item (@{$images}) {
1474: $defaults{'showlogo'}{$item} = 1;
1475: }
1476: } else {
1477: %defaults = (
1478: img => $defaultdesign{$role.'.img'},
1479: font => $defaultdesign{$role.'.font'},
1480: fontmenu => $defaultdesign{$role.'.fontmenu'},
1481: );
1482: }
1483: foreach my $item (@{$bgs}) {
1484: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1485: }
1486: foreach my $item (@{$links}) {
1487: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1488: }
1489: foreach my $item (@{$images}) {
1490: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1491: }
1492: return %defaults;
1493: }
1494:
1.6 raeburn 1495: sub display_color_options {
1.9 raeburn 1496: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1497: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1498: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1499: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1500: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1501: '<td>'.$choices->{'font'}.'</td>';
1502: if (!$is_custom->{'font'}) {
1.160.6.87 raeburn 1503: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1504: } else {
1505: $datatable .= '<td> </td>';
1506: }
1.160.6.9 raeburn 1507: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1508:
1.8 raeburn 1509: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1510: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1511: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1512: ' </span></td></tr>';
1.107 raeburn 1513: unless ($role eq 'login') {
1514: $datatable .= '<tr'.$css_class.'>'.
1515: '<td>'.$choices->{'fontmenu'}.'</td>';
1516: if (!$is_custom->{'fontmenu'}) {
1.160.6.87 raeburn 1517: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1518: } else {
1519: $datatable .= '<td> </td>';
1520: }
1.160.6.22 raeburn 1521: $current_color = $designs->{'fontmenu'} ?
1522: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1523: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1524: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1525: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1526: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1527: ' </span></td></tr>';
1.97 tempelho 1528: }
1.9 raeburn 1529: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1530: foreach my $img (@{$images}) {
1.18 albertel 1531: $itemcount ++;
1.6 raeburn 1532: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1533: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1534: '<td>'.$choices->{$img};
1.41 raeburn 1535: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1536: if ($role eq 'login') {
1537: if ($img eq 'login') {
1538: $login_hdr_pick =
1.135 bisitz 1539: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1540: $logincolors =
1541: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1542: $designs,$defaults);
1.70 raeburn 1543: } elsif ($img ne 'domlogo') {
1544: $datatable.= &logo_display_options($img,$defaults,$designs);
1545: }
1546: }
1547: $datatable .= '</td>';
1.6 raeburn 1548: if ($designs->{$img} ne '') {
1549: $imgfile = $designs->{$img};
1.18 albertel 1550: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1551: } else {
1552: $imgfile = $defaults->{$img};
1553: }
1554: if ($imgfile) {
1.9 raeburn 1555: my ($showfile,$fullsize);
1556: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1557: my $urldir = $1;
1558: my $filename = $2;
1559: my @info = &Apache::lonnet::stat_file($designs->{$img});
1560: if (@info) {
1561: my $thumbfile = 'tn-'.$filename;
1562: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1563: if (@thumb) {
1564: $showfile = $urldir.'/'.$thumbfile;
1565: } else {
1566: $showfile = $imgfile;
1567: }
1568: } else {
1569: $showfile = '';
1570: }
1571: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1572: $showfile = $imgfile;
1.6 raeburn 1573: my $imgdir = $1;
1574: my $filename = $2;
1.159 raeburn 1575: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1576: $showfile = "/$imgdir/tn-".$filename;
1577: } else {
1.159 raeburn 1578: my $input = $londocroot.$imgfile;
1579: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1580: if (!-e $output) {
1.9 raeburn 1581: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1582: my ($fullwidth,$fullheight) = &check_dimensions($input);
1583: if ($fullwidth ne '' && $fullheight ne '') {
1584: if ($fullwidth > $width && $fullheight > $height) {
1585: my $size = $width.'x'.$height;
1.160.6.88 raeburn 1586: my @args = ('convert','-sample',$size,$input,$output);
1587: system({$args[0]} @args);
1.159 raeburn 1588: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1589: }
1590: }
1.6 raeburn 1591: }
1592: }
1.16 raeburn 1593: }
1.6 raeburn 1594: if ($showfile) {
1.40 raeburn 1595: if ($showfile =~ m{^/(adm|res)/}) {
1596: if ($showfile =~ m{^/res/}) {
1597: my $local_showfile =
1598: &Apache::lonnet::filelocation('',$showfile);
1599: &Apache::lonnet::repcopy($local_showfile);
1600: }
1601: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1602: }
1603: if ($imgfile) {
1604: if ($imgfile =~ m{^/(adm|res)/}) {
1605: if ($imgfile =~ m{^/res/}) {
1606: my $local_imgfile =
1607: &Apache::lonnet::filelocation('',$imgfile);
1608: &Apache::lonnet::repcopy($local_imgfile);
1609: }
1610: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1611: } else {
1612: $fullsize = $imgfile;
1613: }
1614: }
1.41 raeburn 1615: $datatable .= '<td>';
1616: if ($img eq 'login') {
1.135 bisitz 1617: $datatable .= $login_hdr_pick;
1618: }
1.41 raeburn 1619: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1620: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1621: } else {
1.160.6.22 raeburn 1622: $datatable .= '<td> </td><td class="LC_left_item">'.
1623: &mt('Upload:').'<br />';
1.6 raeburn 1624: }
1625: } else {
1.160.6.22 raeburn 1626: $datatable .= '<td> </td><td class="LC_left_item">'.
1627: &mt('Upload:').'<br />';
1.6 raeburn 1628: }
1.9 raeburn 1629: if ($switchserver) {
1630: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1631: } else {
1.135 bisitz 1632: if ($img ne 'login') { # suppress file selection for Log-in header
1633: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1634: }
1.9 raeburn 1635: }
1636: $datatable .= '</td></tr>';
1.6 raeburn 1637: }
1638: $itemcount ++;
1639: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1640: $datatable .= '<tr'.$css_class.'>'.
1641: '<td>'.$choices->{'bgs'}.'</td>';
1642: my $bgs_def;
1643: foreach my $item (@{$bgs}) {
1644: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1645: $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 1646: }
1647: }
1648: if ($bgs_def) {
1.8 raeburn 1649: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1650: } else {
1651: $datatable .= '<td> </td>';
1652: }
1653: $datatable .= '<td class="LC_right_item">'.
1654: '<table border="0"><tr>';
1.160.6.13 raeburn 1655:
1.6 raeburn 1656: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1657: $datatable .= '<td align="center">'.$choices->{$item};
1658: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1659: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1660: $datatable .= ' ';
1.6 raeburn 1661: }
1.160.6.9 raeburn 1662: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1663: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1664: }
1665: $datatable .= '</tr></table></td></tr>';
1666: $itemcount ++;
1667: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1668: $datatable .= '<tr'.$css_class.'>'.
1669: '<td>'.$choices->{'links'}.'</td>';
1670: my $links_def;
1671: foreach my $item (@{$links}) {
1672: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1673: $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 1674: }
1675: }
1676: if ($links_def) {
1.8 raeburn 1677: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1678: } else {
1679: $datatable .= '<td> </td>';
1680: }
1681: $datatable .= '<td class="LC_right_item">'.
1682: '<table border="0"><tr>';
1683: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1684: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1685: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1686: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1687: $datatable.=' ';
1.6 raeburn 1688: }
1.160.6.9 raeburn 1689: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1690: '" /></td>';
1691: }
1.30 raeburn 1692: $$rowtotal += $itemcount;
1.3 raeburn 1693: return $datatable;
1694: }
1695:
1.70 raeburn 1696: sub logo_display_options {
1697: my ($img,$defaults,$designs) = @_;
1698: my $checkedon;
1699: if (ref($defaults) eq 'HASH') {
1700: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1701: if ($defaults->{'showlogo'}{$img}) {
1702: $checkedon = 'checked="checked" ';
1703: }
1704: }
1705: }
1706: if (ref($designs) eq 'HASH') {
1707: if (ref($designs->{'showlogo'}) eq 'HASH') {
1708: if (defined($designs->{'showlogo'}{$img})) {
1709: if ($designs->{'showlogo'}{$img} == 0) {
1710: $checkedon = '';
1711: } elsif ($designs->{'showlogo'}{$img} == 1) {
1712: $checkedon = 'checked="checked" ';
1713: }
1714: }
1715: }
1716: }
1717: return '<br /><label> <input type="checkbox" name="'.
1718: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1719: &mt('show').'</label>'."\n";
1720: }
1721:
1.41 raeburn 1722: sub login_header_options {
1.135 bisitz 1723: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1724: my $output = '';
1.41 raeburn 1725: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1726: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1727: if (!$is_custom->{'textcol'}) {
1728: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1729: ' ';
1730: }
1731: if (!$is_custom->{'bgcol'}) {
1732: $output .= $choices->{'bgcol'}.': '.
1733: '<span id="css_'.$role.'_font" style="background-color: '.
1734: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1735: }
1736: $output .= '<br />';
1737: }
1738: $output .='<br />';
1739: return $output;
1740: }
1741:
1742: sub login_text_colors {
1.160.6.22 raeburn 1743: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1744: my $color_menu = '<table border="0"><tr>';
1745: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1746: $color_menu .= '<td align="center">'.$choices->{$item};
1747: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1748: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1749: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1750: }
1751: $color_menu .= '</tr></table><br />';
1752: return $color_menu;
1753: }
1754:
1755: sub image_changes {
1756: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1757: my $output;
1.135 bisitz 1758: if ($img eq 'login') {
1.160.6.87 raeburn 1759: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 1760: } elsif (!$is_custom) {
1.70 raeburn 1761: if ($img ne 'domlogo') {
1.160.6.87 raeburn 1762: $output = &mt('Default image:').'<br />';
1.41 raeburn 1763: } else {
1.160.6.87 raeburn 1764: $output = &mt('Default in use:').'<br />';
1.41 raeburn 1765: }
1766: }
1.160.6.87 raeburn 1767: if ($img ne 'login') {
1.135 bisitz 1768: if ($img_import) {
1769: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1770: }
1771: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1772: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1773: if ($is_custom) {
1774: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1775: '<input type="checkbox" name="'.
1776: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1777: '</label> '.&mt('Replace:').'</span><br />';
1778: } else {
1.160.6.22 raeburn 1779: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1780: }
1.41 raeburn 1781: }
1782: return $output;
1783: }
1784:
1.3 raeburn 1785: sub print_quotas {
1.86 raeburn 1786: my ($dom,$settings,$rowtotal,$action) = @_;
1787: my $context;
1788: if ($action eq 'quotas') {
1789: $context = 'tools';
1790: } else {
1791: $context = $action;
1792: }
1.160.6.20 raeburn 1793: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1794: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1795: my $typecount = 0;
1.101 raeburn 1796: my ($css_class,%titles);
1.86 raeburn 1797: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1798: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1799: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1800: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1801: %titles = &courserequest_titles();
1.160.6.5 raeburn 1802: } elsif ($context eq 'requestauthor') {
1803: @usertools = ('author');
1804: @options = ('norequest','approval','automatic');
1805: %titles = &authorrequest_titles();
1.86 raeburn 1806: } else {
1.160.6.4 raeburn 1807: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1808: %titles = &tool_titles();
1.86 raeburn 1809: }
1.26 raeburn 1810: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1811: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1812: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1813: unless (($context eq 'requestcourses') ||
1814: ($context eq 'requestauthor')) {
1.86 raeburn 1815: if (ref($settings) eq 'HASH') {
1816: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1817: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1818: } else {
1819: $currdefquota = $settings->{$type};
1820: }
1.160.6.20 raeburn 1821: if (ref($settings->{authorquota}) eq 'HASH') {
1822: $currauthorquota = $settings->{authorquota}->{$type};
1823: }
1.78 raeburn 1824: }
1.72 raeburn 1825: }
1.3 raeburn 1826: if (defined($usertypes->{$type})) {
1827: $typecount ++;
1828: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1829: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1830: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1831: '<td class="LC_left_item">';
1.101 raeburn 1832: if ($context eq 'requestcourses') {
1833: $datatable .= '<table><tr>';
1834: }
1835: my %cell;
1.72 raeburn 1836: foreach my $item (@usertools) {
1.101 raeburn 1837: if ($context eq 'requestcourses') {
1838: my ($curroption,$currlimit);
1839: if (ref($settings) eq 'HASH') {
1840: if (ref($settings->{$item}) eq 'HASH') {
1841: $curroption = $settings->{$item}->{$type};
1842: if ($curroption =~ /^autolimit=(\d*)$/) {
1843: $currlimit = $1;
1844: }
1845: }
1846: }
1847: if (!$curroption) {
1848: $curroption = 'norequest';
1849: }
1850: $datatable .= '<th>'.$titles{$item}.'</th>';
1851: foreach my $option (@options) {
1852: my $val = $option;
1853: if ($option eq 'norequest') {
1854: $val = 0;
1855: }
1856: if ($option eq 'validate') {
1857: my $canvalidate = 0;
1858: if (ref($validations{$item}) eq 'HASH') {
1859: if ($validations{$item}{$type}) {
1860: $canvalidate = 1;
1861: }
1862: }
1863: next if (!$canvalidate);
1864: }
1865: my $checked = '';
1866: if ($option eq $curroption) {
1867: $checked = ' checked="checked"';
1868: } elsif ($option eq 'autolimit') {
1869: if ($curroption =~ /^autolimit/) {
1870: $checked = ' checked="checked"';
1871: }
1872: }
1873: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1874: '<input type="radio" name="crsreq_'.$item.
1875: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1876: $titles{$option}.'</label>';
1.101 raeburn 1877: if ($option eq 'autolimit') {
1.127 raeburn 1878: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1879: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1880: 'value="'.$currlimit.'" />';
1.101 raeburn 1881: }
1.127 raeburn 1882: $cell{$item} .= '</span> ';
1.103 raeburn 1883: if ($option eq 'autolimit') {
1.127 raeburn 1884: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1885: }
1.101 raeburn 1886: }
1.160.6.5 raeburn 1887: } elsif ($context eq 'requestauthor') {
1888: my $curroption;
1889: if (ref($settings) eq 'HASH') {
1890: $curroption = $settings->{$type};
1891: }
1892: if (!$curroption) {
1893: $curroption = 'norequest';
1894: }
1895: foreach my $option (@options) {
1896: my $val = $option;
1897: if ($option eq 'norequest') {
1898: $val = 0;
1899: }
1900: my $checked = '';
1901: if ($option eq $curroption) {
1902: $checked = ' checked="checked"';
1903: }
1904: $datatable .= '<span class="LC_nobreak"><label>'.
1905: '<input type="radio" name="authorreq_'.$type.
1906: '" value="'.$val.'"'.$checked.' />'.
1907: $titles{$option}.'</label></span> ';
1908: }
1.101 raeburn 1909: } else {
1910: my $checked = 'checked="checked" ';
1911: if (ref($settings) eq 'HASH') {
1912: if (ref($settings->{$item}) eq 'HASH') {
1913: if ($settings->{$item}->{$type} == 0) {
1914: $checked = '';
1915: } elsif ($settings->{$item}->{$type} == 1) {
1916: $checked = 'checked="checked" ';
1917: }
1.78 raeburn 1918: }
1.72 raeburn 1919: }
1.101 raeburn 1920: $datatable .= '<span class="LC_nobreak"><label>'.
1921: '<input type="checkbox" name="'.$context.'_'.$item.
1922: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1923: '</label></span> ';
1.72 raeburn 1924: }
1.101 raeburn 1925: }
1926: if ($context eq 'requestcourses') {
1927: $datatable .= '</tr><tr>';
1928: foreach my $item (@usertools) {
1.106 raeburn 1929: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1930: }
1931: $datatable .= '</tr></table>';
1.72 raeburn 1932: }
1.86 raeburn 1933: $datatable .= '</td>';
1.160.6.5 raeburn 1934: unless (($context eq 'requestcourses') ||
1935: ($context eq 'requestauthor')) {
1.86 raeburn 1936: $datatable .=
1.160.6.20 raeburn 1937: '<td class="LC_right_item">'.
1938: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1939: '<input type="text" name="quota_'.$type.
1.72 raeburn 1940: '" value="'.$currdefquota.
1.160.6.20 raeburn 1941: '" size="5" /></span>'.(' ' x 2).
1942: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1943: '<input type="text" name="authorquota_'.$type.
1944: '" value="'.$currauthorquota.
1945: '" size="5" /></span></td>';
1.86 raeburn 1946: }
1947: $datatable .= '</tr>';
1.3 raeburn 1948: }
1949: }
1950: }
1.160.6.5 raeburn 1951: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1952: $defaultquota = '20';
1.160.6.20 raeburn 1953: $authorquota = '500';
1.86 raeburn 1954: if (ref($settings) eq 'HASH') {
1955: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1956: $defaultquota = $settings->{'defaultquota'}->{'default'};
1957: } elsif (defined($settings->{'default'})) {
1958: $defaultquota = $settings->{'default'};
1959: }
1.160.6.20 raeburn 1960: if (ref($settings->{'authorquota'}) eq 'HASH') {
1961: $authorquota = $settings->{'authorquota'}->{'default'};
1962: }
1.3 raeburn 1963: }
1964: }
1965: $typecount ++;
1966: $css_class = $typecount%2?' class="LC_odd_row"':'';
1967: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1968: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1969: '<td class="LC_left_item">';
1.101 raeburn 1970: if ($context eq 'requestcourses') {
1971: $datatable .= '<table><tr>';
1972: }
1973: my %defcell;
1.72 raeburn 1974: foreach my $item (@usertools) {
1.101 raeburn 1975: if ($context eq 'requestcourses') {
1976: my ($curroption,$currlimit);
1977: if (ref($settings) eq 'HASH') {
1978: if (ref($settings->{$item}) eq 'HASH') {
1979: $curroption = $settings->{$item}->{'default'};
1980: if ($curroption =~ /^autolimit=(\d*)$/) {
1981: $currlimit = $1;
1982: }
1983: }
1984: }
1985: if (!$curroption) {
1986: $curroption = 'norequest';
1987: }
1988: $datatable .= '<th>'.$titles{$item}.'</th>';
1989: foreach my $option (@options) {
1990: my $val = $option;
1991: if ($option eq 'norequest') {
1992: $val = 0;
1993: }
1994: if ($option eq 'validate') {
1995: my $canvalidate = 0;
1996: if (ref($validations{$item}) eq 'HASH') {
1997: if ($validations{$item}{'default'}) {
1998: $canvalidate = 1;
1999: }
2000: }
2001: next if (!$canvalidate);
2002: }
2003: my $checked = '';
2004: if ($option eq $curroption) {
2005: $checked = ' checked="checked"';
2006: } elsif ($option eq 'autolimit') {
2007: if ($curroption =~ /^autolimit/) {
2008: $checked = ' checked="checked"';
2009: }
2010: }
2011: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2012: '<input type="radio" name="crsreq_'.$item.
2013: '_default" value="'.$val.'"'.$checked.' />'.
2014: $titles{$option}.'</label>';
2015: if ($option eq 'autolimit') {
1.127 raeburn 2016: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2017: $item.'_limit_default" size="1" '.
2018: 'value="'.$currlimit.'" />';
2019: }
1.127 raeburn 2020: $defcell{$item} .= '</span> ';
1.104 raeburn 2021: if ($option eq 'autolimit') {
1.127 raeburn 2022: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2023: }
1.101 raeburn 2024: }
1.160.6.5 raeburn 2025: } elsif ($context eq 'requestauthor') {
2026: my $curroption;
2027: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 2028: $curroption = $settings->{'default'};
1.160.6.5 raeburn 2029: }
2030: if (!$curroption) {
2031: $curroption = 'norequest';
2032: }
2033: foreach my $option (@options) {
2034: my $val = $option;
2035: if ($option eq 'norequest') {
2036: $val = 0;
2037: }
2038: my $checked = '';
2039: if ($option eq $curroption) {
2040: $checked = ' checked="checked"';
2041: }
2042: $datatable .= '<span class="LC_nobreak"><label>'.
2043: '<input type="radio" name="authorreq_default"'.
2044: ' value="'.$val.'"'.$checked.' />'.
2045: $titles{$option}.'</label></span> ';
2046: }
1.101 raeburn 2047: } else {
2048: my $checked = 'checked="checked" ';
2049: if (ref($settings) eq 'HASH') {
2050: if (ref($settings->{$item}) eq 'HASH') {
2051: if ($settings->{$item}->{'default'} == 0) {
2052: $checked = '';
2053: } elsif ($settings->{$item}->{'default'} == 1) {
2054: $checked = 'checked="checked" ';
2055: }
1.78 raeburn 2056: }
1.72 raeburn 2057: }
1.101 raeburn 2058: $datatable .= '<span class="LC_nobreak"><label>'.
2059: '<input type="checkbox" name="'.$context.'_'.$item.
2060: '" value="default" '.$checked.'/>'.$titles{$item}.
2061: '</label></span> ';
2062: }
2063: }
2064: if ($context eq 'requestcourses') {
2065: $datatable .= '</tr><tr>';
2066: foreach my $item (@usertools) {
1.106 raeburn 2067: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2068: }
1.101 raeburn 2069: $datatable .= '</tr></table>';
1.72 raeburn 2070: }
1.86 raeburn 2071: $datatable .= '</td>';
1.160.6.5 raeburn 2072: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2073: $datatable .= '<td class="LC_right_item">'.
2074: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2075: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2076: $defaultquota.'" size="5" /></span>'.(' ' x2).
2077: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2078: '<input type="text" name="authorquota" value="'.
2079: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2080: }
2081: $datatable .= '</tr>';
1.72 raeburn 2082: $typecount ++;
2083: $css_class = $typecount%2?' class="LC_odd_row"':'';
2084: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2085: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2086: if ($context eq 'requestcourses') {
1.109 raeburn 2087: $datatable .= &mt('(overrides affiliation, if set)').
2088: '</td>'.
2089: '<td class="LC_left_item">'.
2090: '<table><tr>';
1.101 raeburn 2091: } else {
1.109 raeburn 2092: $datatable .= &mt('(overrides affiliation, if checked)').
2093: '</td>'.
2094: '<td class="LC_left_item" colspan="2">'.
2095: '<br />';
1.101 raeburn 2096: }
2097: my %advcell;
1.72 raeburn 2098: foreach my $item (@usertools) {
1.101 raeburn 2099: if ($context eq 'requestcourses') {
2100: my ($curroption,$currlimit);
2101: if (ref($settings) eq 'HASH') {
2102: if (ref($settings->{$item}) eq 'HASH') {
2103: $curroption = $settings->{$item}->{'_LC_adv'};
2104: if ($curroption =~ /^autolimit=(\d*)$/) {
2105: $currlimit = $1;
2106: }
2107: }
2108: }
2109: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2110: my $checked = '';
2111: if ($curroption eq '') {
2112: $checked = ' checked="checked"';
2113: }
2114: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2115: '<input type="radio" name="crsreq_'.$item.
2116: '__LC_adv" value=""'.$checked.' />'.
2117: &mt('No override set').'</label></span> ';
1.101 raeburn 2118: foreach my $option (@options) {
2119: my $val = $option;
2120: if ($option eq 'norequest') {
2121: $val = 0;
2122: }
2123: if ($option eq 'validate') {
2124: my $canvalidate = 0;
2125: if (ref($validations{$item}) eq 'HASH') {
2126: if ($validations{$item}{'_LC_adv'}) {
2127: $canvalidate = 1;
2128: }
2129: }
2130: next if (!$canvalidate);
2131: }
2132: my $checked = '';
1.104 raeburn 2133: if ($val eq $curroption) {
1.101 raeburn 2134: $checked = ' checked="checked"';
2135: } elsif ($option eq 'autolimit') {
2136: if ($curroption =~ /^autolimit/) {
2137: $checked = ' checked="checked"';
2138: }
2139: }
2140: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2141: '<input type="radio" name="crsreq_'.$item.
2142: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2143: $titles{$option}.'</label>';
2144: if ($option eq 'autolimit') {
1.127 raeburn 2145: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2146: $item.'_limit__LC_adv" size="1" '.
2147: 'value="'.$currlimit.'" />';
2148: }
1.127 raeburn 2149: $advcell{$item} .= '</span> ';
1.104 raeburn 2150: if ($option eq 'autolimit') {
1.127 raeburn 2151: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2152: }
1.101 raeburn 2153: }
1.160.6.5 raeburn 2154: } elsif ($context eq 'requestauthor') {
2155: my $curroption;
2156: if (ref($settings) eq 'HASH') {
2157: $curroption = $settings->{'_LC_adv'};
2158: }
2159: my $checked = '';
2160: if ($curroption eq '') {
2161: $checked = ' checked="checked"';
2162: }
2163: $datatable .= '<span class="LC_nobreak"><label>'.
2164: '<input type="radio" name="authorreq__LC_adv"'.
2165: ' value=""'.$checked.' />'.
2166: &mt('No override set').'</label></span> ';
2167: foreach my $option (@options) {
2168: my $val = $option;
2169: if ($option eq 'norequest') {
2170: $val = 0;
2171: }
2172: my $checked = '';
2173: if ($val eq $curroption) {
2174: $checked = ' checked="checked"';
2175: }
2176: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2177: '<input type="radio" name="authorreq__LC_adv"'.
2178: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2179: $titles{$option}.'</label></span> ';
2180: }
1.101 raeburn 2181: } else {
2182: my $checked = 'checked="checked" ';
2183: if (ref($settings) eq 'HASH') {
2184: if (ref($settings->{$item}) eq 'HASH') {
2185: if ($settings->{$item}->{'_LC_adv'} == 0) {
2186: $checked = '';
2187: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2188: $checked = 'checked="checked" ';
2189: }
1.79 raeburn 2190: }
1.72 raeburn 2191: }
1.101 raeburn 2192: $datatable .= '<span class="LC_nobreak"><label>'.
2193: '<input type="checkbox" name="'.$context.'_'.$item.
2194: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2195: '</label></span> ';
2196: }
2197: }
2198: if ($context eq 'requestcourses') {
2199: $datatable .= '</tr><tr>';
2200: foreach my $item (@usertools) {
1.106 raeburn 2201: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2202: }
1.101 raeburn 2203: $datatable .= '</tr></table>';
1.72 raeburn 2204: }
1.98 raeburn 2205: $datatable .= '</td></tr>';
1.30 raeburn 2206: $$rowtotal += $typecount;
1.3 raeburn 2207: return $datatable;
2208: }
2209:
1.160.6.5 raeburn 2210: sub print_requestmail {
1.160.6.93 raeburn 2211: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25 raeburn 2212: my ($now,$datatable,%currapp);
1.102 raeburn 2213: $now = time;
2214: if (ref($settings) eq 'HASH') {
2215: if (ref($settings->{'notify'}) eq 'HASH') {
2216: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2217: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2218: }
2219: }
2220: }
1.160.6.16 raeburn 2221: my $numinrow = 2;
1.160.6.34 raeburn 2222: my $css_class;
1.160.6.93 raeburn 2223: if ($$rowtotal%2) {
2224: $css_class = 'LC_odd_row';
2225: }
2226: if ($customcss) {
2227: $css_class .= " $customcss";
2228: }
2229: $css_class =~ s/^\s+//;
2230: if ($css_class) {
2231: $css_class = ' class="'.$css_class.'"';
2232: }
2233: if ($rowstyle) {
2234: $css_class .= ' style="'.$rowstyle.'"';
2235: }
1.160.6.5 raeburn 2236: my $text;
2237: if ($action eq 'requestcourses') {
2238: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2239: } elsif ($action eq 'requestauthor') {
2240: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2241: } else {
1.160.6.34 raeburn 2242: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2243: }
1.160.6.34 raeburn 2244: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2245: ' <td>'.$text.'</td>'.
1.102 raeburn 2246: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2247: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2248: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2249: if ($numdc > 0) {
2250: $datatable .= $table;
1.102 raeburn 2251: } else {
2252: $datatable .= &mt('There are no active Domain Coordinators');
2253: }
2254: $datatable .='</td></tr>';
2255: return $datatable;
2256: }
2257:
1.160.6.30 raeburn 2258: sub print_studentcode {
2259: my ($settings,$rowtotal) = @_;
2260: my $rownum = 0;
2261: my ($output,%current);
2262: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2263: if (ref($settings) eq 'HASH') {
2264: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2265: foreach my $type (@crstypes) {
2266: $current{$type} = $settings->{'uniquecode'}{$type};
2267: }
1.160.6.30 raeburn 2268: }
2269: }
2270: $output .= '<tr>'.
2271: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2272: '<td class="LC_left_item">';
2273: foreach my $type (@crstypes) {
2274: my $check = ' ';
2275: if ($current{$type}) {
2276: $check = ' checked="checked" ';
2277: }
2278: $output .= '<span class="LC_nobreak"><label>'.
2279: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2280: &mt($type).'</label></span>'.(' 'x2).' ';
2281: }
2282: $output .= '</td></tr>';
2283: $$rowtotal ++;
2284: return $output;
2285: }
2286:
2287: sub print_textbookcourses {
1.160.6.46 raeburn 2288: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2289: my $rownum = 0;
2290: my $css_class;
2291: my $itemcount = 1;
2292: my $maxnum = 0;
2293: my $bookshash;
2294: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2295: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2296: }
2297: my %ordered;
2298: if (ref($bookshash) eq 'HASH') {
2299: foreach my $item (keys(%{$bookshash})) {
2300: if (ref($bookshash->{$item}) eq 'HASH') {
2301: my $num = $bookshash->{$item}{'order'};
2302: $ordered{$num} = $item;
2303: }
2304: }
2305: }
2306: my $confname = $dom.'-domainconfig';
2307: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2308: my $maxnum = scalar(keys(%ordered));
2309: my $datatable;
1.160.6.30 raeburn 2310: if (keys(%ordered)) {
2311: my @items = sort { $a <=> $b } keys(%ordered);
2312: for (my $i=0; $i<@items; $i++) {
2313: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2314: my $key = $ordered{$items[$i]};
2315: my %coursehash=&Apache::lonnet::coursedescription($key);
2316: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2317: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2318: if (ref($bookshash->{$key}) eq 'HASH') {
2319: $subject = $bookshash->{$key}->{'subject'};
2320: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2321: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2322: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2323: $author = $bookshash->{$key}->{'author'};
2324: $image = $bookshash->{$key}->{'image'};
2325: if ($image ne '') {
2326: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2327: my $imagethumb = "$path/tn-".$imagefile;
2328: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2329: }
1.160.6.30 raeburn 2330: }
2331: }
1.160.6.46 raeburn 2332: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2333: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2334: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2335: for (my $k=0; $k<=$maxnum; $k++) {
2336: my $vpos = $k+1;
2337: my $selstr;
2338: if ($k == $i) {
2339: $selstr = ' selected="selected" ';
2340: }
2341: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2342: }
2343: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2344: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2345: &mt('Delete?').'</label></span></td>'.
2346: '<td colspan="2">'.
1.160.6.46 raeburn 2347: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2348: (' 'x2).
1.160.6.46 raeburn 2349: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2350: if ($type eq 'textbooks') {
2351: $datatable .= (' 'x2).
1.160.6.47 raeburn 2352: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2353: (' 'x2).
1.160.6.46 raeburn 2354: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2355: (' 'x2).
2356: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2357: if ($image) {
2358: $datatable .= '<span class="LC_nobreak">'.
2359: $imgsrc.
2360: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2361: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2362: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2363: }
2364: if ($switchserver) {
2365: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2366: } else {
2367: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2368: }
1.160.6.30 raeburn 2369: }
1.160.6.46 raeburn 2370: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2371: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2372: $coursetitle.'</span></td></tr>'."\n";
2373: $itemcount ++;
2374: }
2375: }
2376: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2377: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2378: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2379: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2380: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2381: for (my $k=0; $k<$maxnum+1; $k++) {
2382: my $vpos = $k+1;
2383: my $selstr;
2384: if ($k == $maxnum) {
2385: $selstr = ' selected="selected" ';
2386: }
2387: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2388: }
2389: $datatable .= '</select> '."\n".
1.160.6.87 raeburn 2390: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2391: '<td colspan="2">'.
1.160.6.46 raeburn 2392: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2393: (' 'x2).
1.160.6.46 raeburn 2394: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2395: (' 'x2);
2396: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2397: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2398: (' 'x2).
2399: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2400: (' 'x2).
2401: '<span class="LC_nobreak">'.&mt('Image:').' ';
2402: if ($switchserver) {
2403: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2404: } else {
2405: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2406: }
1.160.6.87 raeburn 2407: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2408: }
1.160.6.87 raeburn 2409: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2410: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2411: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2412: &Apache::loncommon::selectcourse_link
1.160.6.87 raeburn 2413: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2414: '</span></td>'."\n".
2415: '</tr>'."\n";
2416: $itemcount ++;
2417: return $datatable;
2418: }
2419:
2420: sub textbookcourses_javascript {
1.160.6.46 raeburn 2421: my ($settings) = @_;
2422: return unless(ref($settings) eq 'HASH');
2423: my (%ordered,%total,%jstext);
2424: foreach my $type ('textbooks','templates') {
2425: $total{$type} = 0;
2426: if (ref($settings->{$type}) eq 'HASH') {
2427: foreach my $item (keys(%{$settings->{$type}})) {
2428: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2429: my $num = $settings->{$type}->{$item}{'order'};
2430: $ordered{$type}{$num} = $item;
2431: }
2432: }
2433: $total{$type} = scalar(keys(%{$settings->{$type}}));
2434: }
2435: my @jsarray = ();
2436: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2437: push(@jsarray,$ordered{$type}{$item});
2438: }
2439: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2440: }
2441: return <<"ENDSCRIPT";
2442: <script type="text/javascript">
2443: // <![CDATA[
1.160.6.46 raeburn 2444: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2445: var changedVal;
1.160.6.46 raeburn 2446: $jstext{'textbooks'};
2447: $jstext{'templates'};
2448: var newpos;
2449: var maxh;
2450: if (caller == 'textbooks') {
2451: newpos = 'textbooks_addbook_pos';
2452: maxh = 1 + $total{'textbooks'};
2453: } else {
2454: newpos = 'templates_addbook_pos';
2455: maxh = 1 + $total{'templates'};
2456: }
1.160.6.30 raeburn 2457: var current = new Array;
2458: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2459: if (item == newpos) {
2460: changedVal = newitemVal;
2461: } else {
2462: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2463: current[newitemVal] = newpos;
2464: }
1.160.6.46 raeburn 2465: if (caller == 'textbooks') {
2466: for (var i=0; i<textbooks.length; i++) {
2467: var elementName = 'textbooks_'+textbooks[i];
2468: if (elementName != item) {
2469: if (form.elements[elementName]) {
2470: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2471: current[currVal] = elementName;
2472: }
2473: }
2474: }
2475: }
2476: if (caller == 'templates') {
2477: for (var i=0; i<templates.length; i++) {
2478: var elementName = 'templates_'+templates[i];
2479: if (elementName != item) {
2480: if (form.elements[elementName]) {
2481: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2482: current[currVal] = elementName;
2483: }
1.160.6.30 raeburn 2484: }
2485: }
2486: }
2487: var oldVal;
2488: for (var j=0; j<maxh; j++) {
2489: if (current[j] == undefined) {
2490: oldVal = j;
2491: }
2492: }
2493: if (oldVal < changedVal) {
2494: for (var k=oldVal+1; k<=changedVal ; k++) {
2495: var elementName = current[k];
2496: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2497: }
2498: } else {
2499: for (var k=changedVal; k<oldVal; k++) {
2500: var elementName = current[k];
2501: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2502: }
2503: }
2504: return;
2505: }
2506:
2507: // ]]>
2508: </script>
2509:
2510: ENDSCRIPT
2511: }
2512:
1.3 raeburn 2513: sub print_autoenroll {
1.30 raeburn 2514: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2515: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68 raeburn 2516: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2517: if (ref($settings) eq 'HASH') {
2518: if (exists($settings->{'run'})) {
2519: if ($settings->{'run'} eq '0') {
2520: $runoff = ' checked="checked" ';
2521: $runon = ' ';
2522: } else {
2523: $runon = ' checked="checked" ';
2524: $runoff = ' ';
2525: }
2526: } else {
2527: if ($autorun) {
2528: $runon = ' checked="checked" ';
2529: $runoff = ' ';
2530: } else {
2531: $runoff = ' checked="checked" ';
2532: $runon = ' ';
2533: }
2534: }
1.129 raeburn 2535: if (exists($settings->{'co-owners'})) {
2536: if ($settings->{'co-owners'} eq '0') {
2537: $coownersoff = ' checked="checked" ';
2538: $coownerson = ' ';
2539: } else {
2540: $coownerson = ' checked="checked" ';
2541: $coownersoff = ' ';
2542: }
2543: } else {
2544: $coownersoff = ' checked="checked" ';
2545: $coownerson = ' ';
2546: }
1.3 raeburn 2547: if (exists($settings->{'sender_domain'})) {
2548: $defdom = $settings->{'sender_domain'};
2549: }
1.160.6.68 raeburn 2550: if (exists($settings->{'autofailsafe'})) {
2551: $failsafe = $settings->{'autofailsafe'};
2552: }
1.14 raeburn 2553: } else {
2554: if ($autorun) {
2555: $runon = ' checked="checked" ';
2556: $runoff = ' ';
2557: } else {
2558: $runoff = ' checked="checked" ';
2559: $runon = ' ';
2560: }
1.3 raeburn 2561: }
2562: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2563: my $notif_sender;
2564: if (ref($settings) eq 'HASH') {
2565: $notif_sender = $settings->{'sender_uname'};
2566: }
1.3 raeburn 2567: my $datatable='<tr class="LC_odd_row">'.
2568: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2569: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2570: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2571: $runon.' value="1" />'.&mt('Yes').'</label> '.
2572: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2573: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2574: '</tr><tr>'.
2575: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2576: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2577: &mt('username').': '.
2578: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2579: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2580: ': '.$domform.'</span></td></tr>'.
2581: '<tr class="LC_odd_row">'.
2582: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2583: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2584: '<input type="radio" name="autoassign_coowners"'.
2585: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2586: '<label><input type="radio" name="autoassign_coowners"'.
2587: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 2588: '</tr><tr>'.
2589: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2590: '<td class="LC_right_item"><span class="LC_nobreak">'.
2591: '<input type="text" name="autoenroll_failsafe"'.
1.160.6.87 raeburn 2592: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.160.6.68 raeburn 2593: $$rowtotal += 4;
1.3 raeburn 2594: return $datatable;
2595: }
2596:
2597: sub print_autoupdate {
1.30 raeburn 2598: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2599: my $datatable;
2600: if ($position eq 'top') {
2601: my $updateon = ' ';
2602: my $updateoff = ' checked="checked" ';
2603: my $classlistson = ' ';
2604: my $classlistsoff = ' checked="checked" ';
2605: if (ref($settings) eq 'HASH') {
2606: if ($settings->{'run'} eq '1') {
2607: $updateon = $updateoff;
2608: $updateoff = ' ';
2609: }
2610: if ($settings->{'classlists'} eq '1') {
2611: $classlistson = $classlistsoff;
2612: $classlistsoff = ' ';
2613: }
2614: }
2615: my %title = (
2616: run => 'Auto-update active?',
2617: classlists => 'Update information in classlists?',
2618: );
2619: $datatable = '<tr class="LC_odd_row">'.
2620: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2621: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2622: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2623: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2624: '<label><input type="radio" name="autoupdate_run"'.
2625: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2626: '</tr><tr>'.
2627: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2628: '<td class="LC_right_item"><span class="LC_nobreak">'.
2629: '<label><input type="radio" name="classlists"'.
2630: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2631: '<label><input type="radio" name="classlists"'.
2632: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2633: '</tr>';
1.30 raeburn 2634: $$rowtotal += 2;
1.131 raeburn 2635: } elsif ($position eq 'middle') {
2636: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2637: my $numinrow = 3;
2638: my $locknamesettings;
2639: $datatable .= &insttypes_row($settings,$types,$usertypes,
2640: $dom,$numinrow,$othertitle,
1.160.6.93 raeburn 2641: 'lockablenames',$rowtotal);
1.131 raeburn 2642: $$rowtotal ++;
1.3 raeburn 2643: } else {
1.44 raeburn 2644: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2645: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2646: 'permanentemail','id');
1.33 raeburn 2647: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2648: my $numrows = 0;
1.26 raeburn 2649: if (ref($types) eq 'ARRAY') {
2650: if (@{$types} > 0) {
2651: $datatable =
2652: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2653: \@fields,$types,\$numrows);
1.30 raeburn 2654: $$rowtotal += @{$types};
1.26 raeburn 2655: }
1.3 raeburn 2656: }
2657: $datatable .=
2658: &usertype_update_row($settings,{'default' => $othertitle},
2659: \%fieldtitles,\@fields,['default'],
2660: \$numrows);
1.30 raeburn 2661: $$rowtotal ++;
1.3 raeburn 2662: }
2663: return $datatable;
2664: }
2665:
1.125 raeburn 2666: sub print_autocreate {
2667: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2668: my (%createon,%createoff,%currhash);
1.125 raeburn 2669: my @types = ('xml','req');
2670: if (ref($settings) eq 'HASH') {
2671: foreach my $item (@types) {
2672: $createoff{$item} = ' checked="checked" ';
2673: $createon{$item} = ' ';
2674: if (exists($settings->{$item})) {
2675: if ($settings->{$item}) {
2676: $createon{$item} = ' checked="checked" ';
2677: $createoff{$item} = ' ';
2678: }
2679: }
2680: }
1.160.6.16 raeburn 2681: if ($settings->{'xmldc'} ne '') {
2682: $currhash{$settings->{'xmldc'}} = 1;
2683: }
1.125 raeburn 2684: } else {
2685: foreach my $item (@types) {
2686: $createoff{$item} = ' checked="checked" ';
2687: $createon{$item} = ' ';
2688: }
2689: }
2690: $$rowtotal += 2;
1.160.6.16 raeburn 2691: my $numinrow = 2;
1.125 raeburn 2692: my $datatable='<tr class="LC_odd_row">'.
2693: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2694: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2695: '<input type="radio" name="autocreate_xml"'.
2696: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2697: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2698: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2699: '</td></tr><tr>'.
2700: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2701: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2702: '<input type="radio" name="autocreate_req"'.
2703: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2704: '<label><input type="radio" name="autocreate_req"'.
2705: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2706: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2707: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 2708: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2709: if ($numdc > 1) {
1.160.6.50 raeburn 2710: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2711: '</td><td class="LC_left_item">';
1.125 raeburn 2712: } else {
1.160.6.50 raeburn 2713: $datatable .= &mt('Course creation processed as:').
2714: '</td><td class="LC_right_item">';
1.125 raeburn 2715: }
1.160.6.50 raeburn 2716: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2717: $$rowtotal += $rows;
1.125 raeburn 2718: return $datatable;
2719: }
2720:
1.23 raeburn 2721: sub print_directorysrch {
1.160.6.72 raeburn 2722: my ($position,$dom,$settings,$rowtotal) = @_;
2723: my $datatable;
2724: if ($position eq 'top') {
2725: my $instsrchon = ' ';
2726: my $instsrchoff = ' checked="checked" ';
2727: my ($exacton,$containson,$beginson);
2728: my $instlocalon = ' ';
2729: my $instlocaloff = ' checked="checked" ';
2730: if (ref($settings) eq 'HASH') {
2731: if ($settings->{'available'} eq '1') {
2732: $instsrchon = $instsrchoff;
2733: $instsrchoff = ' ';
2734: }
2735: if ($settings->{'localonly'} eq '1') {
2736: $instlocalon = $instlocaloff;
2737: $instlocaloff = ' ';
2738: }
2739: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2740: foreach my $type (@{$settings->{'searchtypes'}}) {
2741: if ($type eq 'exact') {
2742: $exacton = ' checked="checked" ';
2743: } elsif ($type eq 'contains') {
2744: $containson = ' checked="checked" ';
2745: } elsif ($type eq 'begins') {
2746: $beginson = ' checked="checked" ';
2747: }
2748: }
2749: } else {
2750: if ($settings->{'searchtypes'} eq 'exact') {
2751: $exacton = ' checked="checked" ';
2752: } elsif ($settings->{'searchtypes'} eq 'contains') {
2753: $containson = ' checked="checked" ';
2754: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2755: $exacton = ' checked="checked" ';
2756: $containson = ' checked="checked" ';
2757: }
2758: }
1.23 raeburn 2759: }
1.160.6.72 raeburn 2760: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2761: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2762:
1.160.6.72 raeburn 2763: my $numinrow = 4;
2764: my $cansrchrow = 0;
2765: $datatable='<tr class="LC_odd_row">'.
2766: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2767: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2768: '<input type="radio" name="dirsrch_available"'.
2769: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2770: '<label><input type="radio" name="dirsrch_available"'.
2771: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2772: '</tr><tr>'.
2773: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2774: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2775: '<input type="radio" name="dirsrch_instlocalonly"'.
2776: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2777: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2778: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2779: '</tr>';
2780: $$rowtotal += 2;
2781: if (ref($usertypes) eq 'HASH') {
2782: if (keys(%{$usertypes}) > 0) {
2783: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93 raeburn 2784: $numinrow,$othertitle,'cansearch',
2785: $rowtotal);
1.160.6.72 raeburn 2786: $cansrchrow = 1;
2787: }
1.26 raeburn 2788: }
1.160.6.72 raeburn 2789: if ($cansrchrow) {
2790: $$rowtotal ++;
2791: $datatable .= '<tr>';
2792: } else {
2793: $datatable .= '<tr class="LC_odd_row">';
2794: }
2795: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2796: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2797: foreach my $title (@{$titleorder}) {
2798: if (defined($searchtitles->{$title})) {
2799: my $check = ' ';
2800: if (ref($settings) eq 'HASH') {
2801: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2802: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2803: $check = ' checked="checked" ';
2804: }
1.39 raeburn 2805: }
1.25 raeburn 2806: }
1.160.6.72 raeburn 2807: $datatable .= '<td class="LC_left_item">'.
2808: '<span class="LC_nobreak"><label>'.
2809: '<input type="checkbox" name="searchby" '.
2810: 'value="'.$title.'"'.$check.'/>'.
2811: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2812: }
2813: }
1.160.6.72 raeburn 2814: $datatable .= '</tr></table></td></tr>';
2815: $$rowtotal ++;
2816: if ($cansrchrow) {
2817: $datatable .= '<tr class="LC_odd_row">';
2818: } else {
2819: $datatable .= '<tr>';
2820: }
2821: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2822: '<td class="LC_left_item" colspan="2">'.
2823: '<span class="LC_nobreak"><label>'.
2824: '<input type="checkbox" name="searchtypes" '.
2825: $exacton.' value="exact" />'.&mt('Exact match').
2826: '</label> '.
2827: '<label><input type="checkbox" name="searchtypes" '.
2828: $beginson.' value="begins" />'.&mt('Begins with').
2829: '</label> '.
2830: '<label><input type="checkbox" name="searchtypes" '.
2831: $containson.' value="contains" />'.&mt('Contains').
2832: '</label></span></td></tr>';
2833: $$rowtotal ++;
1.26 raeburn 2834: } else {
1.160.6.72 raeburn 2835: my $domsrchon = ' checked="checked" ';
2836: my $domsrchoff = ' ';
2837: my $domlocalon = ' ';
2838: my $domlocaloff = ' checked="checked" ';
2839: if (ref($settings) eq 'HASH') {
2840: if ($settings->{'lclocalonly'} eq '1') {
2841: $domlocalon = $domlocaloff;
2842: $domlocaloff = ' ';
2843: }
2844: if ($settings->{'lcavailable'} eq '0') {
2845: $domsrchoff = $domsrchon;
2846: $domsrchon = ' ';
2847: }
2848: }
2849: $datatable='<tr class="LC_odd_row">'.
2850: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2851: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2852: '<input type="radio" name="dirsrch_domavailable"'.
2853: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2854: '<label><input type="radio" name="dirsrch_domavailable"'.
2855: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2856: '</tr><tr>'.
2857: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2858: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2859: '<input type="radio" name="dirsrch_domlocalonly"'.
2860: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2861: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2862: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2863: '</tr>';
2864: $$rowtotal += 2;
1.26 raeburn 2865: }
1.25 raeburn 2866: return $datatable;
2867: }
2868:
1.28 raeburn 2869: sub print_contacts {
1.160.6.78 raeburn 2870: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 2871: my $datatable;
2872: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 2873: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.160.6.107! raeburn 2874: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.160.6.78 raeburn 2875: if ($position eq 'top') {
2876: if (ref($settings) eq 'HASH') {
2877: foreach my $item (@contacts) {
2878: if (exists($settings->{$item})) {
2879: $to{$item} = $settings->{$item};
2880: }
1.28 raeburn 2881: }
2882: }
1.160.6.78 raeburn 2883: } elsif ($position eq 'middle') {
2884: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91 raeburn 2885: 'updatesmail','idconflictsmail','hostipmail');
1.28 raeburn 2886: foreach my $type (@mailings) {
1.160.6.78 raeburn 2887: $otheremails{$type} = '';
2888: }
1.160.6.107! raeburn 2889: } elsif ($position eq 'lower') {
! 2890: if (ref($settings) eq 'HASH') {
! 2891: if (ref($settings->{'lonstatus'}) eq 'HASH') {
! 2892: %lonstatus = %{$settings->{'lonstatus'}};
! 2893: }
! 2894: }
1.160.6.78 raeburn 2895: } else {
2896: @mailings = ('helpdeskmail','otherdomsmail');
2897: foreach my $type (@mailings) {
2898: $otheremails{$type} = '';
2899: }
2900: $bccemails{'helpdeskmail'} = '';
2901: $bccemails{'otherdomsmail'} = '';
2902: $includestr{'helpdeskmail'} = '';
2903: $includestr{'otherdomsmail'} = '';
2904: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
2905: }
2906: if (ref($settings) eq 'HASH') {
1.160.6.107! raeburn 2907: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 2908: foreach my $type (@mailings) {
2909: if (exists($settings->{$type})) {
2910: if (ref($settings->{$type}) eq 'HASH') {
2911: foreach my $item (@contacts) {
2912: if ($settings->{$type}{$item}) {
2913: $checked{$type}{$item} = ' checked="checked" ';
2914: }
1.28 raeburn 2915: }
1.160.6.78 raeburn 2916: $otheremails{$type} = $settings->{$type}{'others'};
2917: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2918: $bccemails{$type} = $settings->{$type}{'bcc'};
2919: if ($settings->{$type}{'include'} ne '') {
2920: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2921: $includestr{$type} = &unescape($includestr{$type});
2922: }
2923: }
2924: }
2925: } elsif ($type eq 'lonstatusmail') {
2926: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2927: }
2928: }
2929: }
2930: if ($position eq 'bottom') {
2931: foreach my $type (@mailings) {
2932: $bccemails{$type} = $settings->{$type}{'bcc'};
2933: if ($settings->{$type}{'include'} ne '') {
2934: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2935: $includestr{$type} = &unescape($includestr{$type});
2936: }
2937: }
2938: if (ref($settings->{'helpform'}) eq 'HASH') {
2939: if (ref($fields) eq 'ARRAY') {
2940: foreach my $field (@{$fields}) {
2941: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 2942: }
1.160.6.78 raeburn 2943: }
2944: if (exists($settings->{'helpform'}{'maxsize'})) {
2945: $maxsize = $settings->{'helpform'}{'maxsize'};
2946: } else {
2947: $maxsize = '1.0';
2948: }
2949: } else {
2950: if (ref($fields) eq 'ARRAY') {
2951: foreach my $field (@{$fields}) {
2952: $currfield{$field} = 'yes';
1.134 raeburn 2953: }
1.28 raeburn 2954: }
1.160.6.78 raeburn 2955: $maxsize = '1.0';
1.28 raeburn 2956: }
2957: }
2958: } else {
1.160.6.78 raeburn 2959: if ($position eq 'top') {
2960: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2961: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2962: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2963: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
2964: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2965: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
2966: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2967: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91 raeburn 2968: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78 raeburn 2969: } elsif ($position eq 'bottom') {
2970: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2971: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
2972: if (ref($fields) eq 'ARRAY') {
2973: foreach my $field (@{$fields}) {
2974: $currfield{$field} = 'yes';
2975: }
2976: }
2977: $maxsize = '1.0';
2978: }
1.28 raeburn 2979: }
2980: my ($titles,$short_titles) = &contact_titles();
2981: my $rownum = 0;
2982: my $css_class;
1.160.6.78 raeburn 2983: if ($position eq 'top') {
2984: foreach my $item (@contacts) {
2985: $css_class = $rownum%2?' class="LC_odd_row"':'';
2986: $datatable .= '<tr'.$css_class.'>'.
2987: '<td><span class="LC_nobreak">'.$titles->{$item}.
2988: '</span></td><td class="LC_right_item">'.
2989: '<input type="text" name="'.$item.'" value="'.
2990: $to{$item}.'" /></td></tr>';
2991: $rownum ++;
2992: }
1.160.6.101 raeburn 2993: } elsif ($position eq 'bottom') {
2994: $css_class = $rownum%2?' class="LC_odd_row"':'';
2995: $datatable .= '<tr'.$css_class.'>'.
2996: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
2997: &mt('(e-mail, subject, and description always shown)').
2998: '</td><td class="LC_left_item">';
2999: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3000: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3001: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3002: foreach my $field (@{$fields}) {
3003: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3004: if (($field eq 'screenshot') || ($field eq 'cc')) {
3005: $datatable .= ' '.&mt('(logged-in users)');
3006: }
3007: $datatable .='</td><td>';
3008: my $clickaction;
3009: if ($field eq 'screenshot') {
3010: $clickaction = ' onclick="screenshotSize(this);"';
3011: }
3012: if (ref($possoptions->{$field}) eq 'ARRAY') {
3013: foreach my $option (@{$possoptions->{$field}}) {
3014: my $checked;
3015: if ($currfield{$field} eq $option) {
3016: $checked = ' checked="checked"';
3017: }
3018: $datatable .= '<span class="LC_nobreak"><label>'.
3019: '<input type="radio" name="helpform_'.$field.'" '.
3020: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3021: '</label></span>'.(' 'x2);
3022: }
3023: }
3024: if ($field eq 'screenshot') {
3025: my $display;
3026: if ($currfield{$field} eq 'no') {
3027: $display = ' style="display:none"';
3028: }
3029: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
3030: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3031: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3032: }
3033: $datatable .= '</td></tr>';
3034: }
3035: $datatable .= '</table>';
3036: }
3037: $datatable .= '</td></tr>'."\n";
3038: $rownum ++;
3039: }
1.160.6.107! raeburn 3040: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 3041: foreach my $type (@mailings) {
3042: $css_class = $rownum%2?' class="LC_odd_row"':'';
3043: $datatable .= '<tr'.$css_class.'>'.
3044: '<td><span class="LC_nobreak">'.
3045: $titles->{$type}.': </span></td>'.
3046: '<td class="LC_left_item">';
3047: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3048: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3049: }
3050: $datatable .= '<span class="LC_nobreak">';
3051: foreach my $item (@contacts) {
3052: $datatable .= '<label>'.
3053: '<input type="checkbox" name="'.$type.'"'.
3054: $checked{$type}{$item}.
3055: ' value="'.$item.'" />'.$short_titles->{$item}.
3056: '</label> ';
3057: }
3058: $datatable .= '</span><br />'.&mt('Others').': '.
3059: '<input type="text" name="'.$type.'_others" '.
3060: 'value="'.$otheremails{$type}.'" />';
3061: my %locchecked;
3062: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3063: foreach my $loc ('s','b') {
3064: if ($includeloc{$type} eq $loc) {
3065: $locchecked{$loc} = ' checked="checked"';
3066: last;
3067: }
3068: }
3069: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3070: '<input type="text" name="'.$type.'_bcc" '.
3071: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3072: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3073: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 3074: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 3075: '<span class="LC_nobreak">'.&mt('Location:').' '.
3076: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3077: (' 'x2).
3078: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3079: '</span></fieldset>';
3080: }
3081: $datatable .= '</td></tr>'."\n";
3082: $rownum ++;
3083: }
1.28 raeburn 3084: }
1.160.6.78 raeburn 3085: if ($position eq 'middle') {
3086: my %choices;
1.160.6.107! raeburn 3087: my $corelink = &core_link_msu();
! 3088: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.160.6.78 raeburn 3089: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.160.6.107! raeburn 3090: $corelink);
! 3091: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
! 3092: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.160.6.78 raeburn 3093: my %defaultchecked = ('reporterrors' => 'on',
1.160.6.107! raeburn 3094: 'reportupdates' => 'on',
! 3095: 'reportstatus' => 'on');
1.160.6.78 raeburn 3096: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3097: \%choices,$rownum);
3098: $datatable .= $reports;
1.160.6.107! raeburn 3099: } elsif ($position eq 'lower') {
! 3100: $css_class = $rownum%2?' class="LC_odd_row"':'';
! 3101: my ($threshold,$sysmail,%excluded,%weights);
! 3102: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
! 3103: if ($lonstatus{'threshold'} =~ /^\d+$/) {
! 3104: $threshold = $lonstatus{'threshold'};
! 3105: } else {
! 3106: $threshold = $defaults->{'threshold'};
! 3107: }
! 3108: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
! 3109: $sysmail = $lonstatus{'sysmail'};
! 3110: } else {
! 3111: $sysmail = $defaults->{'sysmail'};
! 3112: }
! 3113: if (ref($lonstatus{'weights'}) eq 'HASH') {
! 3114: foreach my $type ('E','W','N','U') {
! 3115: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
! 3116: $weights{$type} = $lonstatus{'weights'}{$type};
! 3117: } else {
! 3118: $weights{$type} = $defaults->{$type};
! 3119: }
! 3120: }
! 3121: } else {
! 3122: foreach my $type ('E','W','N','U') {
! 3123: $weights{$type} = $defaults->{$type};
! 3124: }
! 3125: }
! 3126: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
! 3127: if (@{$lonstatus{'excluded'}} > 0) {
! 3128: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
! 3129: }
! 3130: }
! 3131: $datatable .= '<tr'.$css_class.'>'.
! 3132: '<td class="LC_left_item"><span class="LC_nobreak">'.
! 3133: $titles->{'errorthreshold'}.
! 3134: '</span></td><td class="LC_left_item">'.
! 3135: '<input type="text" name="errorthreshold" value="'.
! 3136: $threshold.'" size="5" /></td></tr>';
! 3137: $rownum ++;
! 3138: $css_class = $rownum%2?' class="LC_odd_row"':'';
! 3139: $datatable .= '<tr'.$css_class.'>'.
! 3140: '<td class="LC_left_item">'.
! 3141: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
! 3142: '</span></td><td class="LC_left_item"><table><tr>';
! 3143: foreach my $type ('E','W','N','U') {
! 3144: $datatable .= '<td>'.$names->{$type}.'<br />'.
! 3145: '<input type="text" name="errorweights_'.$type.'" value="'.
! 3146: $weights{$type}.'" size="5" /></td>';
! 3147: }
! 3148: $datatable .= '</tr></table></tr>';
! 3149: $rownum ++;
! 3150: $css_class = $rownum%2?' class="LC_odd_row"':'';
! 3151: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
! 3152: $titles->{'errorexcluded'}.'</td>'.
! 3153: '<td class="LC_left_item"><table>';
! 3154: my $numinrow = 4;
! 3155: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
! 3156: for (my $i=0; $i<@ids; $i++) {
! 3157: my $rem = $i%($numinrow);
! 3158: if ($rem == 0) {
! 3159: if ($i > 0) {
! 3160: $datatable .= '</tr>';
! 3161: }
! 3162: $datatable .= '<tr>';
! 3163: }
! 3164: my $check;
! 3165: if ($excluded{$ids[$i]}) {
! 3166: $check = ' checked="checked" ';
! 3167: }
! 3168: $datatable .= '<td class="LC_left_item">'.
! 3169: '<span class="LC_nobreak"><label>'.
! 3170: '<input type="checkbox" name="errorexcluded" '.
! 3171: 'value="'.$ids[$i].'"'.$check.' />'.
! 3172: $ids[$i].'</label></span></td>';
! 3173: }
! 3174: my $colsleft = $numinrow - @ids%($numinrow);
! 3175: if ($colsleft > 1 ) {
! 3176: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
! 3177: ' </td>';
! 3178: } elsif ($colsleft == 1) {
! 3179: $datatable .= '<td class="LC_left_item"> </td>';
! 3180: }
! 3181: $datatable .= '</tr></table></td></tr>';
! 3182: $rownum ++;
! 3183: $css_class = $rownum%2?' class="LC_odd_row"':'';
! 3184: $datatable .= '<tr'.$css_class.'>'.
! 3185: '<td class="LC_left_item"><span class="LC_nobreak">'.
! 3186: $titles->{'errorsysmail'}.
! 3187: '</span></td><td class="LC_left_item">'.
! 3188: '<input type="text" name="errorsysmail" value="'.
! 3189: $sysmail.'" size="5" /></td></tr>';
! 3190: $rownum ++;
1.160.6.78 raeburn 3191: } elsif ($position eq 'bottom') {
1.160.6.101 raeburn 3192: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3193: my (@posstypes,%usertypeshash);
3194: if (ref($types) eq 'ARRAY') {
3195: @posstypes = @{$types};
3196: }
3197: if (@posstypes) {
3198: if (ref($usertypes) eq 'HASH') {
3199: %usertypeshash = %{$usertypes};
3200: }
3201: my @overridden;
3202: my $numinrow = 4;
3203: if (ref($settings) eq 'HASH') {
3204: if (ref($settings->{'overrides'}) eq 'HASH') {
3205: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3206: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3207: push(@overridden,$key);
3208: foreach my $item (@contacts) {
3209: if ($settings->{'overrides'}{$key}{$item}) {
3210: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3211: }
3212: }
3213: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3214: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3215: $includeloc{'override_'.$key} = '';
3216: $includestr{'override_'.$key} = '';
3217: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3218: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3219: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3220: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3221: }
1.160.6.78 raeburn 3222: }
3223: }
3224: }
1.160.6.101 raeburn 3225: }
3226: my $customclass = 'LC_helpdesk_override';
3227: my $optionsprefix = 'LC_options_helpdesk_';
3228:
3229: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3230:
3231: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3232: $numinrow,$othertitle,'overrides',
3233: \$rownum,$onclicktypes,$customclass);
3234: $rownum ++;
3235: $usertypeshash{'default'} = $othertitle;
3236: foreach my $status (@posstypes) {
3237: my $css_class;
3238: if ($rownum%2) {
3239: $css_class = 'LC_odd_row ';
3240: }
3241: $css_class .= $customclass;
3242: my $rowid = $optionsprefix.$status;
3243: my $hidden = 1;
3244: my $currstyle = 'display:none';
3245: if (grep(/^\Q$status\E$/,@overridden)) {
3246: $currstyle = 'display:table-row';
3247: $hidden = 0;
3248: }
3249: my $key = 'override_'.$status;
3250: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3251: $includeloc{$key},$includestr{$key},$status,$rowid,
3252: $usertypeshash{$status},$css_class,$currstyle,
3253: \@contacts,$short_titles);
3254: unless ($hidden) {
3255: $rownum ++;
1.160.6.78 raeburn 3256: }
3257: }
1.134 raeburn 3258: }
1.28 raeburn 3259: }
1.30 raeburn 3260: $$rowtotal += $rownum;
1.28 raeburn 3261: return $datatable;
3262: }
3263:
1.160.6.107! raeburn 3264: sub core_link_msu {
! 3265: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
! 3266: &mt('LON-CAPA core group - MSU'),600,500);
! 3267: }
! 3268:
1.160.6.101 raeburn 3269: sub overridden_helpdesk {
3270: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3271: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3272: my $class = 'LC_left_item';
3273: if ($css_class) {
3274: $css_class = ' class="'.$css_class.'"';
3275: }
3276: if ($rowid) {
3277: $rowid = ' id="'.$rowid.'"';
3278: }
3279: if ($rowstyle) {
3280: $rowstyle = ' style="'.$rowstyle.'"';
3281: }
3282: my ($output,$description);
3283: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3284: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3285: "<td>$description</td>\n".
3286: '<td class="'.$class.'" colspan="2">'.
3287: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3288: '<span class="LC_nobreak">';
3289: if (ref($contacts) eq 'ARRAY') {
3290: foreach my $item (@{$contacts}) {
3291: my $check;
3292: if (ref($checked) eq 'HASH') {
3293: $check = $checked->{$item};
3294: }
3295: my $title;
3296: if (ref($short_titles) eq 'HASH') {
3297: $title = $short_titles->{$item};
3298: }
3299: $output .= '<label>'.
3300: '<input type="checkbox" name="override_'.$type.'"'.$check.
3301: ' value="'.$item.'" />'.$title.'</label> ';
3302: }
3303: }
3304: $output .= '</span><br />'.&mt('Others').': '.
3305: '<input type="text" name="override_'.$type.'_others" '.
3306: 'value="'.$otheremails.'" />';
3307: my %locchecked;
3308: foreach my $loc ('s','b') {
3309: if ($includeloc eq $loc) {
3310: $locchecked{$loc} = ' checked="checked"';
3311: last;
3312: }
3313: }
3314: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3315: '<input type="text" name="override_'.$type.'_bcc" '.
3316: 'value="'.$bccemails.'" /></fieldset>'.
3317: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3318: &mt('Text automatically added to e-mail:').' '.
3319: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
3320: '<span class="LC_nobreak">'.&mt('Location:').' '.
3321: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3322: (' 'x2).
3323: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3324: '</span></fieldset>'.
3325: '</td></tr>'."\n";
3326: return $output;
3327: }
3328:
1.160.6.78 raeburn 3329: sub contacts_javascript {
3330: return <<"ENDSCRIPT";
3331:
3332: <script type="text/javascript">
3333: // <![CDATA[
3334:
3335: function screenshotSize(field) {
3336: if (document.getElementById('help_screenshotsize')) {
3337: if (field.value == 'no') {
3338: document.getElementById('help_screenshotsize').style.display="none";
3339: } else {
3340: document.getElementById('help_screenshotsize').style.display="";
3341: }
3342: }
3343: return;
3344: }
3345:
1.160.6.101 raeburn 3346: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3347: if (form.elements[checkbox].length != undefined) {
3348: var count = 0;
3349: if (docount) {
3350: for (var i=0; i<form.elements[checkbox].length; i++) {
3351: if (form.elements[checkbox][i].checked) {
3352: count ++;
3353: }
3354: }
3355: }
3356: for (var i=0; i<form.elements[checkbox].length; i++) {
3357: var type = form.elements[checkbox][i].value;
3358: if (document.getElementById(prefix+type)) {
3359: if (form.elements[checkbox][i].checked) {
3360: document.getElementById(prefix+type).style.display = 'table-row';
3361: if (count % 2 == 1) {
3362: document.getElementById(prefix+type).className = target+' LC_odd_row';
3363: } else {
3364: document.getElementById(prefix+type).className = target;
3365: }
3366: count ++;
3367: } else {
3368: document.getElementById(prefix+type).style.display = 'none';
3369: }
3370: }
3371: }
3372: }
3373: return;
3374: }
3375:
1.160.6.78 raeburn 3376: // ]]>
3377: </script>
3378:
3379: ENDSCRIPT
3380: }
3381:
1.118 jms 3382: sub print_helpsettings {
1.160.6.73 raeburn 3383: my ($position,$dom,$settings,$rowtotal) = @_;
3384: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 3385: my $formname = 'display';
1.160.6.5 raeburn 3386: my ($datatable,$itemcount);
1.160.6.73 raeburn 3387: if ($position eq 'top') {
3388: $itemcount = 1;
3389: my (%choices,%defaultchecked,@toggles);
3390: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3391: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3392: &mt('LON-CAPA bug tracker'),600,500));
3393: %defaultchecked = ('submitbugs' => 'on');
3394: @toggles = ('submitbugs');
3395: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3396: \%choices,$itemcount);
3397: $$rowtotal ++;
3398: } else {
3399: my $css_class;
3400: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 3401: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 3402: if (ref($settings) eq 'HASH') {
3403: if (ref($settings->{'adhoc'}) eq 'HASH') {
3404: %current = %{$settings->{'adhoc'}};
3405: }
1.160.6.77 raeburn 3406: }
3407: my $count = 0;
3408: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 3409: if ($key=~/^rolesdef\_(\w+)$/) {
3410: my $rolename = $1;
1.160.6.77 raeburn 3411: my (%privs,$order);
1.160.6.73 raeburn 3412: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3413: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 3414: if (ref($current{$rolename}) eq 'HASH') {
3415: $order = $current{$rolename}{'order'};
3416: }
3417: if ($order eq '') {
3418: $order = $count;
3419: }
3420: $ordered{$order} = $rolename;
3421: $count++;
1.160.6.73 raeburn 3422: }
3423: }
1.160.6.77 raeburn 3424: my $maxnum = scalar(keys(%ordered));
3425: my @roles_by_num = ();
3426: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3427: push(@roles_by_num,$item);
3428: }
3429: my $context = 'domprefs';
3430: my $crstype = 'Course';
3431: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 3432: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 3433: my ($numstatustypes,@jsarray);
3434: if (ref($types) eq 'ARRAY') {
3435: if (@{$types} > 0) {
3436: $numstatustypes = scalar(@{$types});
3437: push(@accesstypes,'status');
3438: @jsarray = ('bystatus');
3439: }
3440: }
1.160.6.86 raeburn 3441: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 3442: if (keys(%domhelpdesk)) {
3443: push(@accesstypes,('inc','exc'));
3444: push(@jsarray,('notinc','notexc'));
3445: }
3446: my $hiddenstr = join("','",@jsarray);
3447: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 3448: my $context = 'domprefs';
3449: my $crstype = 'Course';
1.160.6.77 raeburn 3450: my $prefix = 'helproles_';
3451: my $add_class = 'LC_hidden';
3452: foreach my $num (@roles_by_num) {
3453: my $role = $ordered{$num};
3454: my ($desc,$access,@statuses);
3455: if (ref($current{$role}) eq 'HASH') {
3456: $desc = $current{$role}{'desc'};
3457: $access = $current{$role}{'access'};
3458: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3459: @statuses = @{$current{$role}{'insttypes'}};
3460: }
3461: }
3462: if ($desc eq '') {
3463: $desc = $role;
3464: }
3465: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 3466: my %full=();
3467: my %levels= (
3468: course => {},
3469: domain => {},
3470: system => {},
3471: );
3472: my %levelscurrent=(
3473: course => {},
3474: domain => {},
3475: system => {},
3476: );
3477: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3478: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3479: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 3480: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3481: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3482: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3483: for (my $k=0; $k<=$maxnum; $k++) {
3484: my $vpos = $k+1;
3485: my $selstr;
3486: if ($k == $num) {
3487: $selstr = ' selected="selected" ';
3488: }
3489: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3490: }
3491: $datatable .= '</select>'.(' 'x2).
3492: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3493: '</td>'.
3494: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3495: &mt('Name shown to users:').
3496: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3497: '</fieldset>'.
3498: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3499: $othertitle,$usertypes,$types,\%domhelpdesk).
3500: '<fieldset>'.
3501: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 3502: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 3503: \%levelscurrent,$identifier,
3504: 'LC_hidden',$prefix.$num.'_privs').
3505: '</fieldset></td>';
1.160.6.73 raeburn 3506: $itemcount ++;
3507: }
3508: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3509: my $newcust = 'custhelp'.$count;
3510: my (%privs,%levelscurrent);
3511: my %full=();
3512: my %levels= (
3513: course => {},
3514: domain => {},
3515: system => {},
3516: );
3517: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3518: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 3519: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3520: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3521: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3522: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3523: for (my $k=0; $k<$maxnum+1; $k++) {
3524: my $vpos = $k+1;
3525: my $selstr;
3526: if ($k == $maxnum) {
3527: $selstr = ' selected="selected" ';
3528: }
3529: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3530: }
3531: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 3532: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3533: '</label></span></td>'.
1.160.6.77 raeburn 3534: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3535: '<span class="LC_nobreak">'.
3536: &mt('Internal name:').
3537: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3538: '</span>'.(' 'x4).
3539: '<span class="LC_nobreak">'.
3540: &mt('Name shown to users:').
3541: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3542: '</span></fieldset>'.
3543: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3544: $usertypes,$types,\%domhelpdesk).
3545: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 3546: &Apache::lonuserutils::custom_role_header($context,$crstype,
3547: \@templateroles,$newcust).
3548: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3549: \%levelscurrent,$newcust).
1.160.6.87 raeburn 3550: '</fieldset>'.
3551: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
3552: '</td></tr>';
1.160.6.73 raeburn 3553: $count ++;
3554: $$rowtotal += $count;
3555: }
1.160.6.5 raeburn 3556: return $datatable;
1.121 raeburn 3557: }
3558:
1.160.6.77 raeburn 3559: sub adhocbutton {
3560: my ($prefix,$num,$field,$visibility) = @_;
3561: my %lt = &Apache::lonlocal::texthash(
3562: show => 'Show details',
3563: hide => 'Hide details',
3564: );
3565: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3566: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3567: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3568: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3569: }
3570:
3571: sub helpsettings_javascript {
3572: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3573: return unless(ref($roles_by_num) eq 'ARRAY');
3574: my %html_js_lt = &Apache::lonlocal::texthash(
3575: show => 'Show details',
3576: hide => 'Hide details',
3577: );
3578: &html_escape(\%html_js_lt);
3579: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3580: return <<"ENDSCRIPT";
3581: <script type="text/javascript">
3582: // <![CDATA[
3583:
3584: function reorderHelpRoles(form,item) {
3585: var changedVal;
3586: $jstext
3587: var newpos = 'helproles_${total}_pos';
3588: var maxh = 1 + $total;
3589: var current = new Array();
3590: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3591: if (item == newpos) {
3592: changedVal = newitemVal;
3593: } else {
3594: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3595: current[newitemVal] = newpos;
3596: }
3597: for (var i=0; i<helproles.length; i++) {
3598: var elementName = 'helproles_'+helproles[i]+'_pos';
3599: if (elementName != item) {
3600: if (form.elements[elementName]) {
3601: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3602: current[currVal] = elementName;
3603: }
3604: }
3605: }
3606: var oldVal;
3607: for (var j=0; j<maxh; j++) {
3608: if (current[j] == undefined) {
3609: oldVal = j;
3610: }
3611: }
3612: if (oldVal < changedVal) {
3613: for (var k=oldVal+1; k<=changedVal ; k++) {
3614: var elementName = current[k];
3615: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3616: }
3617: } else {
3618: for (var k=changedVal; k<oldVal; k++) {
3619: var elementName = current[k];
3620: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3621: }
3622: }
3623: return;
3624: }
3625:
3626: function helpdeskAccess(num) {
3627: var curraccess = null;
3628: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3629: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3630: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3631: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3632: }
3633: }
3634: }
3635: var shown = Array();
3636: var hidden = Array();
3637: if (curraccess == 'none') {
3638: hidden = Array('$hiddenstr');
3639: } else {
3640: if (curraccess == 'status') {
3641: shown = Array('bystatus');
3642: hidden = Array('notinc','notexc');
3643: } else {
3644: if (curraccess == 'exc') {
3645: shown = Array('notexc');
3646: hidden = Array('notinc','bystatus');
3647: }
3648: if (curraccess == 'inc') {
3649: shown = Array('notinc');
3650: hidden = Array('notexc','bystatus');
3651: }
1.160.6.79 raeburn 3652: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 3653: hidden = Array('notinc','notexc','bystatus');
3654: }
3655: }
3656: }
3657: if (hidden.length > 0) {
3658: for (var i=0; i<hidden.length; i++) {
3659: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3660: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3661: }
3662: }
3663: }
3664: if (shown.length > 0) {
3665: for (var i=0; i<shown.length; i++) {
3666: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3667: if (shown[i] == 'privs') {
3668: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3669: } else {
3670: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3671: }
3672: }
3673: }
3674: }
3675: return;
3676: }
3677:
3678: function toggleHelpdeskItem(num,field) {
3679: if (document.getElementById('helproles_'+num+'_'+field)) {
3680: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
3681: document.getElementById('helproles_'+num+'_'+field).className =
3682: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3683: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3684: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3685: }
3686: } else {
3687: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3688: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3689: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3690: }
3691: }
3692: }
3693: return;
3694: }
3695:
3696: // ]]>
3697: </script>
3698:
3699: ENDSCRIPT
3700: }
3701:
3702: sub helpdeskroles_access {
3703: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3704: $usertypes,$types,$domhelpdesk) = @_;
3705: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3706: my %lt = &Apache::lonlocal::texthash(
3707: 'rou' => 'Role usage',
3708: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 3709: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3710: 'dh' => 'All with domain helpdesk role',
3711: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 3712: 'none' => 'None',
3713: 'status' => 'Determined based on institutional status',
3714: 'inc' => 'Include all, but exclude specific personnel',
3715: 'exc' => 'Exclude all, but include specific personnel',
3716: );
3717: my %usecheck = (
3718: all => ' checked="checked"',
3719: );
3720: my %displaydiv = (
3721: status => 'none',
3722: inc => 'none',
3723: exc => 'none',
3724: priv => 'block',
3725: );
3726: my $output;
3727: if (ref($current) eq 'HASH') {
3728: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3729: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3730: $usecheck{$current->{access}} = $usecheck{'all'};
3731: delete($usecheck{'all'});
3732: if ($current->{access} =~ /^(status|inc|exc)$/) {
3733: my $access = $1;
3734: $displaydiv{$access} = 'inline';
3735: } elsif ($current->{access} eq 'none') {
3736: $displaydiv{'priv'} = 'none';
3737: }
3738: }
3739: }
3740: }
3741: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3742: '<p>'.$lt{'whi'}.'</p>';
3743: foreach my $access (@{$accesstypes}) {
3744: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3745: ' onclick="helpdeskAccess('."'$num'".');" />'.
3746: $lt{$access}.'</label>';
3747: if ($access eq 'status') {
3748: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3749: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3750: $othertitle,$usertypes,$types).
3751: '</div>';
3752: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3753: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3754: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3755: '</div>';
3756: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3757: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3758: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3759: '</div>';
3760: }
3761: $output .= '</p>';
3762: }
3763: $output .= '</fieldset>';
3764: return $output;
3765: }
3766:
1.121 raeburn 3767: sub radiobutton_prefs {
1.160.6.16 raeburn 3768: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 3769: $additional,$align) = @_;
1.121 raeburn 3770: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3771: (ref($choices) eq 'HASH'));
3772:
3773: my (%checkedon,%checkedoff,$datatable,$css_class);
3774:
3775: foreach my $item (@{$toggles}) {
3776: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3777: $checkedon{$item} = ' checked="checked" ';
3778: $checkedoff{$item} = ' ';
1.121 raeburn 3779: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3780: $checkedoff{$item} = ' checked="checked" ';
3781: $checkedon{$item} = ' ';
3782: }
3783: }
3784: if (ref($settings) eq 'HASH') {
1.121 raeburn 3785: foreach my $item (@{$toggles}) {
1.118 jms 3786: if ($settings->{$item} eq '1') {
3787: $checkedon{$item} = ' checked="checked" ';
3788: $checkedoff{$item} = ' ';
3789: } elsif ($settings->{$item} eq '0') {
3790: $checkedoff{$item} = ' checked="checked" ';
3791: $checkedon{$item} = ' ';
3792: }
3793: }
1.121 raeburn 3794: }
1.160.6.16 raeburn 3795: if ($onclick) {
3796: $onclick = ' onclick="'.$onclick.'"';
3797: }
1.121 raeburn 3798: foreach my $item (@{$toggles}) {
1.118 jms 3799: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3800: $datatable .=
1.160.6.16 raeburn 3801: '<tr'.$css_class.'><td valign="top">'.
3802: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 3803: '</span></td>';
3804: if ($align eq 'left') {
3805: $datatable .= '<td class="LC_left_item">';
3806: } else {
3807: $datatable .= '<td class="LC_right_item">';
3808: }
3809: $datatable .=
3810: '<span class="LC_nobreak">'.
1.118 jms 3811: '<label><input type="radio" name="'.
1.160.6.16 raeburn 3812: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3813: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 3814: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3815: '</span>'.$additional.
3816: '</td>'.
1.118 jms 3817: '</tr>';
3818: $itemcount ++;
1.121 raeburn 3819: }
3820: return ($datatable,$itemcount);
3821: }
3822:
3823: sub print_coursedefaults {
1.139 raeburn 3824: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3825: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3826: my $itemcount = 1;
1.160.6.16 raeburn 3827: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 3828: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 3829: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3830: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 3831: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3832: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.90 raeburn 3833: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 3834: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 3835: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 3836: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 3837: );
1.160.6.21 raeburn 3838: my %staticdefaults = (
3839: anonsurvey_threshold => 10,
3840: uploadquota => 500,
1.160.6.57 raeburn 3841: postsubmit => 60,
1.160.6.70 raeburn 3842: mysqltables => 172800,
1.160.6.21 raeburn 3843: );
1.139 raeburn 3844: if ($position eq 'top') {
1.160.6.57 raeburn 3845: %defaultchecked = (
3846: 'uselcmath' => 'on',
3847: 'usejsme' => 'on',
1.160.6.64 raeburn 3848: 'canclone' => 'none',
1.160.6.57 raeburn 3849: );
3850: @toggles = ('uselcmath','usejsme');
1.160.6.90 raeburn 3851: my $deftex = $Apache::lonnet::deftex;
3852: if (ref($settings) eq 'HASH') {
3853: if ($settings->{'texengine'}) {
3854: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
3855: $deftex = $settings->{'texengine'};
3856: }
3857: }
3858: }
3859: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3860: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
3861: '<span class="LC_nobreak">'.$choices{'texengine'}.
3862: '</span></td><td class="LC_right_item">'.
3863: '<select name="texengine">'."\n";
3864: my %texoptions = (
3865: MathJax => 'MathJax',
3866: mimetex => &mt('Convert to Images'),
3867: tth => &mt('TeX to HTML'),
3868: );
3869: foreach my $renderer ('MathJax','mimetex','tth') {
3870: my $selected = '';
3871: if ($renderer eq $deftex) {
3872: $selected = ' selected="selected"';
3873: }
3874: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
3875: }
3876: $mathdisp .= '</select></td></tr>'."\n";
3877: $itemcount ++;
1.139 raeburn 3878: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3879: \%choices,$itemcount);
1.160.6.90 raeburn 3880: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 3881: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3882: $datatable .=
3883: '<tr'.$css_class.'><td valign="top">'.
3884: '<span class="LC_nobreak">'.$choices{'canclone'}.
3885: '</span></td><td class="LC_left_item">';
3886: my $currcanclone = 'none';
3887: my $onclick;
3888: my @cloneoptions = ('none','domain');
3889: my %clonetitles = (
3890: none => 'No additional course requesters',
3891: domain => "Any course requester in course's domain",
3892: instcode => 'Course requests for official courses ...',
3893: );
3894: my (%codedefaults,@code_order,@posscodes);
3895: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3896: \@code_order) eq 'ok') {
3897: if (@code_order > 0) {
3898: push(@cloneoptions,'instcode');
3899: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3900: }
3901: }
3902: if (ref($settings) eq 'HASH') {
3903: if ($settings->{'canclone'}) {
3904: if (ref($settings->{'canclone'}) eq 'HASH') {
3905: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3906: if (@code_order > 0) {
3907: $currcanclone = 'instcode';
3908: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3909: }
3910: }
3911: } elsif ($settings->{'canclone'} eq 'domain') {
3912: $currcanclone = $settings->{'canclone'};
3913: }
3914: }
3915: }
3916: foreach my $option (@cloneoptions) {
3917: my ($checked,$additional);
3918: if ($currcanclone eq $option) {
3919: $checked = ' checked="checked"';
3920: }
3921: if ($option eq 'instcode') {
3922: if (@code_order) {
3923: my $show = 'none';
3924: if ($checked) {
3925: $show = 'block';
3926: }
3927: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3928: &mt('Institutional codes for new and cloned course have identical:').
3929: '<br />';
3930: foreach my $item (@code_order) {
3931: my $codechk;
3932: if ($checked) {
3933: if (grep(/^\Q$item\E$/,@posscodes)) {
3934: $codechk = ' checked="checked"';
3935: }
3936: }
3937: $additional .= '<label>'.
3938: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3939: $item.'</label>';
3940: }
3941: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3942: }
3943: }
3944: $datatable .=
3945: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3946: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3947: '</label> '.$additional.'</span><br />';
3948: }
3949: $datatable .= '</td>'.
3950: '</tr>';
3951: $itemcount ++;
1.139 raeburn 3952: } else {
3953: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 3954: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 3955: my $currusecredits = 0;
1.160.6.57 raeburn 3956: my $postsubmitclient = 1;
1.160.6.30 raeburn 3957: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 3958: if (ref($settings) eq 'HASH') {
3959: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 3960: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3961: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3962: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3963: }
3964: }
1.160.6.16 raeburn 3965: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 3966: foreach my $type (@types) {
3967: next if ($type eq 'community');
3968: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3969: if ($defcredits{$type} ne '') {
3970: $currusecredits = 1;
3971: }
3972: }
3973: }
3974: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3975: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3976: $postsubmitclient = 0;
3977: foreach my $type (@types) {
3978: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3979: }
3980: } else {
3981: foreach my $type (@types) {
3982: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3983: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3984: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3985: } else {
3986: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3987: }
3988: } else {
3989: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3990: }
3991: }
3992: }
3993: } else {
3994: foreach my $type (@types) {
3995: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 3996: }
3997: }
1.160.6.70 raeburn 3998: if (ref($settings->{'mysqltables'}) eq 'HASH') {
3999: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4000: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4001: }
4002: } else {
4003: foreach my $type (@types) {
4004: $currmysql{$type} = $staticdefaults{'mysqltables'};
4005: }
4006: }
1.160.6.58 raeburn 4007: } else {
4008: foreach my $type (@types) {
4009: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4010: }
1.139 raeburn 4011: }
4012: if (!$currdefresponder) {
1.160.6.21 raeburn 4013: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4014: } elsif ($currdefresponder < 1) {
4015: $currdefresponder = 1;
4016: }
1.160.6.21 raeburn 4017: foreach my $type (@types) {
4018: if ($curruploadquota{$type} eq '') {
4019: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4020: }
4021: }
1.139 raeburn 4022: $datatable .=
1.160.6.16 raeburn 4023: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4024: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4025: '</span></td>'.
4026: '<td class="LC_right_item"><span class="LC_nobreak">'.
4027: '<input type="text" name="anonsurvey_threshold"'.
4028: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 4029: '</td></tr>'."\n";
4030: $itemcount ++;
4031: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4032: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4033: $choices{'uploadquota'}.
4034: '</span></td>'.
4035: '<td align="right" class="LC_right_item">'.
4036: '<table><tr>';
1.160.6.21 raeburn 4037: foreach my $type (@types) {
4038: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4039: '<input type="text" name="uploadquota_'.$type.'"'.
4040: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4041: }
4042: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 4043: $itemcount ++;
1.160.6.40 raeburn 4044: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 4045: my $display = 'none';
4046: if ($currusecredits) {
4047: $display = 'block';
4048: }
4049: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 4050: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4051: foreach my $type (@types) {
4052: next if ($type eq 'community');
4053: $additional .= '<td align="center">'.&mt($type).'<br />'.
4054: '<input type="text" name="'.$type.'_credits"'.
4055: ' value="'.$defcredits{$type}.'" size="3" /></td>';
4056: }
4057: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 4058: %defaultchecked = ('coursecredits' => 'off');
4059: @toggles = ('coursecredits');
4060: my $current = {
4061: 'coursecredits' => $currusecredits,
4062: };
4063: (my $table,$itemcount) =
4064: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 4065: \%choices,$itemcount,$onclick,$additional,'left');
4066: $datatable .= $table;
4067: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4068: my $display = 'none';
4069: if ($postsubmitclient) {
4070: $display = 'block';
4071: }
4072: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 4073: &mt('Number of seconds submit is disabled').'<br />'.
4074: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4075: '<table><tr>';
1.160.6.57 raeburn 4076: foreach my $type (@types) {
4077: $additional .= '<td align="center">'.&mt($type).'<br />'.
4078: '<input type="text" name="'.$type.'_timeout" value="'.
4079: $deftimeout{$type}.'" size="5" /></td>';
4080: }
4081: $additional .= '</tr></table></div>'."\n";
4082: %defaultchecked = ('postsubmit' => 'on');
4083: @toggles = ('postsubmit');
1.160.6.70 raeburn 4084: $current = {
4085: 'postsubmit' => $postsubmitclient,
4086: };
1.160.6.57 raeburn 4087: ($table,$itemcount) =
4088: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4089: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 4090: $datatable .= $table;
1.160.6.70 raeburn 4091: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4092: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4093: $choices{'mysqltables'}.
4094: '</span></td>'.
4095: '<td align="right" class="LC_right_item">'.
4096: '<table><tr>';
4097: foreach my $type (@types) {
4098: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4099: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 4100: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 4101: }
4102: $datatable .= '</tr></table></td></tr>'."\n";
4103: $itemcount ++;
4104:
1.160.6.37 raeburn 4105: }
4106: $$rowtotal += $itemcount;
4107: return $datatable;
4108: }
4109:
4110: sub print_selfenrollment {
4111: my ($position,$dom,$settings,$rowtotal) = @_;
4112: my ($css_class,$datatable);
4113: my $itemcount = 1;
4114: my @types = ('official','unofficial','community','textbook');
4115: if (($position eq 'top') || ($position eq 'middle')) {
4116: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4117: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
4118: my @rows;
4119: my $key;
4120: if ($position eq 'top') {
4121: $key = 'admin';
4122: if (ref($rowsref) eq 'ARRAY') {
4123: @rows = @{$rowsref};
4124: }
4125: } elsif ($position eq 'middle') {
4126: $key = 'default';
4127: @rows = ('types','registered','approval','limit');
4128: }
4129: foreach my $row (@rows) {
4130: if (defined($titlesref->{$row})) {
4131: $itemcount ++;
4132: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4133: $datatable .= '<tr'.$css_class.'>'.
4134: '<td>'.$titlesref->{$row}.'</td>'.
4135: '<td class="LC_left_item">'.
4136: '<table><tr>';
4137: my (%current,%currentcap);
4138: if (ref($settings) eq 'HASH') {
4139: if (ref($settings->{$key}) eq 'HASH') {
4140: foreach my $type (@types) {
4141: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4142: $current{$type} = $settings->{$key}->{$type}->{$row};
4143: }
4144: if (($row eq 'limit') && ($key eq 'default')) {
4145: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4146: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4147: }
4148: }
4149: }
4150: }
4151: }
4152: my %roles = (
4153: '0' => &Apache::lonnet::plaintext('dc'),
4154: );
4155:
4156: foreach my $type (@types) {
4157: unless (($row eq 'registered') && ($key eq 'default')) {
4158: $datatable .= '<th>'.&mt($type).'</th>';
4159: }
4160: }
4161: unless (($row eq 'registered') && ($key eq 'default')) {
4162: $datatable .= '</tr><tr>';
4163: }
4164: foreach my $type (@types) {
4165: if ($type eq 'community') {
4166: $roles{'1'} = &mt('Community personnel');
4167: } else {
4168: $roles{'1'} = &mt('Course personnel');
4169: }
4170: $datatable .= '<td style="vertical-align: top">';
4171: if ($position eq 'top') {
4172: my %checked;
4173: if ($current{$type} eq '0') {
4174: $checked{'0'} = ' checked="checked"';
4175: } else {
4176: $checked{'1'} = ' checked="checked"';
4177: }
4178: foreach my $role ('1','0') {
4179: $datatable .= '<span class="LC_nobreak"><label>'.
4180: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4181: 'value="'.$role.'"'.$checked{$role}.' />'.
4182: $roles{$role}.'</label></span> ';
4183: }
4184: } else {
4185: if ($row eq 'types') {
4186: my %checked;
4187: if ($current{$type} =~ /^(all|dom)$/) {
4188: $checked{$1} = ' checked="checked"';
4189: } else {
4190: $checked{''} = ' checked="checked"';
4191: }
4192: foreach my $val ('','dom','all') {
4193: $datatable .= '<span class="LC_nobreak"><label>'.
4194: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4195: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4196: }
4197: } elsif ($row eq 'registered') {
4198: my %checked;
4199: if ($current{$type} eq '1') {
4200: $checked{'1'} = ' checked="checked"';
4201: } else {
4202: $checked{'0'} = ' checked="checked"';
4203: }
4204: foreach my $val ('0','1') {
4205: $datatable .= '<span class="LC_nobreak"><label>'.
4206: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4207: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4208: }
4209: } elsif ($row eq 'approval') {
4210: my %checked;
4211: if ($current{$type} =~ /^([12])$/) {
4212: $checked{$1} = ' checked="checked"';
4213: } else {
4214: $checked{'0'} = ' checked="checked"';
4215: }
4216: for my $val (0..2) {
4217: $datatable .= '<span class="LC_nobreak"><label>'.
4218: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4219: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4220: }
4221: } elsif ($row eq 'limit') {
4222: my %checked;
4223: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4224: $checked{$1} = ' checked="checked"';
4225: } else {
4226: $checked{'none'} = ' checked="checked"';
4227: }
4228: my $cap;
4229: if ($currentcap{$type} =~ /^\d+$/) {
4230: $cap = $currentcap{$type};
4231: }
4232: foreach my $val ('none','allstudents','selfenrolled') {
4233: $datatable .= '<span class="LC_nobreak"><label>'.
4234: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4235: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4236: }
4237: $datatable .= '<br />'.
4238: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4239: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4240: '</span>';
4241: }
4242: }
4243: $datatable .= '</td>';
4244: }
4245: $datatable .= '</tr>';
4246: }
4247: $datatable .= '</table></td></tr>';
4248: }
4249: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 4250: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4251: }
4252: $$rowtotal += $itemcount;
4253: return $datatable;
4254: }
4255:
4256: sub print_validation_rows {
4257: my ($caller,$dom,$settings,$rowtotal) = @_;
4258: my ($itemsref,$namesref,$fieldsref);
4259: if ($caller eq 'selfenroll') {
4260: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4261: } elsif ($caller eq 'requestcourses') {
4262: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4263: }
4264: my %currvalidation;
4265: if (ref($settings) eq 'HASH') {
4266: if (ref($settings->{'validation'}) eq 'HASH') {
4267: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 4268: }
1.160.6.39 raeburn 4269: }
4270: my $datatable;
4271: my $itemcount = 0;
4272: foreach my $item (@{$itemsref}) {
4273: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4274: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4275: $namesref->{$item}.
4276: '</span></td>'.
4277: '<td class="LC_left_item">';
4278: if (($item eq 'url') || ($item eq 'button')) {
4279: $datatable .= '<span class="LC_nobreak">'.
4280: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4281: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4282: } elsif ($item eq 'fields') {
4283: my @currfields;
4284: if (ref($currvalidation{$item}) eq 'ARRAY') {
4285: @currfields = @{$currvalidation{$item}};
4286: }
4287: foreach my $field (@{$fieldsref}) {
4288: my $check = '';
4289: if (grep(/^\Q$field\E$/,@currfields)) {
4290: $check = ' checked="checked"';
4291: }
4292: $datatable .= '<span class="LC_nobreak"><label>'.
4293: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4294: ' value="'.$field.'"'.$check.' />'.$field.
4295: '</label></span> ';
4296: }
4297: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 4298: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 4299: $currvalidation{$item}.
1.160.6.37 raeburn 4300: '</textarea>';
1.160.6.39 raeburn 4301: }
4302: $datatable .= '</td></tr>'."\n";
4303: if (ref($rowtotal)) {
1.160.6.37 raeburn 4304: $itemcount ++;
4305: }
1.139 raeburn 4306: }
1.160.6.39 raeburn 4307: if ($caller eq 'requestcourses') {
4308: my %currhash;
1.160.6.51 raeburn 4309: if (ref($settings) eq 'HASH') {
4310: if (ref($settings->{'validation'}) eq 'HASH') {
4311: if ($settings->{'validation'}{'dc'} ne '') {
4312: $currhash{$settings->{'validation'}{'dc'}} = 1;
4313: }
1.160.6.39 raeburn 4314: }
4315: }
4316: my $numinrow = 2;
4317: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4318: 'validationdc',%currhash);
1.160.6.50 raeburn 4319: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 4320: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 4321: if ($numdc > 1) {
1.160.6.50 raeburn 4322: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 4323: } else {
1.160.6.50 raeburn 4324: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 4325: }
1.160.6.50 raeburn 4326: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 4327: $itemcount ++;
4328: }
4329: if (ref($rowtotal)) {
4330: $$rowtotal += $itemcount;
4331: }
1.121 raeburn 4332: return $datatable;
1.118 jms 4333: }
4334:
1.160.6.98 raeburn 4335: sub print_passwords {
4336: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
4337: my ($datatable,$css_class);
4338: my $itemcount = 0;
4339: my %titles = &Apache::lonlocal::texthash (
4340: captcha => '"Forgot Password" CAPTCHA validation',
4341: link => 'Reset link expiration (hours)',
4342: case => 'Case-sensitive usernames/e-mail',
4343: prelink => 'Information required (form 1)',
4344: postlink => 'Information required (form 2)',
4345: emailsrc => 'LON-CAPA e-mail address type(s)',
4346: customtext => 'Domain specific text (HTML)',
4347: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
4348: intauth_check => 'Check bcrypt cost if authenticated',
4349: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
4350: permanent => 'Permanent e-mail address',
4351: critical => 'Critical notification address',
4352: notify => 'Notification address',
4353: min => 'Minimum password length',
4354: max => 'Maximum password length',
4355: chars => 'Required characters',
4356: numsaved => 'Number of previous passwords to save and disallow reuse',
4357: );
4358: if ($position eq 'top') {
4359: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4360: my $shownlinklife = 2;
4361: my $prelink = 'both';
4362: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
4363: if (ref($settings) eq 'HASH') {
4364: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
4365: $shownlinklife = $settings->{resetlink};
4366: }
4367: if (ref($settings->{resetcase}) eq 'ARRAY') {
4368: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
4369: }
4370: if ($settings->{resetprelink} =~ /^(both|either)$/) {
4371: $prelink = $settings->{resetprelink};
4372: }
4373: if (ref($settings->{resetpostlink}) eq 'HASH') {
4374: %postlink = %{$settings->{resetpostlink}};
4375: }
4376: if (ref($settings->{resetemail}) eq 'ARRAY') {
4377: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
4378: }
4379: if ($settings->{resetremove}) {
4380: $nostdtext = 1;
4381: }
4382: if ($settings->{resetcustom}) {
4383: $customurl = $settings->{resetcustom};
4384: }
4385: } else {
4386: if (ref($types) eq 'ARRAY') {
4387: foreach my $item (@{$types}) {
4388: $casesens{$item} = 1;
4389: $postlink{$item} = ['username','email'];
4390: }
4391: }
4392: $casesens{'default'} = 1;
4393: $postlink{'default'} = ['username','email'];
4394: $prelink = 'both';
4395: %emailsrc = (
4396: permanent => 1,
4397: critical => 1,
4398: notify => 1,
4399: );
4400: }
4401: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
4402: $itemcount ++;
4403: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4404: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
4405: '<td class="LC_left_item">'.
4406: '<input type="textbox" value="'.$shownlinklife.'" '.
4407: 'name="passwords_link" size="3" /></td></tr>';
4408: $itemcount ++;
4409: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4410: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
4411: '<td class="LC_left_item">';
4412: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
4413: foreach my $item (@{$types}) {
4414: my $checkedcase;
4415: if ($casesens{$item}) {
4416: $checkedcase = ' checked="checked"';
4417: }
4418: $datatable .= '<span class="LC_nobreak"><label>'.
4419: '<input type="checkbox" name="passwords_case_sensitive" value="'.
4420: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.160.6.104 raeburn 4421: '</span> ';
1.160.6.98 raeburn 4422: }
4423: }
4424: my $checkedcase;
4425: if ($casesens{'default'}) {
4426: $checkedcase = ' checked="checked"';
4427: }
4428: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
4429: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
4430: $othertitle.'</label></span></td>';
4431: $itemcount ++;
4432: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4433: my %checkedpre = (
4434: both => ' checked="checked"',
4435: either => '',
4436: );
4437: if ($prelink eq 'either') {
4438: $checkedpre{either} = ' checked="checked"';
4439: $checkedpre{both} = '';
4440: }
4441: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
4442: '<td class="LC_left_item"><span class="LC_nobreak">'.
4443: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
4444: &mt('Both username and e-mail address').'</label></span> '.
4445: '<span class="LC_nobreak"><label>'.
4446: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
4447: &mt('Either username or e-mail address').'</label></span></td></tr>';
4448: $itemcount ++;
4449: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4450: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
4451: '<td class="LC_left_item">';
4452: my %postlinked;
4453: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
4454: foreach my $item (@{$types}) {
4455: undef(%postlinked);
4456: $datatable .= '<fieldset style="display: inline-block;">'.
4457: '<legend>'.$usertypes->{$item}.'</legend>';
4458: if (ref($postlink{$item}) eq 'ARRAY') {
4459: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
4460: }
4461: foreach my $field ('email','username') {
4462: my $checked;
4463: if ($postlinked{$field}) {
4464: $checked = ' checked="checked"';
4465: }
4466: $datatable .= '<span class="LC_nobreak"><label>'.
4467: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
4468: $field.'"'.$checked.' />'.$field.'</label>'.
4469: '<span> ';
4470: }
4471: $datatable .= '</fieldset>';
4472: }
4473: }
4474: if (ref($postlink{'default'}) eq 'ARRAY') {
4475: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
4476: }
4477: $datatable .= '<fieldset style="display: inline-block;">'.
4478: '<legend>'.$othertitle.'</legend>';
4479: foreach my $field ('email','username') {
4480: my $checked;
4481: if ($postlinked{$field}) {
4482: $checked = ' checked="checked"';
4483: }
4484: $datatable .= '<span class="LC_nobreak"><label>'.
4485: '<input type="checkbox" name="passwords_postlink_default" value="'.
4486: $field.'"'.$checked.' />'.$field.'</label>'.
4487: '<span> ';
4488: }
4489: $datatable .= '</fieldset></td></tr>';
4490: $itemcount ++;
4491: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4492: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
4493: '<td class="LC_left_item">';
4494: foreach my $type ('permanent','critical','notify') {
4495: my $checkedemail;
4496: if ($emailsrc{$type}) {
4497: $checkedemail = ' checked="checked"';
4498: }
4499: $datatable .= '<span class="LC_nobreak"><label>'.
4500: '<input type="checkbox" name="passwords_emailsrc" value="'.
4501: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
4502: '<span> ';
4503: }
4504: $datatable .= '</td></tr>';
4505: $itemcount ++;
4506: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4507: my $switchserver = &check_switchserver($dom,$confname);
4508: my ($showstd,$noshowstd);
4509: if ($nostdtext) {
4510: $noshowstd = ' checked="checked"';
4511: } else {
4512: $showstd = ' checked="checked"';
4513: }
4514: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
4515: '<td class="LC_left_item"><span class="LC_nobreak">'.
4516: &mt('Retain standard text:').
4517: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
4518: &mt('Yes').'</label>'.' '.
4519: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
4520: &mt('No').'</label></span><br />'.
4521: '<span class="LC_fontsize_small">'.
4522: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
4523: &mt('Include custom text:');
4524: if ($customurl) {
1.160.6.104 raeburn 4525: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.160.6.98 raeburn 4526: undef,undef,undef,undef,'background-color:#ffffff');
4527: $datatable .= '<span class="LC_nobreak"> '.$link.
4528: '<label><input type="checkbox" name="passwords_custom_del"'.
4529: ' value="1" />'.&mt('Delete?').'</label></span>'.
4530: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
4531: }
4532: if ($switchserver) {
4533: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
4534: } else {
4535: $datatable .='<span class="LC_nobreak"> '.
4536: '<input type="file" name="passwords_customfile" /></span>';
4537: }
4538: $datatable .= '</td></tr>';
4539: } elsif ($position eq 'middle') {
4540: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
4541: my @items = ('intauth_cost','intauth_check','intauth_switch');
4542: my %defaults;
4543: if (ref($domconf{'defaults'}) eq 'HASH') {
4544: %defaults = %{$domconf{'defaults'}};
4545: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
4546: $defaults{'intauth_cost'} = 10;
4547: }
4548: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
4549: $defaults{'intauth_check'} = 0;
4550: }
4551: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
4552: $defaults{'intauth_switch'} = 0;
4553: }
4554: } else {
4555: %defaults = (
4556: 'intauth_cost' => 10,
4557: 'intauth_check' => 0,
4558: 'intauth_switch' => 0,
4559: );
4560: }
4561: foreach my $item (@items) {
4562: if ($itemcount%2) {
4563: $css_class = '';
4564: } else {
4565: $css_class = ' class="LC_odd_row" ';
4566: }
4567: $datatable .= '<tr'.$css_class.'>'.
4568: '<td><span class="LC_nobreak">'.$titles{$item}.
4569: '</span></td><td class="LC_left_item" colspan="3">';
4570: if ($item eq 'intauth_switch') {
4571: my @options = (0,1,2);
4572: my %optiondesc = &Apache::lonlocal::texthash (
4573: 0 => 'No',
4574: 1 => 'Yes',
4575: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
4576: );
4577: $datatable .= '<table width="100%">';
4578: foreach my $option (@options) {
4579: my $checked = ' ';
4580: if ($defaults{$item} eq $option) {
4581: $checked = ' checked="checked"';
4582: }
4583: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
4584: '<label><input type="radio" name="'.$item.
4585: '" value="'.$option.'"'.$checked.' />'.
4586: $optiondesc{$option}.'</label></span></td></tr>';
4587: }
4588: $datatable .= '</table>';
4589: } elsif ($item eq 'intauth_check') {
4590: my @options = (0,1,2);
4591: my %optiondesc = &Apache::lonlocal::texthash (
4592: 0 => 'No',
4593: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
4594: 2 => 'Yes, disallow login if stored cost is less than domain default',
4595: );
4596: $datatable .= '<table width="100%">';
4597: foreach my $option (@options) {
4598: my $checked = ' ';
4599: my $onclick;
4600: if ($defaults{$item} eq $option) {
4601: $checked = ' checked="checked"';
4602: }
4603: if ($option == 2) {
4604: $onclick = ' onclick="javascript:warnIntAuth(this);"';
4605: }
4606: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
4607: '<label><input type="radio" name="'.$item.
4608: '" value="'.$option.'"'.$checked.$onclick.' />'.
4609: $optiondesc{$option}.'</label></span></td></tr>';
4610: }
4611: $datatable .= '</table>';
4612: } else {
4613: $datatable .= '<input type="text" name="'.$item.'" value="'.
4614: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
4615: }
4616: $datatable .= '</td></tr>';
4617: $itemcount ++;
4618: }
4619: } elsif ($position eq 'lower') {
4620: my ($min,$max,%chars,$numsaved);
1.160.6.99 raeburn 4621: $min = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 4622: if (ref($settings) eq 'HASH') {
4623: if ($settings->{min}) {
4624: $min = $settings->{min};
4625: }
4626: if ($settings->{max}) {
4627: $max = $settings->{max};
4628: }
4629: if (ref($settings->{chars}) eq 'ARRAY') {
4630: map { $chars{$_} = 1; } (@{$settings->{chars}});
4631: }
4632: if ($settings->{numsaved}) {
4633: $numsaved = $settings->{numsaved};
4634: }
4635: }
4636: my %rulenames = &Apache::lonlocal::texthash(
4637: uc => 'At least one upper case letter',
4638: lc => 'At least one lower case letter',
4639: num => 'At least one number',
4640: spec => 'At least one non-alphanumeric',
4641: );
4642: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4643: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
4644: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 4645: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
4646: 'onblur="javascript:warnIntPass(this);" />'.
4647: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.160.6.98 raeburn 4648: '</span></td></tr>';
4649: $itemcount ++;
4650: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4651: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
4652: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 4653: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
4654: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 4655: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
4656: '</span></td></tr>';
4657: $itemcount ++;
4658: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4659: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
4660: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
4661: '</span></td>';
4662: my $numinrow = 2;
4663: my @possrules = ('uc','lc','num','spec');
4664: $datatable .= '<td class="LC_left_item"><table>';
4665: for (my $i=0; $i<@possrules; $i++) {
4666: my ($rem,$checked);
4667: if ($chars{$possrules[$i]}) {
4668: $checked = ' checked="checked"';
4669: }
4670: $rem = $i%($numinrow);
4671: if ($rem == 0) {
4672: if ($i > 0) {
4673: $datatable .= '</tr>';
4674: }
4675: $datatable .= '<tr>';
4676: }
4677: $datatable .= '<td><span class="LC_nobreak"><label>'.
4678: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
4679: $rulenames{$possrules[$i]}.'</label></span></td>';
4680: }
4681: my $rem = @possrules%($numinrow);
4682: my $colsleft = $numinrow - $rem;
4683: if ($colsleft > 1 ) {
4684: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4685: ' </td>';
4686: } elsif ($colsleft == 1) {
4687: $datatable .= '<td class="LC_left_item"> </td>';
4688: }
4689: $datatable .='</table></td></tr>';
4690: $itemcount ++;
4691: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4692: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
4693: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.100 raeburn 4694: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
1.160.6.99 raeburn 4695: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 4696: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
4697: '</span></td></tr>';
4698: } else {
4699: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4700: my %ownerchg = (
4701: by => {},
4702: for => {},
4703: );
4704: my %ownertitles = &Apache::lonlocal::texthash (
4705: by => 'Course owner status(es) allowed',
4706: for => 'Student status(es) allowed',
4707: );
4708: if (ref($settings) eq 'HASH') {
4709: if (ref($settings->{crsownerchg}) eq 'HASH') {
4710: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
4711: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
4712: }
4713: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
4714: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
4715: }
4716: }
4717: }
4718: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4719: $datatable .= '<tr '.$css_class.'>'.
4720: '<td>'.
4721: &mt('Requirements').'<ul>'.
4722: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
4723: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
4724: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
4725: '<li>'.&mt('User, course, and student share same domain').'</li>'.
4726: '</ul>'.
4727: '</td>'.
4728: '<td class="LC_left_item">';
4729: foreach my $item ('by','for') {
4730: $datatable .= '<fieldset style="display: inline-block;">'.
4731: '<legend>'.$ownertitles{$item}.'</legend>';
4732: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
4733: foreach my $type (@{$types}) {
4734: my $checked;
4735: if ($ownerchg{$item}{$type}) {
4736: $checked = ' checked="checked"';
4737: }
4738: $datatable .= '<span class="LC_nobreak"><label>'.
4739: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
4740: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.160.6.104 raeburn 4741: '</span> ';
1.160.6.98 raeburn 4742: }
4743: }
4744: my $checked;
4745: if ($ownerchg{$item}{'default'}) {
4746: $checked = ' checked="checked"';
4747: }
4748: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
4749: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
4750: $othertitle.'</label></span></fieldset>';
4751: }
4752: $datatable .= '</td></tr>';
4753: }
4754: return $datatable;
4755: }
4756:
1.137 raeburn 4757: sub print_usersessions {
4758: my ($position,$dom,$settings,$rowtotal) = @_;
4759: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 4760: my (%by_ip,%by_location,@intdoms);
4761: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 4762:
4763: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 4764: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 4765: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 4766: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 4767: my $itemcount = 1;
4768: if ($position eq 'top') {
1.152 raeburn 4769: if (keys(%serverhomes) > 1) {
1.145 raeburn 4770: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.105 raeburn 4771: my ($curroffloadnow,$curroffloadoth);
1.160.6.61 raeburn 4772: if (ref($settings) eq 'HASH') {
4773: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4774: $curroffloadnow = $settings->{'offloadnow'};
4775: }
1.160.6.105 raeburn 4776: if (ref($settings->{'offloadoth'}) eq 'HASH') {
4777: $curroffloadoth = $settings->{'offloadoth'};
4778: }
1.160.6.61 raeburn 4779: }
1.160.6.105 raeburn 4780: my $other_insts = scalar(keys(%by_location));
4781: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
4782: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 4783: } else {
1.140 raeburn 4784: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 4785: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 4786: }
1.137 raeburn 4787: } else {
1.145 raeburn 4788: if (keys(%by_location) == 0) {
4789: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 4790: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 4791: } else {
4792: my %lt = &usersession_titles();
4793: my $numinrow = 5;
4794: my $prefix;
4795: my @types;
4796: if ($position eq 'bottom') {
4797: $prefix = 'remote';
4798: @types = ('version','excludedomain','includedomain');
4799: } else {
4800: $prefix = 'hosted';
4801: @types = ('excludedomain','includedomain');
4802: }
4803: my (%current,%checkedon,%checkedoff);
4804: my @lcversions = &Apache::lonnet::all_loncaparevs();
4805: my @locations = sort(keys(%by_location));
4806: foreach my $type (@types) {
4807: $checkedon{$type} = '';
4808: $checkedoff{$type} = ' checked="checked"';
4809: }
4810: if (ref($settings) eq 'HASH') {
4811: if (ref($settings->{$prefix}) eq 'HASH') {
4812: foreach my $key (keys(%{$settings->{$prefix}})) {
4813: $current{$key} = $settings->{$prefix}{$key};
4814: if ($key eq 'version') {
4815: if ($current{$key} ne '') {
4816: $checkedon{$key} = ' checked="checked"';
4817: $checkedoff{$key} = '';
4818: }
4819: } elsif (ref($current{$key}) eq 'ARRAY') {
4820: $checkedon{$key} = ' checked="checked"';
4821: $checkedoff{$key} = '';
4822: }
1.137 raeburn 4823: }
4824: }
4825: }
1.145 raeburn 4826: foreach my $type (@types) {
4827: next if ($type ne 'version' && !@locations);
4828: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4829: $datatable .= '<tr'.$css_class.'>
4830: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
4831: <span class="LC_nobreak">
4832: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4833: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4834: if ($type eq 'version') {
4835: my $selector = '<select name="'.$prefix.'_version">';
4836: foreach my $version (@lcversions) {
4837: my $selected = '';
4838: if ($current{'version'} eq $version) {
4839: $selected = ' selected="selected"';
4840: }
4841: $selector .= ' <option value="'.$version.'"'.
4842: $selected.'>'.$version.'</option>';
4843: }
4844: $selector .= '</select> ';
4845: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4846: } else {
4847: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4848: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4849: ' />'.(' 'x2).
4850: '<input type="button" value="'.&mt('uncheck all').'" '.
4851: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4852: "\n".
4853: '</div><div><table>';
4854: my $rem;
4855: for (my $i=0; $i<@locations; $i++) {
4856: my ($showloc,$value,$checkedtype);
4857: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
4858: my $ip = $by_location{$locations[$i]}->[0];
4859: if (ref($by_ip{$ip}) eq 'ARRAY') {
4860: $value = join(':',@{$by_ip{$ip}});
4861: $showloc = join(', ',@{$by_ip{$ip}});
4862: if (ref($current{$type}) eq 'ARRAY') {
4863: foreach my $loc (@{$by_ip{$ip}}) {
4864: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4865: $checkedtype = ' checked="checked"';
4866: last;
4867: }
4868: }
1.138 raeburn 4869: }
4870: }
4871: }
1.145 raeburn 4872: $rem = $i%($numinrow);
4873: if ($rem == 0) {
4874: if ($i > 0) {
4875: $datatable .= '</tr>';
4876: }
4877: $datatable .= '<tr>';
4878: }
4879: $datatable .= '<td class="LC_left_item">'.
4880: '<span class="LC_nobreak"><label>'.
4881: '<input type="checkbox" name="'.$prefix.'_'.$type.
4882: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4883: '</label></span></td>';
1.137 raeburn 4884: }
1.145 raeburn 4885: $rem = @locations%($numinrow);
4886: my $colsleft = $numinrow - $rem;
4887: if ($colsleft > 1 ) {
4888: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4889: ' </td>';
4890: } elsif ($colsleft == 1) {
4891: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4892: }
1.145 raeburn 4893: $datatable .= '</tr></table>';
1.137 raeburn 4894: }
1.145 raeburn 4895: $datatable .= '</td></tr>';
4896: $itemcount ++;
1.137 raeburn 4897: }
4898: }
4899: }
4900: $$rowtotal += $itemcount;
4901: return $datatable;
4902: }
4903:
1.138 raeburn 4904: sub build_location_hashes {
4905: my ($intdoms,$by_ip,$by_location) = @_;
4906: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
4907: (ref($by_location) eq 'HASH'));
4908: my %iphost = &Apache::lonnet::get_iphost();
4909: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4910: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4911: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4912: foreach my $id (@{$iphost{$primary_ip}}) {
4913: my $intdom = &Apache::lonnet::internet_dom($id);
4914: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4915: push(@{$intdoms},$intdom);
4916: }
4917: }
4918: }
4919: foreach my $ip (keys(%iphost)) {
4920: if (ref($iphost{$ip}) eq 'ARRAY') {
4921: foreach my $id (@{$iphost{$ip}}) {
4922: my $location = &Apache::lonnet::internet_dom($id);
4923: if ($location) {
4924: next if (grep(/^\Q$location\E$/,@{$intdoms}));
4925: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4926: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4927: push(@{$by_ip->{$ip}},$location);
4928: }
4929: } else {
4930: $by_ip->{$ip} = [$location];
4931: }
4932: }
4933: }
4934: }
4935: }
4936: foreach my $ip (sort(keys(%{$by_ip}))) {
4937: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4938: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4939: my $first = $by_ip->{$ip}->[0];
4940: if (ref($by_location->{$first}) eq 'ARRAY') {
4941: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4942: push(@{$by_location->{$first}},$ip);
4943: }
4944: } else {
4945: $by_location->{$first} = [$ip];
4946: }
4947: }
4948: }
4949: return;
4950: }
4951:
1.145 raeburn 4952: sub current_offloads_to {
4953: my ($dom,$settings,$servers) = @_;
4954: my (%spareid,%otherdomconfigs);
1.152 raeburn 4955: if (ref($servers) eq 'HASH') {
1.145 raeburn 4956: foreach my $lonhost (sort(keys(%{$servers}))) {
4957: my $gotspares;
1.152 raeburn 4958: if (ref($settings) eq 'HASH') {
4959: if (ref($settings->{'spares'}) eq 'HASH') {
4960: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4961: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4962: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4963: $gotspares = 1;
4964: }
1.145 raeburn 4965: }
4966: }
4967: unless ($gotspares) {
4968: my $gotspares;
4969: my $serverhomeID =
4970: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4971: my $serverhomedom =
4972: &Apache::lonnet::host_domain($serverhomeID);
4973: if ($serverhomedom ne $dom) {
4974: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4975: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4976: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4977: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4978: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4979: $gotspares = 1;
4980: }
4981: }
4982: } else {
4983: $otherdomconfigs{$serverhomedom} =
4984: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4985: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4986: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4987: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4988: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4989: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4990: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4991: $gotspares = 1;
4992: }
4993: }
4994: }
4995: }
4996: }
4997: }
4998: }
4999: unless ($gotspares) {
5000: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
5001: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5002: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5003: } else {
5004: my $server_hostname = &Apache::lonnet::hostname($lonhost);
5005: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
5006: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
5007: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5008: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5009: } else {
1.150 raeburn 5010: my %what = (
5011: spareid => 1,
5012: );
5013: my ($result,$returnhash) =
5014: &Apache::lonnet::get_remote_globals($lonhost,\%what);
5015: if ($result eq 'ok') {
5016: if (ref($returnhash) eq 'HASH') {
5017: if (ref($returnhash->{'spareid'}) eq 'HASH') {
5018: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
5019: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
5020: }
5021: }
1.145 raeburn 5022: }
5023: }
5024: }
5025: }
5026: }
5027: }
5028: return %spareid;
5029: }
5030:
5031: sub spares_row {
1.160.6.105 raeburn 5032: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
5033: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 5034: my $css_class;
5035: my $numinrow = 4;
5036: my $itemcount = 1;
5037: my $datatable;
1.152 raeburn 5038: my %typetitles = &sparestype_titles();
5039: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 5040: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 5041: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
5042: my ($othercontrol,$serverdom);
5043: if ($serverhome ne $server) {
5044: $serverdom = &Apache::lonnet::host_domain($serverhome);
5045: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5046: } else {
5047: $serverdom = &Apache::lonnet::host_domain($server);
5048: if ($serverdom ne $dom) {
5049: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5050: }
5051: }
5052: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.105 raeburn 5053: my ($checkednow,$checkedoth);
1.160.6.61 raeburn 5054: if (ref($curroffloadnow) eq 'HASH') {
5055: if ($curroffloadnow->{$server}) {
5056: $checkednow = ' checked="checked"';
5057: }
5058: }
1.160.6.105 raeburn 5059: if (ref($curroffloadoth) eq 'HASH') {
5060: if ($curroffloadoth->{$server}) {
5061: $checkedoth = ' checked="checked"';
5062: }
5063: }
1.145 raeburn 5064: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5065: $datatable .= '<tr'.$css_class.'>
5066: <td rowspan="2">
1.160.6.13 raeburn 5067: <span class="LC_nobreak">'.
5068: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 5069: ,'<b>'.$server.'</b>').'</span><br />'.
5070: '<span class="LC_nobreak">'."\n".
5071: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.160.6.105 raeburn 5072: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.160.6.13 raeburn 5073: "\n";
1.160.6.105 raeburn 5074: if ($other_insts) {
5075: $datatable .= '<br />'.
5076: '<span class="LC_nobreak">'."\n".
5077: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
5078: ' '.&mt('Switch other institutions on next access').'</label></span>'.
5079: "\n";
5080: }
1.145 raeburn 5081: my (%current,%canselect);
1.152 raeburn 5082: my @choices =
5083: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
5084: foreach my $type ('primary','default') {
5085: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 5086: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
5087: my @spares = @{$spareid->{$server}{$type}};
5088: if (@spares > 0) {
1.152 raeburn 5089: if ($othercontrol) {
5090: $current{$type} = join(', ',@spares);
5091: } else {
5092: $current{$type} .= '<table>';
5093: my $numspares = scalar(@spares);
5094: for (my $i=0; $i<@spares; $i++) {
5095: my $rem = $i%($numinrow);
5096: if ($rem == 0) {
5097: if ($i > 0) {
5098: $current{$type} .= '</tr>';
5099: }
5100: $current{$type} .= '<tr>';
1.145 raeburn 5101: }
1.152 raeburn 5102: $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'".');" /> '.
5103: $spareid->{$server}{$type}[$i].
5104: '</label></td>'."\n";
5105: }
5106: my $rem = @spares%($numinrow);
5107: my $colsleft = $numinrow - $rem;
5108: if ($colsleft > 1 ) {
5109: $current{$type} .= '<td colspan="'.$colsleft.
5110: '" class="LC_left_item">'.
5111: ' </td>';
5112: } elsif ($colsleft == 1) {
5113: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 5114: }
1.152 raeburn 5115: $current{$type} .= '</tr></table>';
1.150 raeburn 5116: }
1.145 raeburn 5117: }
5118: }
5119: if ($current{$type} eq '') {
5120: $current{$type} = &mt('None specified');
5121: }
1.152 raeburn 5122: if ($othercontrol) {
5123: if ($type eq 'primary') {
5124: $canselect{$type} = $othercontrol;
5125: }
5126: } else {
5127: $canselect{$type} =
5128: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
5129: '<select name="newspare_'.$type.'_'.$server.'" '.
5130: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
5131: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
5132: if (@choices > 0) {
5133: foreach my $lonhost (@choices) {
5134: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
5135: }
5136: }
5137: $canselect{$type} .= '</select>'."\n";
5138: }
5139: } else {
5140: $current{$type} = &mt('Could not be determined');
5141: if ($type eq 'primary') {
5142: $canselect{$type} = $othercontrol;
5143: }
1.145 raeburn 5144: }
1.152 raeburn 5145: if ($type eq 'default') {
5146: $datatable .= '<tr'.$css_class.'>';
5147: }
5148: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
5149: '<td>'.$current{$type}.'</td>'."\n".
5150: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 5151: }
5152: $itemcount ++;
5153: }
5154: }
5155: $$rowtotal += $itemcount;
5156: return $datatable;
5157: }
5158:
1.152 raeburn 5159: sub possible_newspares {
5160: my ($server,$currspares,$serverhomes,$altids) = @_;
5161: my $serverhostname = &Apache::lonnet::hostname($server);
5162: my %excluded;
5163: if ($serverhostname ne '') {
5164: %excluded = (
5165: $serverhostname => 1,
5166: );
5167: }
5168: if (ref($currspares) eq 'HASH') {
5169: foreach my $type (keys(%{$currspares})) {
5170: if (ref($currspares->{$type}) eq 'ARRAY') {
5171: if (@{$currspares->{$type}} > 0) {
5172: foreach my $curr (@{$currspares->{$type}}) {
5173: my $hostname = &Apache::lonnet::hostname($curr);
5174: $excluded{$hostname} = 1;
5175: }
5176: }
5177: }
5178: }
5179: }
5180: my @choices;
5181: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
5182: if (keys(%{$serverhomes}) > 1) {
5183: foreach my $name (sort(keys(%{$serverhomes}))) {
5184: unless ($excluded{$name}) {
5185: if (exists($altids->{$serverhomes->{$name}})) {
5186: push(@choices,$altids->{$serverhomes->{$name}});
5187: } else {
5188: push(@choices,$serverhomes->{$name});
1.145 raeburn 5189: }
5190: }
5191: }
5192: }
5193: }
1.152 raeburn 5194: return sort(@choices);
1.145 raeburn 5195: }
5196:
1.150 raeburn 5197: sub print_loadbalancing {
5198: my ($dom,$settings,$rowtotal) = @_;
5199: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5200: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5201: my $numinrow = 1;
5202: my $datatable;
5203: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 5204: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 5205: if (ref($settings) eq 'HASH') {
5206: %existing = %{$settings};
5207: }
5208: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5209: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 5210: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 5211: } else {
5212: return;
5213: }
5214: my ($othertitle,$usertypes,$types) =
5215: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 5216: my $rownum = 8;
1.150 raeburn 5217: if (ref($types) eq 'ARRAY') {
5218: $rownum += scalar(@{$types});
5219: }
1.160.6.7 raeburn 5220: my @css_class = ('LC_odd_row','LC_even_row');
5221: my $balnum = 0;
5222: my $islast;
5223: my (@toshow,$disabledtext);
5224: if (keys(%currbalancer) > 0) {
5225: @toshow = sort(keys(%currbalancer));
5226: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5227: push(@toshow,'');
5228: }
5229: } else {
5230: @toshow = ('');
5231: $disabledtext = &mt('No existing load balancer');
5232: }
5233: foreach my $lonhost (@toshow) {
5234: if ($balnum == scalar(@toshow)-1) {
5235: $islast = 1;
5236: } else {
5237: $islast = 0;
5238: }
5239: my $cssidx = $balnum%2;
5240: my $targets_div_style = 'display: none';
5241: my $disabled_div_style = 'display: block';
5242: my $homedom_div_style = 'display: none';
5243: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
5244: '<td rowspan="'.$rownum.'" valign="top">'.
5245: '<p>';
5246: if ($lonhost eq '') {
5247: $datatable .= '<span class="LC_nobreak">';
5248: if (keys(%currbalancer) > 0) {
5249: $datatable .= &mt('Add balancer:');
5250: } else {
5251: $datatable .= &mt('Enable balancer:');
5252: }
5253: $datatable .= ' '.
5254: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5255: ' id="loadbalancing_lonhost_'.$balnum.'"'.
5256: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
5257: '<option value="" selected="selected">'.&mt('None').
5258: '</option>'."\n";
5259: foreach my $server (sort(keys(%servers))) {
5260: next if ($currbalancer{$server});
5261: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
5262: }
5263: $datatable .=
5264: '</select>'."\n".
5265: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
5266: } else {
5267: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
5268: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
5269: &mt('Stop balancing').'</label>'.
5270: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
5271: $targets_div_style = 'display: block';
5272: $disabled_div_style = 'display: none';
5273: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
5274: $homedom_div_style = 'display: block';
5275: }
5276: }
5277: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
5278: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
5279: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
5280: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
5281: my ($numspares,@spares) = &count_servers($lonhost,%servers);
5282: my @sparestypes = ('primary','default');
5283: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 5284: my %hostherechecked = (
5285: no => ' checked="checked"',
5286: );
1.160.6.94 raeburn 5287: my %balcookiechecked = (
5288: no => ' checked="checked"',
5289: );
1.160.6.7 raeburn 5290: foreach my $sparetype (@sparestypes) {
5291: my $targettable;
5292: for (my $i=0; $i<$numspares; $i++) {
5293: my $checked;
5294: if (ref($currtargets{$lonhost}) eq 'HASH') {
5295: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5296: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5297: $checked = ' checked="checked"';
5298: }
5299: }
5300: }
5301: my ($chkboxval,$disabled);
5302: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5303: $chkboxval = $spares[$i];
5304: }
5305: if (exists($currbalancer{$spares[$i]})) {
5306: $disabled = ' disabled="disabled"';
5307: }
5308: $targettable .=
1.160.6.55 raeburn 5309: '<td><span class="LC_nobreak"><label>'.
5310: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 5311: $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 5312: '</span></label></span></td>';
1.160.6.7 raeburn 5313: my $rem = $i%($numinrow);
5314: if ($rem == 0) {
5315: if (($i > 0) && ($i < $numspares-1)) {
5316: $targettable .= '</tr>';
5317: }
5318: if ($i < $numspares-1) {
5319: $targettable .= '<tr>';
1.150 raeburn 5320: }
5321: }
5322: }
1.160.6.7 raeburn 5323: if ($targettable ne '') {
5324: my $rem = $numspares%($numinrow);
5325: my $colsleft = $numinrow - $rem;
5326: if ($colsleft > 1 ) {
5327: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5328: ' </td>';
5329: } elsif ($colsleft == 1) {
5330: $targettable .= '<td class="LC_left_item"> </td>';
5331: }
5332: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5333: '<table><tr>'.$targettable.'</tr></table><br />';
5334: }
1.160.6.76 raeburn 5335: $hostherechecked{$sparetype} = '';
5336: if (ref($currtargets{$lonhost}) eq 'HASH') {
5337: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5338: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5339: $hostherechecked{$sparetype} = ' checked="checked"';
5340: $hostherechecked{'no'} = '';
5341: }
5342: }
5343: }
5344: }
1.160.6.94 raeburn 5345: if ($currcookies{$lonhost}) {
5346: %balcookiechecked = (
5347: yes => ' checked="checked"',
5348: );
5349: }
1.160.6.76 raeburn 5350: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5351: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5352: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5353: foreach my $sparetype (@sparestypes) {
5354: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5355: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5356: '</i></label><br />';
1.160.6.7 raeburn 5357: }
1.160.6.94 raeburn 5358: $datatable .= &mt('Use balancer cookie').'<br />'.
5359: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
5360: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
5361: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
5362: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
5363: '</div></td></tr>'.
1.160.6.7 raeburn 5364: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5365: $othertitle,$usertypes,$types,\%servers,
5366: \%currbalancer,$lonhost,
5367: $targets_div_style,$homedom_div_style,
5368: $css_class[$cssidx],$balnum,$islast);
5369: $$rowtotal += $rownum;
5370: $balnum ++;
5371: }
5372: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5373: return $datatable;
5374: }
5375:
5376: sub get_loadbalancers_config {
1.160.6.94 raeburn 5377: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 5378: return unless ((ref($servers) eq 'HASH') &&
5379: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 5380: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
5381: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 5382: if (keys(%{$existing}) > 0) {
5383: my $oldlonhost;
5384: foreach my $key (sort(keys(%{$existing}))) {
5385: if ($key eq 'lonhost') {
5386: $oldlonhost = $existing->{'lonhost'};
5387: $currbalancer->{$oldlonhost} = 1;
5388: } elsif ($key eq 'targets') {
5389: if ($oldlonhost) {
5390: $currtargets->{$oldlonhost} = $existing->{'targets'};
5391: }
5392: } elsif ($key eq 'rules') {
5393: if ($oldlonhost) {
5394: $currrules->{$oldlonhost} = $existing->{'rules'};
5395: }
5396: } elsif (ref($existing->{$key}) eq 'HASH') {
5397: $currbalancer->{$key} = 1;
5398: $currtargets->{$key} = $existing->{$key}{'targets'};
5399: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 5400: if ($existing->{$key}{'cookie'}) {
5401: $currcookies->{$key} = 1;
5402: }
1.150 raeburn 5403: }
5404: }
1.160.6.7 raeburn 5405: } else {
5406: my ($balancerref,$targetsref) =
5407: &Apache::lonnet::get_lonbalancer_config($servers);
5408: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5409: foreach my $server (sort(keys(%{$balancerref}))) {
5410: $currbalancer->{$server} = 1;
5411: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 5412: }
5413: }
5414: }
1.160.6.7 raeburn 5415: return;
1.150 raeburn 5416: }
5417:
5418: sub loadbalancing_rules {
5419: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 5420: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5421: $css_class,$balnum,$islast) = @_;
1.150 raeburn 5422: my $output;
1.160.6.7 raeburn 5423: my $num = 0;
5424: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 5425: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5426: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5427: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 5428: $num ++;
1.150 raeburn 5429: my $current;
5430: if (ref($currrules) eq 'HASH') {
5431: $current = $currrules->{$type};
5432: }
1.160.6.55 raeburn 5433: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 5434: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 5435: $current = '';
5436: }
5437: }
5438: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 5439: $servers,$currbalancer,$lonhost,$dom,
5440: $targets_div_style,$homedom_div_style,
5441: $css_class,$balnum,$num,$islast);
1.150 raeburn 5442: }
5443: }
5444: return $output;
5445: }
5446:
5447: sub loadbalancing_titles {
5448: my ($dom,$intdom,$usertypes,$types) = @_;
5449: my %othertypes = (
5450: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5451: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5452: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5453: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 5454: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5455: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 5456: );
1.160.6.26 raeburn 5457: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 5458: my @available;
1.150 raeburn 5459: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 5460: @available = @{$types};
1.150 raeburn 5461: }
1.160.6.89 raeburn 5462: unless (grep(/^default$/,@available)) {
5463: push(@available,'default');
5464: }
5465: unshift(@alltypes,@available);
1.150 raeburn 5466: my %titles;
5467: foreach my $type (@alltypes) {
5468: if ($type =~ /^_LC_/) {
5469: $titles{$type} = $othertypes{$type};
5470: } elsif ($type eq 'default') {
5471: $titles{$type} = &mt('All users from [_1]',$dom);
5472: if (ref($types) eq 'ARRAY') {
5473: if (@{$types} > 0) {
5474: $titles{$type} = &mt('Other users from [_1]',$dom);
5475: }
5476: }
5477: } elsif (ref($usertypes) eq 'HASH') {
5478: $titles{$type} = $usertypes->{$type};
5479: }
5480: }
5481: return (\@alltypes,\%othertypes,\%titles);
5482: }
5483:
5484: sub loadbalance_rule_row {
1.160.6.7 raeburn 5485: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
5486: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 5487: my @rulenames;
1.150 raeburn 5488: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 5489: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 5490: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 5491: } else {
1.160.6.26 raeburn 5492: @rulenames = ('default','homeserver');
5493: if ($type eq '_LC_external') {
5494: push(@rulenames,'externalbalancer');
5495: } else {
5496: push(@rulenames,'specific');
5497: }
5498: push(@rulenames,'none');
1.150 raeburn 5499: }
5500: my $style = $targets_div_style;
1.160.6.55 raeburn 5501: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 5502: $style = $homedom_div_style;
5503: }
1.160.6.7 raeburn 5504: my $space;
5505: if ($islast && $num == 1) {
5506: $space = '<div display="inline-block"> </div>';
5507: }
5508: my $output =
5509: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
5510: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
5511: '<td valaign="top">'.$space.
5512: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 5513: for (my $i=0; $i<@rulenames; $i++) {
5514: my $rule = $rulenames[$i];
5515: my ($checked,$extra);
5516: if ($rulenames[$i] eq 'default') {
5517: $rule = '';
5518: }
5519: if ($rulenames[$i] eq 'specific') {
5520: if (ref($servers) eq 'HASH') {
5521: my $default;
5522: if (($current ne '') && (exists($servers->{$current}))) {
5523: $checked = ' checked="checked"';
5524: }
5525: unless ($checked) {
5526: $default = ' selected="selected"';
5527: }
1.160.6.7 raeburn 5528: $extra =
5529: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
5530: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
5531: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
5532: '<option value=""'.$default.'></option>'."\n";
5533: foreach my $server (sort(keys(%{$servers}))) {
5534: if (ref($currbalancer) eq 'HASH') {
5535: next if (exists($currbalancer->{$server}));
5536: }
1.150 raeburn 5537: my $selected;
1.160.6.7 raeburn 5538: if ($server eq $current) {
1.150 raeburn 5539: $selected = ' selected="selected"';
5540: }
1.160.6.7 raeburn 5541: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 5542: }
5543: $extra .= '</select>';
5544: }
5545: } elsif ($rule eq $current) {
5546: $checked = ' checked="checked"';
5547: }
5548: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 5549: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
5550: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
5551: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 5552: ')"'.$checked.' /> ';
1.160.6.56 raeburn 5553: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 5554: $output .= $ruletitles{'particular'};
5555: } else {
5556: $output .= $ruletitles{$rulenames[$i]};
5557: }
5558: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 5559: }
5560: $output .= '</div></td></tr>'."\n";
5561: return $output;
5562: }
5563:
5564: sub offloadtype_text {
5565: my %ruletitles = &Apache::lonlocal::texthash (
5566: 'default' => 'Offloads to default destinations',
5567: 'homeserver' => "Offloads to user's home server",
5568: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
5569: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 5570: 'none' => 'No offload',
1.160.6.26 raeburn 5571: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
5572: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 5573: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 5574: );
5575: return %ruletitles;
5576: }
5577:
5578: sub sparestype_titles {
5579: my %typestitles = &Apache::lonlocal::texthash (
5580: 'primary' => 'primary',
5581: 'default' => 'default',
5582: );
5583: return %typestitles;
5584: }
5585:
1.28 raeburn 5586: sub contact_titles {
5587: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 5588: 'supportemail' => 'Support E-mail address',
5589: 'adminemail' => 'Default Server Admin E-mail address',
5590: 'errormail' => 'Error reports to be e-mailed to',
5591: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.101 raeburn 5592: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
5593: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 5594: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
5595: 'requestsmail' => 'E-mail from course requests requiring approval',
5596: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 5597: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 5598: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.160.6.107! raeburn 5599: 'errorthreshold' => 'Error/warning threshold for status e-mail',
! 5600: 'errorsysmail' => 'Error threshold for e-mail to core group',
! 5601: 'errorweights' => 'Weights used to compute error count',
! 5602: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 5603: );
5604: my %short_titles = &Apache::lonlocal::texthash (
5605: adminemail => 'Admin E-mail address',
5606: supportemail => 'Support E-mail',
5607: );
5608: return (\%titles,\%short_titles);
5609: }
5610:
1.160.6.78 raeburn 5611: sub helpform_fields {
5612: my %titles = &Apache::lonlocal::texthash (
5613: 'username' => 'Name',
5614: 'user' => 'Username/domain',
5615: 'phone' => 'Phone',
5616: 'cc' => 'Cc e-mail',
5617: 'course' => 'Course Details',
5618: 'section' => 'Sections',
5619: 'screenshot' => 'File upload',
5620: );
5621: my @fields = ('username','phone','user','course','section','cc','screenshot');
5622: my %possoptions = (
5623: username => ['yes','no','req'],
5624: phone => ['yes','no','req'],
5625: user => ['yes','no'],
5626: cc => ['yes','no'],
5627: course => ['yes','no'],
5628: section => ['yes','no'],
5629: screenshot => ['yes','no'],
5630: );
5631: my %fieldoptions = &Apache::lonlocal::texthash (
5632: 'yes' => 'Optional',
5633: 'req' => 'Required',
5634: 'no' => "Not shown",
5635: );
5636: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
5637: }
5638:
1.72 raeburn 5639: sub tool_titles {
5640: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 5641: aboutme => 'Personal web page',
1.86 raeburn 5642: blog => 'Blog',
1.160.6.4 raeburn 5643: webdav => 'WebDAV',
1.86 raeburn 5644: portfolio => 'Portfolio',
1.88 bisitz 5645: official => 'Official courses (with institutional codes)',
5646: unofficial => 'Unofficial courses',
1.98 raeburn 5647: community => 'Communities',
1.160.6.30 raeburn 5648: textbook => 'Textbook courses',
1.86 raeburn 5649: );
1.72 raeburn 5650: return %titles;
5651: }
5652:
1.101 raeburn 5653: sub courserequest_titles {
5654: my %titles = &Apache::lonlocal::texthash (
5655: official => 'Official',
5656: unofficial => 'Unofficial',
5657: community => 'Communities',
1.160.6.30 raeburn 5658: textbook => 'Textbook',
1.101 raeburn 5659: norequest => 'Not allowed',
1.104 raeburn 5660: approval => 'Approval by Dom. Coord.',
1.101 raeburn 5661: validate => 'With validation',
5662: autolimit => 'Numerical limit',
1.103 raeburn 5663: unlimited => '(blank for unlimited)',
1.101 raeburn 5664: );
5665: return %titles;
5666: }
5667:
1.160.6.5 raeburn 5668: sub authorrequest_titles {
5669: my %titles = &Apache::lonlocal::texthash (
5670: norequest => 'Not allowed',
5671: approval => 'Approval by Dom. Coord.',
5672: automatic => 'Automatic approval',
5673: );
5674: return %titles;
5675: }
5676:
1.101 raeburn 5677: sub courserequest_conditions {
5678: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 5679: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 5680: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 5681: );
5682: return %conditions;
5683: }
5684:
5685:
1.27 raeburn 5686: sub print_usercreation {
1.30 raeburn 5687: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 5688: my $numinrow = 4;
1.28 raeburn 5689: my $datatable;
5690: if ($position eq 'top') {
1.30 raeburn 5691: $$rowtotal ++;
1.34 raeburn 5692: my $rowcount = 0;
1.32 raeburn 5693: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 5694: if (ref($rules) eq 'HASH') {
5695: if (keys(%{$rules}) > 0) {
1.32 raeburn 5696: $datatable .= &user_formats_row('username',$settings,$rules,
5697: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 5698: $$rowtotal ++;
1.32 raeburn 5699: $rowcount ++;
5700: }
5701: }
5702: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
5703: if (ref($idrules) eq 'HASH') {
5704: if (keys(%{$idrules}) > 0) {
5705: $datatable .= &user_formats_row('id',$settings,$idrules,
5706: $idruleorder,$numinrow,$rowcount);
5707: $$rowtotal ++;
5708: $rowcount ++;
1.28 raeburn 5709: }
5710: }
1.39 raeburn 5711: if ($rowcount == 0) {
5712: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
5713: $$rowtotal ++;
5714: $rowcount ++;
5715: }
1.34 raeburn 5716: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 5717: my @creators = ('author','course','requestcrs');
1.37 raeburn 5718: my ($rules,$ruleorder) =
5719: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 5720: my %lt = &usercreation_types();
5721: my %checked;
5722: if (ref($settings) eq 'HASH') {
5723: if (ref($settings->{'cancreate'}) eq 'HASH') {
5724: foreach my $item (@creators) {
5725: $checked{$item} = $settings->{'cancreate'}{$item};
5726: }
5727: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
5728: foreach my $item (@creators) {
5729: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
5730: $checked{$item} = 'none';
5731: }
5732: }
5733: }
5734: }
5735: my $rownum = 0;
5736: foreach my $item (@creators) {
5737: $rownum ++;
1.160.6.34 raeburn 5738: if ($checked{$item} eq '') {
5739: $checked{$item} = 'any';
1.34 raeburn 5740: }
5741: my $css_class;
5742: if ($rownum%2) {
5743: $css_class = '';
5744: } else {
5745: $css_class = ' class="LC_odd_row" ';
5746: }
5747: $datatable .= '<tr'.$css_class.'>'.
5748: '<td><span class="LC_nobreak">'.$lt{$item}.
5749: '</span></td><td align="right">';
1.160.6.34 raeburn 5750: my @options = ('any');
5751: if (ref($rules) eq 'HASH') {
5752: if (keys(%{$rules}) > 0) {
5753: push(@options,('official','unofficial'));
1.37 raeburn 5754: }
5755: }
1.160.6.34 raeburn 5756: push(@options,'none');
1.37 raeburn 5757: foreach my $option (@options) {
1.50 raeburn 5758: my $type = 'radio';
1.34 raeburn 5759: my $check = ' ';
1.160.6.34 raeburn 5760: if ($checked{$item} eq $option) {
5761: $check = ' checked="checked" ';
1.34 raeburn 5762: }
5763: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 5764: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 5765: $item.'" value="'.$option.'"'.$check.'/> '.
5766: $lt{$option}.'</label> </span>';
5767: }
5768: $datatable .= '</td></tr>';
5769: }
1.28 raeburn 5770: } else {
5771: my @contexts = ('author','course','domain');
5772: my @authtypes = ('int','krb4','krb5','loc');
5773: my %checked;
5774: if (ref($settings) eq 'HASH') {
5775: if (ref($settings->{'authtypes'}) eq 'HASH') {
5776: foreach my $item (@contexts) {
5777: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5778: foreach my $auth (@authtypes) {
5779: if ($settings->{'authtypes'}{$item}{$auth}) {
5780: $checked{$item}{$auth} = ' checked="checked" ';
5781: }
5782: }
5783: }
5784: }
1.27 raeburn 5785: }
1.35 raeburn 5786: } else {
5787: foreach my $item (@contexts) {
1.36 raeburn 5788: foreach my $auth (@authtypes) {
1.35 raeburn 5789: $checked{$item}{$auth} = ' checked="checked" ';
5790: }
5791: }
1.27 raeburn 5792: }
1.28 raeburn 5793: my %title = &context_names();
5794: my %authname = &authtype_names();
5795: my $rownum = 0;
5796: my $css_class;
5797: foreach my $item (@contexts) {
5798: if ($rownum%2) {
5799: $css_class = '';
5800: } else {
5801: $css_class = ' class="LC_odd_row" ';
5802: }
1.30 raeburn 5803: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5804: '<td>'.$title{$item}.
5805: '</td><td class="LC_left_item">'.
5806: '<span class="LC_nobreak">';
5807: foreach my $auth (@authtypes) {
5808: $datatable .= '<label>'.
5809: '<input type="checkbox" name="'.$item.'_auth" '.
5810: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5811: $authname{$auth}.'</label> ';
5812: }
5813: $datatable .= '</span></td></tr>';
5814: $rownum ++;
1.27 raeburn 5815: }
1.30 raeburn 5816: $$rowtotal += $rownum;
1.27 raeburn 5817: }
5818: return $datatable;
5819: }
5820:
1.160.6.34 raeburn 5821: sub print_selfcreation {
5822: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 5823: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
5824: $emaildomain,$datatable);
1.160.6.34 raeburn 5825: if (ref($settings) eq 'HASH') {
5826: if (ref($settings->{'cancreate'}) eq 'HASH') {
5827: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 5828: if (ref($createsettings) eq 'HASH') {
5829: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5830: @selfcreate = @{$createsettings->{'selfcreate'}};
5831: } elsif ($createsettings->{'selfcreate'} ne '') {
5832: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5833: @selfcreate = ('email','login','sso');
5834: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5835: @selfcreate = ($createsettings->{'selfcreate'});
5836: }
5837: }
5838: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5839: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 5840: }
1.160.6.93 raeburn 5841: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
5842: $emailoptions = $createsettings->{'emailoptions'};
5843: }
5844: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
5845: $emailverified = $createsettings->{'emailverified'};
5846: }
5847: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
5848: $emaildomain = $createsettings->{'emaildomain'};
5849: }
1.160.6.34 raeburn 5850: }
5851: }
5852: }
5853: my %radiohash;
5854: my $numinrow = 4;
5855: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 5856: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 5857: if ($position eq 'top') {
5858: my %choices = &Apache::lonlocal::texthash (
5859: cancreate_login => 'Institutional Login',
5860: cancreate_sso => 'Institutional Single Sign On',
5861: );
5862: my @toggles = sort(keys(%choices));
5863: my %defaultchecked = (
5864: 'cancreate_login' => 'off',
5865: 'cancreate_sso' => 'off',
5866: );
1.160.6.35 raeburn 5867: my ($onclick,$itemcount);
1.160.6.34 raeburn 5868: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5869: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 5870: $$rowtotal += $itemcount;
1.160.6.34 raeburn 5871:
5872: if (ref($usertypes) eq 'HASH') {
5873: if (keys(%{$usertypes}) > 0) {
5874: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5875: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 5876: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 5877: $$rowtotal ++;
5878: }
5879: }
1.160.6.44 raeburn 5880: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5881: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5882: $fieldtitles{'inststatus'} = &mt('Institutional status');
5883: my $rem;
5884: my $numperrow = 2;
5885: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5886: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 5887: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 5888: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 5889: '<table>'."\n";
1.160.6.44 raeburn 5890: for (my $i=0; $i<@fields; $i++) {
5891: $rem = $i%($numperrow);
5892: if ($rem == 0) {
5893: if ($i > 0) {
5894: $datatable .= '</tr>';
5895: }
5896: $datatable .= '<tr>';
5897: }
5898: my $currval;
1.160.6.51 raeburn 5899: if (ref($createsettings) eq 'HASH') {
5900: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5901: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5902: }
1.160.6.44 raeburn 5903: }
5904: $datatable .= '<td class="LC_left_item">'.
5905: '<span class="LC_nobreak">'.
5906: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5907: 'value="'.$currval.'" size="10" /> '.
5908: $fieldtitles{$fields[$i]}.'</span></td>';
5909: }
5910: my $colsleft = $numperrow - $rem;
5911: if ($colsleft > 1 ) {
5912: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5913: ' </td>';
5914: } elsif ($colsleft == 1) {
5915: $datatable .= '<td class="LC_left_item"> </td>';
5916: }
5917: $datatable .= '</tr></table></td></tr>';
5918: $$rowtotal ++;
1.160.6.34 raeburn 5919: } elsif ($position eq 'middle') {
5920: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 5921: my @posstypes;
1.160.6.34 raeburn 5922: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 5923: @posstypes = @{$types};
5924: }
5925: unless (grep(/^default$/,@posstypes)) {
5926: push(@posstypes,'default');
5927: }
5928: my %usertypeshash;
5929: if (ref($usertypes) eq 'HASH') {
5930: %usertypeshash = %{$usertypes};
5931: }
5932: $usertypeshash{'default'} = $othertitle;
5933: foreach my $status (@posstypes) {
5934: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
5935: $numinrow,$$rowtotal,\%usertypeshash);
5936: $$rowtotal ++;
1.160.6.34 raeburn 5937: }
5938: } else {
1.160.6.40 raeburn 5939: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 5940: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 5941: );
5942: my @toggles = sort(keys(%choices));
5943: my %defaultchecked = (
5944: 'cancreate_email' => 'off',
5945: );
1.160.6.93 raeburn 5946: my $customclass = 'LC_selfcreate_email';
5947: my $classprefix = 'LC_canmodify_emailusername_';
5948: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 5949: my $display = 'none';
1.160.6.93 raeburn 5950: my $rowstyle = 'display:none';
1.160.6.40 raeburn 5951: if (grep(/^\Qemail\E$/,@selfcreate)) {
5952: $display = 'block';
1.160.6.93 raeburn 5953: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 5954: }
1.160.6.93 raeburn 5955: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
5956: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5957: \%choices,$$rowtotal,$onclick);
5958: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
5959: $rowstyle);
5960: $$rowtotal ++;
5961: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
5962: $rowstyle);
5963: $$rowtotal ++;
5964: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 5965: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 5966: my ($emailrules,$emailruleorder) =
5967: &Apache::lonnet::inst_userrules($dom,'email');
5968: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5969: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5970: if (ref($types) eq 'ARRAY') {
5971: @posstypes = @{$types};
5972: }
5973: if (@posstypes) {
5974: unless (grep(/^default$/,@posstypes)) {
5975: push(@posstypes,'default');
1.160.6.89 raeburn 5976: }
5977: if (ref($usertypes) eq 'HASH') {
5978: %usertypeshash = %{$usertypes};
5979: }
1.160.6.93 raeburn 5980: my $currassign;
5981: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
5982: $currassign = {
5983: selfassign => $domdefaults{'inststatusguest'},
5984: };
5985: @ordered = @{$domdefaults{'inststatusguest'}};
5986: } else {
5987: $currassign = { selfassign => [] };
5988: }
5989: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
5990: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
5991: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
5992: $numinrow,$othertitle,'selfassign',
5993: $rowtotal,$onclicktypes,$customclass,
5994: $rowstyle);
5995: $$rowtotal ++;
1.160.6.89 raeburn 5996: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 5997: foreach my $status (@posstypes) {
5998: my $css_class;
5999: if ($$rowtotal%2) {
6000: $css_class = 'LC_odd_row ';
6001: }
6002: $css_class .= $customclass;
6003: my $rowid = $optionsprefix.$status;
6004: my $hidden = 1;
6005: my $currstyle = 'display:none';
6006: if (grep(/^\Q$status\E$/,@ordered)) {
6007: $currstyle = $rowstyle;
6008: $hidden = 0;
6009: }
6010: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6011: $emailrules,$emailruleorder,$settings,$status,$rowid,
6012: $usertypeshash{$status},$css_class,$currstyle,$intdom);
6013: unless ($hidden) {
6014: $$rowtotal ++;
6015: }
1.160.6.89 raeburn 6016: }
6017: } else {
1.160.6.93 raeburn 6018: my $css_class;
6019: if ($$rowtotal%2) {
6020: $css_class = 'LC_odd_row ';
6021: }
6022: $css_class .= $customclass;
1.160.6.89 raeburn 6023: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 6024: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6025: $emailrules,$emailruleorder,$settings,'default','',
6026: $othertitle,$css_class,$rowstyle,$intdom);
6027: $$rowtotal ++;
1.160.6.34 raeburn 6028: }
1.160.6.35 raeburn 6029: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
6030: $numinrow = 1;
1.160.6.93 raeburn 6031: if (@posstypes) {
6032: foreach my $status (@posstypes) {
6033: my $rowid = $classprefix.$status;
6034: my $datarowstyle = 'display:none';
6035: if (grep(/^\Q$status\E$/,@ordered)) {
6036: $datarowstyle = $rowstyle;
6037: }
6038: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
6039: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6040: $infotitles,$rowid,$customclass,$datarowstyle);
6041: unless ($datarowstyle eq 'display:none') {
6042: $$rowtotal ++;
6043: }
1.160.6.34 raeburn 6044: }
1.160.6.93 raeburn 6045: } else {
6046: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
6047: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6048: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 6049: }
6050: }
6051: return $datatable;
6052: }
6053:
1.160.6.93 raeburn 6054: sub selfcreate_javascript {
6055: return <<"ENDSCRIPT";
6056:
6057: <script type="text/javascript">
6058: // <![CDATA[
6059:
6060: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
6061: var x = document.getElementsByClassName(target);
6062: var insttypes = 0;
6063: var insttypeRegExp = new RegExp(prefix);
6064: if ((x.length != undefined) && (x.length > 0)) {
6065: if (form.elements[radio].length != undefined) {
6066: for (var i=0; i<form.elements[radio].length; i++) {
6067: if (form.elements[radio][i].checked) {
6068: if (form.elements[radio][i].value == 1) {
6069: for (var j=0; j<x.length; j++) {
6070: if (x[j].id == 'undefined') {
6071: x[j].style.display = 'table-row';
6072: } else if (insttypeRegExp.test(x[j].id)) {
6073: insttypes ++;
6074: } else {
6075: x[j].style.display = 'table-row';
6076: }
6077: }
6078: } else {
6079: for (var j=0; j<x.length; j++) {
6080: x[j].style.display = 'none';
6081: }
1.160.6.40 raeburn 6082: }
1.160.6.93 raeburn 6083: break;
6084: }
6085: }
6086: if (insttypes > 0) {
6087: toggleDataRow(form,checkbox,target,altprefix);
6088: toggleDataRow(form,checkbox,target,prefix,1);
6089: }
6090: }
6091: }
6092: return;
6093: }
6094:
6095: function toggleDataRow(form,checkbox,target,prefix,docount) {
6096: if (form.elements[checkbox].length != undefined) {
6097: var count = 0;
6098: if (docount) {
6099: for (var i=0; i<form.elements[checkbox].length; i++) {
6100: if (form.elements[checkbox][i].checked) {
6101: count ++;
6102: }
6103: }
6104: }
6105: for (var i=0; i<form.elements[checkbox].length; i++) {
6106: var type = form.elements[checkbox][i].value;
6107: if (document.getElementById(prefix+type)) {
6108: if (form.elements[checkbox][i].checked) {
6109: document.getElementById(prefix+type).style.display = 'table-row';
6110: if (count % 2 == 1) {
6111: document.getElementById(prefix+type).className = target+' LC_odd_row';
6112: } else {
6113: document.getElementById(prefix+type).className = target;
6114: }
6115: count ++;
1.160.6.40 raeburn 6116: } else {
1.160.6.93 raeburn 6117: document.getElementById(prefix+type).style.display = 'none';
6118: }
6119: }
6120: }
6121: }
6122: return;
6123: }
6124:
6125: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
6126: var caller = radio+'_'+status;
6127: if (form.elements[caller].length != undefined) {
6128: for (var i=0; i<form.elements[caller].length; i++) {
6129: if (form.elements[caller][i].checked) {
6130: if (document.getElementById(altprefix+'_inst_'+status)) {
6131: var curr = form.elements[caller][i].value;
6132: if (prefix) {
6133: document.getElementById(prefix+'_'+status).style.display = 'none';
6134: }
6135: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
6136: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
6137: if (curr == 'custom') {
6138: if (prefix) {
6139: document.getElementById(prefix+'_'+status).style.display = 'inline';
6140: }
6141: } else if (curr == 'inst') {
6142: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
6143: } else if (curr == 'noninst') {
6144: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 6145: }
1.160.6.93 raeburn 6146: break;
1.160.6.40 raeburn 6147: }
1.160.6.93 raeburn 6148: }
6149: }
6150: }
6151: }
6152:
6153: // ]]>
6154: </script>
6155:
6156: ENDSCRIPT
6157: }
6158:
6159: sub noninst_users {
6160: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
6161: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
6162: my $class = 'LC_left_item';
6163: if ($css_class) {
6164: $css_class = ' class="'.$css_class.'"';
6165: }
6166: if ($rowid) {
6167: $rowid = ' id="'.$rowid.'"';
6168: }
6169: if ($rowstyle) {
6170: $rowstyle = ' style="'.$rowstyle.'"';
6171: }
6172: my ($output,$description);
6173: if ($type eq 'default') {
6174: $description = &mt('Requests for: [_1]',$typetitle);
6175: } else {
6176: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
6177: }
6178: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
6179: "<td>$description</td>\n".
6180: '<td class="'.$class.'" colspan="2">'.
6181: '<table><tr>';
6182: my %headers = &Apache::lonlocal::texthash(
6183: approve => 'Processing',
6184: email => 'E-mail',
6185: username => 'Username',
6186: );
6187: foreach my $item ('approve','email','username') {
6188: $output .= '<th>'.$headers{$item}.'</th>';
6189: }
6190: $output .= '</tr><tr>';
6191: foreach my $item ('approve','email','username') {
6192: $output .= '<td valign="top">';
6193: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
6194: if ($item eq 'approve') {
6195: %choices = &Apache::lonlocal::texthash (
6196: automatic => 'Automatically approved',
6197: approval => 'Queued for approval',
6198: );
6199: @options = ('automatic','approval');
6200: $hashref = $processing;
6201: $defoption = 'automatic';
6202: $name = 'cancreate_emailprocess_'.$type;
6203: } elsif ($item eq 'email') {
6204: %choices = &Apache::lonlocal::texthash (
6205: any => 'Any e-mail',
6206: inst => 'Institutional only',
6207: noninst => 'Non-institutional only',
6208: custom => 'Custom restrictions',
6209: );
6210: @options = ('any','inst','noninst');
6211: my $showcustom;
6212: if (ref($emailrules) eq 'HASH') {
6213: if (keys(%{$emailrules}) > 0) {
6214: push(@options,'custom');
6215: $showcustom = 'cancreate_emailrule';
6216: if (ref($settings) eq 'HASH') {
6217: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
6218: foreach my $rule (@{$settings->{'email_rule'}}) {
6219: if (exists($emailrules->{$rule})) {
6220: $hascustom ++;
6221: }
6222: }
6223: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
6224: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
6225: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
6226: if (exists($emailrules->{$rule})) {
6227: $hascustom ++;
6228: }
6229: }
6230: }
6231: }
6232: }
6233: }
6234: }
6235: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
6236: "'cancreate_emaildomain','$type'".');"';
6237: $hashref = $emailoptions;
6238: $defoption = 'any';
6239: $name = 'cancreate_emailoptions_'.$type;
6240: } elsif ($item eq 'username') {
6241: %choices = &Apache::lonlocal::texthash (
6242: all => 'Same as e-mail',
6243: first => 'Omit @domain',
6244: free => 'Free to choose',
6245: );
6246: @options = ('all','first','free');
6247: $hashref = $emailverified;
6248: $defoption = 'all';
6249: $name = 'cancreate_usernameoptions_'.$type;
6250: }
6251: foreach my $option (@options) {
6252: my $checked;
6253: if (ref($hashref) eq 'HASH') {
6254: if ($type eq '') {
6255: if (!exists($hashref->{'default'})) {
6256: if ($option eq $defoption) {
6257: $checked = ' checked="checked"';
6258: }
6259: } else {
6260: if ($hashref->{'default'} eq $option) {
6261: $checked = ' checked="checked"';
6262: }
1.160.6.40 raeburn 6263: }
6264: } else {
1.160.6.93 raeburn 6265: if (!exists($hashref->{$type})) {
6266: if ($option eq $defoption) {
6267: $checked = ' checked="checked"';
6268: }
6269: } else {
6270: if ($hashref->{$type} eq $option) {
6271: $checked = ' checked="checked"';
6272: }
1.160.6.40 raeburn 6273: }
6274: }
1.160.6.93 raeburn 6275: } elsif (($item eq 'email') && ($hascustom)) {
6276: if ($option eq 'custom') {
6277: $checked = ' checked="checked"';
6278: }
6279: } elsif ($option eq $defoption) {
6280: $checked = ' checked="checked"';
6281: }
6282: $output .= '<span class="LC_nobreak"><label>'.
6283: '<input type="radio" name="'.$name.'"'.
6284: $checked.' value="'.$option.'"'.$onclick.' />'.
6285: $choices{$option}.'</label></span><br />';
6286: if ($item eq 'email') {
6287: if ($option eq 'custom') {
6288: my $id = 'cancreate_emailrule_'.$type;
6289: my $display = 'none';
6290: if ($checked) {
6291: $display = 'inline';
6292: }
6293: my $numinrow = 2;
6294: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
6295: '<legend>'.&mt('Disallow').'</legend><table>'.
6296: &user_formats_row('email',$settings,$emailrules,
6297: $emailruleorder,$numinrow,'',$type);
6298: '</table></fieldset>';
6299: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
6300: my %text = &Apache::lonlocal::texthash (
6301: inst => 'must end:',
6302: noninst => 'cannot end:',
6303: );
6304: my $value;
6305: if (ref($emaildomain) eq 'HASH') {
6306: if (ref($emaildomain->{$type}) eq 'HASH') {
6307: $value = $emaildomain->{$type}->{$option};
6308: }
6309: }
6310: if ($value eq '') {
6311: $value = '@'.$intdom;
6312: }
6313: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
6314: my $display = 'none';
6315: if ($checked) {
6316: $display = 'inline';
6317: }
6318: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
6319: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
6320: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
6321: '</div>';
6322: }
1.160.6.40 raeburn 6323: }
6324: }
1.160.6.93 raeburn 6325: $output .= '</td>'."\n";
1.160.6.40 raeburn 6326: }
1.160.6.93 raeburn 6327: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 6328: return $output;
6329: }
6330:
1.160.6.5 raeburn 6331: sub captcha_choice {
1.160.6.93 raeburn 6332: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 6333: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
6334: $vertext,$currver);
1.160.6.5 raeburn 6335: my %lt = &captcha_phrases();
6336: $keyentry = 'hidden';
1.160.6.98 raeburn 6337: my $colspan=2;
1.160.6.5 raeburn 6338: if ($context eq 'cancreate') {
1.160.6.34 raeburn 6339: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 6340: } elsif ($context eq 'login') {
6341: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98 raeburn 6342: } elsif ($context eq 'passwords') {
6343: $rowname = &mt('"Forgot Password" CAPTCHA validation');
6344: $colspan=1;
1.160.6.5 raeburn 6345: }
6346: if (ref($settings) eq 'HASH') {
6347: if ($settings->{'captcha'}) {
6348: $checked{$settings->{'captcha'}} = ' checked="checked"';
6349: } else {
6350: $checked{'original'} = ' checked="checked"';
6351: }
6352: if ($settings->{'captcha'} eq 'recaptcha') {
6353: $pubtext = $lt{'pub'};
6354: $privtext = $lt{'priv'};
6355: $keyentry = 'text';
1.160.6.69 raeburn 6356: $vertext = $lt{'ver'};
6357: $currver = $settings->{'recaptchaversion'};
6358: if ($currver ne '2') {
6359: $currver = 1;
6360: }
1.160.6.5 raeburn 6361: }
6362: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
6363: $currpub = $settings->{'recaptchakeys'}{'public'};
6364: $currpriv = $settings->{'recaptchakeys'}{'private'};
6365: }
6366: } else {
6367: $checked{'original'} = ' checked="checked"';
6368: }
1.160.6.93 raeburn 6369: my $css_class;
6370: if ($itemcount%2) {
6371: $css_class = 'LC_odd_row';
6372: }
6373: if ($customcss) {
6374: $css_class .= " $customcss";
6375: }
6376: $css_class =~ s/^\s+//;
6377: if ($css_class) {
6378: $css_class = ' class="'.$css_class.'"';
6379: }
6380: if ($rowstyle) {
6381: $css_class .= ' style="'.$rowstyle.'"';
6382: }
1.160.6.5 raeburn 6383: my $output = '<tr'.$css_class.'>'.
1.160.6.98 raeburn 6384: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 6385: '<table><tr><td>'."\n";
6386: foreach my $option ('original','recaptcha','notused') {
6387: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
6388: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
6389: $lt{$option}.'</label></span>';
6390: unless ($option eq 'notused') {
6391: $output .= (' 'x2)."\n";
6392: }
6393: }
6394: #
6395: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
6396: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
6397: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
6398: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
6399: #
6400: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 6401: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 6402: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
6403: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
6404: $currpub.'" size="40" /></span><br />'."\n".
6405: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
6406: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 6407: $currpriv.'" size="40" /></span><br />'.
6408: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
6409: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
6410: $currver.'" size="3" /></span><br />'.
6411: '</td></tr></table>'."\n".
1.160.6.5 raeburn 6412: '</td></tr>';
6413: return $output;
6414: }
6415:
1.32 raeburn 6416: sub user_formats_row {
1.160.6.93 raeburn 6417: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 6418: my $output;
6419: my %text = (
6420: 'username' => 'new usernames',
6421: 'id' => 'IDs',
6422: );
1.160.6.93 raeburn 6423: unless ($type eq 'email') {
6424: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6425: $output = '<tr '.$css_class.'>'.
6426: '<td><span class="LC_nobreak">'.
6427: &mt("Format rules to check for $text{$type}: ").
6428: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 6429: }
1.27 raeburn 6430: my $rem;
6431: if (ref($ruleorder) eq 'ARRAY') {
6432: for (my $i=0; $i<@{$ruleorder}; $i++) {
6433: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
6434: my $rem = $i%($numinrow);
6435: if ($rem == 0) {
6436: if ($i > 0) {
6437: $output .= '</tr>';
6438: }
6439: $output .= '<tr>';
6440: }
6441: my $check = ' ';
1.39 raeburn 6442: if (ref($settings) eq 'HASH') {
6443: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
6444: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
6445: $check = ' checked="checked" ';
6446: }
1.160.6.93 raeburn 6447: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
6448: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
6449: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
6450: $check = ' checked="checked" ';
6451: }
6452: }
1.27 raeburn 6453: }
6454: }
1.160.6.93 raeburn 6455: my $name = $type.'_rule';
6456: if ($type eq 'email') {
6457: $name .= '_'.$status;
6458: }
1.27 raeburn 6459: $output .= '<td class="LC_left_item">'.
6460: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 6461: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 6462: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
6463: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
6464: }
6465: }
6466: $rem = @{$ruleorder}%($numinrow);
6467: }
1.160.6.93 raeburn 6468: my $colsleft;
6469: if ($rem) {
6470: $colsleft = $numinrow - $rem;
6471: }
1.27 raeburn 6472: if ($colsleft > 1 ) {
6473: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6474: ' </td>';
6475: } elsif ($colsleft == 1) {
6476: $output .= '<td class="LC_left_item"> </td>';
6477: }
1.160.6.93 raeburn 6478: $output .= '</tr></table>';
6479: unless ($type eq 'email') {
6480: $output .= '</td></tr>';
6481: }
1.27 raeburn 6482: return $output;
6483: }
6484:
1.34 raeburn 6485: sub usercreation_types {
6486: my %lt = &Apache::lonlocal::texthash (
6487: author => 'When adding a co-author',
6488: course => 'When adding a user to a course',
1.100 raeburn 6489: requestcrs => 'When requesting a course',
1.34 raeburn 6490: any => 'Any',
6491: official => 'Institutional only ',
6492: unofficial => 'Non-institutional only',
6493: none => 'None',
6494: );
6495: return %lt;
1.48 raeburn 6496: }
1.34 raeburn 6497:
1.160.6.34 raeburn 6498: sub selfcreation_types {
6499: my %lt = &Apache::lonlocal::texthash (
6500: selfcreate => 'User creates own account',
6501: any => 'Any',
6502: official => 'Institutional only ',
6503: unofficial => 'Non-institutional only',
6504: email => 'E-mail address',
6505: login => 'Institutional Login',
6506: sso => 'SSO',
6507: );
6508: }
6509:
1.28 raeburn 6510: sub authtype_names {
6511: my %lt = &Apache::lonlocal::texthash(
6512: int => 'Internal',
6513: krb4 => 'Kerberos 4',
6514: krb5 => 'Kerberos 5',
6515: loc => 'Local',
6516: );
6517: return %lt;
6518: }
6519:
6520: sub context_names {
6521: my %context_title = &Apache::lonlocal::texthash(
6522: author => 'Creating users when an Author',
6523: course => 'Creating users when in a course',
6524: domain => 'Creating users when a Domain Coordinator',
6525: );
6526: return %context_title;
6527: }
6528:
1.33 raeburn 6529: sub print_usermodification {
6530: my ($position,$dom,$settings,$rowtotal) = @_;
6531: my $numinrow = 4;
6532: my ($context,$datatable,$rowcount);
6533: if ($position eq 'top') {
6534: $rowcount = 0;
6535: $context = 'author';
6536: foreach my $role ('ca','aa') {
6537: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6538: $numinrow,$rowcount);
6539: $$rowtotal ++;
6540: $rowcount ++;
6541: }
1.160.6.37 raeburn 6542: } elsif ($position eq 'bottom') {
1.33 raeburn 6543: $context = 'course';
6544: $rowcount = 0;
6545: foreach my $role ('st','ep','ta','in','cr') {
6546: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6547: $numinrow,$rowcount);
6548: $$rowtotal ++;
6549: $rowcount ++;
6550: }
6551: }
6552: return $datatable;
6553: }
6554:
1.43 raeburn 6555: sub print_defaults {
1.160.6.40 raeburn 6556: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 6557: my $rownum = 0;
1.160.6.80 raeburn 6558: my ($datatable,$css_class,$titles);
6559: unless ($position eq 'bottom') {
6560: $titles = &defaults_titles($dom);
6561: }
1.160.6.40 raeburn 6562: if ($position eq 'top') {
6563: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
6564: 'datelocale_def','portal_def');
6565: my %defaults;
6566: if (ref($settings) eq 'HASH') {
6567: %defaults = %{$settings};
1.43 raeburn 6568: } else {
1.160.6.40 raeburn 6569: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
6570: foreach my $item (@items) {
6571: $defaults{$item} = $domdefaults{$item};
6572: }
1.43 raeburn 6573: }
1.160.6.40 raeburn 6574: foreach my $item (@items) {
6575: if ($rownum%2) {
6576: $css_class = '';
6577: } else {
6578: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 6579: }
1.160.6.40 raeburn 6580: $datatable .= '<tr'.$css_class.'>'.
6581: '<td><span class="LC_nobreak">'.$titles->{$item}.
6582: '</span></td><td class="LC_right_item" colspan="3">';
6583: if ($item eq 'auth_def') {
6584: my @authtypes = ('internal','krb4','krb5','localauth');
6585: my %shortauth = (
6586: internal => 'int',
6587: krb4 => 'krb4',
6588: krb5 => 'krb5',
6589: localauth => 'loc'
6590: );
6591: my %authnames = &authtype_names();
6592: foreach my $auth (@authtypes) {
6593: my $checked = ' ';
6594: if ($defaults{$item} eq $auth) {
6595: $checked = ' checked="checked" ';
6596: }
6597: $datatable .= '<label><input type="radio" name="'.$item.
6598: '" value="'.$auth.'"'.$checked.'/>'.
6599: $authnames{$shortauth{$auth}}.'</label> ';
6600: }
6601: } elsif ($item eq 'timezone_def') {
6602: my $includeempty = 1;
6603: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
6604: } elsif ($item eq 'datelocale_def') {
1.160.6.98 raeburn 6605: my $includeempty = 1;
6606: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
6607: } elsif ($item eq 'lang_def') {
6608: my $includeempty = 1;
6609: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.80 raeburn 6610: } else {
1.160.6.98 raeburn 6611: my $size;
6612: if ($item eq 'portal_def') {
6613: $size = ' size="25"';
6614: }
1.160.6.80 raeburn 6615: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.98 raeburn 6616: $defaults{$item}.'"'.$size.' />';
1.160.6.80 raeburn 6617: }
6618: $datatable .= '</td></tr>';
6619: $rownum ++;
6620: }
1.160.6.40 raeburn 6621: } else {
1.160.6.80 raeburn 6622: my %defaults;
1.160.6.40 raeburn 6623: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 6624: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 6625: my $maxnum = @{$settings->{'inststatusorder'}};
6626: for (my $i=0; $i<$maxnum; $i++) {
6627: $css_class = $rownum%2?' class="LC_odd_row"':'';
6628: my $item = $settings->{'inststatusorder'}->[$i];
6629: my $title = $settings->{'inststatustypes'}->{$item};
6630: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
6631: $datatable .= '<tr'.$css_class.'>'.
6632: '<td><span class="LC_nobreak">'.
6633: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
6634: for (my $k=0; $k<=$maxnum; $k++) {
6635: my $vpos = $k+1;
6636: my $selstr;
6637: if ($k == $i) {
6638: $selstr = ' selected="selected" ';
6639: }
6640: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6641: }
6642: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
6643: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
6644: &mt('delete').'</span></td>'.
6645: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
6646: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 6647: '</span></td></tr>';
1.160.6.40 raeburn 6648: }
6649: $css_class = $rownum%2?' class="LC_odd_row"':'';
6650: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
6651: $datatable .= '<tr '.$css_class.'>'.
6652: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
6653: for (my $k=0; $k<=$maxnum; $k++) {
6654: my $vpos = $k+1;
6655: my $selstr;
6656: if ($k == $maxnum) {
6657: $selstr = ' selected="selected" ';
6658: }
6659: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6660: }
6661: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 6662: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 6663: ' '.&mt('(new)').
6664: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
6665: &mt('Name displayed:').
6666: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
6667: '</tr>'."\n";
6668: $rownum ++;
1.141 raeburn 6669: }
1.43 raeburn 6670: }
6671: }
6672: $$rowtotal += $rownum;
6673: return $datatable;
6674: }
6675:
1.160.6.5 raeburn 6676: sub get_languages_hash {
6677: my %langchoices;
6678: foreach my $id (&Apache::loncommon::languageids()) {
6679: my $code = &Apache::loncommon::supportedlanguagecode($id);
6680: if ($code ne '') {
6681: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
6682: }
6683: }
6684: return %langchoices;
6685: }
6686:
1.43 raeburn 6687: sub defaults_titles {
1.141 raeburn 6688: my ($dom) = @_;
1.43 raeburn 6689: my %titles = &Apache::lonlocal::texthash (
6690: 'auth_def' => 'Default authentication type',
6691: 'auth_arg_def' => 'Default authentication argument',
6692: 'lang_def' => 'Default language',
1.54 raeburn 6693: 'timezone_def' => 'Default timezone',
1.68 raeburn 6694: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 6695: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 6696: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
6697: 'intauth_check' => 'Check bcrypt cost if authenticated',
6698: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 6699: );
1.141 raeburn 6700: if ($dom) {
6701: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
6702: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
6703: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
6704: $protocol = 'http' if ($protocol ne 'https');
6705: if ($uint_dom) {
6706: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
6707: $uint_dom);
6708: }
6709: }
1.43 raeburn 6710: return (\%titles);
6711: }
6712:
1.160.6.97 raeburn 6713: sub print_scantron {
6714: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
6715: if ($position eq 'top') {
6716: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
6717: } else {
6718: return &print_scantronconfig($dom,$settings,\$rowtotal);
6719: }
6720: }
6721:
6722: sub scantron_javascript {
6723: return <<"ENDSCRIPT";
6724:
6725: <script type="text/javascript">
6726: // <![CDATA[
6727:
6728: function toggleScantron(form) {
6729: var csvfieldset = new Array();
6730: if (document.getElementById('scantroncsv_cols')) {
6731: csvfieldset.push(document.getElementById('scantroncsv_cols'));
6732: }
6733: if (document.getElementById('scantroncsv_options')) {
6734: csvfieldset.push(document.getElementById('scantroncsv_options'));
6735: }
6736: if (csvfieldset.length) {
6737: if (document.getElementById('scantronconfcsv')) {
6738: var scantroncsv = document.getElementById('scantronconfcsv');
6739: if (scantroncsv.checked) {
6740: for (var i=0; i<csvfieldset.length; i++) {
6741: csvfieldset[i].style.display = 'block';
6742: }
6743: } else {
6744: for (var i=0; i<csvfieldset.length; i++) {
6745: csvfieldset[i].style.display = 'none';
6746: }
6747: var csvselects = document.getElementsByClassName('scantronconfig_csv');
6748: if (csvselects.length) {
6749: for (var j=0; j<csvselects.length; j++) {
6750: csvselects[j].selectedIndex = 0;
6751: }
6752: }
6753: }
6754: }
6755: }
6756: return;
6757: }
6758: // ]]>
6759: </script>
6760:
6761: ENDSCRIPT
6762:
6763: }
6764:
1.46 raeburn 6765: sub print_scantronformat {
6766: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
6767: my $itemcount = 1;
1.60 raeburn 6768: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
6769: %confhash);
1.46 raeburn 6770: my $switchserver = &check_switchserver($dom,$confname);
6771: my %lt = &Apache::lonlocal::texthash (
1.95 www 6772: default => 'Default bubblesheet format file error',
6773: custom => 'Custom bubblesheet format file error',
1.46 raeburn 6774: );
6775: my %scantronfiles = (
6776: default => 'default.tab',
6777: custom => 'custom.tab',
6778: );
6779: foreach my $key (keys(%scantronfiles)) {
6780: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
6781: .$scantronfiles{$key};
6782: }
6783: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
6784: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
6785: if (!$switchserver) {
6786: my $servadm = $r->dir_config('lonAdmEMail');
6787: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
6788: if ($configuserok eq 'ok') {
6789: if ($author_ok eq 'ok') {
6790: my %legacyfile = (
1.160.6.97 raeburn 6791: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
6792: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 6793: );
6794: my %md5chk;
6795: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6796: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
6797: chomp($md5chk{$type});
1.46 raeburn 6798: }
6799: if ($md5chk{'default'} ne $md5chk{'custom'}) {
6800: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 6801: ($scantronurls{$type},my $error) =
1.46 raeburn 6802: &legacy_scantronformat($r,$dom,$confname,
6803: $type,$legacyfile{$type},
6804: $scantronurls{$type},
6805: $scantronfiles{$type});
1.60 raeburn 6806: if ($error ne '') {
6807: $error{$type} = $error;
6808: }
6809: }
6810: if (keys(%error) == 0) {
6811: $is_custom = 1;
1.160.6.97 raeburn 6812: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 6813: $scantronurls{'custom'};
1.160.6.97 raeburn 6814: my $putresult =
1.60 raeburn 6815: &Apache::lonnet::put_dom('configuration',
6816: \%confhash,$dom);
6817: if ($putresult ne 'ok') {
1.160.6.97 raeburn 6818: $error{'custom'} =
1.60 raeburn 6819: '<span class="LC_error">'.
6820: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6821: }
1.46 raeburn 6822: }
6823: } else {
1.60 raeburn 6824: ($scantronurls{'default'},my $error) =
1.46 raeburn 6825: &legacy_scantronformat($r,$dom,$confname,
6826: 'default',$legacyfile{'default'},
6827: $scantronurls{'default'},
6828: $scantronfiles{'default'});
1.60 raeburn 6829: if ($error eq '') {
6830: $confhash{'scantron'}{'scantronformat'} = '';
6831: my $putresult =
6832: &Apache::lonnet::put_dom('configuration',
6833: \%confhash,$dom);
6834: if ($putresult ne 'ok') {
6835: $error{'default'} =
6836: '<span class="LC_error">'.
6837: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6838: }
6839: } else {
6840: $error{'default'} = $error;
6841: }
1.46 raeburn 6842: }
6843: }
6844: }
6845: } else {
1.95 www 6846: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 6847: }
6848: }
6849: if (ref($settings) eq 'HASH') {
6850: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
6851: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
6852: if ((!@info) || ($info[0] eq 'no_such_dir')) {
6853: $scantronurl = '';
6854: } else {
6855: $scantronurl = $settings->{'scantronformat'};
6856: }
6857: $is_custom = 1;
6858: } else {
6859: $scantronurl = $scantronurls{'default'};
6860: }
6861: } else {
1.60 raeburn 6862: if ($is_custom) {
6863: $scantronurl = $scantronurls{'custom'};
6864: } else {
6865: $scantronurl = $scantronurls{'default'};
6866: }
1.46 raeburn 6867: }
6868: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6869: $datatable .= '<tr'.$css_class.'>';
6870: if (!$is_custom) {
1.65 raeburn 6871: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
6872: '<span class="LC_nobreak">';
1.46 raeburn 6873: if ($scantronurl) {
1.160.6.21 raeburn 6874: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
6875: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 6876: } else {
6877: $datatable = &mt('File unavailable for display');
6878: }
1.65 raeburn 6879: $datatable .= '</span></td>';
1.60 raeburn 6880: if (keys(%error) == 0) {
6881: $datatable .= '<td valign="bottom">';
6882: if (!$switchserver) {
6883: $datatable .= &mt('Upload:').'<br />';
6884: }
6885: } else {
6886: my $errorstr;
6887: foreach my $key (sort(keys(%error))) {
6888: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6889: }
6890: $datatable .= '<td>'.$errorstr;
6891: }
1.46 raeburn 6892: } else {
6893: if (keys(%error) > 0) {
6894: my $errorstr;
6895: foreach my $key (sort(keys(%error))) {
6896: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6897: }
1.60 raeburn 6898: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 6899: } elsif ($scantronurl) {
1.160.6.26 raeburn 6900: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 6901: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 6902: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 6903: $link.
6904: '<label><input type="checkbox" name="scantronformat_del"'.
6905: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 6906: '<td><span class="LC_nobreak"> '.
6907: &mt('Replace:').'</span><br />';
1.46 raeburn 6908: }
6909: }
6910: if (keys(%error) == 0) {
6911: if ($switchserver) {
6912: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6913: } else {
1.65 raeburn 6914: $datatable .='<span class="LC_nobreak"> '.
6915: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 6916: }
6917: }
6918: $datatable .= '</td></tr>';
6919: $$rowtotal ++;
6920: return $datatable;
6921: }
6922:
6923: sub legacy_scantronformat {
6924: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
6925: my ($url,$error);
6926: my @statinfo = &Apache::lonnet::stat_file($newurl);
6927: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
6928: (my $result,$url) =
6929: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
6930: '','',$newfile);
6931: if ($result ne 'ok') {
1.130 raeburn 6932: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 6933: }
6934: }
6935: return ($url,$error);
6936: }
1.43 raeburn 6937:
1.160.6.97 raeburn 6938: sub print_scantronconfig {
6939: my ($dom,$settings,$rowtotal) = @_;
6940: my $itemcount = 2;
6941: my $is_checked = ' checked="checked"';
6942: my %optionson = (
6943: hdr => ' checked="checked"',
6944: pad => ' checked="checked"',
6945: rem => ' checked="checked"',
6946: );
6947: my %optionsoff = (
6948: hdr => '',
6949: pad => '',
6950: rem => '',
6951: );
6952: my $currcsvsty = 'none';
6953: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
6954: my @fields = &scantroncsv_fields();
6955: my %titles = &scantronconfig_titles();
6956: if (ref($settings) eq 'HASH') {
6957: if (ref($settings->{config}) eq 'HASH') {
6958: if ($settings->{config}->{dat}) {
6959: $checked{'dat'} = $is_checked;
6960: }
6961: if (ref($settings->{config}->{csv}) eq 'HASH') {
6962: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
6963: %csvfields = %{$settings->{config}->{csv}->{fields}};
6964: if (keys(%csvfields) > 0) {
6965: $checked{'csv'} = $is_checked;
6966: $currcsvsty = 'block';
6967: }
6968: }
6969: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
6970: %csvoptions = %{$settings->{config}->{csv}->{options}};
6971: foreach my $option (keys(%optionson)) {
6972: unless ($csvoptions{$option}) {
6973: $optionsoff{$option} = $optionson{$option};
6974: $optionson{$option} = '';
6975: }
6976: }
6977: }
6978: }
6979: } else {
6980: $checked{'dat'} = $is_checked;
6981: }
6982: } else {
6983: $checked{'dat'} = $is_checked;
6984: }
6985: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
6986: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6987: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
6988: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
6989: foreach my $item ('dat','csv') {
6990: my $id;
6991: if ($item eq 'csv') {
6992: $id = 'id="scantronconfcsv" ';
6993: }
6994: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
6995: $titles{$item}.'</label>'.(' 'x3);
6996: if ($item eq 'csv') {
6997: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
6998: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
6999: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
7000: foreach my $col (@fields) {
7001: my $selnone;
7002: if ($csvfields{$col} eq '') {
7003: $selnone = ' selected="selected"';
7004: }
7005: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
7006: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
7007: '<option value=""'.$selnone.'></option>';
7008: for (my $i=0; $i<20; $i++) {
7009: my $shown = $i+1;
7010: my $sel;
7011: unless ($selnone) {
7012: if (exists($csvfields{$col})) {
7013: if ($csvfields{$col} == $i) {
7014: $sel = ' selected="selected"';
7015: }
7016: }
7017: }
7018: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
7019: }
7020: $datatable .= '</select></td></tr>';
7021: }
7022: $datatable .= '</table></fieldset>'.
7023: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
7024: '<legend>'.&mt('CSV Options').'</legend>';
7025: foreach my $option ('hdr','pad','rem') {
7026: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
7027: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
7028: &mt('Yes').'</label>'.(' 'x2)."\n".
7029: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
7030: }
7031: $datatable .= '</fieldset>';
7032: $itemcount ++;
7033: }
7034: }
7035: $datatable .= '</td></tr>';
7036: $$rowtotal ++;
7037: return $datatable;
7038: }
7039:
7040: sub scantronconfig_titles {
7041: return &Apache::lonlocal::texthash(
7042: dat => 'Standard format (.dat)',
7043: csv => 'Comma separated values (.csv)',
7044: hdr => 'Remove first line in file (contains column titles)',
7045: pad => 'Prepend 0s to PaperID',
7046: rem => 'Remove leading spaces (except Question Response columns)',
7047: CODE => 'CODE',
7048: ID => 'Student ID',
7049: PaperID => 'Paper ID',
7050: FirstName => 'First Name',
7051: LastName => 'Last Name',
7052: FirstQuestion => 'First Question Response',
7053: Section => 'Section',
7054: );
7055: }
7056:
7057: sub scantroncsv_fields {
7058: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
7059: }
7060:
1.49 raeburn 7061: sub print_coursecategories {
1.57 raeburn 7062: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
7063: my $datatable;
7064: if ($position eq 'top') {
1.160.6.42 raeburn 7065: my (%checked);
7066: my @catitems = ('unauth','auth');
7067: my @cattypes = ('std','domonly','codesrch','none');
7068: $checked{'unauth'} = 'std';
7069: $checked{'auth'} = 'std';
7070: if (ref($settings) eq 'HASH') {
7071: foreach my $type (@cattypes) {
7072: if ($type eq $settings->{'unauth'}) {
7073: $checked{'unauth'} = $type;
7074: }
7075: if ($type eq $settings->{'auth'}) {
7076: $checked{'auth'} = $type;
7077: }
7078: }
7079: }
7080: my %lt = &Apache::lonlocal::texthash (
7081: unauth => 'Catalog type for unauthenticated users',
7082: auth => 'Catalog type for authenticated users',
7083: none => 'No catalog',
7084: std => 'Standard catalog',
7085: domonly => 'Domain-only catalog',
7086: codesrch => "Code search form",
7087: );
7088: my $itemcount = 0;
7089: foreach my $item (@catitems) {
7090: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7091: $datatable .= '<tr '.$css_class.'>'.
7092: '<td>'.$lt{$item}.'</td>'.
7093: '<td class="LC_right_item"><span class="LC_nobreak">';
7094: foreach my $type (@cattypes) {
7095: my $ischecked;
7096: if ($checked{$item} eq $type) {
7097: $ischecked=' checked="checked"';
7098: }
7099: $datatable .= '<label>'.
7100: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
7101: ' />'.$lt{$type}.'</label> ';
7102: }
1.160.6.87 raeburn 7103: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 7104: $itemcount ++;
7105: }
7106: $$rowtotal += $itemcount;
7107: } elsif ($position eq 'middle') {
1.57 raeburn 7108: my $toggle_cats_crs = ' ';
7109: my $toggle_cats_dom = ' checked="checked" ';
7110: my $can_cat_crs = ' ';
7111: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 7112: my $toggle_catscomm_comm = ' ';
7113: my $toggle_catscomm_dom = ' checked="checked" ';
7114: my $can_catcomm_comm = ' ';
7115: my $can_catcomm_dom = ' checked="checked" ';
7116:
1.57 raeburn 7117: if (ref($settings) eq 'HASH') {
7118: if ($settings->{'togglecats'} eq 'crs') {
7119: $toggle_cats_crs = $toggle_cats_dom;
7120: $toggle_cats_dom = ' ';
7121: }
7122: if ($settings->{'categorize'} eq 'crs') {
7123: $can_cat_crs = $can_cat_dom;
7124: $can_cat_dom = ' ';
7125: }
1.120 raeburn 7126: if ($settings->{'togglecatscomm'} eq 'comm') {
7127: $toggle_catscomm_comm = $toggle_catscomm_dom;
7128: $toggle_catscomm_dom = ' ';
7129: }
7130: if ($settings->{'categorizecomm'} eq 'comm') {
7131: $can_catcomm_comm = $can_catcomm_dom;
7132: $can_catcomm_dom = ' ';
7133: }
1.57 raeburn 7134: }
7135: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 7136: togglecats => 'Show/Hide a course in catalog',
7137: togglecatscomm => 'Show/Hide a community in catalog',
7138: categorize => 'Assign a category to a course',
7139: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7140: );
7141: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 7142: dom => 'Set in Domain',
7143: crs => 'Set in Course',
7144: comm => 'Set in Community',
1.57 raeburn 7145: );
7146: $datatable = '<tr class="LC_odd_row">'.
7147: '<td>'.$title{'togglecats'}.'</td>'.
7148: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7149: '<input type="radio" name="togglecats"'.
7150: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7151: '<label><input type="radio" name="togglecats"'.
7152: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
7153: '</tr><tr>'.
7154: '<td>'.$title{'categorize'}.'</td>'.
7155: '<td class="LC_right_item"><span class="LC_nobreak">'.
7156: '<label><input type="radio" name="categorize"'.
7157: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7158: '<label><input type="radio" name="categorize"'.
7159: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 7160: '</tr><tr class="LC_odd_row">'.
7161: '<td>'.$title{'togglecatscomm'}.'</td>'.
7162: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7163: '<input type="radio" name="togglecatscomm"'.
7164: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7165: '<label><input type="radio" name="togglecatscomm"'.
7166: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
7167: '</tr><tr>'.
7168: '<td>'.$title{'categorizecomm'}.'</td>'.
7169: '<td class="LC_right_item"><span class="LC_nobreak">'.
7170: '<label><input type="radio" name="categorizecomm"'.
7171: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7172: '<label><input type="radio" name="categorizecomm"'.
7173: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 7174: '</tr>';
1.120 raeburn 7175: $$rowtotal += 4;
1.57 raeburn 7176: } else {
7177: my $css_class;
7178: my $itemcount = 1;
7179: my $cathash;
7180: if (ref($settings) eq 'HASH') {
7181: $cathash = $settings->{'cats'};
7182: }
7183: if (ref($cathash) eq 'HASH') {
7184: my (@cats,@trails,%allitems,%idx,@jsarray);
7185: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
7186: \%allitems,\%idx,\@jsarray);
7187: my $maxdepth = scalar(@cats);
7188: my $colattrib = '';
7189: if ($maxdepth > 2) {
7190: $colattrib = ' colspan="2" ';
7191: }
7192: my @path;
7193: if (@cats > 0) {
7194: if (ref($cats[0]) eq 'ARRAY') {
7195: my $numtop = @{$cats[0]};
7196: my $maxnum = $numtop;
1.120 raeburn 7197: my %default_names = (
7198: instcode => &mt('Official courses'),
7199: communities => &mt('Communities'),
7200: );
7201:
7202: if ((!grep(/^instcode$/,@{$cats[0]})) ||
7203: ($cathash->{'instcode::0'} eq '') ||
7204: (!grep(/^communities$/,@{$cats[0]})) ||
7205: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 7206: $maxnum ++;
7207: }
7208: my $lastidx;
7209: for (my $i=0; $i<$numtop; $i++) {
7210: my $parent = $cats[0][$i];
7211: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7212: my $item = &escape($parent).'::0';
7213: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
7214: $lastidx = $idx{$item};
7215: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7216: .'<select name="'.$item.'"'.$chgstr.'>';
7217: for (my $k=0; $k<=$maxnum; $k++) {
7218: my $vpos = $k+1;
7219: my $selstr;
7220: if ($k == $i) {
7221: $selstr = ' selected="selected" ';
7222: }
7223: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7224: }
1.160.6.29 raeburn 7225: $datatable .= '</select></span></td><td>';
1.120 raeburn 7226: if ($parent eq 'instcode' || $parent eq 'communities') {
7227: $datatable .= '<span class="LC_nobreak">'
7228: .$default_names{$parent}.'</span>';
7229: if ($parent eq 'instcode') {
7230: $datatable .= '<br /><span class="LC_nobreak">('
7231: .&mt('with institutional codes')
7232: .')</span></td><td'.$colattrib.'>';
7233: } else {
7234: $datatable .= '<table><tr><td>';
7235: }
7236: $datatable .= '<span class="LC_nobreak">'
7237: .'<label><input type="radio" name="'
7238: .$parent.'" value="1" checked="checked" />'
7239: .&mt('Display').'</label>';
7240: if ($parent eq 'instcode') {
7241: $datatable .= ' ';
7242: } else {
7243: $datatable .= '</span></td></tr><tr><td>'
7244: .'<span class="LC_nobreak">';
7245: }
7246: $datatable .= '<label><input type="radio" name="'
7247: .$parent.'" value="0" />'
7248: .&mt('Do not display').'</label></span>';
7249: if ($parent eq 'communities') {
7250: $datatable .= '</td></tr></table>';
7251: }
7252: $datatable .= '</td>';
1.57 raeburn 7253: } else {
7254: $datatable .= $parent
1.160.6.29 raeburn 7255: .' <span class="LC_nobreak"><label>'
7256: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 7257: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
7258: }
7259: my $depth = 1;
7260: push(@path,$parent);
7261: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
7262: pop(@path);
7263: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
7264: $itemcount ++;
7265: }
1.48 raeburn 7266: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 7267: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
7268: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 7269: for (my $k=0; $k<=$maxnum; $k++) {
7270: my $vpos = $k+1;
7271: my $selstr;
1.57 raeburn 7272: if ($k == $numtop) {
1.48 raeburn 7273: $selstr = ' selected="selected" ';
7274: }
7275: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7276: }
1.59 bisitz 7277: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 7278: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
7279: .'</tr>'."\n";
1.48 raeburn 7280: $itemcount ++;
1.120 raeburn 7281: foreach my $default ('instcode','communities') {
7282: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
7283: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7284: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
7285: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
7286: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
7287: for (my $k=0; $k<=$maxnum; $k++) {
7288: my $vpos = $k+1;
7289: my $selstr;
7290: if ($k == $maxnum) {
7291: $selstr = ' selected="selected" ';
7292: }
7293: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 7294: }
1.120 raeburn 7295: $datatable .= '</select></span></td>'.
7296: '<td><span class="LC_nobreak">'.
7297: $default_names{$default}.'</span>';
7298: if ($default eq 'instcode') {
7299: $datatable .= '<br /><span class="LC_nobreak">('
7300: .&mt('with institutional codes').')</span>';
7301: }
7302: $datatable .= '</td>'
7303: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
7304: .&mt('Display').'</label> '
7305: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
7306: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 7307: }
7308: }
7309: }
1.57 raeburn 7310: } else {
7311: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 7312: }
7313: } else {
1.160.6.87 raeburn 7314: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 7315: .&initialize_categories($itemcount);
1.48 raeburn 7316: }
1.57 raeburn 7317: $$rowtotal += $itemcount;
1.48 raeburn 7318: }
7319: return $datatable;
7320: }
7321:
1.69 raeburn 7322: sub print_serverstatuses {
7323: my ($dom,$settings,$rowtotal) = @_;
7324: my $datatable;
7325: my @pages = &serverstatus_pages();
7326: my (%namedaccess,%machineaccess);
7327: foreach my $type (@pages) {
7328: $namedaccess{$type} = '';
7329: $machineaccess{$type}= '';
7330: }
7331: if (ref($settings) eq 'HASH') {
7332: foreach my $type (@pages) {
7333: if (exists($settings->{$type})) {
7334: if (ref($settings->{$type}) eq 'HASH') {
7335: foreach my $key (keys(%{$settings->{$type}})) {
7336: if ($key eq 'namedusers') {
7337: $namedaccess{$type} = $settings->{$type}->{$key};
7338: } elsif ($key eq 'machines') {
7339: $machineaccess{$type} = $settings->{$type}->{$key};
7340: }
7341: }
7342: }
7343: }
7344: }
7345: }
1.81 raeburn 7346: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7347: my $rownum = 0;
7348: my $css_class;
7349: foreach my $type (@pages) {
7350: $rownum ++;
7351: $css_class = $rownum%2?' class="LC_odd_row"':'';
7352: $datatable .= '<tr'.$css_class.'>'.
7353: '<td><span class="LC_nobreak">'.
7354: $titles->{$type}.'</span></td>'.
7355: '<td class="LC_left_item">'.
7356: '<input type="text" name="'.$type.'_namedusers" '.
7357: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
7358: '<td class="LC_right_item">'.
7359: '<span class="LC_nobreak">'.
7360: '<input type="text" name="'.$type.'_machines" '.
7361: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 7362: '</span></td></tr>'."\n";
1.69 raeburn 7363: }
7364: $$rowtotal += $rownum;
7365: return $datatable;
7366: }
7367:
7368: sub serverstatus_pages {
7369: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 7370: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 7371: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 7372: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 7373: }
7374:
1.160.6.40 raeburn 7375: sub defaults_javascript {
7376: my ($settings) = @_;
1.160.6.98 raeburn 7377: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 7378: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
7379: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
7380: if ($maxnum eq '') {
7381: $maxnum = 0;
7382: }
7383: $maxnum ++;
1.160.6.51 raeburn 7384: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 7385: return <<"ENDSCRIPT";
7386: <script type="text/javascript">
7387: // <![CDATA[
7388: function reorderTypes(form,caller) {
7389: var changedVal;
7390: $jstext
7391: var newpos = 'addinststatus_pos';
7392: var current = new Array;
7393: var maxh = $maxnum;
7394: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7395: var oldVal;
7396: if (caller == newpos) {
7397: changedVal = newitemVal;
7398: } else {
7399: var curritem = 'inststatus_pos_'+caller;
7400: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
7401: current[newitemVal] = newpos;
7402: }
7403: for (var i=0; i<inststatuses.length; i++) {
7404: if (inststatuses[i] != caller) {
7405: var elementName = 'inststatus_pos_'+inststatuses[i];
7406: if (form.elements[elementName]) {
7407: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7408: current[currVal] = elementName;
7409: }
7410: }
7411: }
7412: for (var j=0; j<maxh; j++) {
7413: if (current[j] == undefined) {
7414: oldVal = j;
7415: }
7416: }
7417: if (oldVal < changedVal) {
7418: for (var k=oldVal+1; k<=changedVal ; k++) {
7419: var elementName = current[k];
7420: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7421: }
7422: } else {
7423: for (var k=changedVal; k<oldVal; k++) {
7424: var elementName = current[k];
7425: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7426: }
7427: }
7428: return;
7429: }
7430:
7431: // ]]>
7432: </script>
7433:
7434: ENDSCRIPT
7435: }
7436: }
7437:
1.160.6.98 raeburn 7438: sub passwords_javascript {
1.160.6.99 raeburn 7439: my %intalert = &Apache::lonlocal::texthash (
7440: authcheck => 'Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.',
7441: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
7442: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
7443: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
7444: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
7445: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
7446: );
7447: &js_escape(\%intalert);
7448: my $defmin = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 7449: my $intauthjs = <<"ENDSCRIPT";
7450:
7451: function warnIntAuth(field) {
7452: if (field.name == 'intauth_check') {
7453: if (field.value == '2') {
1.160.6.99 raeburn 7454: alert('$intalert{authcheck}');
1.160.6.98 raeburn 7455: }
7456: }
7457: if (field.name == 'intauth_cost') {
7458: field.value.replace(/\s/g,'');
7459: if (field.value != '') {
7460: var regexdigit=/^\\d+\$/;
7461: if (!regexdigit.test(field.value)) {
1.160.6.99 raeburn 7462: alert('$intalert{authcost}');
7463: }
7464: }
7465: }
7466: return;
7467: }
7468:
7469: function warnIntPass(field) {
7470: field.value.replace(/^\s+/,'');
7471: field.value.replace(/\s+\$/,'');
7472: var regexdigit=/^\\d+\$/;
7473: if (field.name == 'passwords_min') {
7474: if (field.value == '') {
7475: alert('$intalert{passmin}');
7476: field.value = '$defmin';
7477: } else {
7478: if (!regexdigit.test(field.value)) {
7479: alert('$intalert{passmin}');
7480: field.value = '$defmin';
7481: }
7482: var minval = parseInt(field.value,10);
7483: if (minval < $defmin) {
7484: alert('$intalert{passmin}');
7485: field.value = '$defmin';
7486: }
7487: }
7488: } else {
7489: if (field.value == '0') {
7490: field.value = '';
7491: }
7492: if (field.value != '') {
7493: if (field.name == 'passwords_expire') {
7494: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
7495: if (!regexpposnum.test(field.value)) {
7496: alert('$intalert{passexp}');
7497: field.value = '';
7498: } else {
7499: var expval = parseFloat(field.value);
7500: if (expval == 0) {
7501: alert('$intalert{passexp}');
7502: field.value = '';
7503: }
7504: }
7505: } else {
7506: if (!regexdigit.test(field.value)) {
7507: if (field.name == 'passwords_max') {
7508: alert('$intalert{passmax}');
7509: } else {
7510: if (field.name == 'passwords_numsaved') {
7511: alert('$intalert{passnum}');
7512: }
7513: }
1.160.6.104 raeburn 7514: field.value = '';
1.160.6.99 raeburn 7515: }
1.160.6.98 raeburn 7516: }
7517: }
7518: }
7519: return;
7520: }
7521:
7522: ENDSCRIPT
7523: return &Apache::lonhtmlcommon::scripttag($intauthjs);
7524: }
7525:
1.49 raeburn 7526: sub coursecategories_javascript {
7527: my ($settings) = @_;
1.57 raeburn 7528: my ($output,$jstext,$cathash);
1.49 raeburn 7529: if (ref($settings) eq 'HASH') {
1.57 raeburn 7530: $cathash = $settings->{'cats'};
7531: }
7532: if (ref($cathash) eq 'HASH') {
1.49 raeburn 7533: my (@cats,@jsarray,%idx);
1.57 raeburn 7534: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 7535: if (@jsarray > 0) {
7536: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
7537: for (my $i=0; $i<@jsarray; $i++) {
7538: if (ref($jsarray[$i]) eq 'ARRAY') {
7539: my $catstr = join('","',@{$jsarray[$i]});
7540: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
7541: }
7542: }
7543: }
7544: } else {
7545: $jstext = ' var categories = Array(1);'."\n".
7546: ' categories[0] = Array("instcode_pos");'."\n";
7547: }
1.160.6.42 raeburn 7548: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
7549: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 7550: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
7551: &js_escape(\$instcode_reserved);
7552: &js_escape(\$communities_reserved);
7553: &js_escape(\$choose_again);
1.49 raeburn 7554: $output = <<"ENDSCRIPT";
7555: <script type="text/javascript">
1.109 raeburn 7556: // <![CDATA[
1.49 raeburn 7557: function reorderCats(form,parent,item,idx) {
7558: var changedVal;
7559: $jstext
7560: var newpos = 'addcategory_pos';
7561: if (parent == '') {
7562: var has_instcode = 0;
7563: var maxtop = categories[idx].length;
7564: for (var j=0; j<maxtop; j++) {
7565: if (categories[idx][j] == 'instcode::0') {
7566: has_instcode == 1;
7567: }
7568: }
7569: if (has_instcode == 0) {
7570: categories[idx][maxtop] = 'instcode_pos';
7571: }
7572: } else {
7573: newpos += '_'+parent;
7574: }
7575: var maxh = 1 + categories[idx].length;
7576: var current = new Array;
7577: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7578: if (item == newpos) {
7579: changedVal = newitemVal;
7580: } else {
7581: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
7582: current[newitemVal] = newpos;
7583: }
7584: for (var i=0; i<categories[idx].length; i++) {
7585: var elementName = categories[idx][i];
7586: if (elementName != item) {
7587: if (form.elements[elementName]) {
7588: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7589: current[currVal] = elementName;
7590: }
7591: }
7592: }
7593: var oldVal;
7594: for (var j=0; j<maxh; j++) {
7595: if (current[j] == undefined) {
7596: oldVal = j;
7597: }
7598: }
7599: if (oldVal < changedVal) {
7600: for (var k=oldVal+1; k<=changedVal ; k++) {
7601: var elementName = current[k];
7602: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7603: }
7604: } else {
7605: for (var k=changedVal; k<oldVal; k++) {
7606: var elementName = current[k];
7607: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7608: }
7609: }
7610: return;
7611: }
1.120 raeburn 7612:
7613: function categoryCheck(form) {
7614: if (form.elements['addcategory_name'].value == 'instcode') {
7615: alert('$instcode_reserved\\n$choose_again');
7616: return false;
7617: }
7618: if (form.elements['addcategory_name'].value == 'communities') {
7619: alert('$communities_reserved\\n$choose_again');
7620: return false;
7621: }
7622: return true;
7623: }
7624:
1.109 raeburn 7625: // ]]>
1.49 raeburn 7626: </script>
7627:
7628: ENDSCRIPT
7629: return $output;
7630: }
7631:
1.48 raeburn 7632: sub initialize_categories {
7633: my ($itemcount) = @_;
1.120 raeburn 7634: my ($datatable,$css_class,$chgstr);
7635: my %default_names = (
7636: instcode => 'Official courses (with institutional codes)',
7637: communities => 'Communities',
7638: );
7639: my $select0 = ' selected="selected"';
7640: my $select1 = '';
7641: foreach my $default ('instcode','communities') {
7642: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 7643: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 7644: if ($default eq 'communities') {
7645: $select1 = $select0;
7646: $select0 = '';
7647: }
7648: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7649: .'<select name="'.$default.'_pos">'
7650: .'<option value="0"'.$select0.'>1</option>'
7651: .'<option value="1"'.$select1.'>2</option>'
7652: .'<option value="2">3</option></select> '
7653: .$default_names{$default}
7654: .'</span></td><td><span class="LC_nobreak">'
7655: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
7656: .&mt('Display').'</label> <label>'
7657: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 7658: .'</label></span></td></tr>';
1.120 raeburn 7659: $itemcount ++;
7660: }
1.48 raeburn 7661: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 7662: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 7663: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 7664: .'<select name="addcategory_pos"'.$chgstr.'>'
7665: .'<option value="0">1</option>'
7666: .'<option value="1">2</option>'
7667: .'<option value="2" selected="selected">3</option></select> '
1.160.6.103 raeburn 7668: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
1.160.6.87 raeburn 7669: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
7670: .'</td></tr>';
1.48 raeburn 7671: return $datatable;
7672: }
7673:
7674: sub build_category_rows {
1.49 raeburn 7675: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
7676: my ($text,$name,$item,$chgstr);
1.48 raeburn 7677: if (ref($cats) eq 'ARRAY') {
7678: my $maxdepth = scalar(@{$cats});
7679: if (ref($cats->[$depth]) eq 'HASH') {
7680: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
7681: my $numchildren = @{$cats->[$depth]{$parent}};
7682: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 7683: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 7684: my ($idxnum,$parent_name,$parent_item);
7685: my $higher = $depth - 1;
7686: if ($higher == 0) {
7687: $parent_name = &escape($parent).'::'.$higher;
7688: } else {
7689: if (ref($path) eq 'ARRAY') {
7690: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7691: }
7692: }
7693: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 7694: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 7695: if ($j < $numchildren) {
1.48 raeburn 7696: $name = $cats->[$depth]{$parent}[$j];
7697: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 7698: $idxnum = $idx->{$item};
7699: } else {
7700: $name = $parent_name;
7701: $item = $parent_item;
1.48 raeburn 7702: }
1.49 raeburn 7703: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
7704: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 7705: for (my $i=0; $i<=$numchildren; $i++) {
7706: my $vpos = $i+1;
7707: my $selstr;
7708: if ($j == $i) {
7709: $selstr = ' selected="selected" ';
7710: }
7711: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
7712: }
7713: $text .= '</select> ';
7714: if ($j < $numchildren) {
7715: my $deeper = $depth+1;
7716: $text .= $name.' '
7717: .'<label><input type="checkbox" name="deletecategory" value="'
7718: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
7719: if(ref($path) eq 'ARRAY') {
7720: push(@{$path},$name);
1.49 raeburn 7721: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 7722: pop(@{$path});
7723: }
7724: } else {
1.160.6.87 raeburn 7725: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 7726: if ($j == $numchildren) {
7727: $text .= $name;
7728: } else {
7729: $text .= $item;
7730: }
7731: $text .= '" value="" />';
7732: }
7733: $text .= '</td></tr>';
7734: }
7735: $text .= '</table></td>';
7736: } else {
7737: my $higher = $depth-1;
7738: if ($higher == 0) {
7739: $name = &escape($parent).'::'.$higher;
7740: } else {
7741: if (ref($path) eq 'ARRAY') {
7742: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7743: }
7744: }
7745: my $colspan;
7746: if ($parent ne 'instcode') {
7747: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 7748: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 7749: }
7750: }
7751: }
7752: }
7753: return $text;
7754: }
7755:
1.33 raeburn 7756: sub modifiable_userdata_row {
1.160.6.93 raeburn 7757: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
7758: $rowid,$customcss,$rowstyle) = @_;
1.160.6.35 raeburn 7759: my ($role,$rolename,$statustype);
7760: $role = $item;
1.160.6.34 raeburn 7761: if ($context eq 'cancreate') {
1.160.6.93 raeburn 7762: if ($item =~ /^(emailusername)_(.+)$/) {
7763: $role = $1;
7764: $statustype = $2;
1.160.6.35 raeburn 7765: if (ref($usertypes) eq 'HASH') {
7766: if ($usertypes->{$statustype}) {
7767: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
7768: } else {
7769: $rolename = &mt('Data provided by user');
7770: }
7771: }
1.160.6.34 raeburn 7772: }
7773: } elsif ($context eq 'selfcreate') {
1.63 raeburn 7774: if (ref($usertypes) eq 'HASH') {
7775: $rolename = $usertypes->{$role};
7776: } else {
7777: $rolename = $role;
7778: }
1.33 raeburn 7779: } else {
1.63 raeburn 7780: if ($role eq 'cr') {
7781: $rolename = &mt('Custom role');
7782: } else {
7783: $rolename = &Apache::lonnet::plaintext($role);
7784: }
1.33 raeburn 7785: }
1.160.6.34 raeburn 7786: my (@fields,%fieldtitles);
7787: if (ref($fieldsref) eq 'ARRAY') {
7788: @fields = @{$fieldsref};
7789: } else {
7790: @fields = ('lastname','firstname','middlename','generation',
7791: 'permanentemail','id');
7792: }
7793: if ((ref($titlesref) eq 'HASH')) {
7794: %fieldtitles = %{$titlesref};
7795: } else {
7796: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7797: }
1.33 raeburn 7798: my $output;
1.160.6.93 raeburn 7799: my $css_class;
7800: if ($rowcount%2) {
7801: $css_class = 'LC_odd_row';
7802: }
7803: if ($customcss) {
7804: $css_class .= " $customcss";
7805: }
7806: $css_class =~ s/^\s+//;
7807: if ($css_class) {
7808: $css_class = ' class="'.$css_class.'"';
7809: }
7810: if ($rowstyle) {
7811: $css_class .= ' style="'.$rowstyle.'"';
7812: }
7813: if ($rowid) {
7814: $rowid = ' id="'.$rowid.'"';
7815: }
7816:
7817: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 7818: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
7819: '<td class="LC_left_item" colspan="2"><table>';
7820: my $rem;
7821: my %checks;
7822: if (ref($settings) eq 'HASH') {
7823: if (ref($settings->{$context}) eq 'HASH') {
7824: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 7825: my $hashref = $settings->{$context}->{$role};
7826: if ($role eq 'emailusername') {
7827: if ($statustype) {
7828: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
7829: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 7830: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 7831: foreach my $field (@fields) {
7832: if ($hashref->{$field}) {
7833: $checks{$field} = $hashref->{$field};
7834: }
7835: }
7836: }
7837: }
7838: }
7839: } else {
7840: if (ref($hashref) eq 'HASH') {
7841: foreach my $field (@fields) {
7842: if ($hashref->{$field}) {
7843: $checks{$field} = ' checked="checked" ';
7844: }
7845: }
1.33 raeburn 7846: }
7847: }
7848: }
7849: }
7850: }
1.160.6.93 raeburn 7851:
7852: my $total = scalar(@fields);
7853: for (my $i=0; $i<$total; $i++) {
7854: $rem = $i%($numinrow);
1.33 raeburn 7855: if ($rem == 0) {
7856: if ($i > 0) {
7857: $output .= '</tr>';
7858: }
7859: $output .= '<tr>';
7860: }
7861: my $check = ' ';
1.160.6.35 raeburn 7862: unless ($role eq 'emailusername') {
7863: if (exists($checks{$fields[$i]})) {
1.160.6.98 raeburn 7864: $check = $checks{$fields[$i]};
1.160.6.35 raeburn 7865: } else {
7866: if ($role eq 'st') {
7867: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 7868: $check = ' checked="checked" ';
1.160.6.35 raeburn 7869: }
1.33 raeburn 7870: }
7871: }
7872: }
7873: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 7874: '<span class="LC_nobreak">';
7875: if ($role eq 'emailusername') {
7876: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
7877: $checks{$fields[$i]} = 'omit';
7878: }
7879: foreach my $option ('required','optional','omit') {
7880: my $checked='';
7881: if ($checks{$fields[$i]} eq $option) {
7882: $checked='checked="checked" ';
7883: }
7884: $output .= '<label>'.
7885: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
7886: &mt($option).'</label>'.(' ' x2);
7887: }
7888: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
7889: } else {
7890: $output .= '<label>'.
7891: '<input type="checkbox" name="canmodify_'.$role.'" '.
7892: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
7893: '</label>';
7894: }
7895: $output .= '</span></td>';
1.33 raeburn 7896: }
1.160.6.93 raeburn 7897: $rem = $total%$numinrow;
7898: my $colsleft;
7899: if ($rem) {
7900: $colsleft = $numinrow - $rem;
7901: }
7902: if ($colsleft > 1) {
1.33 raeburn 7903: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7904: ' </td>';
7905: } elsif ($colsleft == 1) {
7906: $output .= '<td class="LC_left_item"> </td>';
7907: }
7908: $output .= '</tr></table></td></tr>';
7909: return $output;
7910: }
1.28 raeburn 7911:
1.93 raeburn 7912: sub insttypes_row {
1.160.6.93 raeburn 7913: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
7914: $customcss,$rowstyle) = @_;
1.93 raeburn 7915: my %lt = &Apache::lonlocal::texthash (
7916: cansearch => 'Users allowed to search',
7917: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 7918: lockablenames => 'User preference to lock name',
1.160.6.93 raeburn 7919: selfassign => 'Self-reportable affiliations',
1.160.6.101 raeburn 7920: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 7921: );
7922: my $showdom;
7923: if ($context eq 'cansearch') {
7924: $showdom = ' ('.$dom.')';
7925: }
1.160.6.5 raeburn 7926: my $class = 'LC_left_item';
7927: if ($context eq 'statustocreate') {
7928: $class = 'LC_right_item';
7929: }
1.160.6.93 raeburn 7930: my $css_class;
7931: if ($$rowtotal%2) {
7932: $css_class = 'LC_odd_row';
7933: }
7934: if ($customcss) {
7935: $css_class .= ' '.$customcss;
7936: }
7937: $css_class =~ s/^\s+//;
7938: if ($css_class) {
7939: $css_class = ' class="'.$css_class.'"';
7940: }
7941: if ($rowstyle) {
7942: $css_class .= ' style="'.$rowstyle.'"';
7943: }
7944: if ($onclick) {
7945: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 7946: }
7947: my $output = '<tr'.$css_class.'>'.
7948: '<td>'.$lt{$context}.$showdom.
7949: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 7950: my $rem;
7951: if (ref($types) eq 'ARRAY') {
7952: for (my $i=0; $i<@{$types}; $i++) {
7953: if (defined($usertypes->{$types->[$i]})) {
7954: my $rem = $i%($numinrow);
7955: if ($rem == 0) {
7956: if ($i > 0) {
7957: $output .= '</tr>';
7958: }
7959: $output .= '<tr>';
1.23 raeburn 7960: }
1.26 raeburn 7961: my $check = ' ';
1.99 raeburn 7962: if (ref($settings) eq 'HASH') {
7963: if (ref($settings->{$context}) eq 'ARRAY') {
7964: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
7965: $check = ' checked="checked" ';
7966: }
1.160.6.101 raeburn 7967: } elsif (ref($settings->{$context}) eq 'HASH') {
7968: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
7969: $check = ' checked="checked" ';
7970: }
1.99 raeburn 7971: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7972: $check = ' checked="checked" ';
7973: }
1.23 raeburn 7974: }
1.26 raeburn 7975: $output .= '<td class="LC_left_item">'.
7976: '<span class="LC_nobreak"><label>'.
1.93 raeburn 7977: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 7978: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
1.26 raeburn 7979: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 7980: }
7981: }
1.26 raeburn 7982: $rem = @{$types}%($numinrow);
1.23 raeburn 7983: }
7984: my $colsleft = $numinrow - $rem;
1.160.6.101 raeburn 7985: if ($context eq 'overrides') {
7986: if ($colsleft > 1) {
7987: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
7988: } else {
7989: $output .= '<td class="LC_left_item">';
7990: }
7991: $output .= ' ';
1.23 raeburn 7992: } else {
1.160.6.101 raeburn 7993: if ($rem == 0) {
7994: $output .= '<tr>';
7995: }
7996: if ($colsleft > 1) {
7997: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
7998: } else {
7999: $output .= '<td class="LC_left_item">';
8000: }
8001: my $defcheck = ' ';
8002: if (ref($settings) eq 'HASH') {
8003: if (ref($settings->{$context}) eq 'ARRAY') {
8004: if (grep(/^default$/,@{$settings->{$context}})) {
8005: $defcheck = ' checked="checked" ';
8006: }
8007: } elsif ($context eq 'statustocreate') {
1.99 raeburn 8008: $defcheck = ' checked="checked" ';
8009: }
1.26 raeburn 8010: }
1.160.6.101 raeburn 8011: $output .= '<span class="LC_nobreak"><label>'.
8012: '<input type="checkbox" name="'.$context.'" '.
8013: 'value="default"'.$defcheck.$onclick.' />'.
8014: $othertitle.'</label></span>';
1.23 raeburn 8015: }
1.160.6.101 raeburn 8016: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 8017: return $output;
1.23 raeburn 8018: }
8019:
8020: sub sorted_searchtitles {
8021: my %searchtitles = &Apache::lonlocal::texthash(
8022: 'uname' => 'username',
8023: 'lastname' => 'last name',
8024: 'lastfirst' => 'last name, first name',
8025: );
8026: my @titleorder = ('uname','lastname','lastfirst');
8027: return (\%searchtitles,\@titleorder);
8028: }
8029:
1.25 raeburn 8030: sub sorted_searchtypes {
8031: my %srchtypes_desc = (
8032: exact => 'is exact match',
8033: contains => 'contains ..',
8034: begins => 'begins with ..',
8035: );
8036: my @srchtypeorder = ('exact','begins','contains');
8037: return (\%srchtypes_desc,\@srchtypeorder);
8038: }
8039:
1.3 raeburn 8040: sub usertype_update_row {
8041: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
8042: my $datatable;
8043: my $numinrow = 4;
8044: foreach my $type (@{$types}) {
8045: if (defined($usertypes->{$type})) {
8046: $$rownums ++;
8047: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
8048: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
8049: '</td><td class="LC_left_item"><table>';
8050: for (my $i=0; $i<@{$fields}; $i++) {
8051: my $rem = $i%($numinrow);
8052: if ($rem == 0) {
8053: if ($i > 0) {
8054: $datatable .= '</tr>';
8055: }
8056: $datatable .= '<tr>';
8057: }
8058: my $check = ' ';
1.39 raeburn 8059: if (ref($settings) eq 'HASH') {
8060: if (ref($settings->{'fields'}) eq 'HASH') {
8061: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
8062: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
8063: $check = ' checked="checked" ';
8064: }
1.3 raeburn 8065: }
8066: }
8067: }
8068:
8069: if ($i == @{$fields}-1) {
8070: my $colsleft = $numinrow - $rem;
8071: if ($colsleft > 1) {
8072: $datatable .= '<td colspan="'.$colsleft.'">';
8073: } else {
8074: $datatable .= '<td>';
8075: }
8076: } else {
8077: $datatable .= '<td>';
8078: }
1.8 raeburn 8079: $datatable .= '<span class="LC_nobreak"><label>'.
8080: '<input type="checkbox" name="updateable_'.$type.
8081: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
8082: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 8083: }
8084: $datatable .= '</tr></table></td></tr>';
8085: }
8086: }
8087: return $datatable;
1.1 raeburn 8088: }
8089:
8090: sub modify_login {
1.160.6.24 raeburn 8091: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 8092: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
8093: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
8094: %title = ( coursecatalog => 'Display course catalog',
8095: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 8096: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 8097: newuser => 'Link for visitors to create a user account',
8098: loginheader => 'Log-in box header');
8099: @offon = ('off','on');
1.112 raeburn 8100: if (ref($domconfig{login}) eq 'HASH') {
8101: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
8102: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
8103: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
8104: }
8105: }
8106: }
1.9 raeburn 8107: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
8108: \%domconfig,\%loginhash);
1.160.6.14 raeburn 8109: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8110: foreach my $item (@toggles) {
8111: $loginhash{login}{$item} = $env{'form.'.$item};
8112: }
1.41 raeburn 8113: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 8114: if (ref($colchanges{'login'}) eq 'HASH') {
8115: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
8116: \%loginhash);
8117: }
1.110 raeburn 8118:
1.149 raeburn 8119: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 8120: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 8121: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 8122: if (keys(%servers) > 1) {
8123: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 8124: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
8125: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
8126: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
8127: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
8128: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
8129: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8130: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8131: $changes{'loginvia'}{$lonhost} = 1;
8132: } else {
8133: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
8134: $changes{'loginvia'}{$lonhost} = 1;
8135: }
8136: } else {
8137: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8138: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8139: $changes{'loginvia'}{$lonhost} = 1;
8140: }
8141: }
8142: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
8143: foreach my $item (@loginvia_attribs) {
8144: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
8145: }
8146: } else {
8147: foreach my $item (@loginvia_attribs) {
8148: my $new = $env{'form.'.$lonhost.'_'.$item};
8149: if (($item eq 'serverpath') && ($new eq 'custom')) {
8150: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
8151: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8152: $new = '/';
8153: }
8154: }
8155: if (($item eq 'custompath') &&
8156: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8157: $new = '';
8158: }
8159: if ($new ne $curr_loginvia{$lonhost}{$item}) {
8160: $changes{'loginvia'}{$lonhost} = 1;
8161: }
8162: if ($item eq 'exempt') {
1.160.6.56 raeburn 8163: $new = &check_exempt_addresses($new);
1.128 raeburn 8164: }
8165: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8166: }
8167: }
1.112 raeburn 8168: } else {
1.128 raeburn 8169: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8170: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 8171: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 8172: foreach my $item (@loginvia_attribs) {
8173: my $new = $env{'form.'.$lonhost.'_'.$item};
8174: if (($item eq 'serverpath') && ($new eq 'custom')) {
8175: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8176: $new = '/';
8177: }
8178: }
8179: if (($item eq 'custompath') &&
8180: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8181: $new = '';
8182: }
8183: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8184: }
1.110 raeburn 8185: }
8186: }
8187: }
8188: }
1.119 raeburn 8189:
1.160.6.5 raeburn 8190: my $servadm = $r->dir_config('lonAdmEMail');
8191: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
8192: if (ref($domconfig{'login'}) eq 'HASH') {
8193: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
8194: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
8195: if ($lang eq 'nolang') {
8196: push(@currlangs,$lang);
8197: } elsif (defined($langchoices{$lang})) {
8198: push(@currlangs,$lang);
8199: } else {
8200: next;
8201: }
8202: }
8203: }
8204: }
8205: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
8206: if (@currlangs > 0) {
8207: foreach my $lang (@currlangs) {
8208: if (grep(/^\Q$lang\E$/,@delurls)) {
8209: $changes{'helpurl'}{$lang} = 1;
8210: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
8211: $changes{'helpurl'}{$lang} = 1;
8212: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
8213: push(@newlangs,$lang);
8214: } else {
8215: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8216: }
8217: }
8218: }
8219: unless (grep(/^nolang$/,@currlangs)) {
8220: if ($env{'form.loginhelpurl_nolang.filename'}) {
8221: $changes{'helpurl'}{'nolang'} = 1;
8222: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
8223: push(@newlangs,'nolang');
8224: }
8225: }
8226: if ($env{'form.loginhelpurl_add_lang'}) {
8227: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
8228: ($env{'form.loginhelpurl_add_file.filename'})) {
8229: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
8230: $addedfile = $env{'form.loginhelpurl_add_lang'};
8231: }
8232: }
8233: if ((@newlangs > 0) || ($addedfile)) {
8234: my $error;
8235: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8236: if ($configuserok eq 'ok') {
8237: if ($switchserver) {
8238: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
8239: } elsif ($author_ok eq 'ok') {
8240: my @allnew = @newlangs;
8241: if ($addedfile ne '') {
8242: push(@allnew,$addedfile);
8243: }
8244: foreach my $lang (@allnew) {
8245: my $formelem = 'loginhelpurl_'.$lang;
8246: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
8247: $formelem = 'loginhelpurl_add_file';
8248: }
8249: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8250: "help/$lang",'','',$newfile{$lang});
8251: if ($result eq 'ok') {
8252: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
8253: $changes{'helpurl'}{$lang} = 1;
8254: } else {
8255: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
8256: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
8257: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
8258: (!grep(/^\Q$lang\E$/,@delurls))) {
8259: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8260: }
8261: }
8262: }
8263: } else {
8264: $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);
8265: }
8266: } else {
8267: $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);
8268: }
8269: if ($error) {
8270: &Apache::lonnet::logthis($error);
8271: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8272: }
8273: }
1.160.6.56 raeburn 8274:
8275: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
8276: if (ref($domconfig{'login'}) eq 'HASH') {
8277: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
8278: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
8279: if ($domservers{$lonhost}) {
8280: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8281: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 8282: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 8283: }
8284: }
8285: }
8286: }
8287: }
8288: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
8289: foreach my $lonhost (sort(keys(%domservers))) {
8290: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8291: $changes{'headtag'}{$lonhost} = 1;
8292: } else {
8293: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
8294: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
8295: }
8296: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
8297: push(@newhosts,$lonhost);
8298: } elsif ($currheadtagurls{$lonhost}) {
8299: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
8300: if ($currexempt{$lonhost}) {
8301: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
8302: $changes{'headtag'}{$lonhost} = 1;
8303: }
8304: } elsif ($possexempt{$lonhost}) {
8305: $changes{'headtag'}{$lonhost} = 1;
8306: }
8307: if ($possexempt{$lonhost}) {
8308: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8309: }
8310: }
8311: }
8312: }
8313: if (@newhosts) {
8314: my $error;
8315: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8316: if ($configuserok eq 'ok') {
8317: if ($switchserver) {
8318: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
8319: } elsif ($author_ok eq 'ok') {
8320: foreach my $lonhost (@newhosts) {
8321: my $formelem = 'loginheadtag_'.$lonhost;
8322: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8323: "login/headtag/$lonhost",'','',
8324: $env{'form.loginheadtag_'.$lonhost.'.filename'});
8325: if ($result eq 'ok') {
8326: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
8327: $changes{'headtag'}{$lonhost} = 1;
8328: if ($possexempt{$lonhost}) {
8329: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8330: }
8331: } else {
8332: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
8333: $newheadtagurls{$lonhost},$result);
8334: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
8335: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
8336: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
8337: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
8338: }
8339: }
8340: }
8341: } else {
8342: $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);
8343: }
8344: } else {
8345: $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);
8346: }
8347: if ($error) {
8348: &Apache::lonnet::logthis($error);
8349: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8350: }
8351: }
1.160.6.5 raeburn 8352: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
8353:
8354: my $defaulthelpfile = '/adm/loginproblems.html';
8355: my $defaulttext = &mt('Default in use');
8356:
1.1 raeburn 8357: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
8358: $dom);
8359: if ($putresult eq 'ok') {
1.160.6.14 raeburn 8360: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8361: my %defaultchecked = (
8362: 'coursecatalog' => 'on',
1.160.6.14 raeburn 8363: 'helpdesk' => 'on',
1.42 raeburn 8364: 'adminmail' => 'off',
1.43 raeburn 8365: 'newuser' => 'off',
1.42 raeburn 8366: );
1.55 raeburn 8367: if (ref($domconfig{'login'}) eq 'HASH') {
8368: foreach my $item (@toggles) {
8369: if ($defaultchecked{$item} eq 'on') {
8370: if (($domconfig{'login'}{$item} eq '0') &&
8371: ($env{'form.'.$item} eq '1')) {
8372: $changes{$item} = 1;
8373: } elsif (($domconfig{'login'}{$item} eq '' ||
8374: $domconfig{'login'}{$item} eq '1') &&
8375: ($env{'form.'.$item} eq '0')) {
8376: $changes{$item} = 1;
8377: }
8378: } elsif ($defaultchecked{$item} eq 'off') {
8379: if (($domconfig{'login'}{$item} eq '1') &&
8380: ($env{'form.'.$item} eq '0')) {
8381: $changes{$item} = 1;
8382: } elsif (($domconfig{'login'}{$item} eq '' ||
8383: $domconfig{'login'}{$item} eq '0') &&
8384: ($env{'form.'.$item} eq '1')) {
8385: $changes{$item} = 1;
8386: }
1.42 raeburn 8387: }
8388: }
1.41 raeburn 8389: }
1.6 raeburn 8390: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 8391: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8392: if (ref($lastactref) eq 'HASH') {
8393: $lastactref->{'domainconfig'} = 1;
8394: }
1.1 raeburn 8395: $resulttext = &mt('Changes made:').'<ul>';
8396: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 8397: if ($item eq 'loginvia') {
1.112 raeburn 8398: if (ref($changes{$item}) eq 'HASH') {
8399: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
8400: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 8401: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
8402: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
8403: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
8404: $protocol = 'http' if ($protocol ne 'https');
8405: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
8406:
8407: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
8408: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
8409: } else {
8410: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
8411: }
8412: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
8413: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
8414: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
8415: }
8416: $resulttext .= '</li>';
8417: } else {
8418: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
8419: }
1.112 raeburn 8420: } else {
1.128 raeburn 8421: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 8422: }
8423: }
1.128 raeburn 8424: $resulttext .= '</ul></li>';
1.112 raeburn 8425: }
1.160.6.5 raeburn 8426: } elsif ($item eq 'helpurl') {
8427: if (ref($changes{$item}) eq 'HASH') {
8428: foreach my $lang (sort(keys(%{$changes{$item}}))) {
8429: if (grep(/^\Q$lang\E$/,@delurls)) {
8430: my ($chg,$link);
8431: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
8432: if ($lang eq 'nolang') {
8433: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
8434: } else {
8435: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
8436: }
8437: $resulttext .= '<li>'.$chg.'</li>';
8438: } else {
8439: my $chg;
8440: if ($lang eq 'nolang') {
8441: $chg = &mt('custom log-in help file for no preferred language');
8442: } else {
8443: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
8444: }
8445: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
8446: $loginhash{'login'}{'helpurl'}{$lang}.
8447: '?inhibitmenu=yes',$chg,600,500).
8448: '</li>';
8449: }
8450: }
8451: }
1.160.6.56 raeburn 8452: } elsif ($item eq 'headtag') {
8453: if (ref($changes{$item}) eq 'HASH') {
8454: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
8455: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8456: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
8457: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8458: $resulttext .= '<li><a href="'.
8459: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
8460: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
8461: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
8462: if ($possexempt{$lonhost}) {
8463: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
8464: } else {
8465: $resulttext .= &mt('included for any client IP');
8466: }
8467: $resulttext .= '</li>';
8468: }
8469: }
8470: }
1.160.6.5 raeburn 8471: } elsif ($item eq 'captcha') {
8472: if (ref($loginhash{'login'}) eq 'HASH') {
8473: my $chgtxt;
8474: if ($loginhash{'login'}{$item} eq 'notused') {
8475: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
8476: } else {
8477: my %captchas = &captcha_phrases();
8478: if ($captchas{$loginhash{'login'}{$item}}) {
8479: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
8480: } else {
8481: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
8482: }
8483: }
8484: $resulttext .= '<li>'.$chgtxt.'</li>';
8485: }
8486: } elsif ($item eq 'recaptchakeys') {
8487: if (ref($loginhash{'login'}) eq 'HASH') {
8488: my ($privkey,$pubkey);
8489: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
8490: $pubkey = $loginhash{'login'}{$item}{'public'};
8491: $privkey = $loginhash{'login'}{$item}{'private'};
8492: }
8493: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
8494: if (!$pubkey) {
8495: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
8496: } else {
8497: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8498: }
8499: if (!$privkey) {
8500: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
8501: } else {
1.160.6.53 raeburn 8502: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 8503: }
8504: $chgtxt .= '</ul>';
8505: $resulttext .= '<li>'.$chgtxt.'</li>';
8506: }
1.160.6.69 raeburn 8507: } elsif ($item eq 'recaptchaversion') {
8508: if (ref($loginhash{'login'}) eq 'HASH') {
8509: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
8510: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
8511: '</li>';
8512: }
8513: }
1.41 raeburn 8514: } else {
8515: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
8516: }
1.1 raeburn 8517: }
1.6 raeburn 8518: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 8519: } else {
8520: $resulttext = &mt('No changes made to log-in page settings');
8521: }
8522: } else {
1.11 albertel 8523: $resulttext = '<span class="LC_error">'.
8524: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8525: }
1.6 raeburn 8526: if ($errors) {
1.9 raeburn 8527: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 8528: $errors.'</ul>';
8529: }
8530: return $resulttext;
8531: }
8532:
1.160.6.56 raeburn 8533: sub check_exempt_addresses {
8534: my ($iplist) = @_;
8535: $iplist =~ s/^\s+//;
8536: $iplist =~ s/\s+$//;
8537: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
8538: my (@okips,$new);
8539: foreach my $ip (@poss_ips) {
8540: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
8541: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
8542: push(@okips,$ip);
8543: }
8544: }
8545: }
8546: if (@okips > 0) {
8547: $new = join(',',@okips);
8548: } else {
8549: $new = '';
8550: }
8551: return $new;
8552: }
8553:
1.6 raeburn 8554: sub color_font_choices {
8555: my %choices =
8556: &Apache::lonlocal::texthash (
8557: img => "Header",
8558: bgs => "Background colors",
8559: links => "Link colors",
1.55 raeburn 8560: images => "Images",
1.6 raeburn 8561: font => "Font color",
1.160.6.22 raeburn 8562: fontmenu => "Font menu",
1.76 raeburn 8563: pgbg => "Page",
1.6 raeburn 8564: tabbg => "Header",
8565: sidebg => "Border",
8566: link => "Link",
8567: alink => "Active link",
8568: vlink => "Visited link",
8569: );
8570: return %choices;
8571: }
8572:
8573: sub modify_rolecolors {
1.160.6.24 raeburn 8574: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 8575: my ($resulttext,%rolehash);
8576: $rolehash{'rolecolors'} = {};
1.55 raeburn 8577: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
8578: if ($domconfig{'rolecolors'} eq '') {
8579: $domconfig{'rolecolors'} = {};
8580: }
8581: }
1.9 raeburn 8582: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 8583: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
8584: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
8585: $dom);
8586: if ($putresult eq 'ok') {
8587: if (keys(%changes) > 0) {
1.41 raeburn 8588: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8589: if (ref($lastactref) eq 'HASH') {
8590: $lastactref->{'domainconfig'} = 1;
8591: }
1.6 raeburn 8592: $resulttext = &display_colorchgs($dom,\%changes,$roles,
8593: $rolehash{'rolecolors'});
8594: } else {
8595: $resulttext = &mt('No changes made to default color schemes');
8596: }
8597: } else {
1.11 albertel 8598: $resulttext = '<span class="LC_error">'.
8599: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 8600: }
8601: if ($errors) {
8602: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8603: $errors.'</ul>';
8604: }
8605: return $resulttext;
8606: }
8607:
8608: sub modify_colors {
1.9 raeburn 8609: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 8610: my (%changes,%choices);
1.51 raeburn 8611: my @bgs;
1.6 raeburn 8612: my @links = ('link','alink','vlink');
1.41 raeburn 8613: my @logintext;
1.6 raeburn 8614: my @images;
8615: my $servadm = $r->dir_config('lonAdmEMail');
8616: my $errors;
1.160.6.22 raeburn 8617: my %defaults;
1.6 raeburn 8618: foreach my $role (@{$roles}) {
8619: if ($role eq 'login') {
1.12 raeburn 8620: %choices = &login_choices();
1.41 raeburn 8621: @logintext = ('textcol','bgcol');
1.12 raeburn 8622: } else {
8623: %choices = &color_font_choices();
8624: }
8625: if ($role eq 'login') {
1.41 raeburn 8626: @images = ('img','logo','domlogo','login');
1.51 raeburn 8627: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 8628: } else {
8629: @images = ('img');
1.160.6.22 raeburn 8630: @bgs = ('pgbg','tabbg','sidebg');
8631: }
8632: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
8633: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
8634: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
8635: }
8636: if ($role eq 'login') {
8637: foreach my $item (@logintext) {
1.160.6.39 raeburn 8638: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8639: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8640: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8641: }
8642: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 8643: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8644: }
8645: }
8646: } else {
1.160.6.39 raeburn 8647: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
8648: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
8649: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
8650: }
8651: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 8652: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
8653: }
1.6 raeburn 8654: }
1.160.6.22 raeburn 8655: foreach my $item (@bgs) {
1.160.6.39 raeburn 8656: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8657: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8658: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8659: }
8660: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 8661: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8662: }
8663: }
8664: foreach my $item (@links) {
1.160.6.39 raeburn 8665: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8666: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8667: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8668: }
8669: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 8670: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8671: }
1.6 raeburn 8672: }
1.46 raeburn 8673: my ($configuserok,$author_ok,$switchserver) =
8674: &config_check($dom,$confname,$servadm);
1.9 raeburn 8675: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 8676: if (ref($domconfig->{$role}) ne 'HASH') {
8677: $domconfig->{$role} = {};
8678: }
1.8 raeburn 8679: foreach my $img (@images) {
1.70 raeburn 8680: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
8681: if (defined($env{'form.login_showlogo_'.$img})) {
8682: $confhash->{$role}{'showlogo'}{$img} = 1;
8683: } else {
8684: $confhash->{$role}{'showlogo'}{$img} = 0;
8685: }
8686: }
1.18 albertel 8687: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
8688: && !defined($domconfig->{$role}{$img})
8689: && !$env{'form.'.$role.'_del_'.$img}
8690: && $env{'form.'.$role.'_import_'.$img}) {
8691: # import the old configured image from the .tab setting
8692: # if they haven't provided a new one
8693: $domconfig->{$role}{$img} =
8694: $env{'form.'.$role.'_import_'.$img};
8695: }
1.6 raeburn 8696: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 8697: my $error;
1.6 raeburn 8698: if ($configuserok eq 'ok') {
1.9 raeburn 8699: if ($switchserver) {
1.12 raeburn 8700: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 8701: } else {
8702: if ($author_ok eq 'ok') {
8703: my ($result,$logourl) =
8704: &publishlogo($r,'upload',$role.'_'.$img,
8705: $dom,$confname,$img,$width,$height);
8706: if ($result eq 'ok') {
8707: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 8708: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8709: } else {
1.12 raeburn 8710: $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 8711: }
8712: } else {
1.46 raeburn 8713: $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 8714: }
8715: }
8716: } else {
1.46 raeburn 8717: $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 8718: }
8719: if ($error) {
1.8 raeburn 8720: &Apache::lonnet::logthis($error);
1.11 albertel 8721: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 8722: }
8723: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 8724: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
8725: my $error;
8726: if ($configuserok eq 'ok') {
8727: # is confname an author?
8728: if ($switchserver eq '') {
8729: if ($author_ok eq 'ok') {
8730: my ($result,$logourl) =
8731: &publishlogo($r,'copy',$domconfig->{$role}{$img},
8732: $dom,$confname,$img,$width,$height);
8733: if ($result eq 'ok') {
8734: $confhash->{$role}{$img} = $logourl;
1.18 albertel 8735: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8736: }
8737: }
8738: }
8739: }
1.6 raeburn 8740: }
8741: }
8742: }
8743: if (ref($domconfig) eq 'HASH') {
8744: if (ref($domconfig->{$role}) eq 'HASH') {
8745: foreach my $img (@images) {
8746: if ($domconfig->{$role}{$img} ne '') {
8747: if ($env{'form.'.$role.'_del_'.$img}) {
8748: $confhash->{$role}{$img} = '';
1.12 raeburn 8749: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8750: } else {
1.9 raeburn 8751: if ($confhash->{$role}{$img} eq '') {
8752: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
8753: }
1.6 raeburn 8754: }
8755: } else {
8756: if ($env{'form.'.$role.'_del_'.$img}) {
8757: $confhash->{$role}{$img} = '';
1.12 raeburn 8758: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8759: }
8760: }
1.70 raeburn 8761: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
8762: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
8763: if ($confhash->{$role}{'showlogo'}{$img} ne
8764: $domconfig->{$role}{'showlogo'}{$img}) {
8765: $changes{$role}{'showlogo'}{$img} = 1;
8766: }
8767: } else {
8768: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8769: $changes{$role}{'showlogo'}{$img} = 1;
8770: }
8771: }
8772: }
8773: }
1.6 raeburn 8774: if ($domconfig->{$role}{'font'} ne '') {
8775: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
8776: $changes{$role}{'font'} = 1;
8777: }
8778: } else {
8779: if ($confhash->{$role}{'font'}) {
8780: $changes{$role}{'font'} = 1;
8781: }
8782: }
1.107 raeburn 8783: if ($role ne 'login') {
8784: if ($domconfig->{$role}{'fontmenu'} ne '') {
8785: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
8786: $changes{$role}{'fontmenu'} = 1;
8787: }
8788: } else {
8789: if ($confhash->{$role}{'fontmenu'}) {
8790: $changes{$role}{'fontmenu'} = 1;
8791: }
1.97 tempelho 8792: }
8793: }
1.6 raeburn 8794: foreach my $item (@bgs) {
8795: if ($domconfig->{$role}{$item} ne '') {
8796: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8797: $changes{$role}{'bgs'}{$item} = 1;
8798: }
8799: } else {
8800: if ($confhash->{$role}{$item}) {
8801: $changes{$role}{'bgs'}{$item} = 1;
8802: }
8803: }
8804: }
8805: foreach my $item (@links) {
8806: if ($domconfig->{$role}{$item} ne '') {
8807: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8808: $changes{$role}{'links'}{$item} = 1;
8809: }
8810: } else {
8811: if ($confhash->{$role}{$item}) {
8812: $changes{$role}{'links'}{$item} = 1;
8813: }
8814: }
8815: }
1.41 raeburn 8816: foreach my $item (@logintext) {
8817: if ($domconfig->{$role}{$item} ne '') {
8818: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8819: $changes{$role}{'logintext'}{$item} = 1;
8820: }
8821: } else {
8822: if ($confhash->{$role}{$item}) {
8823: $changes{$role}{'logintext'}{$item} = 1;
8824: }
8825: }
8826: }
1.6 raeburn 8827: } else {
8828: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8829: \@logintext,$confhash,\%changes);
1.6 raeburn 8830: }
8831: } else {
8832: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8833: \@logintext,$confhash,\%changes);
1.6 raeburn 8834: }
8835: }
8836: return ($errors,%changes);
8837: }
8838:
1.46 raeburn 8839: sub config_check {
8840: my ($dom,$confname,$servadm) = @_;
8841: my ($configuserok,$author_ok,$switchserver,%currroles);
8842: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8843: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8844: $confname,$servadm);
8845: if ($configuserok eq 'ok') {
8846: $switchserver = &check_switchserver($dom,$confname);
8847: if ($switchserver eq '') {
8848: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8849: }
8850: }
8851: return ($configuserok,$author_ok,$switchserver);
8852: }
8853:
1.6 raeburn 8854: sub default_change_checker {
1.41 raeburn 8855: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 8856: foreach my $item (@{$links}) {
8857: if ($confhash->{$role}{$item}) {
8858: $changes->{$role}{'links'}{$item} = 1;
8859: }
8860: }
8861: foreach my $item (@{$bgs}) {
8862: if ($confhash->{$role}{$item}) {
8863: $changes->{$role}{'bgs'}{$item} = 1;
8864: }
8865: }
1.41 raeburn 8866: foreach my $item (@{$logintext}) {
8867: if ($confhash->{$role}{$item}) {
8868: $changes->{$role}{'logintext'}{$item} = 1;
8869: }
8870: }
1.6 raeburn 8871: foreach my $img (@{$images}) {
8872: if ($env{'form.'.$role.'_del_'.$img}) {
8873: $confhash->{$role}{$img} = '';
1.12 raeburn 8874: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 8875: }
1.70 raeburn 8876: if ($role eq 'login') {
8877: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8878: $changes->{$role}{'showlogo'}{$img} = 1;
8879: }
8880: }
1.6 raeburn 8881: }
8882: if ($confhash->{$role}{'font'}) {
8883: $changes->{$role}{'font'} = 1;
8884: }
1.48 raeburn 8885: }
1.6 raeburn 8886:
8887: sub display_colorchgs {
8888: my ($dom,$changes,$roles,$confhash) = @_;
8889: my (%choices,$resulttext);
8890: if (!grep(/^login$/,@{$roles})) {
8891: $resulttext = &mt('Changes made:').'<br />';
8892: }
8893: foreach my $role (@{$roles}) {
8894: if ($role eq 'login') {
8895: %choices = &login_choices();
8896: } else {
8897: %choices = &color_font_choices();
8898: }
8899: if (ref($changes->{$role}) eq 'HASH') {
8900: if ($role ne 'login') {
8901: $resulttext .= '<h4>'.&mt($role).'</h4>';
8902: }
8903: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8904: if ($role ne 'login') {
8905: $resulttext .= '<ul>';
8906: }
8907: if (ref($changes->{$role}{$key}) eq 'HASH') {
8908: if ($role ne 'login') {
8909: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
8910: }
8911: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 8912: if (($role eq 'login') && ($key eq 'showlogo')) {
8913: if ($confhash->{$role}{$key}{$item}) {
8914: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
8915: } else {
8916: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
8917: }
8918: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 8919: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
8920: } else {
1.12 raeburn 8921: my $newitem = $confhash->{$role}{$item};
8922: if ($key eq 'images') {
8923: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
8924: }
8925: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 8926: }
8927: }
8928: if ($role ne 'login') {
8929: $resulttext .= '</ul></li>';
8930: }
8931: } else {
8932: if ($confhash->{$role}{$key} eq '') {
8933: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
8934: } else {
8935: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8936: }
8937: }
8938: if ($role ne 'login') {
8939: $resulttext .= '</ul>';
8940: }
8941: }
8942: }
8943: }
1.3 raeburn 8944: return $resulttext;
1.1 raeburn 8945: }
8946:
1.9 raeburn 8947: sub thumb_dimensions {
8948: return ('200','50');
8949: }
8950:
1.16 raeburn 8951: sub check_dimensions {
8952: my ($inputfile) = @_;
8953: my ($fullwidth,$fullheight);
8954: if ($inputfile =~ m|^[/\w.\-]+$|) {
8955: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8956: my $imageinfo = <PIPE>;
8957: if (!close(PIPE)) {
8958: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8959: }
8960: chomp($imageinfo);
8961: my ($fullsize) =
1.21 raeburn 8962: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 8963: if ($fullsize) {
8964: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8965: }
8966: }
8967: }
8968: return ($fullwidth,$fullheight);
8969: }
8970:
1.9 raeburn 8971: sub check_configuser {
8972: my ($uhome,$dom,$confname,$servadm) = @_;
8973: my ($configuserok,%currroles);
8974: if ($uhome eq 'no_host') {
8975: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98 raeburn 8976: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 8977: $configuserok =
8978: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8979: $configpass,'','','','','',undef,$servadm);
8980: } else {
8981: $configuserok = 'ok';
8982: %currroles =
8983: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
8984: }
8985: return ($configuserok,%currroles);
8986: }
8987:
8988: sub check_authorstatus {
8989: my ($dom,$confname,%currroles) = @_;
8990: my $author_ok;
1.40 raeburn 8991: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 8992: my $start = time;
8993: my $end = 0;
8994: $author_ok =
8995: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 8996: 'au',$end,$start,'','','domconfig');
1.9 raeburn 8997: } else {
8998: $author_ok = 'ok';
8999: }
9000: return $author_ok;
9001: }
9002:
9003: sub publishlogo {
1.46 raeburn 9004: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 9005: my ($output,$fname,$logourl);
9006: if ($action eq 'upload') {
9007: $fname=$env{'form.'.$formname.'.filename'};
9008: chop($env{'form.'.$formname});
9009: } else {
9010: ($fname) = ($formname =~ /([^\/]+)$/);
9011: }
1.46 raeburn 9012: if ($savefileas ne '') {
9013: $fname = $savefileas;
9014: }
1.9 raeburn 9015: $fname=&Apache::lonnet::clean_filename($fname);
9016: # See if there is anything left
9017: unless ($fname) { return ('error: no uploaded file'); }
9018: $fname="$subdir/$fname";
1.160.6.5 raeburn 9019: my $docroot=$r->dir_config('lonDocRoot');
9020: my $filepath="$docroot/priv";
9021: my $relpath = "$dom/$confname";
1.9 raeburn 9022: my ($fnamepath,$file,$fetchthumb);
9023: $file=$fname;
9024: if ($fname=~m|/|) {
9025: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
9026: }
1.160.6.26 raeburn 9027: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 9028: my $count;
1.160.6.5 raeburn 9029: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 9030: $filepath.="/$parts[$count]";
9031: if ((-e $filepath)!=1) {
9032: mkdir($filepath,02770);
9033: }
9034: }
9035: # Check for bad extension and disallow upload
9036: if ($file=~/\.(\w+)$/ &&
9037: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
9038: $output =
1.160.6.25 raeburn 9039: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 9040: } elsif ($file=~/\.(\w+)$/ &&
9041: !defined(&Apache::loncommon::fileembstyle($1))) {
9042: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
9043: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 9044: $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 9045: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 9046: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 9047: } else {
9048: my $source = $filepath.'/'.$file;
9049: my $logfile;
1.160.6.88 raeburn 9050: if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 9051: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 9052: }
9053: print $logfile
9054: "\n================= Publish ".localtime()." ================\n".
9055: $env{'user.name'}.':'.$env{'user.domain'}."\n";
9056: # Save the file
1.160.6.88 raeburn 9057: if (!open(FH,">",$source)) {
1.9 raeburn 9058: &Apache::lonnet::logthis('Failed to create '.$source);
9059: return (&mt('Failed to create file'));
9060: }
9061: if ($action eq 'upload') {
9062: if (!print FH ($env{'form.'.$formname})) {
9063: &Apache::lonnet::logthis('Failed to write to '.$source);
9064: return (&mt('Failed to write file'));
9065: }
9066: } else {
9067: my $original = &Apache::lonnet::filelocation('',$formname);
9068: if(!copy($original,$source)) {
9069: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
9070: return (&mt('Failed to write file'));
9071: }
9072: }
9073: close(FH);
9074: chmod(0660, $source); # Permissions to rw-rw---.
9075:
9076: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
9077: my $copyfile=$targetdir.'/'.$file;
9078:
9079: my @parts=split(/\//,$targetdir);
9080: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
9081: for (my $count=5;$count<=$#parts;$count++) {
9082: $path.="/$parts[$count]";
9083: if (!-e $path) {
9084: print $logfile "\nCreating directory ".$path;
9085: mkdir($path,02770);
9086: }
9087: }
9088: my $versionresult;
9089: if (-e $copyfile) {
9090: $versionresult = &logo_versioning($targetdir,$file,$logfile);
9091: } else {
9092: $versionresult = 'ok';
9093: }
9094: if ($versionresult eq 'ok') {
9095: if (copy($source,$copyfile)) {
9096: print $logfile "\nCopied original source to ".$copyfile."\n";
9097: $output = 'ok';
9098: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 9099: push(@{$modified_urls},[$copyfile,$source]);
9100: my $metaoutput =
9101: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
9102: unless ($registered_cleanup) {
9103: my $handlers = $r->get_handlers('PerlCleanupHandler');
9104: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9105: $registered_cleanup=1;
9106: }
1.9 raeburn 9107: } else {
9108: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
9109: $output = &mt('Failed to copy file to RES space').", $!";
9110: }
9111: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
9112: my $inputfile = $filepath.'/'.$file;
9113: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 9114: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
9115: if ($fullwidth ne '' && $fullheight ne '') {
9116: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
9117: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88 raeburn 9118: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
9119: system({$args[0]} @args);
1.16 raeburn 9120: chmod(0660, $filepath.'/tn-'.$file);
9121: if (-e $outfile) {
9122: my $copyfile=$targetdir.'/tn-'.$file;
9123: if (copy($outfile,$copyfile)) {
9124: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 9125: my $thumb_metaoutput =
9126: &write_metadata($dom,$confname,$formname,
9127: $targetdir,'tn-'.$file,$logfile);
9128: push(@{$modified_urls},[$copyfile,$outfile]);
9129: unless ($registered_cleanup) {
9130: my $handlers = $r->get_handlers('PerlCleanupHandler');
9131: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9132: $registered_cleanup=1;
9133: }
1.16 raeburn 9134: } else {
9135: print $logfile "\nUnable to write ".$copyfile.
9136: ':'.$!."\n";
9137: }
9138: }
1.9 raeburn 9139: }
9140: }
9141: }
9142: } else {
9143: $output = $versionresult;
9144: }
9145: }
9146: return ($output,$logourl);
9147: }
9148:
9149: sub logo_versioning {
9150: my ($targetdir,$file,$logfile) = @_;
9151: my $target = $targetdir.'/'.$file;
9152: my ($maxversion,$fn,$extn,$output);
9153: $maxversion = 0;
9154: if ($file =~ /^(.+)\.(\w+)$/) {
9155: $fn=$1;
9156: $extn=$2;
9157: }
9158: opendir(DIR,$targetdir);
9159: while (my $filename=readdir(DIR)) {
9160: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
9161: $maxversion=($1>$maxversion)?$1:$maxversion;
9162: }
9163: }
9164: $maxversion++;
9165: print $logfile "\nCreating old version ".$maxversion."\n";
9166: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
9167: if (copy($target,$copyfile)) {
9168: print $logfile "Copied old target to ".$copyfile."\n";
9169: $copyfile=$copyfile.'.meta';
9170: if (copy($target.'.meta',$copyfile)) {
9171: print $logfile "Copied old target metadata to ".$copyfile."\n";
9172: $output = 'ok';
9173: } else {
9174: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
9175: $output = &mt('Failed to copy old meta').", $!, ";
9176: }
9177: } else {
9178: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
9179: $output = &mt('Failed to copy old target').", $!, ";
9180: }
9181: return $output;
9182: }
9183:
9184: sub write_metadata {
9185: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
9186: my (%metadatafields,%metadatakeys,$output);
9187: $metadatafields{'title'}=$formname;
9188: $metadatafields{'creationdate'}=time;
9189: $metadatafields{'lastrevisiondate'}=time;
9190: $metadatafields{'copyright'}='public';
9191: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
9192: $env{'user.domain'};
9193: $metadatafields{'authorspace'}=$confname.':'.$dom;
9194: $metadatafields{'domain'}=$dom;
9195: {
9196: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
9197: my $mfh;
1.160.6.88 raeburn 9198: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 9199: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 9200: unless ($_=~/\./) {
9201: my $unikey=$_;
9202: $unikey=~/^([A-Za-z]+)/;
9203: my $tag=$1;
9204: $tag=~tr/A-Z/a-z/;
9205: print $mfh "\n\<$tag";
9206: foreach (split(/\,/,$metadatakeys{$unikey})) {
9207: my $value=$metadatafields{$unikey.'.'.$_};
9208: $value=~s/\"/\'\'/g;
9209: print $mfh ' '.$_.'="'.$value.'"';
9210: }
9211: print $mfh '>'.
9212: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
9213: .'</'.$tag.'>';
9214: }
9215: }
9216: $output = 'ok';
9217: print $logfile "\nWrote metadata";
9218: close($mfh);
9219: } else {
9220: print $logfile "\nFailed to open metadata file";
1.9 raeburn 9221: $output = &mt('Could not write metadata');
9222: }
9223: }
1.155 raeburn 9224: return $output;
9225: }
9226:
9227: sub notifysubscribed {
9228: foreach my $targetsource (@{$modified_urls}){
9229: next unless (ref($targetsource) eq 'ARRAY');
9230: my ($target,$source)=@{$targetsource};
9231: if ($source ne '') {
1.160.6.88 raeburn 9232: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 9233: print $logfh "\nCleanup phase: Notifications\n";
9234: my @subscribed=&subscribed_hosts($target);
9235: foreach my $subhost (@subscribed) {
9236: print $logfh "\nNotifying host ".$subhost.':';
9237: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
9238: print $logfh $reply;
9239: }
9240: my @subscribedmeta=&subscribed_hosts("$target.meta");
9241: foreach my $subhost (@subscribedmeta) {
9242: print $logfh "\nNotifying host for metadata only ".$subhost.':';
9243: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
9244: $subhost);
9245: print $logfh $reply;
9246: }
9247: print $logfh "\n============ Done ============\n";
1.160 raeburn 9248: close($logfh);
1.155 raeburn 9249: }
9250: }
9251: }
9252: return OK;
9253: }
9254:
9255: sub subscribed_hosts {
9256: my ($target) = @_;
9257: my @subscribed;
1.160.6.88 raeburn 9258: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 9259: while (my $subline=<$fh>) {
9260: if ($subline =~ /^($match_lonid):/) {
9261: my $host = $1;
9262: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
9263: unless (grep(/^\Q$host\E$/,@subscribed)) {
9264: push(@subscribed,$host);
9265: }
9266: }
9267: }
9268: }
9269: }
9270: return @subscribed;
1.9 raeburn 9271: }
9272:
9273: sub check_switchserver {
9274: my ($dom,$confname) = @_;
9275: my ($allowed,$switchserver);
9276: my $home = &Apache::lonnet::homeserver($confname,$dom);
9277: if ($home eq 'no_host') {
9278: $home = &Apache::lonnet::domain($dom,'primary');
9279: }
9280: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 9281: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
9282: if (!$allowed) {
1.160.6.11 raeburn 9283: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 9284: }
9285: return $switchserver;
9286: }
9287:
1.1 raeburn 9288: sub modify_quotas {
1.160.6.30 raeburn 9289: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 9290: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 9291: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 9292: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
9293: $validationfieldsref);
1.86 raeburn 9294: if ($action eq 'quotas') {
9295: $context = 'tools';
1.160.6.26 raeburn 9296: } else {
1.86 raeburn 9297: $context = $action;
9298: }
9299: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 9300: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 9301: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 9302: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
9303: %titles = &courserequest_titles();
9304: $toolregexp = join('|',@usertools);
9305: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 9306: $confname = $dom.'-domainconfig';
9307: my $servadm = $r->dir_config('lonAdmEMail');
9308: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 9309: ($validationitemsref,$validationnamesref,$validationfieldsref) =
9310: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 9311: } elsif ($context eq 'requestauthor') {
9312: @usertools = ('author');
9313: %titles = &authorrequest_titles();
1.86 raeburn 9314: } else {
1.160.6.4 raeburn 9315: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 9316: %titles = &tool_titles();
1.86 raeburn 9317: }
1.160.6.27 raeburn 9318: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 9319: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9320: foreach my $key (keys(%env)) {
1.101 raeburn 9321: if ($context eq 'requestcourses') {
9322: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
9323: my $item = $1;
9324: my $type = $2;
9325: if ($type =~ /^limit_(.+)/) {
9326: $limithash{$item}{$1} = $env{$key};
9327: } else {
9328: $confhash{$item}{$type} = $env{$key};
9329: }
9330: }
1.160.6.5 raeburn 9331: } elsif ($context eq 'requestauthor') {
9332: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
9333: $confhash{$1} = $env{$key};
9334: }
1.101 raeburn 9335: } else {
1.86 raeburn 9336: if ($key =~ /^form\.quota_(.+)$/) {
9337: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 9338: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
9339: $confhash{'authorquota'}{$1} = $env{$key};
9340: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 9341: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
9342: }
1.72 raeburn 9343: }
9344: }
1.160.6.5 raeburn 9345: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 9346: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 9347: @approvalnotify = sort(@approvalnotify);
9348: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 9349: my @crstypes = ('official','unofficial','community','textbook');
9350: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
9351: foreach my $type (@hasuniquecode) {
9352: if (grep(/^\Q$type\E$/,@crstypes)) {
9353: $confhash{'uniquecode'}{$type} = 1;
9354: }
9355: }
1.160.6.46 raeburn 9356: my (%newbook,%allpos);
1.160.6.30 raeburn 9357: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 9358: foreach my $type ('textbooks','templates') {
9359: @{$allpos{$type}} = ();
9360: my $invalid;
9361: if ($type eq 'textbooks') {
9362: $invalid = &mt('Invalid LON-CAPA course for textbook');
9363: } else {
9364: $invalid = &mt('Invalid LON-CAPA course for template');
9365: }
9366: if ($env{'form.'.$type.'_addbook'}) {
9367: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
9368: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
9369: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
9370: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
9371: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
9372: } else {
9373: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
9374: my $position = $env{'form.'.$type.'_addbook_pos'};
9375: $position =~ s/\D+//g;
9376: if ($position ne '') {
9377: $allpos{$type}[$position] = $newbook{$type};
9378: }
1.160.6.30 raeburn 9379: }
1.160.6.46 raeburn 9380: } else {
9381: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 9382: }
9383: }
1.160.6.46 raeburn 9384: }
1.160.6.30 raeburn 9385: }
1.102 raeburn 9386: if (ref($domconfig{$action}) eq 'HASH') {
9387: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
9388: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
9389: $changes{'notify'}{'approval'} = 1;
9390: }
9391: } else {
1.144 raeburn 9392: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9393: $changes{'notify'}{'approval'} = 1;
9394: }
9395: }
1.160.6.30 raeburn 9396: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
9397: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9398: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
9399: unless ($confhash{'uniquecode'}{$crstype}) {
9400: $changes{'uniquecode'} = 1;
9401: }
9402: }
9403: unless ($changes{'uniquecode'}) {
9404: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
9405: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
9406: $changes{'uniquecode'} = 1;
9407: }
9408: }
9409: }
9410: } else {
9411: $changes{'uniquecode'} = 1;
9412: }
9413: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
9414: $changes{'uniquecode'} = 1;
9415: }
9416: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 9417: foreach my $type ('textbooks','templates') {
9418: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9419: my %deletions;
9420: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
9421: if (@todelete) {
9422: map { $deletions{$_} = 1; } @todelete;
9423: }
9424: my %imgdeletions;
9425: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
9426: if (@todeleteimages) {
9427: map { $imgdeletions{$_} = 1; } @todeleteimages;
9428: }
9429: my $maxnum = $env{'form.'.$type.'_maxnum'};
9430: for (my $i=0; $i<=$maxnum; $i++) {
9431: my $itemid = $env{'form.'.$type.'_id_'.$i};
9432: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
9433: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
9434: if ($deletions{$key}) {
9435: if ($domconfig{$action}{$type}{$key}{'image'}) {
9436: #FIXME need to obsolete item in RES space
9437: }
9438: next;
9439: } else {
9440: my $newpos = $env{'form.'.$itemid};
9441: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 9442: foreach my $item ('subject','title','publisher','author') {
9443: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9444: ($type eq 'templates'));
1.160.6.46 raeburn 9445: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
9446: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
9447: $changes{$type}{$key} = 1;
9448: }
9449: }
9450: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 9451: }
1.160.6.46 raeburn 9452: if ($imgdeletions{$key}) {
9453: $changes{$type}{$key} = 1;
9454: #FIXME need to obsolete item in RES space
9455: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
9456: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 9457: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
9458: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
9459: } else {
9460: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
9461: $cdom,$cnum,$type,$configuserok,
9462: $switchserver,$author_ok);
9463: if ($imgurl) {
9464: $confhash{$type}{$key}{'image'} = $imgurl;
9465: $changes{$type}{$key} = 1;
9466: }
9467: if ($error) {
9468: &Apache::lonnet::logthis($error);
9469: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9470: }
1.160.6.46 raeburn 9471: }
9472: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
9473: $confhash{$type}{$key}{'image'} =
9474: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 9475: }
9476: }
9477: }
9478: }
9479: }
9480: }
1.102 raeburn 9481: } else {
1.144 raeburn 9482: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9483: $changes{'notify'}{'approval'} = 1;
9484: }
1.160.6.30 raeburn 9485: if (ref($confhash{'uniquecode'} eq 'HASH')) {
9486: $changes{'uniquecode'} = 1;
9487: }
9488: }
9489: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 9490: foreach my $type ('textbooks','templates') {
9491: if ($newbook{$type}) {
9492: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 9493: foreach my $item ('subject','title','publisher','author') {
9494: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9495: ($type eq 'template'));
1.160.6.46 raeburn 9496: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
9497: if ($env{'form.'.$type.'_addbook_'.$item}) {
9498: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
9499: }
9500: }
9501: if ($type eq 'textbooks') {
9502: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
9503: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 9504: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
9505: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
9506: } else {
9507: my ($imageurl,$error) =
9508: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
9509: $configuserok,$switchserver,$author_ok);
9510: if ($imageurl) {
9511: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
9512: }
9513: if ($error) {
9514: &Apache::lonnet::logthis($error);
9515: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9516: }
1.160.6.46 raeburn 9517: }
9518: }
1.160.6.30 raeburn 9519: }
9520: }
1.160.6.46 raeburn 9521: if (@{$allpos{$type}} > 0) {
9522: my $idx = 0;
9523: foreach my $item (@{$allpos{$type}}) {
9524: if ($item ne '') {
9525: $confhash{$type}{$item}{'order'} = $idx;
9526: if (ref($domconfig{$action}) eq 'HASH') {
9527: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9528: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
9529: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
9530: $changes{$type}{$item} = 1;
9531: }
1.160.6.30 raeburn 9532: }
9533: }
9534: }
1.160.6.46 raeburn 9535: $idx ++;
1.160.6.30 raeburn 9536: }
9537: }
9538: }
9539: }
1.160.6.39 raeburn 9540: if (ref($validationitemsref) eq 'ARRAY') {
9541: foreach my $item (@{$validationitemsref}) {
9542: if ($item eq 'fields') {
9543: my @changed;
9544: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
9545: if (@{$confhash{'validation'}{$item}} > 0) {
9546: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
9547: }
1.160.6.65 raeburn 9548: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9549: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9550: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
9551: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
9552: $domconfig{'requestcourses'}{'validation'}{$item});
9553: } else {
9554: @changed = @{$confhash{'validation'}{$item}};
9555: }
1.160.6.39 raeburn 9556: } else {
9557: @changed = @{$confhash{'validation'}{$item}};
9558: }
9559: } else {
9560: @changed = @{$confhash{'validation'}{$item}};
9561: }
9562: if (@changed) {
9563: if ($confhash{'validation'}{$item}) {
9564: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
9565: } else {
9566: $changes{'validation'}{$item} = &mt('None');
9567: }
9568: }
9569: } else {
9570: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
9571: if ($item eq 'markup') {
9572: if ($env{'form.requestcourses_validation_'.$item}) {
9573: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
9574: }
9575: }
1.160.6.65 raeburn 9576: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9577: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9578: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
9579: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9580: }
9581: } else {
9582: if ($confhash{'validation'}{$item} ne '') {
9583: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9584: }
1.160.6.39 raeburn 9585: }
9586: } else {
9587: if ($confhash{'validation'}{$item} ne '') {
9588: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9589: }
9590: }
9591: }
9592: }
9593: }
9594: if ($env{'form.validationdc'}) {
9595: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 9596: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 9597: if (exists($domcoords{$newval})) {
9598: $confhash{'validation'}{'dc'} = $newval;
9599: }
9600: }
9601: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 9602: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9603: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9604: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9605: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
9606: if ($confhash{'validation'}{'dc'} eq '') {
9607: $changes{'validation'}{'dc'} = &mt('None');
9608: } else {
9609: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9610: }
1.160.6.39 raeburn 9611: }
1.160.6.65 raeburn 9612: } elsif ($confhash{'validation'}{'dc'} ne '') {
9613: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 9614: }
9615: } elsif ($confhash{'validation'}{'dc'} ne '') {
9616: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9617: }
9618: } elsif ($confhash{'validation'}{'dc'} ne '') {
9619: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9620: }
1.160.6.65 raeburn 9621: } else {
9622: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9623: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9624: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9625: $changes{'validation'}{'dc'} = &mt('None');
9626: }
9627: }
1.160.6.39 raeburn 9628: }
9629: }
1.102 raeburn 9630: }
9631: } else {
1.86 raeburn 9632: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 9633: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 9634: }
1.72 raeburn 9635: foreach my $item (@usertools) {
9636: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 9637: my $unset;
1.101 raeburn 9638: if ($context eq 'requestcourses') {
1.104 raeburn 9639: $unset = '0';
9640: if ($type eq '_LC_adv') {
9641: $unset = '';
9642: }
1.101 raeburn 9643: if ($confhash{$item}{$type} eq 'autolimit') {
9644: $confhash{$item}{$type} .= '=';
9645: unless ($limithash{$item}{$type} =~ /\D/) {
9646: $confhash{$item}{$type} .= $limithash{$item}{$type};
9647: }
9648: }
1.160.6.5 raeburn 9649: } elsif ($context eq 'requestauthor') {
9650: $unset = '0';
9651: if ($type eq '_LC_adv') {
9652: $unset = '';
9653: }
1.72 raeburn 9654: } else {
1.101 raeburn 9655: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
9656: $confhash{$item}{$type} = 1;
9657: } else {
9658: $confhash{$item}{$type} = 0;
9659: }
1.72 raeburn 9660: }
1.86 raeburn 9661: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 9662: if ($action eq 'requestauthor') {
9663: if ($domconfig{$action}{$type} ne $confhash{$type}) {
9664: $changes{$type} = 1;
9665: }
9666: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 9667: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
9668: $changes{$item}{$type} = 1;
9669: }
9670: } else {
9671: if ($context eq 'requestcourses') {
1.104 raeburn 9672: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 9673: $changes{$item}{$type} = 1;
9674: }
9675: } else {
9676: if (!$confhash{$item}{$type}) {
9677: $changes{$item}{$type} = 1;
9678: }
9679: }
9680: }
9681: } else {
9682: if ($context eq 'requestcourses') {
1.104 raeburn 9683: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 9684: $changes{$item}{$type} = 1;
9685: }
1.160.6.5 raeburn 9686: } elsif ($context eq 'requestauthor') {
9687: if ($confhash{$type} ne $unset) {
9688: $changes{$type} = 1;
9689: }
1.72 raeburn 9690: } else {
9691: if (!$confhash{$item}{$type}) {
9692: $changes{$item}{$type} = 1;
9693: }
9694: }
9695: }
1.1 raeburn 9696: }
9697: }
1.160.6.5 raeburn 9698: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 9699: if (ref($domconfig{'quotas'}) eq 'HASH') {
9700: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9701: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
9702: if (exists($confhash{'defaultquota'}{$key})) {
9703: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
9704: $changes{'defaultquota'}{$key} = 1;
9705: }
9706: } else {
9707: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 9708: }
9709: }
1.86 raeburn 9710: } else {
9711: foreach my $key (keys(%{$domconfig{'quotas'}})) {
9712: if (exists($confhash{'defaultquota'}{$key})) {
9713: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
9714: $changes{'defaultquota'}{$key} = 1;
9715: }
9716: } else {
9717: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 9718: }
1.1 raeburn 9719: }
9720: }
1.160.6.20 raeburn 9721: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9722: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
9723: if (exists($confhash{'authorquota'}{$key})) {
9724: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
9725: $changes{'authorquota'}{$key} = 1;
9726: }
9727: } else {
9728: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
9729: }
9730: }
9731: }
1.1 raeburn 9732: }
1.86 raeburn 9733: if (ref($confhash{'defaultquota'}) eq 'HASH') {
9734: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
9735: if (ref($domconfig{'quotas'}) eq 'HASH') {
9736: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9737: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
9738: $changes{'defaultquota'}{$key} = 1;
9739: }
9740: } else {
9741: if (!exists($domconfig{'quotas'}{$key})) {
9742: $changes{'defaultquota'}{$key} = 1;
9743: }
1.72 raeburn 9744: }
9745: } else {
1.86 raeburn 9746: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 9747: }
1.1 raeburn 9748: }
9749: }
1.160.6.20 raeburn 9750: if (ref($confhash{'authorquota'}) eq 'HASH') {
9751: foreach my $key (keys(%{$confhash{'authorquota'}})) {
9752: if (ref($domconfig{'quotas'}) eq 'HASH') {
9753: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9754: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
9755: $changes{'authorquota'}{$key} = 1;
9756: }
9757: } else {
9758: $changes{'authorquota'}{$key} = 1;
9759: }
9760: } else {
9761: $changes{'authorquota'}{$key} = 1;
9762: }
9763: }
9764: }
1.1 raeburn 9765: }
1.72 raeburn 9766:
1.160.6.5 raeburn 9767: if ($context eq 'requestauthor') {
9768: $domdefaults{'requestauthor'} = \%confhash;
9769: } else {
9770: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 9771: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 9772: $domdefaults{$key} = $confhash{$key};
9773: }
1.160.6.5 raeburn 9774: }
1.72 raeburn 9775: }
1.160.6.5 raeburn 9776:
1.1 raeburn 9777: my %quotahash = (
1.86 raeburn 9778: $action => { %confhash }
1.1 raeburn 9779: );
9780: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
9781: $dom);
9782: if ($putresult eq 'ok') {
9783: if (keys(%changes) > 0) {
1.72 raeburn 9784: my $cachetime = 24*60*60;
9785: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 9786: if (ref($lastactref) eq 'HASH') {
9787: $lastactref->{'domdefaults'} = 1;
9788: }
1.1 raeburn 9789: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 9790: unless (($context eq 'requestcourses') ||
9791: ($context eq 'requestauthor')) {
1.86 raeburn 9792: if (ref($changes{'defaultquota'}) eq 'HASH') {
9793: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
9794: foreach my $type (@{$types},'default') {
9795: if (defined($changes{'defaultquota'}{$type})) {
9796: my $typetitle = $usertypes->{$type};
9797: if ($type eq 'default') {
9798: $typetitle = $othertitle;
9799: }
1.160.6.28 raeburn 9800: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 9801: }
9802: }
1.86 raeburn 9803: $resulttext .= '</ul></li>';
1.72 raeburn 9804: }
1.160.6.20 raeburn 9805: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 9806: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 9807: foreach my $type (@{$types},'default') {
9808: if (defined($changes{'authorquota'}{$type})) {
9809: my $typetitle = $usertypes->{$type};
9810: if ($type eq 'default') {
9811: $typetitle = $othertitle;
9812: }
1.160.6.28 raeburn 9813: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 9814: }
9815: }
9816: $resulttext .= '</ul></li>';
9817: }
1.72 raeburn 9818: }
1.80 raeburn 9819: my %newenv;
1.72 raeburn 9820: foreach my $item (@usertools) {
1.160.6.5 raeburn 9821: my (%haschgs,%inconf);
9822: if ($context eq 'requestauthor') {
9823: %haschgs = %changes;
9824: %inconf = %confhash;
9825: } else {
9826: if (ref($changes{$item}) eq 'HASH') {
9827: %haschgs = %{$changes{$item}};
9828: }
9829: if (ref($confhash{$item}) eq 'HASH') {
9830: %inconf = %{$confhash{$item}};
9831: }
9832: }
9833: if (keys(%haschgs) > 0) {
1.80 raeburn 9834: my $newacc =
9835: &Apache::lonnet::usertools_access($env{'user.name'},
9836: $env{'user.domain'},
1.86 raeburn 9837: $item,'reload',$context);
1.160.6.5 raeburn 9838: if (($context eq 'requestcourses') ||
9839: ($context eq 'requestauthor')) {
1.108 raeburn 9840: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9841: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 9842: }
9843: } else {
9844: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9845: $newenv{'environment.availabletools.'.$item} = $newacc;
9846: }
1.80 raeburn 9847: }
1.160.6.5 raeburn 9848: unless ($context eq 'requestauthor') {
9849: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9850: }
1.72 raeburn 9851: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 9852: if ($haschgs{$type}) {
1.72 raeburn 9853: my $typetitle = $usertypes->{$type};
9854: if ($type eq 'default') {
9855: $typetitle = $othertitle;
9856: } elsif ($type eq '_LC_adv') {
9857: $typetitle = 'LON-CAPA Advanced Users';
9858: }
1.160.6.5 raeburn 9859: if ($inconf{$type}) {
1.101 raeburn 9860: if ($context eq 'requestcourses') {
9861: my $cond;
1.160.6.5 raeburn 9862: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 9863: if ($1 eq '') {
9864: $cond = &mt('(Automatic processing of any request).');
9865: } else {
9866: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9867: }
9868: } else {
1.160.6.5 raeburn 9869: $cond = $conditions{$inconf{$type}};
1.101 raeburn 9870: }
9871: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 9872: } elsif ($context eq 'requestauthor') {
9873: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9874: $titles{$inconf{$type}},$typetitle);
9875:
1.101 raeburn 9876: } else {
9877: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9878: }
1.72 raeburn 9879: } else {
1.104 raeburn 9880: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 9881: if ($inconf{$type} eq '0') {
1.104 raeburn 9882: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9883: } else {
9884: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9885: }
9886: } else {
9887: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9888: }
1.72 raeburn 9889: }
9890: }
1.26 raeburn 9891: }
1.160.6.5 raeburn 9892: unless ($context eq 'requestauthor') {
9893: $resulttext .= '</ul></li>';
9894: }
1.26 raeburn 9895: }
1.1 raeburn 9896: }
1.160.6.5 raeburn 9897: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 9898: if (ref($changes{'notify'}) eq 'HASH') {
9899: if ($changes{'notify'}{'approval'}) {
9900: if (ref($confhash{'notify'}) eq 'HASH') {
9901: if ($confhash{'notify'}{'approval'}) {
9902: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9903: } else {
1.160.6.5 raeburn 9904: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 9905: }
9906: }
9907: }
9908: }
9909: }
1.160.6.30 raeburn 9910: if ($action eq 'requestcourses') {
9911: my @offon = ('off','on');
9912: if ($changes{'uniquecode'}) {
9913: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9914: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
9915: $resulttext .= '<li>'.
9916: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
9917: '</li>';
9918: } else {
9919: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
9920: '</li>';
9921: }
9922: }
1.160.6.46 raeburn 9923: foreach my $type ('textbooks','templates') {
9924: if (ref($changes{$type}) eq 'HASH') {
9925: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
9926: foreach my $key (sort(keys(%{$changes{$type}}))) {
9927: my %coursehash = &Apache::lonnet::coursedescription($key);
9928: my $coursetitle = $coursehash{'description'};
9929: my $position = $confhash{$type}{$key}{'order'} + 1;
9930: $resulttext .= '<li>';
1.160.6.47 raeburn 9931: foreach my $item ('subject','title','publisher','author') {
9932: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9933: ($type eq 'templates'));
1.160.6.46 raeburn 9934: my $name = $item.':';
9935: $name =~ s/^(\w)/\U$1/;
9936: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9937: }
9938: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9939: if ($type eq 'textbooks') {
9940: if ($confhash{$type}{$key}{'image'}) {
9941: $resulttext .= ' '.&mt('Image: [_1]',
9942: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9943: ' alt="Textbook cover" />').'<br />';
9944: }
9945: }
9946: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 9947: }
1.160.6.46 raeburn 9948: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 9949: }
9950: }
1.160.6.39 raeburn 9951: if (ref($changes{'validation'}) eq 'HASH') {
9952: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9953: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9954: foreach my $item (@{$validationitemsref}) {
9955: if (exists($changes{'validation'}{$item})) {
9956: if ($item eq 'markup') {
9957: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9958: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9959: } else {
9960: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9961: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9962: }
9963: }
9964: }
9965: if (exists($changes{'validation'}{'dc'})) {
9966: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9967: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9968: }
9969: }
9970: }
1.160.6.30 raeburn 9971: }
1.1 raeburn 9972: $resulttext .= '</ul>';
1.80 raeburn 9973: if (keys(%newenv)) {
9974: &Apache::lonnet::appenv(\%newenv);
9975: }
1.1 raeburn 9976: } else {
1.86 raeburn 9977: if ($context eq 'requestcourses') {
9978: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 9979: } elsif ($context eq 'requestauthor') {
9980: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 9981: } else {
1.90 weissno 9982: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 9983: }
1.1 raeburn 9984: }
9985: } else {
1.11 albertel 9986: $resulttext = '<span class="LC_error">'.
9987: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9988: }
1.160.6.30 raeburn 9989: if ($errors) {
9990: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
9991: '<ul>'.$errors.'</ul></p>';
9992: }
1.3 raeburn 9993: return $resulttext;
1.1 raeburn 9994: }
9995:
1.160.6.30 raeburn 9996: sub process_textbook_image {
1.160.6.46 raeburn 9997: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 9998: my $filename = $env{'form.'.$caller.'.filename'};
9999: my ($error,$url);
10000: my ($width,$height) = (50,50);
10001: if ($configuserok eq 'ok') {
10002: if ($switchserver) {
10003: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
10004: $switchserver);
10005: } elsif ($author_ok eq 'ok') {
10006: my ($result,$imageurl) =
10007: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88 raeburn 10008: "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 10009: if ($result eq 'ok') {
10010: $url = $imageurl;
10011: } else {
10012: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10013: }
10014: } else {
10015: $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);
10016: }
10017: } else {
10018: $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);
10019: }
10020: return ($url,$error);
10021: }
10022:
1.3 raeburn 10023: sub modify_autoenroll {
1.160.6.24 raeburn 10024: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 10025: my ($resulttext,%changes);
10026: my %currautoenroll;
10027: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
10028: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
10029: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
10030: }
10031: }
10032: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
10033: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 10034: sender => 'Sender for notification messages',
1.160.6.68 raeburn 10035: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
10036: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 10037: my @offon = ('off','on');
1.17 raeburn 10038: my $sender_uname = $env{'form.sender_uname'};
10039: my $sender_domain = $env{'form.sender_domain'};
10040: if ($sender_domain eq '') {
10041: $sender_uname = '';
10042: } elsif ($sender_uname eq '') {
10043: $sender_domain = '';
10044: }
1.129 raeburn 10045: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 10046: my $failsafe = $env{'form.autoenroll_failsafe'};
10047: $failsafe =~ s{^\s+|\s+$}{}g;
10048: if ($failsafe =~ /\D/) {
10049: undef($failsafe);
10050: }
1.1 raeburn 10051: my %autoenrollhash = (
1.129 raeburn 10052: autoenroll => { 'run' => $env{'form.autoenroll_run'},
10053: 'sender_uname' => $sender_uname,
10054: 'sender_domain' => $sender_domain,
10055: 'co-owners' => $coowners,
1.160.6.68 raeburn 10056: 'autofailsafe' => $failsafe,
1.1 raeburn 10057: }
10058: );
1.4 raeburn 10059: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
10060: $dom);
1.1 raeburn 10061: if ($putresult eq 'ok') {
10062: if (exists($currautoenroll{'run'})) {
10063: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
10064: $changes{'run'} = 1;
10065: }
10066: } elsif ($autorun) {
10067: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 10068: $changes{'run'} = 1;
1.1 raeburn 10069: }
10070: }
1.17 raeburn 10071: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 10072: $changes{'sender'} = 1;
10073: }
1.17 raeburn 10074: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 10075: $changes{'sender'} = 1;
10076: }
1.129 raeburn 10077: if ($currautoenroll{'co-owners'} ne '') {
10078: if ($currautoenroll{'co-owners'} ne $coowners) {
10079: $changes{'coowners'} = 1;
10080: }
10081: } elsif ($coowners) {
10082: $changes{'coowners'} = 1;
1.160.6.68 raeburn 10083: }
10084: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
10085: $changes{'autofailsafe'} = 1;
10086: }
1.1 raeburn 10087: if (keys(%changes) > 0) {
10088: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 10089: if ($changes{'run'}) {
1.1 raeburn 10090: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
10091: }
10092: if ($changes{'sender'}) {
1.17 raeburn 10093: if ($sender_uname eq '' || $sender_domain eq '') {
10094: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
10095: } else {
10096: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
10097: }
1.1 raeburn 10098: }
1.129 raeburn 10099: if ($changes{'coowners'}) {
10100: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
10101: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10102: if (ref($lastactref) eq 'HASH') {
10103: $lastactref->{'domainconfig'} = 1;
10104: }
1.129 raeburn 10105: }
1.160.6.68 raeburn 10106: if ($changes{'autofailsafe'}) {
10107: if ($failsafe ne '') {
1.160.6.82 raeburn 10108: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68 raeburn 10109: } else {
1.160.6.82 raeburn 10110: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68 raeburn 10111: }
10112: &Apache::lonnet::get_domain_defaults($dom,1);
10113: if (ref($lastactref) eq 'HASH') {
10114: $lastactref->{'domdefaults'} = 1;
10115: }
10116: }
1.1 raeburn 10117: $resulttext .= '</ul>';
10118: } else {
10119: $resulttext = &mt('No changes made to auto-enrollment settings');
10120: }
10121: } else {
1.11 albertel 10122: $resulttext = '<span class="LC_error">'.
10123: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10124: }
1.3 raeburn 10125: return $resulttext;
1.1 raeburn 10126: }
10127:
10128: sub modify_autoupdate {
1.3 raeburn 10129: my ($dom,%domconfig) = @_;
1.1 raeburn 10130: my ($resulttext,%currautoupdate,%fields,%changes);
10131: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
10132: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
10133: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
10134: }
10135: }
10136: my @offon = ('off','on');
10137: my %title = &Apache::lonlocal::texthash (
10138: run => 'Auto-update:',
10139: classlists => 'Updates to user information in classlists?'
10140: );
1.44 raeburn 10141: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10142: my %fieldtitles = &Apache::lonlocal::texthash (
10143: id => 'Student/Employee ID',
1.20 raeburn 10144: permanentemail => 'E-mail address',
1.1 raeburn 10145: lastname => 'Last Name',
10146: firstname => 'First Name',
10147: middlename => 'Middle Name',
1.132 raeburn 10148: generation => 'Generation',
1.1 raeburn 10149: );
1.142 raeburn 10150: $othertitle = &mt('All users');
1.1 raeburn 10151: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 10152: $othertitle = &mt('Other users');
1.1 raeburn 10153: }
10154: foreach my $key (keys(%env)) {
10155: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 10156: my ($usertype,$item) = ($1,$2);
10157: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
10158: if ($usertype eq 'default') {
10159: push(@{$fields{$1}},$2);
10160: } elsif (ref($types) eq 'ARRAY') {
10161: if (grep(/^\Q$usertype\E$/,@{$types})) {
10162: push(@{$fields{$1}},$2);
10163: }
10164: }
10165: }
1.1 raeburn 10166: }
10167: }
1.131 raeburn 10168: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
10169: @lockablenames = sort(@lockablenames);
10170: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
10171: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10172: if (@changed) {
10173: $changes{'lockablenames'} = 1;
10174: }
10175: } else {
10176: if (@lockablenames) {
10177: $changes{'lockablenames'} = 1;
10178: }
10179: }
1.1 raeburn 10180: my %updatehash = (
10181: autoupdate => { run => $env{'form.autoupdate_run'},
10182: classlists => $env{'form.classlists'},
10183: fields => {%fields},
1.131 raeburn 10184: lockablenames => \@lockablenames,
1.1 raeburn 10185: }
10186: );
10187: foreach my $key (keys(%currautoupdate)) {
10188: if (($key eq 'run') || ($key eq 'classlists')) {
10189: if (exists($updatehash{autoupdate}{$key})) {
10190: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
10191: $changes{$key} = 1;
10192: }
10193: }
10194: } elsif ($key eq 'fields') {
10195: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 10196: foreach my $item (@{$types},'default') {
1.1 raeburn 10197: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
10198: my $change = 0;
10199: foreach my $type (@{$currautoupdate{$key}{$item}}) {
10200: if (!exists($fields{$item})) {
10201: $change = 1;
1.132 raeburn 10202: last;
1.1 raeburn 10203: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 10204: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 10205: $change = 1;
1.132 raeburn 10206: last;
1.1 raeburn 10207: }
10208: }
10209: }
10210: if ($change) {
10211: push(@{$changes{$key}},$item);
10212: }
1.26 raeburn 10213: }
1.1 raeburn 10214: }
10215: }
1.131 raeburn 10216: } elsif ($key eq 'lockablenames') {
10217: if (ref($currautoupdate{$key}) eq 'ARRAY') {
10218: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10219: if (@changed) {
10220: $changes{'lockablenames'} = 1;
10221: }
10222: } else {
10223: if (@lockablenames) {
10224: $changes{'lockablenames'} = 1;
10225: }
10226: }
10227: }
10228: }
10229: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
10230: if (@lockablenames) {
10231: $changes{'lockablenames'} = 1;
1.1 raeburn 10232: }
10233: }
1.26 raeburn 10234: foreach my $item (@{$types},'default') {
10235: if (defined($fields{$item})) {
10236: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 10237: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
10238: my $change = 0;
10239: if (ref($fields{$item}) eq 'ARRAY') {
10240: foreach my $type (@{$fields{$item}}) {
10241: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
10242: $change = 1;
10243: last;
10244: }
10245: }
10246: }
10247: if ($change) {
10248: push(@{$changes{'fields'}},$item);
10249: }
10250: } else {
1.26 raeburn 10251: push(@{$changes{'fields'}},$item);
10252: }
10253: } else {
10254: push(@{$changes{'fields'}},$item);
1.1 raeburn 10255: }
10256: }
10257: }
10258: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
10259: $dom);
10260: if ($putresult eq 'ok') {
10261: if (keys(%changes) > 0) {
10262: $resulttext = &mt('Changes made:').'<ul>';
10263: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 10264: if ($key eq 'lockablenames') {
10265: $resulttext .= '<li>';
10266: if (@lockablenames) {
10267: $usertypes->{'default'} = $othertitle;
10268: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
10269: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
10270: } else {
10271: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
10272: }
10273: $resulttext .= '</li>';
10274: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 10275: foreach my $item (@{$changes{$key}}) {
10276: my @newvalues;
10277: foreach my $type (@{$fields{$item}}) {
10278: push(@newvalues,$fieldtitles{$type});
10279: }
1.3 raeburn 10280: my $newvaluestr;
10281: if (@newvalues > 0) {
10282: $newvaluestr = join(', ',@newvalues);
10283: } else {
10284: $newvaluestr = &mt('none');
1.6 raeburn 10285: }
1.1 raeburn 10286: if ($item eq 'default') {
1.26 raeburn 10287: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 10288: } else {
1.26 raeburn 10289: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 10290: }
10291: }
10292: } else {
10293: my $newvalue;
10294: if ($key eq 'run') {
10295: $newvalue = $offon[$env{'form.autoupdate_run'}];
10296: } else {
10297: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 10298: }
1.1 raeburn 10299: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
10300: }
10301: }
10302: $resulttext .= '</ul>';
10303: } else {
1.3 raeburn 10304: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 10305: }
10306: } else {
1.11 albertel 10307: $resulttext = '<span class="LC_error">'.
10308: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10309: }
1.3 raeburn 10310: return $resulttext;
1.1 raeburn 10311: }
10312:
1.125 raeburn 10313: sub modify_autocreate {
10314: my ($dom,%domconfig) = @_;
10315: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
10316: if (ref($domconfig{'autocreate'}) eq 'HASH') {
10317: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
10318: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
10319: }
10320: }
10321: my %title= ( xml => 'Auto-creation of courses in XML course description files',
10322: req => 'Auto-creation of validated requests for official courses',
10323: xmldc => 'Identity of course creator of courses from XML files',
10324: );
10325: my @types = ('xml','req');
10326: foreach my $item (@types) {
10327: $newvals{$item} = $env{'form.autocreate_'.$item};
10328: $newvals{$item} =~ s/\D//g;
10329: $newvals{$item} = 0 if ($newvals{$item} eq '');
10330: }
10331: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 10332: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 10333: unless (exists($domcoords{$newvals{'xmldc'}})) {
10334: $newvals{'xmldc'} = '';
10335: }
10336: %autocreatehash = (
10337: autocreate => { xml => $newvals{'xml'},
10338: req => $newvals{'req'},
10339: }
10340: );
10341: if ($newvals{'xmldc'} ne '') {
10342: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
10343: }
10344: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
10345: $dom);
10346: if ($putresult eq 'ok') {
10347: my @items = @types;
10348: if ($newvals{'xml'}) {
10349: push(@items,'xmldc');
10350: }
10351: foreach my $item (@items) {
10352: if (exists($currautocreate{$item})) {
10353: if ($currautocreate{$item} ne $newvals{$item}) {
10354: $changes{$item} = 1;
10355: }
10356: } elsif ($newvals{$item}) {
10357: $changes{$item} = 1;
10358: }
10359: }
10360: if (keys(%changes) > 0) {
10361: my @offon = ('off','on');
10362: $resulttext = &mt('Changes made:').'<ul>';
10363: foreach my $item (@types) {
10364: if ($changes{$item}) {
10365: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 10366: $resulttext .= '<li>'.
10367: &mt("$title{$item} set to [_1]$newtxt [_2]",
10368: '<b>','</b>').
10369: '</li>';
1.125 raeburn 10370: }
10371: }
10372: if ($changes{'xmldc'}) {
10373: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
10374: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 10375: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 10376: }
10377: $resulttext .= '</ul>';
10378: } else {
10379: $resulttext = &mt('No changes made to auto-creation settings');
10380: }
10381: } else {
10382: $resulttext = '<span class="LC_error">'.
10383: &mt('An error occurred: [_1]',$putresult).'</span>';
10384: }
10385: return $resulttext;
10386: }
10387:
1.23 raeburn 10388: sub modify_directorysrch {
1.160.6.81 raeburn 10389: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 10390: my ($resulttext,%changes);
10391: my %currdirsrch;
10392: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10393: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
10394: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
10395: }
10396: }
1.160.6.72 raeburn 10397: my %title = ( available => 'Institutional directory search available',
10398: localonly => 'Other domains can search institution',
10399: lcavailable => 'LON-CAPA directory search available',
10400: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 10401: searchby => 'Search types',
10402: searchtypes => 'Search latitude');
10403: my @offon = ('off','on');
1.24 raeburn 10404: my @otherdoms = ('Yes','No');
1.23 raeburn 10405:
1.25 raeburn 10406: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 10407: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
10408: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
10409:
1.44 raeburn 10410: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 10411: if (keys(%{$usertypes}) == 0) {
10412: @cansearch = ('default');
10413: } else {
10414: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
10415: foreach my $type (@{$currdirsrch{'cansearch'}}) {
10416: if (!grep(/^\Q$type\E$/,@cansearch)) {
10417: push(@{$changes{'cansearch'}},$type);
10418: }
1.23 raeburn 10419: }
1.26 raeburn 10420: foreach my $type (@cansearch) {
10421: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
10422: push(@{$changes{'cansearch'}},$type);
10423: }
1.23 raeburn 10424: }
1.26 raeburn 10425: } else {
10426: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 10427: }
10428: }
10429:
10430: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
10431: foreach my $by (@{$currdirsrch{'searchby'}}) {
10432: if (!grep(/^\Q$by\E$/,@searchby)) {
10433: push(@{$changes{'searchby'}},$by);
10434: }
10435: }
10436: foreach my $by (@searchby) {
10437: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
10438: push(@{$changes{'searchby'}},$by);
10439: }
10440: }
10441: } else {
10442: push(@{$changes{'searchby'}},@searchby);
10443: }
1.25 raeburn 10444:
10445: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
10446: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
10447: if (!grep(/^\Q$type\E$/,@searchtypes)) {
10448: push(@{$changes{'searchtypes'}},$type);
10449: }
10450: }
10451: foreach my $type (@searchtypes) {
10452: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
10453: push(@{$changes{'searchtypes'}},$type);
10454: }
10455: }
10456: } else {
10457: if (exists($currdirsrch{'searchtypes'})) {
10458: foreach my $type (@searchtypes) {
10459: if ($type ne $currdirsrch{'searchtypes'}) {
10460: push(@{$changes{'searchtypes'}},$type);
10461: }
10462: }
10463: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
10464: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
10465: }
10466: } else {
10467: push(@{$changes{'searchtypes'}},@searchtypes);
10468: }
10469: }
10470:
1.23 raeburn 10471: my %dirsrch_hash = (
10472: directorysrch => { available => $env{'form.dirsrch_available'},
10473: cansearch => \@cansearch,
1.160.6.72 raeburn 10474: localonly => $env{'form.dirsrch_instlocalonly'},
10475: lclocalonly => $env{'form.dirsrch_domlocalonly'},
10476: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 10477: searchby => \@searchby,
1.25 raeburn 10478: searchtypes => \@searchtypes,
1.23 raeburn 10479: }
10480: );
10481: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
10482: $dom);
10483: if ($putresult eq 'ok') {
10484: if (exists($currdirsrch{'available'})) {
10485: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
10486: $changes{'available'} = 1;
10487: }
10488: } else {
10489: if ($env{'form.dirsrch_available'} eq '1') {
10490: $changes{'available'} = 1;
10491: }
10492: }
1.160.6.72 raeburn 10493: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 10494: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
10495: $changes{'lcavailable'} = 1;
10496: }
1.24 raeburn 10497: } else {
1.160.6.72 raeburn 10498: if ($env{'form.dirsrch_lcavailable'} eq '1') {
10499: $changes{'lcavailable'} = 1;
10500: }
10501: }
10502: if (exists($currdirsrch{'localonly'})) {
10503: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 10504: $changes{'localonly'} = 1;
10505: }
1.160.6.72 raeburn 10506: } else {
10507: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
10508: $changes{'localonly'} = 1;
10509: }
10510: }
10511: if (exists($currdirsrch{'lclocalonly'})) {
10512: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
10513: $changes{'lclocalonly'} = 1;
10514: }
10515: } else {
10516: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
10517: $changes{'lclocalonly'} = 1;
10518: }
1.24 raeburn 10519: }
1.23 raeburn 10520: if (keys(%changes) > 0) {
10521: $resulttext = &mt('Changes made:').'<ul>';
10522: if ($changes{'available'}) {
10523: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
10524: }
1.160.6.72 raeburn 10525: if ($changes{'lcavailable'}) {
10526: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
10527: }
1.24 raeburn 10528: if ($changes{'localonly'}) {
1.160.6.72 raeburn 10529: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
10530: }
10531: if ($changes{'lclocalonly'}) {
10532: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 10533: }
1.23 raeburn 10534: if (ref($changes{'cansearch'}) eq 'ARRAY') {
10535: my $chgtext;
1.26 raeburn 10536: if (ref($usertypes) eq 'HASH') {
10537: if (keys(%{$usertypes}) > 0) {
10538: foreach my $type (@{$types}) {
10539: if (grep(/^\Q$type\E$/,@cansearch)) {
10540: $chgtext .= $usertypes->{$type}.'; ';
10541: }
10542: }
10543: if (grep(/^default$/,@cansearch)) {
10544: $chgtext .= $othertitle;
10545: } else {
10546: $chgtext =~ s/\; $//;
10547: }
1.160.6.13 raeburn 10548: $resulttext .=
10549: '<li>'.
10550: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
10551: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
10552: '</li>';
1.23 raeburn 10553: }
10554: }
10555: }
10556: if (ref($changes{'searchby'}) eq 'ARRAY') {
10557: my ($searchtitles,$titleorder) = &sorted_searchtitles();
10558: my $chgtext;
10559: foreach my $type (@{$titleorder}) {
10560: if (grep(/^\Q$type\E$/,@searchby)) {
10561: if (defined($searchtitles->{$type})) {
10562: $chgtext .= $searchtitles->{$type}.'; ';
10563: }
10564: }
10565: }
10566: $chgtext =~ s/\; $//;
10567: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
10568: }
1.25 raeburn 10569: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
10570: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
10571: my $chgtext;
10572: foreach my $type (@{$srchtypeorder}) {
10573: if (grep(/^\Q$type\E$/,@searchtypes)) {
10574: if (defined($srchtypes_desc->{$type})) {
10575: $chgtext .= $srchtypes_desc->{$type}.'; ';
10576: }
10577: }
10578: }
10579: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 10580: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 10581: }
10582: $resulttext .= '</ul>';
1.160.6.81 raeburn 10583: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
10584: if (ref($lastactref) eq 'HASH') {
10585: $lastactref->{'directorysrch'} = 1;
10586: }
1.23 raeburn 10587: } else {
1.160.6.72 raeburn 10588: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 10589: }
10590: } else {
10591: $resulttext = '<span class="LC_error">'.
1.27 raeburn 10592: &mt('An error occurred: [_1]',$putresult).'</span>';
10593: }
10594: return $resulttext;
10595: }
10596:
1.28 raeburn 10597: sub modify_contacts {
1.160.6.24 raeburn 10598: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 10599: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
10600: if (ref($domconfig{'contacts'}) eq 'HASH') {
10601: foreach my $key (keys(%{$domconfig{'contacts'}})) {
10602: $currsetting{$key} = $domconfig{'contacts'}{$key};
10603: }
10604: }
1.160.6.78 raeburn 10605: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 10606: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 10607: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 10608: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.107! raeburn 10609: my @toggles = ('reporterrors','reportupdates','reportstatus');
! 10610: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.160.6.78 raeburn 10611: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 10612: foreach my $type (@mailings) {
10613: @{$newsetting{$type}} =
10614: &Apache::loncommon::get_env_multiple('form.'.$type);
10615: foreach my $item (@contacts) {
10616: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
10617: $contacts_hash{contacts}{$type}{$item} = 1;
10618: } else {
10619: $contacts_hash{contacts}{$type}{$item} = 0;
10620: }
1.160.6.78 raeburn 10621: }
1.28 raeburn 10622: $others{$type} = $env{'form.'.$type.'_others'};
10623: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 10624: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10625: $bcc{$type} = $env{'form.'.$type.'_bcc'};
10626: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 10627: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
10628: $includestr{$type} = $env{'form.'.$type.'_includestr'};
10629: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
10630: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
10631: }
1.134 raeburn 10632: }
1.28 raeburn 10633: }
10634: foreach my $item (@contacts) {
10635: $to{$item} = $env{'form.'.$item};
10636: $contacts_hash{'contacts'}{$item} = $to{$item};
10637: }
1.160.6.23 raeburn 10638: foreach my $item (@toggles) {
10639: if ($env{'form.'.$item} =~ /^(0|1)$/) {
10640: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
10641: }
10642: }
1.160.6.107! raeburn 10643: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
! 10644: foreach my $item (@lonstatus) {
! 10645: if ($item eq 'excluded') {
! 10646: my (%serverhomes,@excluded);
! 10647: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
! 10648: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
! 10649: if (@possexcluded) {
! 10650: foreach my $id (sort(@possexcluded)) {
! 10651: if ($serverhomes{$id}) {
! 10652: push(@excluded,$id);
! 10653: }
! 10654: }
! 10655: }
! 10656: if (@excluded) {
! 10657: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
! 10658: }
! 10659: } elsif ($item eq 'weights') {
! 10660: foreach my $type ('E','W','N','U') {
! 10661: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
! 10662: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
! 10663: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
! 10664: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
! 10665: $env{'form.error'.$item.'_'.$type};
! 10666: }
! 10667: }
! 10668: }
! 10669: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
! 10670: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
! 10671: if ($env{'form.error'.$item} =~ /^\d+$/) {
! 10672: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
! 10673: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
! 10674: }
! 10675: }
! 10676: }
! 10677: }
1.160.6.78 raeburn 10678: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
10679: foreach my $field (@{$fields}) {
10680: if (ref($possoptions->{$field}) eq 'ARRAY') {
10681: my $value = $env{'form.helpform_'.$field};
10682: $value =~ s/^\s+|\s+$//g;
10683: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101 raeburn 10684: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 10685: if ($field eq 'screenshot') {
10686: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
10687: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101 raeburn 10688: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 10689: }
10690: }
10691: }
10692: }
10693: }
10694: }
1.160.6.101 raeburn 10695: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10696: my (@statuses,%usertypeshash,@overrides);
10697: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
10698: @statuses = @{$types};
10699: if (ref($usertypes) eq 'HASH') {
10700: %usertypeshash = %{$usertypes};
10701: }
10702: }
10703: if (@statuses) {
10704: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
10705: foreach my $type (@possoverrides) {
10706: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
10707: push(@overrides,$type);
10708: }
10709: }
10710: if (@overrides) {
10711: foreach my $type (@overrides) {
10712: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
10713: foreach my $item (@contacts) {
10714: if (grep(/^\Q$item\E$/,@standard)) {
10715: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
10716: $newsetting{'override_'.$type}{$item} = 1;
10717: } else {
10718: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
10719: $newsetting{'override_'.$type}{$item} = 0;
10720: }
10721: }
10722: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
10723: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
10724: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
10725: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
10726: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
10727: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
10728: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
10729: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
10730: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
10731: }
10732: }
10733: }
10734: }
1.28 raeburn 10735: if (keys(%currsetting) > 0) {
10736: foreach my $item (@contacts) {
10737: if ($to{$item} ne $currsetting{$item}) {
10738: $changes{$item} = 1;
10739: }
10740: }
10741: foreach my $type (@mailings) {
10742: foreach my $item (@contacts) {
10743: if (ref($currsetting{$type}) eq 'HASH') {
10744: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
10745: push(@{$changes{$type}},$item);
10746: }
10747: } else {
10748: push(@{$changes{$type}},@{$newsetting{$type}});
10749: }
10750: }
10751: if ($others{$type} ne $currsetting{$type}{'others'}) {
10752: push(@{$changes{$type}},'others');
10753: }
1.160.6.78 raeburn 10754: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10755: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
10756: push(@{$changes{$type}},'bcc');
10757: }
1.160.6.78 raeburn 10758: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
10759: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
10760: push(@{$changes{$type}},'include');
10761: }
10762: }
10763: }
10764: if (ref($fields) eq 'ARRAY') {
10765: if (ref($currsetting{'helpform'}) eq 'HASH') {
10766: foreach my $field (@{$fields}) {
10767: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
10768: push(@{$changes{'helpform'}},$field);
10769: }
10770: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10771: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
10772: push(@{$changes{'helpform'}},'maxsize');
10773: }
10774: }
10775: }
10776: } else {
10777: foreach my $field (@{$fields}) {
10778: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10779: push(@{$changes{'helpform'}},$field);
10780: }
10781: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10782: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10783: push(@{$changes{'helpform'}},'maxsize');
10784: }
10785: }
10786: }
1.134 raeburn 10787: }
1.28 raeburn 10788: }
1.160.6.101 raeburn 10789: if (@statuses) {
10790: if (ref($currsetting{'overrides'}) eq 'HASH') {
10791: foreach my $key (keys(%{$currsetting{'overrides'}})) {
10792: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
10793: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
10794: foreach my $item (@contacts,'bcc','others','include') {
10795: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
10796: push(@{$changes{'overrides'}},$key);
10797: last;
10798: }
10799: }
10800: } else {
10801: push(@{$changes{'overrides'}},$key);
10802: }
10803: }
10804: }
10805: foreach my $key (@overrides) {
10806: unless (exists($currsetting{'overrides'}{$key})) {
10807: push(@{$changes{'overrides'}},$key);
10808: }
10809: }
10810: } else {
10811: foreach my $key (@overrides) {
10812: push(@{$changes{'overrides'}},$key);
10813: }
10814: }
10815: }
1.160.6.107! raeburn 10816: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
! 10817: foreach my $key ('excluded','weights','threshold','sysmail') {
! 10818: if ($key eq 'excluded') {
! 10819: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
! 10820: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
! 10821: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
! 10822: (@{$currsetting{'lonstatus'}{$key}})) {
! 10823: my @diffs =
! 10824: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
! 10825: $currsetting{'lonstatus'}{$key});
! 10826: if (@diffs) {
! 10827: push(@{$changes{'lonstatus'}},$key);
! 10828: }
! 10829: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
! 10830: push(@{$changes{'lonstatus'}},$key);
! 10831: }
! 10832: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
! 10833: (@{$currsetting{'lonstatus'}{$key}})) {
! 10834: push(@{$changes{'lonstatus'}},$key);
! 10835: }
! 10836: } elsif ($key eq 'weights') {
! 10837: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
! 10838: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
! 10839: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
! 10840: foreach my $type ('E','W','N','U') {
! 10841: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
! 10842: $currsetting{'lonstatus'}{$key}{$type}) {
! 10843: push(@{$changes{'lonstatus'}},$key);
! 10844: last;
! 10845: }
! 10846: }
! 10847: } else {
! 10848: foreach my $type ('E','W','N','U') {
! 10849: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
! 10850: push(@{$changes{'lonstatus'}},$key);
! 10851: last;
! 10852: }
! 10853: }
! 10854: }
! 10855: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
! 10856: foreach my $type ('E','W','N','U') {
! 10857: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
! 10858: push(@{$changes{'lonstatus'}},$key);
! 10859: last;
! 10860: }
! 10861: }
! 10862: }
! 10863: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
! 10864: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
! 10865: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
! 10866: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
! 10867: push(@{$changes{'lonstatus'}},$key);
! 10868: }
! 10869: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
! 10870: push(@{$changes{'lonstatus'}},$key);
! 10871: }
! 10872: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
! 10873: push(@{$changes{'lonstatus'}},$key);
! 10874: }
! 10875: }
! 10876: }
! 10877: } else {
! 10878: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
! 10879: foreach my $key ('excluded','weights','threshold','sysmail') {
! 10880: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
! 10881: push(@{$changes{'lonstatus'}},$key);
! 10882: }
! 10883: }
! 10884: }
! 10885: }
1.28 raeburn 10886: } else {
10887: my %default;
10888: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
10889: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
10890: $default{'errormail'} = 'adminemail';
10891: $default{'packagesmail'} = 'adminemail';
10892: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 10893: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 10894: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 10895: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 10896: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 10897: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 10898: foreach my $item (@contacts) {
10899: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 10900: $changes{$item} = 1;
1.160.6.23 raeburn 10901: }
1.28 raeburn 10902: }
10903: foreach my $type (@mailings) {
10904: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
10905: push(@{$changes{$type}},@{$newsetting{$type}});
10906: }
10907: if ($others{$type} ne '') {
10908: push(@{$changes{$type}},'others');
1.134 raeburn 10909: }
1.160.6.78 raeburn 10910: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10911: if ($bcc{$type} ne '') {
10912: push(@{$changes{$type}},'bcc');
10913: }
1.160.6.78 raeburn 10914: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
10915: push(@{$changes{$type}},'include');
10916: }
10917: }
10918: }
10919: if (ref($fields) eq 'ARRAY') {
10920: foreach my $field (@{$fields}) {
10921: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10922: push(@{$changes{'helpform'}},$field);
10923: }
10924: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10925: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10926: push(@{$changes{'helpform'}},'maxsize');
10927: }
10928: }
1.134 raeburn 10929: }
1.28 raeburn 10930: }
1.160.6.107! raeburn 10931: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
! 10932: foreach my $key ('excluded','weights','threshold','sysmail') {
! 10933: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
! 10934: push(@{$changes{'lonstatus'}},$key);
! 10935: }
! 10936: }
! 10937: }
1.28 raeburn 10938: }
1.160.6.23 raeburn 10939: foreach my $item (@toggles) {
10940: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
10941: $changes{$item} = 1;
10942: } elsif ((!$env{'form.'.$item}) &&
10943: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
10944: $changes{$item} = 1;
10945: }
10946: }
1.28 raeburn 10947: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
10948: $dom);
10949: if ($putresult eq 'ok') {
10950: if (keys(%changes) > 0) {
1.160.6.24 raeburn 10951: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10952: if (ref($lastactref) eq 'HASH') {
10953: $lastactref->{'domainconfig'} = 1;
10954: }
1.28 raeburn 10955: my ($titles,$short_titles) = &contact_titles();
10956: $resulttext = &mt('Changes made:').'<ul>';
10957: foreach my $item (@contacts) {
10958: if ($changes{$item}) {
10959: $resulttext .= '<li>'.$titles->{$item}.
10960: &mt(' set to: ').
10961: '<span class="LC_cusr_emph">'.
10962: $to{$item}.'</span></li>';
10963: }
10964: }
10965: foreach my $type (@mailings) {
10966: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 10967: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
10968: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
10969: } else {
10970: $resulttext .= '<li>'.$titles->{$type}.': ';
10971: }
1.28 raeburn 10972: my @text;
10973: foreach my $item (@{$newsetting{$type}}) {
10974: push(@text,$short_titles->{$item});
10975: }
10976: if ($others{$type} ne '') {
10977: push(@text,$others{$type});
10978: }
1.160.6.78 raeburn 10979: if (@text) {
10980: $resulttext .= '<span class="LC_cusr_emph">'.
10981: join(', ',@text).'</span>';
10982: }
10983: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10984: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 10985: my $bcctext;
10986: if (@text) {
10987: $bcctext = ' '.&mt('with Bcc to');
10988: } else {
10989: $bcctext = '(Bcc)';
10990: }
10991: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
10992: } elsif (!@text) {
10993: $resulttext .= &mt('No one');
1.134 raeburn 10994: }
1.160.6.78 raeburn 10995: if ($includestr{$type} ne '') {
10996: if ($includeloc{$type} eq 'b') {
10997: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
10998: } elsif ($includeloc{$type} eq 's') {
10999: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
11000: }
11001: }
11002: } elsif (!@text) {
11003: $resulttext .= &mt('No recipients');
1.134 raeburn 11004: }
11005: $resulttext .= '</li>';
1.28 raeburn 11006: }
11007: }
1.160.6.101 raeburn 11008: if (ref($changes{'overrides'}) eq 'ARRAY') {
11009: my @deletions;
11010: foreach my $type (@{$changes{'overrides'}}) {
11011: if ($usertypeshash{$type}) {
11012: if (grep(/^\Q$type\E/,@overrides)) {
11013: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
11014: $usertypeshash{$type}).'<ul><li>';
11015: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
11016: my @text;
11017: foreach my $item (@contacts) {
11018: if ($newsetting{'override_'.$type}{$item}) {
11019: push(@text,$short_titles->{$item});
11020: }
11021: }
11022: if ($newsetting{'override_'.$type}{'others'} ne '') {
11023: push(@text,$newsetting{'override_'.$type}{'others'});
11024: }
11025:
11026: if (@text) {
11027: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
11028: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
11029: }
11030: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
11031: my $bcctext;
11032: if (@text) {
11033: $bcctext = ' '.&mt('with Bcc to');
11034: } else {
11035: $bcctext = '(Bcc)';
11036: }
11037: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
11038: } elsif (!@text) {
11039: $resulttext .= &mt('Helpdesk e-mail sent to no one');
11040: }
11041: $resulttext .= '</li>';
11042: if ($newsetting{'override_'.$type}{'include'} ne '') {
11043: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
11044: if ($loc eq 'b') {
11045: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
11046: } elsif ($loc eq 's') {
11047: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
11048: }
11049: }
11050: }
11051: $resulttext .= '</li></ul></li>';
11052: } else {
11053: push(@deletions,$usertypeshash{$type});
11054: }
11055: }
11056: }
11057: if (@deletions) {
11058: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
11059: join(', ',@deletions)).'</li>';
11060: }
11061: }
1.160.6.23 raeburn 11062: my @offon = ('off','on');
1.160.6.107! raeburn 11063: my $corelink = &core_link_msu();
1.160.6.23 raeburn 11064: if ($changes{'reporterrors'}) {
11065: $resulttext .= '<li>'.
11066: &mt('E-mail error reports to [_1] set to "'.
11067: $offon[$env{'form.reporterrors'}].'".',
1.160.6.107! raeburn 11068: $corelink).
1.160.6.23 raeburn 11069: '</li>';
11070: }
11071: if ($changes{'reportupdates'}) {
11072: $resulttext .= '<li>'.
11073: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
11074: $offon[$env{'form.reportupdates'}].'".',
1.160.6.107! raeburn 11075: $corelink).
1.160.6.23 raeburn 11076: '</li>';
11077: }
1.160.6.107! raeburn 11078: if ($changes{'reportstatus'}) {
! 11079: $resulttext .= '<li>'.
! 11080: &mt('E-mail status if errors above threshold to [_1] set to "'.
! 11081: $offon[$env{'form.reportstatus'}].'".',
! 11082: $corelink).
! 11083: '</li>';
! 11084: }
! 11085: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
! 11086: $resulttext .= '<li>'.
! 11087: &mt('Nightly status check e-mail settings').':<ul>';
! 11088: my (%defval,%use_def,%shown);
! 11089: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
! 11090: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
! 11091: $defval{'weights'} =
! 11092: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
! 11093: $defval{'excluded'} = &mt('None');
! 11094: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
! 11095: foreach my $item ('threshold','sysmail','weights','excluded') {
! 11096: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
! 11097: if (($item eq 'threshold') || ($item eq 'sysmail')) {
! 11098: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
! 11099: } elsif ($item eq 'weights') {
! 11100: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
! 11101: foreach my $type ('E','W','N','U') {
! 11102: $shown{$item} .= $lonstatus_names->{$type}.'=';
! 11103: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
! 11104: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
! 11105: } else {
! 11106: $shown{$item} .= $lonstatus_defs->{$type};
! 11107: }
! 11108: $shown{$item} .= ', ';
! 11109: }
! 11110: $shown{$item} =~ s/, $//;
! 11111: } else {
! 11112: $shown{$item} = $defval{$item};
! 11113: }
! 11114: } elsif ($item eq 'excluded') {
! 11115: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
! 11116: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
! 11117: } else {
! 11118: $shown{$item} = $defval{$item};
! 11119: }
! 11120: }
! 11121: } else {
! 11122: $shown{$item} = $defval{$item};
! 11123: }
! 11124: }
! 11125: } else {
! 11126: foreach my $item ('threshold','weights','excluded','sysmail') {
! 11127: $shown{$item} = $defval{$item};
! 11128: }
! 11129: }
! 11130: foreach my $item ('threshold','weights','excluded','sysmail') {
! 11131: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
! 11132: $shown{$item}).'</li>';
! 11133: }
! 11134: $resulttext .= '</ul></li>';
! 11135: }
1.160.6.78 raeburn 11136: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
11137: my (@optional,@required,@unused,$maxsizechg);
11138: foreach my $field (@{$changes{'helpform'}}) {
11139: if ($field eq 'maxsize') {
11140: $maxsizechg = 1;
11141: next;
11142: }
11143: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
11144: push(@optional,$field);
11145: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
11146: push(@unused,$field);
11147: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
11148: push(@required,$field);
11149: }
11150: }
11151: if (@optional) {
11152: $resulttext .= '<li>'.
11153: &mt('Help form fields changed to "Optional": [_1].',
11154: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
11155: '</li>';
11156: }
11157: if (@required) {
11158: $resulttext .= '<li>'.
11159: &mt('Help form fields changed to "Required": [_1].',
11160: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
11161: '</li>';
11162: }
11163: if (@unused) {
11164: $resulttext .= '<li>'.
11165: &mt('Help form fields changed to "Not shown": [_1].',
11166: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
11167: '</li>';
11168: }
11169: if ($maxsizechg) {
11170: $resulttext .= '<li>'.
11171: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
11172: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
11173: '</li>';
11174: }
11175: }
1.28 raeburn 11176: $resulttext .= '</ul>';
11177: } else {
1.160.6.78 raeburn 11178: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 11179: }
11180: } else {
11181: $resulttext = '<span class="LC_error">'.
11182: &mt('An error occurred: [_1].',$putresult).'</span>';
11183: }
11184: return $resulttext;
11185: }
11186:
1.160.6.98 raeburn 11187: sub modify_passwords {
11188: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
11189: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
11190: $updatedefaults,$updateconf);
11191: my $customfn = 'resetpw.html';
11192: if (ref($domconfig{'passwords'}) eq 'HASH') {
11193: %current = %{$domconfig{'passwords'}};
11194: }
11195: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11196: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11197: if (ref($types) eq 'ARRAY') {
11198: @oktypes = @{$types};
11199: }
11200: push(@oktypes,'default');
11201:
11202: my %titles = &Apache::lonlocal::texthash (
11203: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
11204: intauth_check => 'Check bcrypt cost if authenticated',
11205: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
11206: permanent => 'Permanent e-mail address',
11207: critical => 'Critical notification address',
11208: notify => 'Notification address',
11209: min => 'Minimum password length',
11210: max => 'Maximum password length',
11211: chars => 'Required characters',
11212: numsaved => 'Number of previous passwords to save',
11213: reset => 'Resetting Forgotten Password',
11214: intauth => 'Encryption of Stored Passwords (Internal Auth)',
11215: rules => 'Rules for LON-CAPA Passwords',
11216: crsownerchg => 'Course Owner Changing Student Passwords',
11217: username => 'Username',
11218: email => 'E-mail address',
11219: );
11220:
11221: #
11222: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
11223: #
11224: my (%curr_defaults,%save_defaults);
11225: if (ref($domconfig{'defaults'}) eq 'HASH') {
11226: foreach my $key (keys(%{$domconfig{'defaults'}})) {
11227: if ($key =~ /^intauth_(cost|check|switch)$/) {
11228: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
11229: } else {
11230: $save_defaults{$key} = $domconfig{'defaults'}{$key};
11231: }
11232: }
11233: }
11234: my %staticdefaults = (
11235: 'resetlink' => 2,
11236: 'resetcase' => \@oktypes,
11237: 'resetprelink' => 'both',
11238: 'resetemail' => ['critical','notify','permanent'],
11239: 'intauth_cost' => 10,
11240: 'intauth_check' => 0,
11241: 'intauth_switch' => 0,
11242: );
1.160.6.99 raeburn 11243: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 11244: foreach my $type (@oktypes) {
11245: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
11246: }
11247: my $linklife = $env{'form.passwords_link'};
11248: $linklife =~ s/^\s+|\s+$//g;
11249: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
11250: $newvalues{'resetlink'} = $linklife;
11251: if ($current{'resetlink'}) {
11252: if ($current{'resetlink'} ne $linklife) {
11253: $changes{'reset'} = 1;
11254: }
1.160.6.102 raeburn 11255: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 11256: if ($staticdefaults{'resetlink'} ne $linklife) {
11257: $changes{'reset'} = 1;
11258: }
11259: }
11260: } elsif ($current{'resetlink'}) {
11261: $changes{'reset'} = 1;
11262: }
11263: my @casesens;
11264: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
11265: foreach my $case (sort(@posscase)) {
11266: if (grep(/^\Q$case\E$/,@oktypes)) {
11267: push(@casesens,$case);
11268: }
11269: }
11270: $newvalues{'resetcase'} = \@casesens;
11271: if (ref($current{'resetcase'}) eq 'ARRAY') {
11272: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
11273: if (@diffs > 0) {
11274: $changes{'reset'} = 1;
11275: }
1.160.6.102 raeburn 11276: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 11277: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
11278: if (@diffs > 0) {
11279: $changes{'reset'} = 1;
11280: }
11281: }
11282: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
11283: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
11284: if (exists($current{'resetprelink'})) {
11285: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
11286: $changes{'reset'} = 1;
11287: }
1.160.6.102 raeburn 11288: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 11289: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
11290: $changes{'reset'} = 1;
11291: }
11292: }
11293: } elsif ($current{'resetprelink'}) {
11294: $changes{'reset'} = 1;
11295: }
11296: foreach my $type (@oktypes) {
11297: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
11298: my @postlink;
11299: foreach my $item (sort(@possplink)) {
11300: if ($item =~ /^(email|username)$/) {
11301: push(@postlink,$item);
11302: }
11303: }
11304: $newvalues{'resetpostlink'}{$type} = \@postlink;
11305: unless ($changes{'reset'}) {
11306: if (ref($current{'resetpostlink'}) eq 'HASH') {
11307: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
11308: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
11309: if (@diffs > 0) {
11310: $changes{'reset'} = 1;
11311: }
11312: } else {
11313: $changes{'reset'} = 1;
11314: }
1.160.6.102 raeburn 11315: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 11316: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
11317: if (@diffs > 0) {
11318: $changes{'reset'} = 1;
11319: }
11320: }
11321: }
11322: }
11323: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
11324: my @resetemail;
11325: foreach my $item (sort(@possemailsrc)) {
11326: if ($item =~ /^(permanent|critical|notify)$/) {
11327: push(@resetemail,$item);
11328: }
11329: }
11330: $newvalues{'resetemail'} = \@resetemail;
11331: unless ($changes{'reset'}) {
11332: if (ref($current{'resetemail'}) eq 'ARRAY') {
11333: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
11334: if (@diffs > 0) {
11335: $changes{'reset'} = 1;
11336: }
1.160.6.102 raeburn 11337: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 11338: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
11339: if (@diffs > 0) {
11340: $changes{'reset'} = 1;
11341: }
11342: }
11343: }
11344: if ($env{'form.passwords_stdtext'} == 0) {
11345: $newvalues{'resetremove'} = 1;
11346: unless ($current{'resetremove'}) {
11347: $changes{'reset'} = 1;
11348: }
11349: } elsif ($current{'resetremove'}) {
11350: $changes{'reset'} = 1;
11351: }
11352: if ($env{'form.passwords_customfile.filename'} ne '') {
11353: my $servadm = $r->dir_config('lonAdmEMail');
11354: my $servadm = $r->dir_config('lonAdmEMail');
11355: my ($configuserok,$author_ok,$switchserver) =
11356: &config_check($dom,$confname,$servadm);
11357: my $error;
11358: if ($configuserok eq 'ok') {
11359: if ($switchserver) {
11360: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
11361: } else {
11362: if ($author_ok eq 'ok') {
11363: my ($result,$customurl) =
11364: &publishlogo($r,'upload','passwords_customfile',$dom,
11365: $confname,'customtext/resetpw','','',$customfn);
11366: if ($result eq 'ok') {
11367: $newvalues{'resetcustom'} = $customurl;
11368: $changes{'reset'} = 1;
11369: } else {
11370: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
11371: }
11372: } else {
11373: $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);
11374: }
11375: }
11376: } else {
11377: $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);
11378: }
11379: if ($error) {
11380: &Apache::lonnet::logthis($error);
11381: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11382: }
11383: } elsif ($current{'resetcustom'}) {
11384: if ($env{'form.passwords_custom_del'}) {
11385: $changes{'reset'} = 1;
11386: } else {
11387: $newvalues{'resetcustom'} = $current{'resetcustom'};
11388: }
11389: }
11390: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
11391: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
11392: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
11393: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
11394: $changes{'intauth'} = 1;
11395: }
11396: } else {
11397: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
11398: }
11399: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
11400: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
11401: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
11402: $changes{'intauth'} = 1;
11403: }
11404: } else {
11405: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
11406: }
11407: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
11408: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
11409: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
11410: $changes{'intauth'} = 1;
11411: }
11412: } else {
11413: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
11414: }
11415: foreach my $item ('cost','check','switch') {
11416: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
11417: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
11418: $updatedefaults = 1;
11419: }
11420: }
11421: foreach my $rule ('min','max','numsaved') {
11422: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.160.6.99 raeburn 11423: my $ruleok;
11424: if ($rule eq 'min') {
11425: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
11426: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
11427: $ruleok = 1;
11428: }
11429: }
11430: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
11431: ($env{'form.passwords_'.$rule} ne '0')) {
11432: $ruleok = 1;
11433: }
11434: if ($ruleok) {
1.160.6.98 raeburn 11435: $newvalues{$rule} = $env{'form.passwords_'.$rule};
11436: if (exists($current{$rule})) {
11437: if ($newvalues{$rule} ne $current{$rule}) {
11438: $changes{'rules'} = 1;
11439: }
11440: } elsif ($rule eq 'min') {
11441: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
11442: $changes{'rules'} = 1;
11443: }
1.160.6.104 raeburn 11444: } else {
11445: $changes{'rules'} = 1;
1.160.6.98 raeburn 11446: }
11447: } elsif (exists($current{$rule})) {
11448: $changes{'rules'} = 1;
11449: }
11450: }
11451: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
11452: my @chars;
11453: foreach my $item (sort(@posschars)) {
11454: if ($item =~ /^(uc|lc|num|spec)$/) {
11455: push(@chars,$item);
11456: }
11457: }
11458: $newvalues{'chars'} = \@chars;
11459: unless ($changes{'rules'}) {
11460: if (ref($current{'chars'}) eq 'ARRAY') {
11461: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
11462: if (@diffs > 0) {
11463: $changes{'rules'} = 1;
11464: }
11465: } else {
11466: if (@chars > 0) {
11467: $changes{'rules'} = 1;
11468: }
11469: }
11470: }
11471: my %crsownerchg = (
11472: by => [],
11473: for => [],
11474: );
11475: foreach my $item ('by','for') {
11476: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
11477: foreach my $type (sort(@posstypes)) {
11478: if (grep(/^\Q$type\E$/,@oktypes)) {
11479: push(@{$crsownerchg{$item}},$type);
11480: }
11481: }
11482: }
11483: $newvalues{'crsownerchg'} = \%crsownerchg;
11484: if (ref($current{'crsownerchg'}) eq 'HASH') {
11485: foreach my $item ('by','for') {
11486: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
11487: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
11488: if (@diffs > 0) {
11489: $changes{'crsownerchg'} = 1;
11490: last;
11491: }
11492: }
11493: }
1.160.6.102 raeburn 11494: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98 raeburn 11495: foreach my $item ('by','for') {
11496: if (@{$crsownerchg{$item}} > 0) {
11497: $changes{'crsownerchg'} = 1;
11498: last;
11499: }
11500: }
11501: }
11502:
11503: my %confighash = (
11504: defaults => \%save_defaults,
11505: passwords => \%newvalues,
11506: );
11507: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
11508:
11509: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
11510: if ($putresult eq 'ok') {
11511: if (keys(%changes) > 0) {
11512: $resulttext = &mt('Changes made: ').'<ul>';
11513: foreach my $key ('reset','intauth','rules','crsownerchg') {
11514: if ($changes{$key}) {
11515: unless ($key eq 'intauth') {
11516: $updateconf = 1;
11517: }
11518: $resulttext .= '<li>'.$titles{$key}.':<ul>';
11519: if ($key eq 'reset') {
11520: if ($confighash{'passwords'}{'captcha'} eq 'original') {
11521: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
11522: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
11523: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.160.6.104 raeburn 11524: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
11525: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
11526: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
11527: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
11528: }
1.160.6.98 raeburn 11529: } else {
11530: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
11531: }
11532: if ($confighash{'passwords'}{'resetlink'}) {
11533: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
11534: } else {
11535: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
11536: &mt('Will default to 2 hours').'</li>';
11537: }
11538: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
11539: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
11540: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
11541: } else {
11542: my $casesens;
11543: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
11544: if ($type eq 'default') {
11545: $casesens .= $othertitle.', ';
11546: } elsif ($usertypes->{$type} ne '') {
11547: $casesens .= $usertypes->{$type}.', ';
11548: }
11549: }
11550: $casesens =~ s/\Q, \E$//;
11551: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
11552: }
11553: } else {
11554: $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>';
11555: }
11556: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
11557: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
11558: } else {
11559: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
11560: }
11561: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
11562: my $output;
11563: if (ref($types) eq 'ARRAY') {
11564: foreach my $type (@{$types}) {
11565: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
11566: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
11567: $output .= $usertypes->{$type}.' -- '.&mt('none');
11568: } else {
11569: $output .= $usertypes->{$type}.' -- '.
11570: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
11571: }
11572: }
11573: }
11574: }
11575: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
11576: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
11577: $output .= $othertitle.' -- '.&mt('none');
11578: } else {
11579: $output .= $othertitle.' -- '.
11580: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
11581: }
11582: }
11583: if ($output) {
11584: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
11585: } else {
11586: $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>';
11587: }
11588: } else {
11589: $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>';
11590: }
11591: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
11592: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
11593: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
11594: } else {
11595: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
11596: }
11597: } else {
11598: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA usedfor verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
11599: }
11600: if ($confighash{'passwords'}{'resetremove'}) {
11601: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
11602: } else {
11603: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
11604: }
11605: if ($confighash{'passwords'}{'resetcustom'}) {
11606: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.160.6.104 raeburn 11607: &mt('custom text'),600,500,undef,undef,
11608: undef,undef,'background-color:#ffffff');
11609: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.160.6.98 raeburn 11610: } else {
11611: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
11612: }
11613: } elsif ($key eq 'intauth') {
11614: foreach my $item ('cost','switch','check') {
11615: my $value = $save_defaults{$key.'_'.$item};
11616: if ($item eq 'switch') {
11617: my %optiondesc = &Apache::lonlocal::texthash (
11618: 0 => 'No',
11619: 1 => 'Yes',
11620: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
11621: );
11622: if ($value =~ /^(0|1|2)$/) {
11623: $value = $optiondesc{$value};
11624: } else {
11625: $value = &mt('none -- defaults to No');
11626: }
11627: } elsif ($item eq 'check') {
11628: my %optiondesc = &Apache::lonlocal::texthash (
11629: 0 => 'No',
11630: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
11631: 2 => 'Yes, disallow login if stored cost is less than domain default',
11632: );
11633: if ($value =~ /^(0|1|2)$/) {
11634: $value = $optiondesc{$value};
11635: } else {
11636: $value = &mt('none -- defaults to No');
11637: }
11638: }
11639: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
11640: }
11641: } elsif ($key eq 'rules') {
11642: foreach my $rule ('min','max','numsaved') {
11643: if ($confighash{'passwords'}{$rule} eq '') {
11644: if ($rule eq 'min') {
11645: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99 raeburn 11646: ' '.&mt('Default of [_1] will be used',
11647: $Apache::lonnet::passwdmin).'</li>';
1.160.6.98 raeburn 11648: } else {
11649: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
11650: }
11651: } else {
11652: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
11653: }
11654: }
1.160.6.104 raeburn 11655: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
11656: if (@{$confighash{'passwords'}{'chars'}} > 0) {
11657: my %rulenames = &Apache::lonlocal::texthash(
11658: uc => 'At least one upper case letter',
11659: lc => 'At least one lower case letter',
11660: num => 'At least one number',
11661: spec => 'At least one non-alphanumeric',
11662: );
11663: my $needed = '<ul><li>'.
11664: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
11665: '</li></ul>';
11666: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
11667: } else {
11668: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
11669: }
11670: } else {
11671: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
11672: }
1.160.6.98 raeburn 11673: } elsif ($key eq 'crsownerchg') {
11674: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
11675: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
11676: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
11677: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
11678: } else {
11679: my %crsownerstr;
11680: foreach my $item ('by','for') {
11681: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
11682: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
11683: if ($type eq 'default') {
11684: $crsownerstr{$item} .= $othertitle.', ';
11685: } elsif ($usertypes->{$type} ne '') {
11686: $crsownerstr{$item} .= $usertypes->{$type}.', ';
11687: }
11688: }
11689: $crsownerstr{$item} =~ s/\Q, \E$//;
11690: }
11691: }
11692: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
11693: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
11694: }
11695: } else {
11696: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
11697: }
11698: }
11699: $resulttext .= '</ul></li>';
11700: }
11701: }
11702: $resulttext .= '</ul>';
11703: } else {
11704: $resulttext = &mt('No changes made to password settings');
11705: }
11706: my $cachetime = 24*60*60;
11707: if ($updatedefaults) {
11708: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11709: if (ref($lastactref) eq 'HASH') {
11710: $lastactref->{'domdefaults'} = 1;
11711: }
11712: }
11713: if ($updateconf) {
11714: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
11715: if (ref($lastactref) eq 'HASH') {
11716: $lastactref->{'passwdconf'} = 1;
11717: }
11718: }
11719: } else {
11720: $resulttext = '<span class="LC_error">'.
11721: &mt('An error occurred: [_1]',$putresult).'</span>';
11722: }
11723: if ($errors) {
11724: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
11725: $errors.'</ul></p>';
11726: }
11727: return $resulttext;
11728: }
11729:
1.28 raeburn 11730: sub modify_usercreation {
1.27 raeburn 11731: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 11732: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 11733: my $warningmsg;
1.27 raeburn 11734: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11735: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 11736: if ($key eq 'cancreate') {
11737: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11738: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 11739: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 11740: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 11741: } else {
11742: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 11743: }
1.50 raeburn 11744: }
1.43 raeburn 11745: }
1.160.6.34 raeburn 11746: } elsif ($key eq 'email_rule') {
11747: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11748: } else {
11749: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 11750: }
11751: }
1.34 raeburn 11752: }
1.160.6.34 raeburn 11753: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
11754: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
11755: my @contexts = ('author','course','requestcrs');
11756: foreach my $item(@contexts) {
11757: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 11758: }
1.34 raeburn 11759: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11760: foreach my $item (@contexts) {
1.160.6.34 raeburn 11761: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
11762: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 11763: }
1.27 raeburn 11764: }
1.34 raeburn 11765: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
11766: foreach my $item (@contexts) {
1.43 raeburn 11767: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 11768: if ($cancreate{$item} ne 'any') {
11769: push(@{$changes{'cancreate'}},$item);
11770: }
11771: } else {
11772: if ($cancreate{$item} ne 'none') {
11773: push(@{$changes{'cancreate'}},$item);
11774: }
1.27 raeburn 11775: }
11776: }
11777: } else {
1.43 raeburn 11778: foreach my $item (@contexts) {
1.34 raeburn 11779: push(@{$changes{'cancreate'}},$item);
11780: }
1.27 raeburn 11781: }
1.34 raeburn 11782:
1.27 raeburn 11783: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
11784: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
11785: if (!grep(/^\Q$type\E$/,@username_rule)) {
11786: push(@{$changes{'username_rule'}},$type);
11787: }
11788: }
11789: foreach my $type (@username_rule) {
11790: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
11791: push(@{$changes{'username_rule'}},$type);
11792: }
11793: }
11794: } else {
11795: push(@{$changes{'username_rule'}},@username_rule);
11796: }
11797:
1.32 raeburn 11798: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
11799: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
11800: if (!grep(/^\Q$type\E$/,@id_rule)) {
11801: push(@{$changes{'id_rule'}},$type);
11802: }
11803: }
11804: foreach my $type (@id_rule) {
11805: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
11806: push(@{$changes{'id_rule'}},$type);
11807: }
11808: }
11809: } else {
11810: push(@{$changes{'id_rule'}},@id_rule);
11811: }
11812:
1.43 raeburn 11813: my @authen_contexts = ('author','course','domain');
1.28 raeburn 11814: my @authtypes = ('int','krb4','krb5','loc');
11815: my %authhash;
1.43 raeburn 11816: foreach my $item (@authen_contexts) {
1.28 raeburn 11817: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
11818: foreach my $auth (@authtypes) {
11819: if (grep(/^\Q$auth\E$/,@authallowed)) {
11820: $authhash{$item}{$auth} = 1;
11821: } else {
11822: $authhash{$item}{$auth} = 0;
11823: }
11824: }
11825: }
11826: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 11827: foreach my $item (@authen_contexts) {
1.28 raeburn 11828: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
11829: foreach my $auth (@authtypes) {
11830: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
11831: push(@{$changes{'authtypes'}},$item);
11832: last;
11833: }
11834: }
11835: }
11836: }
11837: } else {
1.43 raeburn 11838: foreach my $item (@authen_contexts) {
1.28 raeburn 11839: push(@{$changes{'authtypes'}},$item);
11840: }
11841: }
11842:
1.160.6.34 raeburn 11843: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
11844: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
11845: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
11846: $save_usercreate{'id_rule'} = \@id_rule;
11847: $save_usercreate{'username_rule'} = \@username_rule,
11848: $save_usercreate{'authtypes'} = \%authhash;
11849:
1.27 raeburn 11850: my %usercreation_hash = (
1.160.6.34 raeburn 11851: usercreation => \%save_usercreate,
11852: );
1.27 raeburn 11853:
11854: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
11855: $dom);
1.50 raeburn 11856:
1.160.6.34 raeburn 11857: if ($putresult eq 'ok') {
11858: if (keys(%changes) > 0) {
11859: $resulttext = &mt('Changes made:').'<ul>';
11860: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11861: my %lt = &usercreation_types();
11862: foreach my $type (@{$changes{'cancreate'}}) {
11863: my $chgtext = $lt{$type}.', ';
11864: if ($cancreate{$type} eq 'none') {
11865: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
11866: } elsif ($cancreate{$type} eq 'any') {
11867: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
11868: } elsif ($cancreate{$type} eq 'official') {
11869: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
11870: } elsif ($cancreate{$type} eq 'unofficial') {
11871: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
11872: }
11873: $resulttext .= '<li>'.$chgtext.'</li>';
11874: }
11875: }
11876: if (ref($changes{'username_rule'}) eq 'ARRAY') {
11877: my ($rules,$ruleorder) =
11878: &Apache::lonnet::inst_userrules($dom,'username');
11879: my $chgtext = '<ul>';
11880: foreach my $type (@username_rule) {
11881: if (ref($rules->{$type}) eq 'HASH') {
11882: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
11883: }
11884: }
11885: $chgtext .= '</ul>';
11886: if (@username_rule > 0) {
11887: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11888: } else {
11889: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
11890: }
11891: }
11892: if (ref($changes{'id_rule'}) eq 'ARRAY') {
11893: my ($idrules,$idruleorder) =
11894: &Apache::lonnet::inst_userrules($dom,'id');
11895: my $chgtext = '<ul>';
11896: foreach my $type (@id_rule) {
11897: if (ref($idrules->{$type}) eq 'HASH') {
11898: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
11899: }
11900: }
11901: $chgtext .= '</ul>';
11902: if (@id_rule > 0) {
11903: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11904: } else {
11905: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
11906: }
11907: }
11908: my %authname = &authtype_names();
11909: my %context_title = &context_names();
11910: if (ref($changes{'authtypes'}) eq 'ARRAY') {
11911: my $chgtext = '<ul>';
11912: foreach my $type (@{$changes{'authtypes'}}) {
11913: my @allowed;
11914: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
11915: foreach my $auth (@authtypes) {
11916: if ($authhash{$type}{$auth}) {
11917: push(@allowed,$authname{$auth});
11918: }
11919: }
11920: if (@allowed > 0) {
11921: $chgtext .= join(', ',@allowed).'</li>';
11922: } else {
11923: $chgtext .= &mt('none').'</li>';
11924: }
11925: }
11926: $chgtext .= '</ul>';
11927: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
11928: $resulttext .= '</li>';
11929: }
11930: $resulttext .= '</ul>';
11931: } else {
11932: $resulttext = &mt('No changes made to user creation settings');
11933: }
11934: } else {
11935: $resulttext = '<span class="LC_error">'.
11936: &mt('An error occurred: [_1]',$putresult).'</span>';
11937: }
11938: if ($warningmsg ne '') {
11939: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11940: }
11941: return $resulttext;
11942: }
11943:
11944: sub modify_selfcreation {
1.160.6.93 raeburn 11945: my ($dom,$lastactref,%domconfig) = @_;
11946: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
11947: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
11948: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11949: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
11950: if (ref($typesref) eq 'ARRAY') {
11951: @types = @{$typesref};
11952: }
11953: if (ref($usertypesref) eq 'HASH') {
11954: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 11955: }
1.160.6.93 raeburn 11956: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 11957: #
11958: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
11959: #
11960: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11961: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
11962: if ($key eq 'cancreate') {
11963: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11964: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
11965: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 11966: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
11967: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
11968: ($item eq 'emailusername') || ($item eq 'shibenv') ||
11969: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
11970: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 11971: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11972: } else {
11973: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11974: }
11975: }
11976: }
11977: } elsif ($key eq 'email_rule') {
11978: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11979: } else {
11980: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11981: }
11982: }
11983: }
11984: #
11985: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
11986: #
11987: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11988: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
11989: if ($key eq 'selfcreate') {
11990: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
11991: } else {
11992: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
11993: }
11994: }
11995: }
1.160.6.93 raeburn 11996: #
11997: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
11998: #
11999: if (ref($domconfig{'inststatus'}) eq 'HASH') {
12000: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
12001: if ($key eq 'inststatusguest') {
12002: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
12003: } else {
12004: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
12005: }
12006: }
12007: }
1.160.6.34 raeburn 12008:
12009: my @contexts = ('selfcreate');
12010: @{$cancreate{'selfcreate'}} = ();
12011: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 12012: if (@types) {
12013: @{$cancreate{'statustocreate'}} = ();
12014: }
1.160.6.40 raeburn 12015: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 12016: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 12017: %{$cancreate{'emailverified'}} = ();
12018: %{$cancreate{'emailoptions'}} = ();
12019: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 12020: my %selfcreatetypes = (
12021: sso => 'users authenticated by institutional single sign on',
12022: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 12023: email => 'users verified by e-mail',
1.50 raeburn 12024: );
1.160.6.34 raeburn 12025: #
12026: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
12027: # is permitted.
12028: #
1.160.6.40 raeburn 12029:
1.160.6.93 raeburn 12030: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 12031:
1.160.6.93 raeburn 12032: my (@statuses,%email_rule);
1.160.6.35 raeburn 12033: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 12034: if ($item eq 'email') {
1.160.6.40 raeburn 12035: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 12036: if (@types) {
12037: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
12038: foreach my $status (@poss_statuses) {
12039: if (grep(/^\Q$status\E$/,(@types,'default'))) {
12040: push(@statuses,$status);
12041: }
12042: }
12043: $save_inststatus{'inststatusguest'} = \@statuses;
12044: } else {
12045: push(@statuses,'default');
12046: }
12047: if (@statuses) {
12048: my %curr_rule;
12049: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
12050: foreach my $type (@statuses) {
12051: $curr_rule{$type} = $curr_usercreation{'email_rule'};
12052: }
12053: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
12054: foreach my $type (@statuses) {
12055: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
12056: }
12057: }
12058: push(@{$cancreate{'selfcreate'}},'email');
12059: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
12060: my %curremaildom;
12061: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
12062: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
12063: }
12064: foreach my $type (@statuses) {
12065: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
12066: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
12067: }
12068: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
12069: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
12070: }
12071: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
12072: #
12073: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
12074: #
12075: my $chosen = $1;
12076: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
12077: my $emaildom;
12078: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
12079: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
12080: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
12081: if (ref($curremaildom{$type}) eq 'HASH') {
12082: if (exists($curremaildom{$type}{$chosen})) {
12083: if ($curremaildom{$type}{$chosen} ne $emaildom) {
12084: push(@{$changes{'cancreate'}},'emaildomain');
12085: }
12086: } elsif ($emaildom ne '') {
12087: push(@{$changes{'cancreate'}},'emaildomain');
12088: }
12089: } elsif ($emaildom ne '') {
12090: push(@{$changes{'cancreate'}},'emaildomain');
12091: }
12092: }
12093: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
12094: } elsif ($chosen eq 'custom') {
12095: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
12096: $email_rule{$type} = [];
12097: if (ref($emailrules) eq 'HASH') {
12098: foreach my $rule (@possemail_rules) {
12099: if (exists($emailrules->{$rule})) {
12100: push(@{$email_rule{$type}},$rule);
12101: }
12102: }
12103: }
12104: if (@{$email_rule{$type}}) {
12105: $cancreate{'emailoptions'}{$type} = 'custom';
12106: if (ref($curr_rule{$type}) eq 'ARRAY') {
12107: if (@{$curr_rule{$type}} > 0) {
12108: foreach my $rule (@{$curr_rule{$type}}) {
12109: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
12110: push(@{$changes{'email_rule'}},$type);
12111: }
12112: }
12113: }
12114: foreach my $type (@{$email_rule{$type}}) {
12115: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
12116: push(@{$changes{'email_rule'}},$type);
12117: }
12118: }
12119: } else {
12120: push(@{$changes{'email_rule'}},$type);
12121: }
12122: }
12123: } else {
12124: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
12125: }
12126: }
12127: }
12128: if (@types) {
12129: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
12130: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
12131: if (@changed) {
12132: push(@{$changes{'inststatus'}},'inststatusguest');
12133: }
12134: } else {
12135: push(@{$changes{'inststatus'}},'inststatusguest');
12136: }
12137: }
12138: } else {
12139: delete($env{'form.cancreate_email'});
12140: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
12141: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
12142: push(@{$changes{'inststatus'}},'inststatusguest');
12143: }
12144: }
12145: }
12146: } else {
12147: $save_inststatus{'inststatusguest'} = [];
12148: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
12149: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
12150: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 12151: }
12152: }
1.160.6.34 raeburn 12153: }
12154: } else {
12155: if ($env{'form.cancreate_'.$item}) {
12156: push(@{$cancreate{'selfcreate'}},$item);
12157: }
12158: }
12159: }
1.160.6.93 raeburn 12160: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 12161: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
12162: #
1.160.6.35 raeburn 12163: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
12164: # 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 12165: #
1.160.6.40 raeburn 12166:
1.160.6.48 raeburn 12167: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 12168: push(@contexts,'emailusername');
1.160.6.93 raeburn 12169: if (@statuses) {
12170: foreach my $type (@statuses) {
1.160.6.35 raeburn 12171: if (ref($infofields) eq 'ARRAY') {
12172: foreach my $field (@{$infofields}) {
12173: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
12174: $cancreate{'emailusername'}{$type}{$field} = $1;
12175: }
12176: }
1.160.6.34 raeburn 12177: }
12178: }
12179: }
12180: #
12181: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 12182: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 12183: #
12184:
12185: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
12186: @approvalnotify = sort(@approvalnotify);
12187: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
12188: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
12189: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
12190: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
12191: push(@{$changes{'cancreate'}},'notify');
12192: }
12193: } else {
12194: if ($cancreate{'notify'}{'approval'}) {
12195: push(@{$changes{'cancreate'}},'notify');
12196: }
12197: }
12198: } elsif ($cancreate{'notify'}{'approval'}) {
12199: push(@{$changes{'cancreate'}},'notify');
12200: }
12201:
12202: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
12203: }
12204: #
1.160.6.40 raeburn 12205: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 12206: # institutional log-in.
12207: #
12208: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
12209: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
12210: ($domdefaults{'auth_def'} eq 'localauth'))) {
12211: $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.').' '.
12212: &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.');
12213: }
12214: }
12215: my @fields = ('lastname','firstname','middlename','generation',
12216: 'permanentemail','id');
1.160.6.44 raeburn 12217: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 12218: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12219: #
12220: # Where usernames may created for institutional log-in and/or institutional single sign on:
12221: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
12222: # may self-create accounts
12223: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
12224: # which the user may supply, if institutional data is unavailable.
12225: #
12226: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 12227: if (@types) {
12228: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
12229: push(@contexts,'statustocreate');
12230: foreach my $type (@types) {
1.160.6.34 raeburn 12231: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
12232: foreach my $field (@fields) {
12233: if (grep(/^\Q$field\E$/,@modifiable)) {
12234: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
12235: } else {
12236: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
12237: }
12238: }
12239: }
12240: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 12241: foreach my $type (@types) {
1.160.6.34 raeburn 12242: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
12243: foreach my $field (@fields) {
12244: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
12245: $curr_usermodify{'selfcreate'}{$type}{$field}) {
12246: push(@{$changes{'selfcreate'}},$type);
12247: last;
12248: }
12249: }
12250: }
12251: }
12252: } else {
1.160.6.93 raeburn 12253: foreach my $type (@types) {
1.160.6.34 raeburn 12254: push(@{$changes{'selfcreate'}},$type);
12255: }
12256: }
12257: }
1.160.6.44 raeburn 12258: foreach my $field (@shibfields) {
12259: if ($env{'form.shibenv_'.$field} ne '') {
12260: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
12261: }
12262: }
12263: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
12264: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
12265: foreach my $field (@shibfields) {
12266: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
12267: push(@{$changes{'cancreate'}},'shibenv');
12268: }
12269: }
12270: } else {
12271: foreach my $field (@shibfields) {
12272: if ($env{'form.shibenv_'.$field}) {
12273: push(@{$changes{'cancreate'}},'shibenv');
12274: last;
12275: }
12276: }
12277: }
12278: }
1.160.6.34 raeburn 12279: }
12280: foreach my $item (@contexts) {
12281: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
12282: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
12283: if (ref($cancreate{$item}) eq 'ARRAY') {
12284: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
12285: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12286: push(@{$changes{'cancreate'}},$item);
12287: }
12288: }
12289: }
12290: }
12291: if (ref($cancreate{$item}) eq 'ARRAY') {
12292: foreach my $type (@{$cancreate{$item}}) {
12293: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
12294: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12295: push(@{$changes{'cancreate'}},$item);
12296: }
12297: }
12298: }
12299: }
12300: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
12301: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 12302: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
12303: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
12304: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
12305: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 12306: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12307: push(@{$changes{'cancreate'}},$item);
12308: }
12309: }
12310: }
1.160.6.93 raeburn 12311: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
12312: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 12313: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12314: push(@{$changes{'cancreate'}},$item);
12315: }
1.160.6.34 raeburn 12316: }
12317: }
12318: }
1.160.6.93 raeburn 12319: foreach my $type (keys(%{$cancreate{$item}})) {
12320: if (ref($cancreate{$item}{$type}) eq 'HASH') {
12321: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
12322: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
12323: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 12324: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12325: push(@{$changes{'cancreate'}},$item);
12326: }
12327: }
12328: } else {
12329: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12330: push(@{$changes{'cancreate'}},$item);
12331: }
12332: }
12333: }
1.160.6.93 raeburn 12334: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
12335: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 12336: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12337: push(@{$changes{'cancreate'}},$item);
12338: }
1.160.6.34 raeburn 12339: }
12340: }
12341: }
12342: }
12343: } elsif ($curr_usercreation{'cancreate'}{$item}) {
12344: if (ref($cancreate{$item}) eq 'ARRAY') {
12345: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
12346: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12347: push(@{$changes{'cancreate'}},$item);
12348: }
12349: }
1.160.6.93 raeburn 12350: }
12351: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
12352: if (ref($cancreate{$item}) eq 'HASH') {
12353: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12354: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 12355: }
12356: }
12357: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 12358: if (ref($cancreate{$item}) eq 'HASH') {
12359: foreach my $type (keys(%{$cancreate{$item}})) {
12360: if (ref($cancreate{$item}{$type}) eq 'HASH') {
12361: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
12362: if ($cancreate{$item}{$type}{$field}) {
12363: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12364: push(@{$changes{'cancreate'}},$item);
12365: }
12366: last;
12367: }
12368: }
12369: }
12370: }
1.160.6.34 raeburn 12371: }
12372: }
12373: }
12374: #
12375: # Populate %save_usercreate hash with updates to self-creation configuration.
12376: #
12377: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
12378: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 12379: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 12380: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
12381: if (ref($cancreate{'notify'}) eq 'HASH') {
12382: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
12383: }
1.160.6.40 raeburn 12384: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
12385: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
12386: }
1.160.6.93 raeburn 12387: if (ref($cancreate{'emailverified'}) eq 'HASH') {
12388: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
12389: }
12390: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
12391: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
12392: }
12393: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
12394: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
12395: }
1.160.6.34 raeburn 12396: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
12397: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
12398: }
1.160.6.44 raeburn 12399: if (ref($cancreate{'shibenv'}) eq 'HASH') {
12400: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
12401: }
1.160.6.34 raeburn 12402: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 12403: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 12404:
12405: my %userconfig_hash = (
12406: usercreation => \%save_usercreate,
12407: usermodification => \%save_usermodify,
1.160.6.93 raeburn 12408: inststatus => \%save_inststatus,
1.160.6.34 raeburn 12409: );
1.160.6.93 raeburn 12410:
1.160.6.34 raeburn 12411: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
12412: $dom);
12413: #
1.160.6.93 raeburn 12414: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 12415: #
1.27 raeburn 12416: if ($putresult eq 'ok') {
12417: if (keys(%changes) > 0) {
12418: $resulttext = &mt('Changes made:').'<ul>';
12419: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 12420: my %lt = &selfcreation_types();
1.34 raeburn 12421: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 12422: my $chgtext = '';
1.45 raeburn 12423: if ($type eq 'selfcreate') {
1.50 raeburn 12424: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 12425: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 12426: } else {
1.160.6.34 raeburn 12427: $chgtext .= &mt('Self-creation of a new account is permitted for:').
12428: '<ul>';
1.50 raeburn 12429: foreach my $case (@{$cancreate{$type}}) {
12430: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
12431: }
12432: $chgtext .= '</ul>';
1.100 raeburn 12433: if (ref($cancreate{$type}) eq 'ARRAY') {
12434: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
12435: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
12436: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 12437: $chgtext .= '<span class="LC_warning">'.
12438: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
12439: '</span><br />';
1.100 raeburn 12440: }
12441: }
12442: }
1.160.6.93 raeburn 12443: if (grep(/^email$/,@{$cancreate{$type}})) {
12444: if (!@statuses) {
12445: $chgtext .= '<span class="LC_warning">'.
12446: &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.").
12447: '</span><br />';
12448:
12449: }
12450: }
1.100 raeburn 12451: }
1.43 raeburn 12452: }
1.160.6.44 raeburn 12453: } elsif ($type eq 'shibenv') {
12454: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 12455: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 12456: } else {
12457: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
12458: '<ul>';
12459: foreach my $field (@shibfields) {
12460: next if ($cancreate{$type}{$field} eq '');
12461: if ($field eq 'inststatus') {
12462: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
12463: } else {
12464: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
12465: }
12466: }
12467: $chgtext .= '</ul>';
1.160.6.93 raeburn 12468: }
1.93 raeburn 12469: } elsif ($type eq 'statustocreate') {
1.96 raeburn 12470: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
12471: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
12472: if (@{$cancreate{'selfcreate'}} > 0) {
12473: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 12474: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 12475: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 12476: $chgtext .= '<br />'.
12477: '<span class="LC_warning">'.
12478: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
12479: '</span>';
12480: }
1.160.6.93 raeburn 12481: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 12482: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 12483: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
12484: } else {
12485: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
12486: }
12487: $chgtext .= '<ul>';
12488: foreach my $case (@{$cancreate{$type}}) {
12489: if ($case eq 'default') {
12490: $chgtext .= '<li>'.$othertitle.'</li>';
12491: } else {
1.160.6.93 raeburn 12492: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 12493: }
12494: }
1.100 raeburn 12495: $chgtext .= '</ul>';
12496: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 12497: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 12498: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
12499: '</span>';
1.100 raeburn 12500: }
12501: }
12502: } else {
12503: if (@{$cancreate{$type}} == 0) {
12504: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
12505: } else {
12506: $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 12507: }
12508: }
1.160.6.93 raeburn 12509: $chgtext .= '<br />';
1.93 raeburn 12510: }
1.160.6.40 raeburn 12511: } elsif ($type eq 'selfcreateprocessing') {
12512: my %choices = &Apache::lonlocal::texthash (
12513: automatic => 'Automatic approval',
12514: approval => 'Queued for approval',
12515: );
1.160.6.93 raeburn 12516: if (@types) {
12517: if (@statuses) {
12518: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
12519: '<ul>';
12520: foreach my $status (@statuses) {
12521: if ($status eq 'default') {
12522: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
12523: } else {
12524: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
12525: }
12526: }
12527: $chgtext .= '</ul>';
12528: }
12529: } else {
12530: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
12531: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
12532: }
12533: } elsif ($type eq 'emailverified') {
12534: my %options = &Apache::lonlocal::texthash (
12535: all => 'Same as e-mail',
12536: first => 'Omit @domain',
12537: free => 'Free to choose',
12538: );
12539: if (@types) {
12540: if (@statuses) {
12541: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
12542: '<ul>';
12543: foreach my $status (@statuses) {
12544: if ($status eq 'default') {
12545: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
12546: } else {
12547: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
12548: }
12549: }
12550: $chgtext .= '</ul>';
12551: }
1.160.6.40 raeburn 12552: } else {
1.160.6.93 raeburn 12553: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
12554: $options{$cancreate{'emailverified'}{'default'}});
12555: }
12556: } elsif ($type eq 'emailoptions') {
12557: my %options = &Apache::lonlocal::texthash (
12558: any => 'Any e-mail',
12559: inst => 'Institutional only',
12560: noninst => 'Non-institutional only',
12561: custom => 'Custom restrictions',
12562: );
12563: if (@types) {
12564: if (@statuses) {
12565: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
12566: '<ul>';
12567: foreach my $status (@statuses) {
12568: if ($type eq 'default') {
12569: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
12570: } else {
12571: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
12572: }
12573: }
12574: $chgtext .= '</ul>';
12575: }
12576: } else {
12577: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
12578: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
12579: } else {
12580: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
12581: $options{$cancreate{'emailoptions'}{'default'}});
12582: }
12583: }
12584: } elsif ($type eq 'emaildomain') {
12585: my $output;
12586: if (@statuses) {
12587: foreach my $type (@statuses) {
12588: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
12589: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
12590: if ($type eq 'default') {
12591: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12592: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
12593: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
12594: } else {
12595: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
12596: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
12597: }
12598: } else {
12599: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12600: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
12601: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
12602: } else {
12603: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
12604: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
12605: }
12606: }
12607: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
12608: if ($type eq 'default') {
12609: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12610: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
12611: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
12612: } else {
12613: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
12614: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
12615: }
12616: } else {
12617: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12618: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
12619: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
12620: } else {
12621: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
12622: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
12623: }
12624: }
12625: }
12626: }
12627: }
12628: }
12629: if ($output ne '') {
12630: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
12631: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 12632: }
1.160.6.5 raeburn 12633: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 12634: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 12635: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
12636: } else {
12637: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 12638: if ($captchas{$savecaptcha{$type}}) {
12639: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 12640: } else {
12641: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
12642: }
12643: }
12644: } elsif ($type eq 'recaptchakeys') {
12645: my ($privkey,$pubkey);
1.160.6.34 raeburn 12646: if (ref($savecaptcha{$type}) eq 'HASH') {
12647: $pubkey = $savecaptcha{$type}{'public'};
12648: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 12649: }
12650: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
12651: if (!$pubkey) {
12652: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
12653: } else {
12654: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12655: }
12656: if (!$privkey) {
12657: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
12658: } else {
12659: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
12660: }
12661: $chgtext .= '</ul>';
1.160.6.69 raeburn 12662: } elsif ($type eq 'recaptchaversion') {
12663: if ($savecaptcha{'captcha'} eq 'recaptcha') {
12664: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
12665: }
1.160.6.34 raeburn 12666: } elsif ($type eq 'emailusername') {
12667: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 12668: if (@statuses) {
12669: foreach my $type (@statuses) {
1.160.6.35 raeburn 12670: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
12671: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 12672: $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 12673: '<ul>';
12674: foreach my $field (@{$infofields}) {
12675: if ($cancreate{'emailusername'}{$type}{$field}) {
12676: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
12677: }
12678: }
1.160.6.50 raeburn 12679: $chgtext .= '</ul>';
12680: } else {
1.160.6.93 raeburn 12681: $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 12682: }
12683: } else {
1.160.6.93 raeburn 12684: $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 12685: }
12686: }
12687: }
12688: }
12689: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 12690: my $numapprove = 0;
1.160.6.34 raeburn 12691: if (ref($changes{'cancreate'}) eq 'ARRAY') {
12692: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
12693: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 12694: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
12695: $numapprove ++;
1.160.6.34 raeburn 12696: }
12697: }
1.43 raeburn 12698: }
1.160.6.93 raeburn 12699: unless ($numapprove) {
12700: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
12701: }
1.34 raeburn 12702: }
1.160.6.34 raeburn 12703: if ($chgtext) {
12704: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 12705: }
12706: }
12707: }
1.160.6.93 raeburn 12708: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 12709: my ($emailrules,$emailruleorder) =
12710: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 12711: foreach my $type (@{$changes{'email_rule'}}) {
12712: if (ref($email_rule{$type}) eq 'ARRAY') {
12713: my $chgtext = '<ul>';
12714: foreach my $rule (@{$email_rule{$type}}) {
12715: if (ref($emailrules->{$rule}) eq 'HASH') {
12716: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
12717: }
12718: }
12719: $chgtext .= '</ul>';
12720: my $typename;
12721: if (@types) {
12722: if ($type eq 'default') {
12723: $typename = $othertitle;
12724: } else {
12725: $typename = $usertypes{$type};
12726: }
12727: $chgtext .= &mt('(Affiliation: [_1])',$typename);
12728: }
12729: if (@{$email_rule{$type}} > 0) {
12730: $resulttext .= '<li>'.
12731: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
12732: $usertypes{$type}).
12733: $chgtext.
12734: '</li>';
12735: } else {
12736: $resulttext .= '<li>'.
12737: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
12738: '</li>'.
12739: &mt('(Affiliation: [_1])',$typename);
12740: }
1.43 raeburn 12741: }
12742: }
1.160.6.93 raeburn 12743: }
12744: if (ref($changes{'inststatus'}) eq 'ARRAY') {
12745: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
12746: if (@{$save_inststatus{'inststatusguest'}} > 0) {
12747: my $chgtext = '<ul>';
12748: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
12749: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
12750: }
12751: $chgtext .= '</ul>';
12752: $resulttext .= '<li>'.
12753: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
12754: $chgtext.
12755: '</li>';
12756: } else {
12757: $resulttext .= '<li>'.
12758: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
12759: '</li>';
12760: }
1.43 raeburn 12761: }
12762: }
1.160.6.34 raeburn 12763: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
12764: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
12765: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12766: foreach my $type (@{$changes{'selfcreate'}}) {
12767: my $typename = $type;
1.160.6.93 raeburn 12768: if (keys(%usertypes) > 0) {
12769: if ($usertypes{$type} ne '') {
12770: $typename = $usertypes{$type};
1.28 raeburn 12771: }
12772: }
1.160.6.34 raeburn 12773: my @modifiable;
12774: $resulttext .= '<li>'.
12775: &mt('Self-creation of account by users with status: [_1]',
12776: '<span class="LC_cusr_emph">'.$typename.'</span>').
12777: ' - '.&mt('modifiable fields (if institutional data blank): ');
12778: foreach my $field (@fields) {
12779: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
12780: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
12781: }
12782: }
12783: if (@modifiable > 0) {
12784: $resulttext .= join(', ',@modifiable);
1.43 raeburn 12785: } else {
1.160.6.34 raeburn 12786: $resulttext .= &mt('none');
1.43 raeburn 12787: }
1.160.6.34 raeburn 12788: $resulttext .= '</li>';
1.28 raeburn 12789: }
1.160.6.34 raeburn 12790: $resulttext .= '</ul></li>';
1.28 raeburn 12791: }
1.27 raeburn 12792: $resulttext .= '</ul>';
1.160.6.93 raeburn 12793: my $cachetime = 24*60*60;
12794: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
12795: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12796: if (ref($lastactref) eq 'HASH') {
12797: $lastactref->{'domdefaults'} = 1;
12798: }
1.27 raeburn 12799: } else {
1.160.6.34 raeburn 12800: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 12801: }
12802: } else {
12803: $resulttext = '<span class="LC_error">'.
1.23 raeburn 12804: &mt('An error occurred: [_1]',$putresult).'</span>';
12805: }
1.43 raeburn 12806: if ($warningmsg ne '') {
12807: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
12808: }
1.23 raeburn 12809: return $resulttext;
12810: }
12811:
1.160.6.5 raeburn 12812: sub process_captcha {
1.160.6.104 raeburn 12813: my ($container,$changes,$newsettings,$currsettings) = @_;
12814: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.160.6.5 raeburn 12815: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
12816: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
12817: $newsettings->{'captcha'} = 'original';
12818: }
1.160.6.104 raeburn 12819: my %current;
12820: if (ref($currsettings) eq 'HASH') {
12821: %current = %{$currsettings};
12822: }
12823: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.160.6.5 raeburn 12824: if ($container eq 'cancreate') {
12825: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12826: push(@{$changes->{'cancreate'}},'captcha');
12827: } elsif (!defined($changes->{'cancreate'})) {
12828: $changes->{'cancreate'} = ['captcha'];
12829: }
1.160.6.102 raeburn 12830: } elsif ($container eq 'passwords') {
12831: $changes->{'reset'} = 1;
1.160.6.5 raeburn 12832: } else {
12833: $changes->{'captcha'} = 1;
12834: }
12835: }
1.160.6.69 raeburn 12836: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 12837: if ($newsettings->{'captcha'} eq 'recaptcha') {
12838: $newpub = $env{'form.'.$container.'_recaptchapub'};
12839: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 12840: $newpub =~ s/[^\w\-]//g;
12841: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 12842: $newsettings->{'recaptchakeys'} = {
12843: public => $newpub,
12844: private => $newpriv,
12845: };
1.160.6.69 raeburn 12846: $newversion = $env{'form.'.$container.'_recaptchaversion'};
12847: $newversion =~ s/\D//g;
12848: if ($newversion ne '2') {
12849: $newversion = 1;
12850: }
12851: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 12852: }
1.160.6.104 raeburn 12853: if (ref($current{'recaptchakeys'}) eq 'HASH') {
12854: $currpub = $current{'recaptchakeys'}{'public'};
12855: $currpriv = $current{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 12856: unless ($newsettings->{'captcha'} eq 'recaptcha') {
12857: $newsettings->{'recaptchakeys'} = {
12858: public => '',
12859: private => '',
12860: }
12861: }
1.160.6.5 raeburn 12862: }
1.160.6.104 raeburn 12863: if ($current{'captcha'} eq 'recaptcha') {
12864: $currversion = $current{'recaptchaversion'};
1.160.6.69 raeburn 12865: if ($currversion ne '2') {
12866: $currversion = 1;
12867: }
12868: }
12869: if ($currversion ne $newversion) {
12870: if ($container eq 'cancreate') {
12871: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12872: push(@{$changes->{'cancreate'}},'recaptchaversion');
12873: } elsif (!defined($changes->{'cancreate'})) {
12874: $changes->{'cancreate'} = ['recaptchaversion'];
12875: }
1.160.6.102 raeburn 12876: } elsif ($container eq 'passwords') {
12877: $changes->{'reset'} = 1;
1.160.6.69 raeburn 12878: } else {
12879: $changes->{'recaptchaversion'} = 1;
12880: }
12881: }
1.160.6.5 raeburn 12882: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
12883: if ($container eq 'cancreate') {
12884: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12885: push(@{$changes->{'cancreate'}},'recaptchakeys');
12886: } elsif (!defined($changes->{'cancreate'})) {
12887: $changes->{'cancreate'} = ['recaptchakeys'];
12888: }
1.160.6.102 raeburn 12889: } elsif ($container eq 'passwords') {
12890: $changes->{'reset'} = 1;
1.160.6.5 raeburn 12891: } else {
12892: $changes->{'recaptchakeys'} = 1;
12893: }
12894: }
12895: return;
12896: }
12897:
1.33 raeburn 12898: sub modify_usermodification {
12899: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 12900: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 12901: if (ref($domconfig{'usermodification'}) eq 'HASH') {
12902: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 12903: if ($key eq 'selfcreate') {
12904: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
12905: } else {
12906: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
12907: }
1.33 raeburn 12908: }
12909: }
1.160.6.34 raeburn 12910: my @contexts = ('author','course');
1.33 raeburn 12911: my %context_title = (
12912: author => 'In author context',
12913: course => 'In course context',
12914: );
12915: my @fields = ('lastname','firstname','middlename','generation',
12916: 'permanentemail','id');
12917: my %roles = (
12918: author => ['ca','aa'],
12919: course => ['st','ep','ta','in','cr'],
12920: );
12921: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12922: foreach my $context (@contexts) {
12923: foreach my $role (@{$roles{$context}}) {
12924: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
12925: foreach my $item (@fields) {
12926: if (grep(/^\Q$item\E$/,@modifiable)) {
12927: $modifyhash{$context}{$role}{$item} = 1;
12928: } else {
12929: $modifyhash{$context}{$role}{$item} = 0;
12930: }
12931: }
12932: }
12933: if (ref($curr_usermodification{$context}) eq 'HASH') {
12934: foreach my $role (@{$roles{$context}}) {
12935: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
12936: foreach my $field (@fields) {
12937: if ($modifyhash{$context}{$role}{$field} ne
12938: $curr_usermodification{$context}{$role}{$field}) {
12939: push(@{$changes{$context}},$role);
12940: last;
12941: }
12942: }
12943: }
12944: }
12945: } else {
12946: foreach my $context (@contexts) {
12947: foreach my $role (@{$roles{$context}}) {
12948: push(@{$changes{$context}},$role);
12949: }
12950: }
12951: }
12952: }
12953: my %usermodification_hash = (
12954: usermodification => \%modifyhash,
12955: );
12956: my $putresult = &Apache::lonnet::put_dom('configuration',
12957: \%usermodification_hash,$dom);
12958: if ($putresult eq 'ok') {
12959: if (keys(%changes) > 0) {
12960: $resulttext = &mt('Changes made: ').'<ul>';
12961: foreach my $context (@contexts) {
12962: if (ref($changes{$context}) eq 'ARRAY') {
12963: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
12964: if (ref($changes{$context}) eq 'ARRAY') {
12965: foreach my $role (@{$changes{$context}}) {
12966: my $rolename;
1.160.6.34 raeburn 12967: if ($role eq 'cr') {
12968: $rolename = &mt('Custom');
1.33 raeburn 12969: } else {
1.160.6.34 raeburn 12970: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 12971: }
12972: my @modifiable;
1.160.6.34 raeburn 12973: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 12974: foreach my $field (@fields) {
12975: if ($modifyhash{$context}{$role}{$field}) {
12976: push(@modifiable,$fieldtitles{$field});
12977: }
12978: }
12979: if (@modifiable > 0) {
12980: $resulttext .= join(', ',@modifiable);
12981: } else {
12982: $resulttext .= &mt('none');
12983: }
12984: $resulttext .= '</li>';
12985: }
12986: $resulttext .= '</ul></li>';
12987: }
12988: }
12989: }
12990: $resulttext .= '</ul>';
12991: } else {
12992: $resulttext = &mt('No changes made to user modification settings');
12993: }
12994: } else {
12995: $resulttext = '<span class="LC_error">'.
12996: &mt('An error occurred: [_1]',$putresult).'</span>';
12997: }
12998: return $resulttext;
12999: }
13000:
1.43 raeburn 13001: sub modify_defaults {
1.160.6.27 raeburn 13002: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 13003: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 13004: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 13005: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98 raeburn 13006: 'portal_def');
1.43 raeburn 13007: my @authtypes = ('internal','krb4','krb5','localauth');
13008: foreach my $item (@items) {
13009: $newvalues{$item} = $env{'form.'.$item};
13010: if ($item eq 'auth_def') {
13011: if ($newvalues{$item} ne '') {
13012: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
13013: push(@errors,$item);
13014: }
13015: }
13016: } elsif ($item eq 'lang_def') {
13017: if ($newvalues{$item} ne '') {
13018: if ($newvalues{$item} =~ /^(\w+)/) {
13019: my $langcode = $1;
1.103 raeburn 13020: if ($langcode ne 'x_chef') {
13021: if (code2language($langcode) eq '') {
13022: push(@errors,$item);
13023: }
1.43 raeburn 13024: }
13025: } else {
13026: push(@errors,$item);
13027: }
13028: }
1.54 raeburn 13029: } elsif ($item eq 'timezone_def') {
13030: if ($newvalues{$item} ne '') {
1.62 raeburn 13031: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 13032: push(@errors,$item);
13033: }
13034: }
1.68 raeburn 13035: } elsif ($item eq 'datelocale_def') {
13036: if ($newvalues{$item} ne '') {
13037: my @datelocale_ids = DateTime::Locale->ids();
13038: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
13039: push(@errors,$item);
13040: }
13041: }
1.141 raeburn 13042: } elsif ($item eq 'portal_def') {
13043: if ($newvalues{$item} ne '') {
13044: 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])\/?$/) {
13045: push(@errors,$item);
13046: }
13047: }
1.43 raeburn 13048: }
13049: if (grep(/^\Q$item\E$/,@errors)) {
13050: $newvalues{$item} = $domdefaults{$item};
13051: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
13052: $changes{$item} = 1;
13053: }
1.72 raeburn 13054: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 13055: }
1.160.6.98 raeburn 13056: my %staticdefaults = (
13057: 'intauth_cost' => 10,
13058: 'intauth_check' => 0,
13059: 'intauth_switch' => 0,
13060: );
13061: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
13062: if (exists($domdefaults{$item})) {
13063: $newvalues{$item} = $domdefaults{$item};
13064: } else {
13065: $newvalues{$item} = $staticdefaults{$item};
13066: }
13067: }
1.43 raeburn 13068: my %defaults_hash = (
1.72 raeburn 13069: defaults => \%newvalues,
13070: );
1.43 raeburn 13071: my $title = &defaults_titles();
1.160.6.40 raeburn 13072:
13073: my $currinststatus;
13074: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13075: $currinststatus = $domconfig{'inststatus'};
13076: } else {
13077: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13078: $currinststatus = {
13079: inststatustypes => $usertypes,
13080: inststatusorder => $types,
13081: inststatusguest => [],
13082: };
13083: }
13084: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
13085: my @allpos;
13086: my %alltypes;
1.160.6.93 raeburn 13087: my @inststatusguest;
13088: if (ref($currinststatus) eq 'HASH') {
13089: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
13090: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
13091: unless (grep(/^\Q$type\E$/,@todelete)) {
13092: push(@inststatusguest,$type);
13093: }
13094: }
13095: }
13096: }
13097: my ($currtitles,$currorder);
1.160.6.40 raeburn 13098: if (ref($currinststatus) eq 'HASH') {
13099: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
13100: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
13101: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
13102: if ($currinststatus->{inststatustypes}->{$type} ne '') {
13103: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
13104: }
13105: }
13106: unless (grep(/^\Q$type\E$/,@todelete)) {
13107: my $position = $env{'form.inststatus_pos_'.$type};
13108: $position =~ s/\D+//g;
13109: $allpos[$position] = $type;
13110: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
13111: $alltypes{$type} =~ s/`//g;
13112: }
13113: }
13114: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
13115: $currtitles =~ s/,$//;
13116: }
13117: }
13118: if ($env{'form.addinststatus'}) {
13119: my $newtype = $env{'form.addinststatus'};
13120: $newtype =~ s/\W//g;
13121: unless (exists($alltypes{$newtype})) {
13122: $alltypes{$newtype} = $env{'form.addinststatus_title'};
13123: $alltypes{$newtype} =~ s/`//g;
13124: my $position = $env{'form.addinststatus_pos'};
13125: $position =~ s/\D+//g;
13126: if ($position ne '') {
13127: $allpos[$position] = $newtype;
13128: }
13129: }
13130: }
1.160.6.93 raeburn 13131: my @orderedstatus;
1.160.6.40 raeburn 13132: foreach my $type (@allpos) {
13133: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
13134: push(@orderedstatus,$type);
13135: }
13136: }
13137: foreach my $type (keys(%alltypes)) {
13138: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
13139: delete($alltypes{$type});
13140: }
13141: }
13142: $defaults_hash{'inststatus'} = {
13143: inststatustypes => \%alltypes,
13144: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 13145: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 13146: };
13147: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
13148: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
13149: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
13150: }
13151: }
13152: if ($currorder ne join(',',@orderedstatus)) {
13153: $changes{'inststatus'}{'inststatusorder'} = 1;
13154: }
13155: my $newtitles;
13156: foreach my $item (@orderedstatus) {
13157: $newtitles .= $alltypes{$item}.',';
13158: }
13159: $newtitles =~ s/,$//;
13160: if ($currtitles ne $newtitles) {
13161: $changes{'inststatus'}{'inststatustypes'} = 1;
13162: }
1.43 raeburn 13163: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
13164: $dom);
13165: if ($putresult eq 'ok') {
13166: if (keys(%changes) > 0) {
13167: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 13168: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 13169: 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";
13170: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 13171: if ($item eq 'inststatus') {
13172: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 13173: if (@orderedstatus) {
1.160.6.40 raeburn 13174: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
13175: foreach my $type (@orderedstatus) {
13176: $resulttext .= $alltypes{$type}.', ';
13177: }
13178: $resulttext =~ s/, $//;
13179: $resulttext .= '</li>';
1.160.6.93 raeburn 13180: } else {
13181: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 13182: }
13183: }
13184: } else {
13185: my $value = $env{'form.'.$item};
13186: if ($value eq '') {
13187: $value = &mt('none');
13188: } elsif ($item eq 'auth_def') {
13189: my %authnames = &authtype_names();
13190: my %shortauth = (
13191: internal => 'int',
13192: krb4 => 'krb4',
13193: krb5 => 'krb5',
13194: localauth => 'loc',
13195: );
13196: $value = $authnames{$shortauth{$value}};
13197: }
13198: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
13199: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 13200: }
13201: }
13202: $resulttext .= '</ul>';
13203: $mailmsgtext .= "\n";
13204: my $cachetime = 24*60*60;
1.72 raeburn 13205: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 13206: if (ref($lastactref) eq 'HASH') {
13207: $lastactref->{'domdefaults'} = 1;
13208: }
1.68 raeburn 13209: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 13210: my $notify = 1;
13211: if (ref($domconfig{'contacts'}) eq 'HASH') {
13212: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
13213: $notify = 0;
13214: }
13215: }
13216: if ($notify) {
13217: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
13218: "LON-CAPA Domain Settings Change - $dom",
13219: $mailmsgtext);
13220: }
1.54 raeburn 13221: }
1.43 raeburn 13222: } else {
1.54 raeburn 13223: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 13224: }
13225: } else {
13226: $resulttext = '<span class="LC_error">'.
13227: &mt('An error occurred: [_1]',$putresult).'</span>';
13228: }
13229: if (@errors > 0) {
13230: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
13231: foreach my $item (@errors) {
13232: $resulttext .= ' "'.$title->{$item}.'",';
13233: }
13234: $resulttext =~ s/,$//;
13235: }
13236: return $resulttext;
13237: }
13238:
1.46 raeburn 13239: sub modify_scantron {
1.160.6.24 raeburn 13240: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 13241: my ($resulttext,%confhash,%changes,$errors);
13242: my $custom = 'custom.tab';
13243: my $default = 'default.tab';
13244: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 13245: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 13246: &config_check($dom,$confname,$servadm);
13247: if ($env{'form.scantronformat.filename'} ne '') {
13248: my $error;
13249: if ($configuserok eq 'ok') {
13250: if ($switchserver) {
1.130 raeburn 13251: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 13252: } else {
13253: if ($author_ok eq 'ok') {
13254: my ($result,$scantronurl) =
13255: &publishlogo($r,'upload','scantronformat',$dom,
13256: $confname,'scantron','','',$custom);
13257: if ($result eq 'ok') {
13258: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 13259: $changes{'scantronformat'} = 1;
1.46 raeburn 13260: } else {
13261: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
13262: }
13263: } else {
13264: $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);
13265: }
13266: }
13267: } else {
13268: $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);
13269: }
13270: if ($error) {
13271: &Apache::lonnet::logthis($error);
13272: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13273: }
13274: }
1.48 raeburn 13275: if (ref($domconfig{'scantron'}) eq 'HASH') {
13276: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
13277: if ($env{'form.scantronformat_del'}) {
13278: $confhash{'scantron'}{'scantronformat'} = '';
13279: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 13280: } else {
13281: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
13282: }
13283: }
13284: }
13285: my @options = ('hdr','pad','rem');
13286: my @fields = &scantroncsv_fields();
13287: my %titles = &scantronconfig_titles();
13288: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
13289: my ($newdat,$currdat,%newcol,%currcol);
13290: if (grep(/^dat$/,@formats)) {
13291: $confhash{'scantron'}{config}{dat} = 1;
13292: $newdat = 1;
13293: } else {
13294: $newdat = 0;
13295: }
13296: if (grep(/^csv$/,@formats)) {
13297: my %bynum;
13298: foreach my $field (@fields) {
13299: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
13300: my $posscol = $1;
13301: if (($posscol < 20) && (!$bynum{$posscol})) {
13302: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
13303: $bynum{$posscol} = $field;
13304: $newcol{$field} = $posscol;
13305: }
13306: }
13307: }
13308: if (keys(%newcol)) {
13309: foreach my $option (@options) {
13310: if ($env{'form.scantroncsv_'.$option}) {
13311: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
13312: }
13313: }
13314: }
13315: }
13316: $currdat = 1;
13317: if (ref($domconfig{'scantron'}) eq 'HASH') {
13318: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
13319: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
13320: $currdat = 0;
13321: }
13322: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
13323: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
13324: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
13325: }
13326: }
13327: }
13328: }
13329: if ($currdat != $newdat) {
13330: $changes{'config'} = 1;
13331: } else {
13332: foreach my $field (@fields) {
13333: if ($currcol{$field} ne '') {
13334: if ($currcol{$field} ne $newcol{$field}) {
13335: $changes{'config'} = 1;
13336: last;
13337: }
13338: } elsif ($newcol{$field} ne '') {
13339: $changes{'config'} = 1;
13340: last;
1.46 raeburn 13341: }
13342: }
13343: }
13344: if (keys(%confhash) > 0) {
13345: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
13346: $dom);
13347: if ($putresult eq 'ok') {
13348: if (keys(%changes) > 0) {
1.48 raeburn 13349: if (ref($confhash{'scantron'}) eq 'HASH') {
13350: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 13351: if ($changes{'scantronformat'}) {
13352: if ($confhash{'scantron'}{'scantronformat'} eq '') {
13353: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
13354: } else {
13355: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
13356: }
13357: }
13358: if ($changes{'config'}) {
13359: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
13360: if ($confhash{'scantron'}{'config'}{'dat'}) {
13361: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
13362: }
13363: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
13364: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
13365: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
13366: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
13367: foreach my $field (@fields) {
13368: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
13369: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
13370: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
13371: }
13372: }
13373: $resulttext .= '</ul></li>';
13374: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
13375: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
13376: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
13377: foreach my $option (@options) {
13378: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
13379: $resulttext .= '<li>'.$titles{$option}.'</li>';
13380: }
13381: }
13382: $resulttext .= '</ul></li>';
13383: }
13384: }
13385: }
13386: }
13387: }
13388: } else {
13389: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
13390: }
1.46 raeburn 13391: }
1.48 raeburn 13392: $resulttext .= '</ul>';
13393: } else {
1.130 raeburn 13394: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 13395: }
13396: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 13397: if (ref($lastactref) eq 'HASH') {
13398: $lastactref->{'domainconfig'} = 1;
13399: }
1.46 raeburn 13400: } else {
1.160.6.97 raeburn 13401: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 13402: }
13403: } else {
13404: $resulttext = '<span class="LC_error">'.
13405: &mt('An error occurred: [_1]',$putresult).'</span>';
13406: }
13407: } else {
1.160.6.97 raeburn 13408: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 13409: }
13410: if ($errors) {
13411: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13412: $errors.'</ul>';
13413: }
13414: return $resulttext;
13415: }
13416:
1.48 raeburn 13417: sub modify_coursecategories {
1.160.6.43 raeburn 13418: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 13419: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
13420: $cathash);
1.48 raeburn 13421: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 13422: my @catitems = ('unauth','auth');
13423: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 13424: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 13425: $cathash = $domconfig{'coursecategories'}{'cats'};
13426: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
13427: $changes{'togglecats'} = 1;
13428: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
13429: }
13430: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
13431: $changes{'categorize'} = 1;
13432: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
13433: }
1.120 raeburn 13434: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
13435: $changes{'togglecatscomm'} = 1;
13436: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
13437: }
13438: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
13439: $changes{'categorizecomm'} = 1;
13440: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
13441: }
1.160.6.42 raeburn 13442: foreach my $item (@catitems) {
13443: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
13444: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
13445: $changes{$item} = 1;
13446: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
13447: }
13448: }
13449: }
1.57 raeburn 13450: } else {
13451: $changes{'togglecats'} = 1;
13452: $changes{'categorize'} = 1;
1.124 raeburn 13453: $changes{'togglecatscomm'} = 1;
13454: $changes{'categorizecomm'} = 1;
1.87 raeburn 13455: $domconfig{'coursecategories'} = {
13456: togglecats => $env{'form.togglecats'},
13457: categorize => $env{'form.categorize'},
1.124 raeburn 13458: togglecatscomm => $env{'form.togglecatscomm'},
13459: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 13460: };
1.160.6.42 raeburn 13461: foreach my $item (@catitems) {
13462: if ($env{'form.coursecat_'.$item} ne 'std') {
13463: $changes{$item} = 1;
13464: }
13465: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
13466: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
13467: }
13468: }
1.57 raeburn 13469: }
13470: if (ref($cathash) eq 'HASH') {
13471: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 13472: push (@deletecategory,'instcode::0');
13473: }
1.120 raeburn 13474: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
13475: push(@deletecategory,'communities::0');
13476: }
1.48 raeburn 13477: }
1.57 raeburn 13478: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
13479: if (ref($cathash) eq 'HASH') {
1.48 raeburn 13480: if (@deletecategory > 0) {
13481: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 13482: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 13483: foreach my $item (@deletecategory) {
1.57 raeburn 13484: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
13485: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 13486: $deletions{$item} = 1;
1.57 raeburn 13487: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 13488: }
13489: }
13490: }
1.57 raeburn 13491: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 13492: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 13493: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 13494: $reorderings{$item} = 1;
1.57 raeburn 13495: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 13496: }
13497: if ($env{'form.addcategory_name_'.$item} ne '') {
13498: my $newcat = $env{'form.addcategory_name_'.$item};
13499: my $newdepth = $depth+1;
13500: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 13501: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 13502: $adds{$newitem} = 1;
13503: }
13504: if ($env{'form.subcat_'.$item} ne '') {
13505: my $newcat = $env{'form.subcat_'.$item};
13506: my $newdepth = $depth+1;
13507: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 13508: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 13509: $adds{$newitem} = 1;
13510: }
13511: }
13512: }
13513: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 13514: if (ref($cathash) eq 'HASH') {
1.48 raeburn 13515: my $newitem = 'instcode::0';
1.57 raeburn 13516: if ($cathash->{$newitem} eq '') {
13517: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 13518: $adds{$newitem} = 1;
13519: }
13520: } else {
13521: my $newitem = 'instcode::0';
1.57 raeburn 13522: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 13523: $adds{$newitem} = 1;
13524: }
13525: }
1.120 raeburn 13526: if ($env{'form.communities'} eq '1') {
13527: if (ref($cathash) eq 'HASH') {
13528: my $newitem = 'communities::0';
13529: if ($cathash->{$newitem} eq '') {
13530: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
13531: $adds{$newitem} = 1;
13532: }
13533: } else {
13534: my $newitem = 'communities::0';
13535: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
13536: $adds{$newitem} = 1;
13537: }
13538: }
1.48 raeburn 13539: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 13540: if (($env{'form.addcategory_name'} ne 'instcode') &&
13541: ($env{'form.addcategory_name'} ne 'communities')) {
13542: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
13543: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
13544: $adds{$newitem} = 1;
13545: }
1.48 raeburn 13546: }
1.57 raeburn 13547: my $putresult;
1.48 raeburn 13548: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
13549: if (keys(%deletions) > 0) {
13550: foreach my $key (keys(%deletions)) {
13551: if ($predelallitems{$key} ne '') {
13552: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
13553: }
13554: }
13555: }
13556: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 13557: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 13558: if (ref($chkcats[0]) eq 'ARRAY') {
13559: my $depth = 0;
13560: my $chg = 0;
13561: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
13562: my $name = $chkcats[0][$i];
13563: my $item;
13564: if ($name eq '') {
13565: $chg ++;
13566: } else {
13567: $item = &escape($name).'::0';
13568: if ($chg) {
1.57 raeburn 13569: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 13570: }
13571: $depth ++;
1.57 raeburn 13572: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 13573: $depth --;
13574: }
13575: }
13576: }
1.57 raeburn 13577: }
13578: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
13579: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 13580: if ($putresult eq 'ok') {
1.57 raeburn 13581: my %title = (
1.120 raeburn 13582: togglecats => 'Show/Hide a course in catalog',
13583: categorize => 'Assign a category to a course',
13584: togglecatscomm => 'Show/Hide a community in catalog',
13585: categorizecomm => 'Assign a category to a community',
1.57 raeburn 13586: );
13587: my %level = (
1.120 raeburn 13588: dom => 'set in Domain ("Modify Course/Community")',
13589: crs => 'set in Course ("Course Configuration")',
13590: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 13591: none => 'No catalog',
13592: std => 'Standard catalog',
13593: domonly => 'Domain-only catalog',
13594: codesrch => 'Code search form',
1.57 raeburn 13595: );
1.48 raeburn 13596: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 13597: if ($changes{'togglecats'}) {
13598: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
13599: }
13600: if ($changes{'categorize'}) {
13601: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 13602: }
1.120 raeburn 13603: if ($changes{'togglecatscomm'}) {
13604: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
13605: }
13606: if ($changes{'categorizecomm'}) {
13607: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
13608: }
1.160.6.42 raeburn 13609: if ($changes{'unauth'}) {
13610: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
13611: }
13612: if ($changes{'auth'}) {
13613: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
13614: }
1.57 raeburn 13615: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
13616: my $cathash;
13617: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
13618: $cathash = $domconfig{'coursecategories'}{'cats'};
13619: } else {
13620: $cathash = {};
13621: }
13622: my (@cats,@trails,%allitems);
13623: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
13624: if (keys(%deletions) > 0) {
13625: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
13626: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
13627: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
13628: }
13629: $resulttext .= '</ul></li>';
13630: }
13631: if (keys(%reorderings) > 0) {
13632: my %sort_by_trail;
13633: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
13634: foreach my $key (keys(%reorderings)) {
13635: if ($allitems{$key} ne '') {
13636: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
13637: }
1.48 raeburn 13638: }
1.57 raeburn 13639: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
13640: $resulttext .= '<li>'.$trails[$trail].'</li>';
13641: }
13642: $resulttext .= '</ul></li>';
1.48 raeburn 13643: }
1.57 raeburn 13644: if (keys(%adds) > 0) {
13645: my %sort_by_trail;
13646: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
13647: foreach my $key (keys(%adds)) {
13648: if ($allitems{$key} ne '') {
13649: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
13650: }
13651: }
13652: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
13653: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 13654: }
1.57 raeburn 13655: $resulttext .= '</ul></li>';
1.48 raeburn 13656: }
1.160.6.92 raeburn 13657: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
13658: if (ref($lastactref) eq 'HASH') {
13659: $lastactref->{'cats'} = 1;
13660: }
1.48 raeburn 13661: }
13662: $resulttext .= '</ul>';
1.160.6.43 raeburn 13663: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 13664: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
13665: if ($changes{'auth'}) {
13666: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
13667: }
13668: if ($changes{'unauth'}) {
13669: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
13670: }
13671: my $cachetime = 24*60*60;
13672: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 13673: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 13674: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 13675: }
13676: }
1.48 raeburn 13677: } else {
13678: $resulttext = '<span class="LC_error">'.
1.57 raeburn 13679: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 13680: }
13681: } else {
1.120 raeburn 13682: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 13683: }
13684: return $resulttext;
13685: }
13686:
1.69 raeburn 13687: sub modify_serverstatuses {
13688: my ($dom,%domconfig) = @_;
13689: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
13690: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
13691: %currserverstatus = %{$domconfig{'serverstatuses'}};
13692: }
13693: my @pages = &serverstatus_pages();
13694: foreach my $type (@pages) {
13695: $newserverstatus{$type}{'namedusers'} = '';
13696: $newserverstatus{$type}{'machines'} = '';
13697: if (defined($env{'form.'.$type.'_namedusers'})) {
13698: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
13699: my @okusers;
13700: foreach my $user (@users) {
13701: my ($uname,$udom) = split(/:/,$user);
13702: if (($udom =~ /^$match_domain$/) &&
13703: (&Apache::lonnet::domain($udom)) &&
13704: ($uname =~ /^$match_username$/)) {
13705: if (!grep(/^\Q$user\E/,@okusers)) {
13706: push(@okusers,$user);
13707: }
13708: }
13709: }
13710: if (@okusers > 0) {
13711: @okusers = sort(@okusers);
13712: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
13713: }
13714: }
13715: if (defined($env{'form.'.$type.'_machines'})) {
13716: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
13717: my @okmachines;
13718: foreach my $ip (@machines) {
13719: my @parts = split(/\./,$ip);
13720: next if (@parts < 4);
13721: my $badip = 0;
13722: for (my $i=0; $i<4; $i++) {
13723: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
13724: $badip = 1;
13725: last;
13726: }
13727: }
13728: if (!$badip) {
13729: push(@okmachines,$ip);
13730: }
13731: }
13732: @okmachines = sort(@okmachines);
13733: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
13734: }
13735: }
13736: my %serverstatushash = (
13737: serverstatuses => \%newserverstatus,
13738: );
13739: foreach my $type (@pages) {
1.83 raeburn 13740: foreach my $setting ('namedusers','machines') {
1.84 raeburn 13741: my (@current,@new);
1.83 raeburn 13742: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 13743: if ($currserverstatus{$type}{$setting} ne '') {
13744: @current = split(/,/,$currserverstatus{$type}{$setting});
13745: }
13746: }
13747: if ($newserverstatus{$type}{$setting} ne '') {
13748: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 13749: }
13750: if (@current > 0) {
13751: if (@new > 0) {
13752: foreach my $item (@current) {
13753: if (!grep(/^\Q$item\E$/,@new)) {
13754: $changes{$type}{$setting} = 1;
1.82 raeburn 13755: last;
13756: }
13757: }
1.84 raeburn 13758: foreach my $item (@new) {
13759: if (!grep(/^\Q$item\E$/,@current)) {
13760: $changes{$type}{$setting} = 1;
13761: last;
1.82 raeburn 13762: }
13763: }
13764: } else {
1.83 raeburn 13765: $changes{$type}{$setting} = 1;
1.69 raeburn 13766: }
1.83 raeburn 13767: } elsif (@new > 0) {
13768: $changes{$type}{$setting} = 1;
1.69 raeburn 13769: }
13770: }
13771: }
13772: if (keys(%changes) > 0) {
1.81 raeburn 13773: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 13774: my $putresult = &Apache::lonnet::put_dom('configuration',
13775: \%serverstatushash,$dom);
13776: if ($putresult eq 'ok') {
13777: $resulttext .= &mt('Changes made:').'<ul>';
13778: foreach my $type (@pages) {
1.84 raeburn 13779: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 13780: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 13781: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 13782: if ($newserverstatus{$type}{'namedusers'} eq '') {
13783: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
13784: } else {
13785: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
13786: }
1.84 raeburn 13787: }
13788: if ($changes{$type}{'machines'}) {
1.69 raeburn 13789: if ($newserverstatus{$type}{'machines'} eq '') {
13790: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
13791: } else {
13792: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
13793: }
13794:
13795: }
13796: $resulttext .= '</ul></li>';
13797: }
13798: }
13799: $resulttext .= '</ul>';
13800: } else {
13801: $resulttext = '<span class="LC_error">'.
13802: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
13803:
13804: }
13805: } else {
13806: $resulttext = &mt('No changes made to access to server status pages');
13807: }
13808: return $resulttext;
13809: }
13810:
1.118 jms 13811: sub modify_helpsettings {
1.160.6.77 raeburn 13812: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 13813: my ($resulttext,$errors,%changes,%helphash);
13814: my %defaultchecked = ('submitbugs' => 'on');
13815: my @offon = ('off','on');
1.118 jms 13816: my @toggles = ('submitbugs');
1.160.6.77 raeburn 13817: my %current = ('submitbugs' => '',
13818: 'adhoc' => {},
13819: );
1.118 jms 13820: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 13821: %current = %{$domconfig{'helpsettings'}};
13822: }
1.160.6.77 raeburn 13823: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 13824: foreach my $item (@toggles) {
13825: if ($defaultchecked{$item} eq 'on') {
13826: if ($current{$item} eq '') {
13827: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 13828: $changes{$item} = 1;
13829: }
1.160.6.73 raeburn 13830: } elsif ($current{$item} ne $env{'form.'.$item}) {
13831: $changes{$item} = 1;
13832: }
13833: } elsif ($defaultchecked{$item} eq 'off') {
13834: if ($current{$item} eq '') {
13835: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 13836: $changes{$item} = 1;
13837: }
1.160.6.73 raeburn 13838: } elsif ($current{$item} ne $env{'form.'.$item}) {
13839: $changes{$item} = 1;
13840: }
13841: }
13842: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
13843: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
13844: }
13845: }
1.160.6.77 raeburn 13846: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 13847: my $confname = $dom.'-domainconfig';
13848: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 13849: my (@allpos,%newsettings,%changedprivs,$newrole);
13850: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 13851: my @accesstypes = ('all','dh','da','none','status','inc','exc');
13852: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 13853: my %lt = &Apache::lonlocal::texthash(
13854: s => 'system',
13855: d => 'domain',
13856: order => 'Display order',
13857: access => 'Role usage',
1.160.6.79 raeburn 13858: all => 'All with domain helpdesk or helpdesk assistant role',
13859: dh => 'All with domain helpdesk role',
13860: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 13861: none => 'None',
13862: status => 'Determined based on institutional status',
13863: inc => 'Include all, but exclude specific personnel',
13864: exc => 'Exclude all, but include specific personnel',
13865: );
13866: for (my $num=0; $num<=$maxnum; $num++) {
13867: my ($prefix,$identifier,$rolename,%curr);
13868: if ($num == $maxnum) {
13869: next unless ($env{'form.newcusthelp'} == $maxnum);
13870: $identifier = 'custhelp'.$num;
13871: $prefix = 'helproles_'.$num;
13872: $rolename = $env{'form.custhelpname'.$num};
13873: $rolename=~s/[^A-Za-z0-9]//gs;
13874: next if ($rolename eq '');
13875: next if (exists($existing{'rolesdef_'.$rolename}));
13876: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
13877: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
13878: $newprivs{'c'},$confname,$dom);
13879: if ($result ne 'ok') {
13880: $errors .= '<li><span class="LC_error">'.
13881: &mt('An error occurred storing the new custom role: [_1]',
13882: $result).'</span></li>';
13883: next;
13884: } else {
13885: $changedprivs{$rolename} = \%newprivs;
13886: $newrole = $rolename;
13887: }
13888: } else {
13889: $prefix = 'helproles_'.$num;
13890: $rolename = $env{'form.'.$prefix};
13891: next if ($rolename eq '');
13892: next unless (exists($existing{'rolesdef_'.$rolename}));
13893: $identifier = 'custhelp'.$num;
13894: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
13895: my %currprivs;
13896: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
13897: split(/\_/,$existing{'rolesdef_'.$rolename});
13898: foreach my $level ('c','d','s') {
13899: if ($newprivs{$level} ne $currprivs{$level}) {
13900: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
13901: $newprivs{'c'},$confname,$dom);
13902: if ($result ne 'ok') {
13903: $errors .= '<li><span class="LC_error">'.
13904: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
13905: $rolename,$result).'</span></li>';
13906: } else {
13907: $changedprivs{$rolename} = \%newprivs;
13908: }
13909: last;
13910: }
13911: }
13912: if (ref($current{'adhoc'}) eq 'HASH') {
13913: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
13914: %curr = %{$current{'adhoc'}{$rolename}};
13915: }
13916: }
13917: }
13918: my $newpos = $env{'form.'.$prefix.'_pos'};
13919: $newpos =~ s/\D+//g;
13920: $allpos[$newpos] = $rolename;
13921: my $newdesc = $env{'form.'.$prefix.'_desc'};
13922: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
13923: if ($curr{'desc'}) {
13924: if ($curr{'desc'} ne $newdesc) {
13925: $changes{'customrole'}{$rolename}{'desc'} = 1;
13926: $newsettings{$rolename}{'desc'} = $newdesc;
13927: }
13928: } elsif ($newdesc ne '') {
13929: $changes{'customrole'}{$rolename}{'desc'} = 1;
13930: $newsettings{$rolename}{'desc'} = $newdesc;
13931: }
13932: my $access = $env{'form.'.$prefix.'_access'};
13933: if (grep(/^\Q$access\E$/,@accesstypes)) {
13934: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
13935: if ($access eq 'status') {
13936: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
13937: if (scalar(@statuses) == 0) {
13938: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
13939: } else {
13940: my (@shownstatus,$numtypes);
13941: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
13942: if (ref($types) eq 'ARRAY') {
13943: $numtypes = scalar(@{$types});
13944: foreach my $type (sort(@statuses)) {
13945: if ($type eq 'default') {
13946: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
13947: } elsif (grep(/^\Q$type\E$/,@{$types})) {
13948: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
13949: push(@shownstatus,$usertypes->{$type});
13950: }
1.160.6.73 raeburn 13951: }
13952: }
1.160.6.77 raeburn 13953: if (grep(/^default$/,@statuses)) {
13954: push(@shownstatus,$othertitle);
13955: }
13956: if (scalar(@shownstatus) == 1+$numtypes) {
13957: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
13958: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
13959: } else {
13960: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
13961: if (ref($curr{'status'}) eq 'ARRAY') {
13962: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
13963: if (@diffs) {
13964: $changes{'customrole'}{$rolename}{$access} = 1;
13965: }
13966: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13967: $changes{'customrole'}{$rolename}{$access} = 1;
13968: }
13969: }
13970: }
13971: } elsif (($access eq 'inc') || ($access eq 'exc')) {
13972: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
13973: my @newspecstaff;
13974: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
13975: foreach my $person (sort(@personnel)) {
13976: if ($domhelpdesk{$person}) {
13977: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
13978: }
13979: }
13980: if (ref($curr{$access}) eq 'ARRAY') {
13981: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
13982: if (@diffs) {
13983: $changes{'customrole'}{$rolename}{$access} = 1;
13984: }
13985: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13986: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 13987: }
1.160.6.77 raeburn 13988: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13989: my ($uname,$udom) = split(/:/,$person);
13990: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
13991: }
13992: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 13993: }
1.160.6.77 raeburn 13994: } else {
13995: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
13996: }
13997: unless ($curr{'access'} eq $access) {
13998: $changes{'customrole'}{$rolename}{'access'} = 1;
13999: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 14000: }
14001: }
1.160.6.77 raeburn 14002: if (@allpos > 0) {
14003: my $idx = 0;
14004: foreach my $rolename (@allpos) {
14005: if ($rolename ne '') {
14006: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
14007: if (ref($current{'adhoc'}) eq 'HASH') {
14008: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
14009: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
14010: $changes{'customrole'}{$rolename}{'order'} = 1;
14011: $newsettings{$rolename}{'order'} = $idx+1;
14012: }
14013: }
1.160.6.73 raeburn 14014: }
1.160.6.77 raeburn 14015: $idx ++;
1.122 jms 14016: }
14017: }
1.118 jms 14018: }
1.123 jms 14019: my $putresult;
14020: if (keys(%changes) > 0) {
1.160.6.5 raeburn 14021: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
14022: if ($putresult eq 'ok') {
1.160.6.77 raeburn 14023: if (ref($helphash{'helpsettings'}) eq 'HASH') {
14024: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
14025: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
14026: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
14027: }
14028: }
14029: my $cachetime = 24*60*60;
14030: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14031: if (ref($lastactref) eq 'HASH') {
14032: $lastactref->{'domdefaults'} = 1;
14033: }
14034: } else {
14035: $errors .= '<li><span class="LC_error">'.
14036: &mt('An error occurred storing the settings: [_1]',
14037: $putresult).'</span></li>';
14038: }
14039: }
14040: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
14041: $resulttext = &mt('Changes made:').'<ul>';
14042: my (%shownprivs,@levelorder);
14043: @levelorder = ('c','d','s');
14044: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 14045: foreach my $item (sort(keys(%changes))) {
14046: if ($item eq 'submitbugs') {
14047: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
14048: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
14049: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 14050: } elsif ($item eq 'customrole') {
14051: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 14052: my @keyorder = ('order','desc','access','status','exc','inc');
14053: my %keytext = &Apache::lonlocal::texthash(
14054: order => 'Order',
14055: desc => 'Role description',
14056: access => 'Role usage',
1.160.6.83 raeburn 14057: status => 'Allowed institutional types',
1.160.6.77 raeburn 14058: exc => 'Allowed personnel',
14059: inc => 'Disallowed personnel',
14060: );
1.160.6.73 raeburn 14061: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 14062: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
14063: if ($role eq $newrole) {
14064: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
14065: $role).'<ul>';
14066: } else {
14067: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
14068: $role).'<ul>';
14069: }
14070: foreach my $key (@keyorder) {
14071: if ($changes{'customrole'}{$role}{$key}) {
14072: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
14073: $keytext{$key},$newsettings{$role}{$key}).
14074: '</li>';
14075: }
14076: }
14077: if (ref($changedprivs{$role}) eq 'HASH') {
14078: $shownprivs{$role} = 1;
14079: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
14080: foreach my $level (@levelorder) {
14081: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
14082: next if ($item eq '');
14083: my ($priv) = split(/\&/,$item,2);
14084: if (&Apache::lonnet::plaintext($priv)) {
14085: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
14086: unless ($level eq 'c') {
14087: $resulttext .= ' ('.$lt{$level}.')';
14088: }
14089: $resulttext .= '</li>';
14090: }
14091: }
14092: }
14093: $resulttext .= '</ul>';
14094: }
14095: $resulttext .= '</ul></li>';
14096: }
1.160.6.73 raeburn 14097: }
14098: }
1.160.6.5 raeburn 14099: }
14100: }
14101: }
1.160.6.77 raeburn 14102: if (keys(%changedprivs)) {
14103: foreach my $role (sort(keys(%changedprivs))) {
14104: unless ($shownprivs{$role}) {
14105: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
14106: $role).'<ul>'.
14107: '<li>'.&mt('Privileges set to :').'<ul>';
14108: foreach my $level (@levelorder) {
14109: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
14110: next if ($item eq '');
14111: my ($priv) = split(/\&/,$item,2);
14112: if (&Apache::lonnet::plaintext($priv)) {
14113: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
14114: unless ($level eq 'c') {
14115: $resulttext .= ' ('.$lt{$level}.')';
14116: }
14117: $resulttext .= '</li>';
14118: }
14119: }
14120: }
14121: $resulttext .= '</ul></li></ul></li>';
14122: }
14123: }
14124: }
14125: $resulttext .= '</ul>';
14126: } else {
14127: $resulttext = &mt('No changes made to help settings');
1.118 jms 14128: }
14129: if ($errors) {
1.160.6.5 raeburn 14130: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 14131: $errors.'</ul>';
1.118 jms 14132: }
14133: return $resulttext;
14134: }
14135:
1.121 raeburn 14136: sub modify_coursedefaults {
1.160.6.27 raeburn 14137: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 14138: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 14139: my %defaultchecked = (
14140: 'uselcmath' => 'on',
14141: 'usejsme' => 'on'
14142: );
14143: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 14144: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 14145: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
14146: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 14147: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 14148: my %staticdefaults = (
14149: anonsurvey_threshold => 10,
14150: uploadquota => 500,
1.160.6.57 raeburn 14151: postsubmit => 60,
1.160.6.70 raeburn 14152: mysqltables => 172800,
1.160.6.21 raeburn 14153: );
1.160.6.90 raeburn 14154: my %texoptions = (
14155: MathJax => 'MathJax',
14156: mimetex => &mt('Convert to Images'),
14157: tth => &mt('TeX to HTML'),
14158: );
1.121 raeburn 14159: $defaultshash{'coursedefaults'} = {};
14160:
14161: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
14162: if ($domconfig{'coursedefaults'} eq '') {
14163: $domconfig{'coursedefaults'} = {};
14164: }
14165: }
14166:
14167: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
14168: foreach my $item (@toggles) {
14169: if ($defaultchecked{$item} eq 'on') {
14170: if (($domconfig{'coursedefaults'}{$item} eq '') &&
14171: ($env{'form.'.$item} eq '0')) {
14172: $changes{$item} = 1;
1.160.6.16 raeburn 14173: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 14174: $changes{$item} = 1;
14175: }
14176: } elsif ($defaultchecked{$item} eq 'off') {
14177: if (($domconfig{'coursedefaults'}{$item} eq '') &&
14178: ($env{'form.'.$item} eq '1')) {
14179: $changes{$item} = 1;
14180: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
14181: $changes{$item} = 1;
14182: }
14183: }
14184: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
14185: }
1.160.6.21 raeburn 14186: foreach my $item (@numbers) {
14187: my ($currdef,$newdef);
1.160.6.26 raeburn 14188: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 14189: if ($item eq 'anonsurvey_threshold') {
14190: $currdef = $domconfig{'coursedefaults'}{$item};
14191: $newdef =~ s/\D//g;
14192: if ($newdef eq '' || $newdef < 1) {
14193: $newdef = 1;
14194: }
14195: $defaultshash{'coursedefaults'}{$item} = $newdef;
14196: } else {
1.160.6.70 raeburn 14197: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
14198: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
14199: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 14200: }
14201: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 14202: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 14203: }
14204: if ($currdef ne $newdef) {
14205: if ($item eq 'anonsurvey_threshold') {
14206: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
14207: $changes{$item} = 1;
14208: }
1.160.6.70 raeburn 14209: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
14210: my $setting = $1;
14211: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
14212: $changes{$setting} = 1;
1.160.6.21 raeburn 14213: }
14214: }
1.139 raeburn 14215: }
14216: }
1.160.6.90 raeburn 14217: my $texengine;
14218: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
14219: $texengine = $env{'form.texengine'};
14220: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
14221: if ($currdef eq '') {
14222: unless ($texengine eq $Apache::lonnet::deftex) {
14223: $changes{'texengine'} = 1;
14224: }
14225: } elsif ($currdef ne $texengine) {
14226: $changes{'texengine'} = 1;
14227: }
14228: }
14229: if ($texengine ne '') {
14230: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
14231: }
1.160.6.64 raeburn 14232: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
14233: my @currclonecode;
14234: if (ref($currclone) eq 'HASH') {
14235: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
14236: @currclonecode = @{$currclone->{'instcode'}};
14237: }
14238: }
14239: my $newclone;
14240: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
14241: $newclone = $env{'form.canclone'};
14242: }
14243: if ($newclone eq 'instcode') {
14244: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
14245: my (%codedefaults,@code_order,@clonecode);
14246: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
14247: \@code_order);
14248: foreach my $item (@code_order) {
14249: if (grep(/^\Q$item\E$/,@newcodes)) {
14250: push(@clonecode,$item);
14251: }
14252: }
14253: if (@clonecode) {
14254: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
14255: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
14256: if (@diffs) {
14257: $changes{'canclone'} = 1;
14258: }
14259: } else {
14260: $newclone eq '';
14261: }
14262: } elsif ($newclone ne '') {
14263: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
14264: }
14265: if ($newclone ne $currclone) {
14266: $changes{'canclone'} = 1;
14267: }
1.160.6.57 raeburn 14268: my %credits;
14269: foreach my $type (@types) {
14270: unless ($type eq 'community') {
14271: $credits{$type} = $env{'form.'.$type.'_credits'};
14272: $credits{$type} =~ s/[^\d.]+//g;
14273: }
14274: }
14275: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
14276: ($env{'form.coursecredits'} eq '1')) {
14277: $changes{'coursecredits'} = 1;
14278: foreach my $type (keys(%credits)) {
14279: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
14280: }
14281: } else {
14282: if ($env{'form.coursecredits'} eq '1') {
14283: foreach my $type (@types) {
14284: unless ($type eq 'community') {
14285: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
14286: $changes{'coursecredits'} = 1;
14287: }
14288: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
14289: }
14290: }
14291: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
14292: foreach my $type (@types) {
14293: unless ($type eq 'community') {
14294: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
14295: $changes{'coursecredits'} = 1;
14296: last;
14297: }
14298: }
14299: }
14300: }
14301: }
14302: if ($env{'form.postsubmit'} eq '1') {
14303: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
14304: my %currtimeout;
14305: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
14306: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
14307: $changes{'postsubmit'} = 1;
14308: }
14309: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
14310: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
14311: }
14312: } else {
14313: $changes{'postsubmit'} = 1;
14314: }
14315: foreach my $type (@types) {
14316: my $timeout = $env{'form.'.$type.'_timeout'};
14317: $timeout =~ s/\D//g;
14318: if ($timeout == $staticdefaults{'postsubmit'}) {
14319: $timeout = '';
14320: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
14321: $timeout = '0';
14322: }
14323: unless ($timeout eq '') {
14324: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
14325: }
14326: if (exists($currtimeout{$type})) {
14327: if ($timeout ne $currtimeout{$type}) {
14328: $changes{'postsubmit'} = 1;
14329: }
14330: } elsif ($timeout ne '') {
14331: $changes{'postsubmit'} = 1;
14332: }
14333: }
14334: } else {
14335: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
14336: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
14337: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
14338: $changes{'postsubmit'} = 1;
14339: }
14340: } else {
14341: $changes{'postsubmit'} = 1;
14342: }
1.160.6.16 raeburn 14343: }
1.121 raeburn 14344: }
14345: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14346: $dom);
14347: if ($putresult eq 'ok') {
14348: if (keys(%changes) > 0) {
1.160.6.27 raeburn 14349: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 14350: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 14351: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.90 raeburn 14352: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
14353: foreach my $item ('uselcmath','usejsme','texengine') {
1.160.6.57 raeburn 14354: if ($changes{$item}) {
14355: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
14356: }
1.160.6.16 raeburn 14357: }
14358: if ($changes{'coursecredits'}) {
14359: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 14360: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
14361: $domdefaults{$type.'credits'} =
14362: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
14363: }
14364: }
14365: }
14366: if ($changes{'postsubmit'}) {
14367: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
14368: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
14369: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
14370: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
14371: $domdefaults{$type.'postsubtimeout'} =
14372: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
14373: }
14374: }
1.160.6.16 raeburn 14375: }
14376: }
1.160.6.21 raeburn 14377: if ($changes{'uploadquota'}) {
14378: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
14379: foreach my $type (@types) {
14380: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
14381: }
14382: }
14383: }
1.160.6.64 raeburn 14384: if ($changes{'canclone'}) {
14385: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
14386: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
14387: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
14388: if (@clonecodes) {
14389: $domdefaults{'canclone'} = join('+',@clonecodes);
14390: }
14391: }
14392: } else {
14393: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
14394: }
14395: }
1.121 raeburn 14396: my $cachetime = 24*60*60;
14397: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 14398: if (ref($lastactref) eq 'HASH') {
14399: $lastactref->{'domdefaults'} = 1;
14400: }
1.121 raeburn 14401: }
14402: $resulttext = &mt('Changes made:').'<ul>';
14403: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 14404: if ($item eq 'uselcmath') {
1.121 raeburn 14405: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 14406: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 14407: } else {
1.160.6.57 raeburn 14408: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
14409: }
14410: } elsif ($item eq 'usejsme') {
14411: if ($env{'form.'.$item} eq '1') {
14412: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
14413: } else {
14414: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 14415: }
1.160.6.90 raeburn 14416: } elsif ($item eq 'texengine') {
14417: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
14418: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
14419: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
14420: }
1.139 raeburn 14421: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 14422: $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 14423: } elsif ($item eq 'uploadquota') {
14424: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
14425: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
14426: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
14427: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 14428: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
14429:
1.160.6.21 raeburn 14430: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
14431: '</ul>'.
14432: '</li>';
14433: } else {
14434: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
14435: }
1.160.6.70 raeburn 14436: } elsif ($item eq 'mysqltables') {
14437: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
14438: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
14439: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
14440: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
14441: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
14442: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
14443: '</ul>'.
14444: '</li>';
14445: } else {
14446: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
14447: }
1.160.6.57 raeburn 14448: } elsif ($item eq 'postsubmit') {
14449: if ($domdefaults{'postsubmit'} eq 'off') {
14450: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
14451: } else {
14452: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
14453: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
14454: $resulttext .= &mt('durations:').'<ul>';
14455: foreach my $type (@types) {
14456: $resulttext .= '<li>';
14457: my $timeout;
14458: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
14459: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
14460: }
14461: my $display;
14462: if ($timeout eq '0') {
14463: $display = &mt('unlimited');
14464: } elsif ($timeout eq '') {
14465: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
14466: } else {
14467: $display = &mt('[quant,_1,second]',$timeout);
14468: }
14469: if ($type eq 'community') {
14470: $resulttext .= &mt('Communities');
14471: } elsif ($type eq 'official') {
14472: $resulttext .= &mt('Official courses');
14473: } elsif ($type eq 'unofficial') {
14474: $resulttext .= &mt('Unofficial courses');
14475: } elsif ($type eq 'textbook') {
14476: $resulttext .= &mt('Textbook courses');
14477: }
14478: $resulttext .= ' -- '.$display.'</li>';
14479: }
14480: $resulttext .= '</ul>';
14481: }
14482: $resulttext .= '</li>';
14483: }
1.160.6.16 raeburn 14484: } elsif ($item eq 'coursecredits') {
14485: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
14486: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 14487: ($domdefaults{'unofficialcredits'} eq '') &&
14488: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 14489: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
14490: } else {
14491: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
14492: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
14493: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 14494: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 14495: '</ul>'.
14496: '</li>';
14497: }
14498: } else {
14499: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
14500: }
1.160.6.64 raeburn 14501: } elsif ($item eq 'canclone') {
14502: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
14503: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
14504: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
14505: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
14506: }
14507: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
14508: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
14509: } else {
14510: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
14511: }
1.140 raeburn 14512: }
1.121 raeburn 14513: }
14514: $resulttext .= '</ul>';
14515: } else {
14516: $resulttext = &mt('No changes made to course defaults');
14517: }
14518: } else {
14519: $resulttext = '<span class="LC_error">'.
14520: &mt('An error occurred: [_1]',$putresult).'</span>';
14521: }
14522: return $resulttext;
14523: }
14524:
1.160.6.37 raeburn 14525: sub modify_selfenrollment {
14526: my ($dom,$lastactref,%domconfig) = @_;
14527: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
14528: my @types = ('official','unofficial','community','textbook');
14529: my %titles = &tool_titles();
14530: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
14531: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
14532: $ordered{'default'} = ['types','registered','approval','limit'];
14533:
14534: my (%roles,%shown,%toplevel);
14535: $roles{'0'} = &Apache::lonnet::plaintext('dc');
14536:
14537: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
14538: if ($domconfig{'selfenrollment'} eq '') {
14539: $domconfig{'selfenrollment'} = {};
14540: }
14541: }
14542: %toplevel = (
14543: admin => 'Configuration Rights',
14544: default => 'Default settings',
14545: validation => 'Validation of self-enrollment requests',
14546: );
14547: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
14548:
14549: if (ref($ordered{'admin'}) eq 'ARRAY') {
14550: foreach my $item (@{$ordered{'admin'}}) {
14551: foreach my $type (@types) {
14552: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
14553: $selfenrollhash{'admin'}{$type}{$item} = 1;
14554: } else {
14555: $selfenrollhash{'admin'}{$type}{$item} = 0;
14556: }
14557: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
14558: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
14559: if ($selfenrollhash{'admin'}{$type}{$item} ne
14560: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
14561: push(@{$changes{'admin'}{$type}},$item);
14562: }
14563: } else {
14564: if (!$selfenrollhash{'admin'}{$type}{$item}) {
14565: push(@{$changes{'admin'}{$type}},$item);
14566: }
14567: }
14568: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
14569: push(@{$changes{'admin'}{$type}},$item);
14570: }
14571: }
14572: }
14573: }
14574:
14575: foreach my $item (@{$ordered{'default'}}) {
14576: foreach my $type (@types) {
14577: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
14578: if ($item eq 'types') {
14579: unless (($value eq 'all') || ($value eq 'dom')) {
14580: $value = '';
14581: }
14582: } elsif ($item eq 'registered') {
14583: unless ($value eq '1') {
14584: $value = 0;
14585: }
14586: } elsif ($item eq 'approval') {
14587: unless ($value =~ /^[012]$/) {
14588: $value = 0;
14589: }
14590: } else {
14591: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
14592: $value = 'none';
14593: }
14594: }
14595: $selfenrollhash{'default'}{$type}{$item} = $value;
14596: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
14597: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
14598: if ($selfenrollhash{'default'}{$type}{$item} ne
14599: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
14600: push(@{$changes{'default'}{$type}},$item);
14601: }
14602: } else {
14603: push(@{$changes{'default'}{$type}},$item);
14604: }
14605: } else {
14606: push(@{$changes{'default'}{$type}},$item);
14607: }
14608: if ($item eq 'limit') {
14609: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
14610: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
14611: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
14612: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
14613: }
14614: } else {
14615: $selfenrollhash{'default'}{$type}{'cap'} = '';
14616: }
14617: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
14618: if ($selfenrollhash{'default'}{$type}{'cap'} ne
14619: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
14620: push(@{$changes{'default'}{$type}},'cap');
14621: }
14622: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
14623: push(@{$changes{'default'}{$type}},'cap');
14624: }
14625: }
14626: }
14627: }
14628:
14629: foreach my $item (@{$itemsref}) {
14630: if ($item eq 'fields') {
14631: my @changed;
14632: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
14633: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
14634: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
14635: }
14636: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
14637: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
14638: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
14639: $domconfig{'selfenrollment'}{'validation'}{$item});
14640: } else {
14641: @changed = @{$selfenrollhash{'validation'}{$item}};
14642: }
14643: } else {
14644: @changed = @{$selfenrollhash{'validation'}{$item}};
14645: }
14646: if (@changed) {
14647: if ($selfenrollhash{'validation'}{$item}) {
14648: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
14649: } else {
14650: $changes{'validation'}{$item} = &mt('None');
14651: }
14652: }
14653: } else {
14654: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
14655: if ($item eq 'markup') {
14656: if ($env{'form.selfenroll_validation_'.$item}) {
14657: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14658: }
14659: }
14660: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
14661: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
14662: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
14663: }
14664: }
14665: }
14666: }
14667:
14668: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
14669: $dom);
14670: if ($putresult eq 'ok') {
14671: if (keys(%changes) > 0) {
14672: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14673: $resulttext = &mt('Changes made:').'<ul>';
14674: foreach my $key ('admin','default','validation') {
14675: if (ref($changes{$key}) eq 'HASH') {
14676: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
14677: if ($key eq 'validation') {
14678: foreach my $item (@{$itemsref}) {
14679: if (exists($changes{$key}{$item})) {
14680: if ($item eq 'markup') {
14681: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
14682: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
14683: } else {
14684: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
14685: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
14686: }
14687: }
14688: }
14689: } else {
14690: foreach my $type (@types) {
14691: if ($type eq 'community') {
14692: $roles{'1'} = &mt('Community personnel');
14693: } else {
14694: $roles{'1'} = &mt('Course personnel');
14695: }
14696: if (ref($changes{$key}{$type}) eq 'ARRAY') {
14697: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
14698: if ($key eq 'admin') {
14699: my @mgrdc = ();
14700: if (ref($ordered{$key}) eq 'ARRAY') {
14701: foreach my $item (@{$ordered{'admin'}}) {
14702: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
14703: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
14704: push(@mgrdc,$item);
14705: }
14706: }
14707: }
14708: if (@mgrdc) {
14709: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
14710: } else {
14711: delete($domdefaults{$type.'selfenrolladmdc'});
14712: }
14713: }
14714: } else {
14715: if (ref($ordered{$key}) eq 'ARRAY') {
14716: foreach my $item (@{$ordered{$key}}) {
14717: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
14718: $domdefaults{$type.'selfenroll'.$item} =
14719: $selfenrollhash{$key}{$type}{$item};
14720: }
14721: }
14722: }
14723: }
14724: }
14725: $resulttext .= '<li>'.$titles{$type}.'<ul>';
14726: foreach my $item (@{$ordered{$key}}) {
14727: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
14728: $resulttext .= '<li>';
14729: if ($key eq 'admin') {
14730: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
14731: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
14732: } else {
14733: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
14734: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
14735: }
14736: $resulttext .= '</li>';
14737: }
14738: }
14739: $resulttext .= '</ul></li>';
14740: }
14741: }
14742: $resulttext .= '</ul></li>';
14743: }
14744: }
1.160.6.93 raeburn 14745: }
14746: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
14747: my $cachetime = 24*60*60;
14748: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14749: if (ref($lastactref) eq 'HASH') {
14750: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 14751: }
14752: }
14753: $resulttext .= '</ul>';
14754: } else {
14755: $resulttext = &mt('No changes made to self-enrollment settings');
14756: }
14757: } else {
14758: $resulttext = '<span class="LC_error">'.
14759: &mt('An error occurred: [_1]',$putresult).'</span>';
14760: }
14761: return $resulttext;
14762: }
14763:
1.137 raeburn 14764: sub modify_usersessions {
1.160.6.27 raeburn 14765: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 14766: my @hostingtypes = ('version','excludedomain','includedomain');
14767: my @offloadtypes = ('primary','default');
14768: my %types = (
14769: remote => \@hostingtypes,
14770: hosted => \@hostingtypes,
14771: spares => \@offloadtypes,
14772: );
14773: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 14774: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 14775: my (%by_ip,%by_location,@intdoms);
14776: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
14777: my @locations = sort(keys(%by_location));
1.137 raeburn 14778: my (%defaultshash,%changes);
14779: foreach my $prefix (@prefixes) {
14780: $defaultshash{'usersessions'}{$prefix} = {};
14781: }
1.160.6.27 raeburn 14782: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 14783: my $resulttext;
1.138 raeburn 14784: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 14785: foreach my $prefix (@prefixes) {
1.145 raeburn 14786: next if ($prefix eq 'spares');
14787: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 14788: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14789: if ($type eq 'version') {
14790: my $value = $env{'form.'.$prefix.'_'.$type};
14791: my $okvalue;
14792: if ($value ne '') {
14793: if (grep(/^\Q$value\E$/,@lcversions)) {
14794: $okvalue = $value;
14795: }
14796: }
14797: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14798: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
14799: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
14800: if ($inuse == 0) {
14801: $changes{$prefix}{$type} = 1;
14802: } else {
14803: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
14804: $changes{$prefix}{$type} = 1;
14805: }
14806: if ($okvalue ne '') {
14807: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14808: }
14809: }
14810: } else {
14811: if (($inuse == 1) && ($okvalue ne '')) {
14812: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14813: $changes{$prefix}{$type} = 1;
14814: }
14815: }
14816: } else {
14817: if (($inuse == 1) && ($okvalue ne '')) {
14818: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14819: $changes{$prefix}{$type} = 1;
14820: }
14821: }
14822: } else {
14823: if (($inuse == 1) && ($okvalue ne '')) {
14824: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14825: $changes{$prefix}{$type} = 1;
14826: }
14827: }
14828: } else {
14829: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14830: my @okvals;
14831: foreach my $val (@vals) {
1.138 raeburn 14832: if ($val =~ /:/) {
14833: my @items = split(/:/,$val);
14834: foreach my $item (@items) {
14835: if (ref($by_location{$item}) eq 'ARRAY') {
14836: push(@okvals,$item);
14837: }
14838: }
14839: } else {
14840: if (ref($by_location{$val}) eq 'ARRAY') {
14841: push(@okvals,$val);
14842: }
1.137 raeburn 14843: }
14844: }
14845: @okvals = sort(@okvals);
14846: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14847: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
14848: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
14849: if ($inuse == 0) {
14850: $changes{$prefix}{$type} = 1;
14851: } else {
14852: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14853: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
14854: if (@changed > 0) {
14855: $changes{$prefix}{$type} = 1;
14856: }
14857: }
14858: } else {
14859: if ($inuse == 1) {
14860: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14861: $changes{$prefix}{$type} = 1;
14862: }
14863: }
14864: } else {
14865: if ($inuse == 1) {
14866: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14867: $changes{$prefix}{$type} = 1;
14868: }
14869: }
14870: } else {
14871: if ($inuse == 1) {
14872: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14873: $changes{$prefix}{$type} = 1;
14874: }
14875: }
14876: }
14877: }
14878: }
1.145 raeburn 14879:
14880: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 14881: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 14882: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
14883: my $savespares;
14884:
14885: foreach my $lonhost (sort(keys(%servers))) {
14886: my $serverhomeID =
14887: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 14888: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 14889: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
14890: my %spareschg;
14891: foreach my $type (@{$types{'spares'}}) {
14892: my @okspares;
14893: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
14894: foreach my $server (@checked) {
1.152 raeburn 14895: if (&Apache::lonnet::hostname($server) ne '') {
14896: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
14897: unless (grep(/^\Q$server\E$/,@okspares)) {
14898: push(@okspares,$server);
14899: }
1.145 raeburn 14900: }
14901: }
14902: }
14903: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
14904: my $newspare;
1.152 raeburn 14905: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
14906: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 14907: $newspare = $new;
14908: }
14909: }
1.152 raeburn 14910: my @spares;
14911: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
14912: @spares = sort(@okspares,$newspare);
14913: } else {
14914: @spares = sort(@okspares);
14915: }
14916: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 14917: if (ref($spareid{$lonhost}) eq 'HASH') {
14918: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 14919: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 14920: if (@diffs > 0) {
14921: $spareschg{$type} = 1;
14922: }
14923: }
14924: }
14925: }
14926: if (keys(%spareschg) > 0) {
14927: $changes{'spares'}{$lonhost} = \%spareschg;
14928: }
14929: }
1.160.6.61 raeburn 14930: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.160.6.105 raeburn 14931: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.160.6.61 raeburn 14932: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
14933: my @okoffload;
14934: if (@offloadnow) {
14935: foreach my $server (@offloadnow) {
14936: if (&Apache::lonnet::hostname($server) ne '') {
14937: unless (grep(/^\Q$server\E$/,@okoffload)) {
14938: push(@okoffload,$server);
14939: }
14940: }
14941: }
14942: if (@okoffload) {
14943: foreach my $lonhost (@okoffload) {
14944: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
14945: }
14946: }
14947: }
1.160.6.105 raeburn 14948: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
14949: my @okoffloadoth;
14950: if (@offloadoth) {
14951: foreach my $server (@offloadoth) {
14952: if (&Apache::lonnet::hostname($server) ne '') {
14953: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
14954: push(@okoffloadoth,$server);
14955: }
14956: }
14957: }
14958: if (@okoffloadoth) {
14959: foreach my $lonhost (@okoffloadoth) {
14960: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
14961: }
14962: }
14963: }
1.145 raeburn 14964: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14965: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
14966: if (ref($changes{'spares'}) eq 'HASH') {
14967: if (keys(%{$changes{'spares'}}) > 0) {
14968: $savespares = 1;
14969: }
14970: }
14971: } else {
14972: $savespares = 1;
14973: }
1.160.6.105 raeburn 14974: foreach my $offload ('offloadnow','offloadoth') {
14975: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
14976: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
14977: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
14978: $changes{$offload} = 1;
1.160.6.61 raeburn 14979: last;
14980: }
14981: }
1.160.6.105 raeburn 14982: unless ($changes{$offload}) {
14983: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
14984: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
14985: $changes{$offload} = 1;
14986: last;
14987: }
14988: }
14989: }
14990: } else {
14991: if (($offload eq 'offloadnow') && (@okoffload)) {
14992: $changes{'offloadnow'} = 1;
14993: }
14994: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
14995: $changes{'offloadoth'} = 1;
14996: }
1.160.6.61 raeburn 14997: }
1.160.6.105 raeburn 14998: }
14999: } else {
15000: if (@okoffload) {
1.160.6.61 raeburn 15001: $changes{'offloadnow'} = 1;
15002: }
1.160.6.105 raeburn 15003: if (@okoffloadoth) {
15004: $changes{'offloadoth'} = 1;
15005: }
1.145 raeburn 15006: }
1.147 raeburn 15007: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
15008: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 15009: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15010: $dom);
15011: if ($putresult eq 'ok') {
15012: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
15013: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
15014: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
15015: }
15016: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
15017: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
15018: }
1.160.6.61 raeburn 15019: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
15020: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
15021: }
1.160.6.105 raeburn 15022: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
15023: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
15024: }
1.137 raeburn 15025: }
15026: my $cachetime = 24*60*60;
15027: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 15028: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 15029: if (ref($lastactref) eq 'HASH') {
15030: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 15031: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 15032: }
1.147 raeburn 15033: if (keys(%changes) > 0) {
15034: my %lt = &usersession_titles();
15035: $resulttext = &mt('Changes made:').'<ul>';
15036: foreach my $prefix (@prefixes) {
15037: if (ref($changes{$prefix}) eq 'HASH') {
15038: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
15039: if ($prefix eq 'spares') {
15040: if (ref($changes{$prefix}) eq 'HASH') {
15041: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
15042: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 15043: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 15044: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
15045: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 15046: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
15047: foreach my $type (@{$types{$prefix}}) {
15048: if ($changes{$prefix}{$lonhost}{$type}) {
15049: my $offloadto = &mt('None');
15050: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
15051: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
15052: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
15053: }
1.145 raeburn 15054: }
1.147 raeburn 15055: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 15056: }
1.137 raeburn 15057: }
15058: }
1.147 raeburn 15059: $resulttext .= '</li>';
1.137 raeburn 15060: }
15061: }
1.147 raeburn 15062: } else {
15063: foreach my $type (@{$types{$prefix}}) {
15064: if (defined($changes{$prefix}{$type})) {
15065: my $newvalue;
15066: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
15067: if (ref($defaultshash{'usersessions'}{$prefix})) {
15068: if ($type eq 'version') {
15069: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
15070: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
15071: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
15072: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
15073: }
1.145 raeburn 15074: }
15075: }
15076: }
1.147 raeburn 15077: if ($newvalue eq '') {
15078: if ($type eq 'version') {
15079: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
15080: } else {
15081: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
15082: }
1.145 raeburn 15083: } else {
1.147 raeburn 15084: if ($type eq 'version') {
15085: $newvalue .= ' '.&mt('(or later)');
15086: }
15087: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 15088: }
1.137 raeburn 15089: }
15090: }
15091: }
1.147 raeburn 15092: $resulttext .= '</ul>';
1.137 raeburn 15093: }
15094: }
1.160.6.61 raeburn 15095: if ($changes{'offloadnow'}) {
15096: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
15097: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.160.6.105 raeburn 15098: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.160.6.61 raeburn 15099: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
15100: $resulttext .= '<li>'.$lonhost.'</li>';
15101: }
15102: $resulttext .= '</ul>';
15103: } else {
1.160.6.105 raeburn 15104: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
15105: }
15106: } else {
15107: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
15108: }
15109: }
15110: if ($changes{'offloadoth'}) {
15111: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
15112: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
15113: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
15114: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
15115: $resulttext .= '<li>'.$lonhost.'</li>';
15116: }
15117: $resulttext .= '</ul>';
15118: } else {
15119: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.160.6.61 raeburn 15120: }
15121: } else {
1.160.6.105 raeburn 15122: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.160.6.61 raeburn 15123: }
15124: }
1.147 raeburn 15125: $resulttext .= '</ul>';
15126: } else {
15127: $resulttext = $nochgmsg;
1.137 raeburn 15128: }
15129: } else {
15130: $resulttext = '<span class="LC_error">'.
15131: &mt('An error occurred: [_1]',$putresult).'</span>';
15132: }
15133: } else {
1.147 raeburn 15134: $resulttext = $nochgmsg;
1.137 raeburn 15135: }
15136: return $resulttext;
15137: }
15138:
1.150 raeburn 15139: sub modify_loadbalancing {
15140: my ($dom,%domconfig) = @_;
15141: my $primary_id = &Apache::lonnet::domain($dom,'primary');
15142: my $intdom = &Apache::lonnet::internet_dom($primary_id);
15143: my ($othertitle,$usertypes,$types) =
15144: &Apache::loncommon::sorted_inst_types($dom);
15145: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 15146: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 15147: my @sparestypes = ('primary','default');
15148: my %typetitles = &sparestype_titles();
15149: my $resulttext;
1.160.6.94 raeburn 15150: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 15151: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
15152: %existing = %{$domconfig{'loadbalancing'}};
15153: }
15154: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 15155: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 15156: my ($saveloadbalancing,%defaultshash,%changes);
15157: my ($alltypes,$othertypes,$titles) =
15158: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
15159: my %ruletitles = &offloadtype_text();
15160: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
15161: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
15162: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
15163: if ($balancer eq '') {
15164: next;
15165: }
15166: if (!exists($servers{$balancer})) {
15167: if (exists($currbalancer{$balancer})) {
15168: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 15169: }
1.160.6.7 raeburn 15170: next;
15171: }
15172: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
15173: push(@{$changes{'delete'}},$balancer);
15174: next;
15175: }
15176: if (!exists($currbalancer{$balancer})) {
15177: push(@{$changes{'add'}},$balancer);
15178: }
15179: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
15180: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
15181: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
15182: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
15183: $saveloadbalancing = 1;
15184: }
15185: foreach my $sparetype (@sparestypes) {
15186: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
15187: my @offloadto;
15188: foreach my $target (@targets) {
15189: if (($servers{$target}) && ($target ne $balancer)) {
15190: if ($sparetype eq 'default') {
15191: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
15192: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 15193: }
15194: }
1.160.6.7 raeburn 15195: unless(grep(/^\Q$target\E$/,@offloadto)) {
15196: push(@offloadto,$target);
15197: }
1.150 raeburn 15198: }
15199: }
1.160.6.76 raeburn 15200: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
15201: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
15202: push(@offloadto,$balancer);
15203: }
15204: }
15205: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 15206: }
1.160.6.94 raeburn 15207: if ($env{'form.loadbalancing_cookie_'.$i}) {
15208: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
15209: if (exists($currbalancer{$balancer})) {
15210: unless ($currcookies{$balancer}) {
15211: $changes{'curr'}{$balancer}{'cookie'} = 1;
15212: }
15213: }
15214: } elsif (exists($currbalancer{$balancer})) {
15215: if ($currcookies{$balancer}) {
15216: $changes{'curr'}{$balancer}{'cookie'} = 1;
15217: }
15218: }
1.160.6.7 raeburn 15219: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 15220: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 15221: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
15222: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 15223: if (@targetdiffs > 0) {
1.160.6.7 raeburn 15224: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 15225: }
1.160.6.7 raeburn 15226: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
15227: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
15228: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 15229: }
15230: }
15231: }
15232: } else {
1.160.6.7 raeburn 15233: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
15234: foreach my $sparetype (@sparestypes) {
15235: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
15236: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
15237: $changes{'curr'}{$balancer}{'targets'} = 1;
15238: }
1.150 raeburn 15239: }
15240: }
1.160.6.7 raeburn 15241: }
1.150 raeburn 15242: }
15243: my $ishomedom;
1.160.6.7 raeburn 15244: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
15245: $ishomedom = 1;
1.150 raeburn 15246: }
15247: if (ref($alltypes) eq 'ARRAY') {
15248: foreach my $type (@{$alltypes}) {
15249: my $rule;
1.160.6.7 raeburn 15250: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 15251: (!$ishomedom)) {
1.160.6.7 raeburn 15252: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
15253: }
15254: if ($rule eq 'specific') {
1.160.6.55 raeburn 15255: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
15256: if (exists($servers{$specifiedhost})) {
15257: $rule = $specifiedhost;
15258: }
1.150 raeburn 15259: }
1.160.6.7 raeburn 15260: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
15261: if (ref($currrules{$balancer}) eq 'HASH') {
15262: if ($rule ne $currrules{$balancer}{$type}) {
15263: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 15264: }
15265: } elsif ($rule ne '') {
1.160.6.7 raeburn 15266: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 15267: }
15268: }
15269: }
1.160.6.7 raeburn 15270: }
15271: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
15272: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
15273: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
15274: $defaultshash{'loadbalancing'} = {};
15275: }
15276: my $putresult = &Apache::lonnet::put_dom('configuration',
15277: \%defaultshash,$dom);
15278: if ($putresult eq 'ok') {
15279: if (keys(%changes) > 0) {
1.160.6.54 raeburn 15280: my %toupdate;
1.160.6.7 raeburn 15281: if (ref($changes{'delete'}) eq 'ARRAY') {
15282: foreach my $balancer (sort(@{$changes{'delete'}})) {
15283: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 15284: $toupdate{$balancer} = 1;
1.150 raeburn 15285: }
1.160.6.7 raeburn 15286: }
15287: if (ref($changes{'add'}) eq 'ARRAY') {
15288: foreach my $balancer (sort(@{$changes{'add'}})) {
15289: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 15290: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 15291: }
15292: }
15293: if (ref($changes{'curr'}) eq 'HASH') {
15294: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 15295: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 15296: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
15297: if ($changes{'curr'}{$balancer}{'targets'}) {
15298: my %offloadstr;
15299: foreach my $sparetype (@sparestypes) {
15300: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
15301: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
15302: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
15303: }
15304: }
1.150 raeburn 15305: }
1.160.6.7 raeburn 15306: if (keys(%offloadstr) == 0) {
15307: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 15308: } else {
1.160.6.7 raeburn 15309: my $showoffload;
15310: foreach my $sparetype (@sparestypes) {
15311: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
15312: if (defined($offloadstr{$sparetype})) {
15313: $showoffload .= $offloadstr{$sparetype};
15314: } else {
15315: $showoffload .= &mt('None');
15316: }
15317: $showoffload .= (' 'x3);
15318: }
15319: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 15320: }
15321: }
15322: }
1.160.6.7 raeburn 15323: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
15324: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
15325: foreach my $type (@{$alltypes}) {
15326: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
15327: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
15328: my $balancetext;
15329: if ($rule eq '') {
15330: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 15331: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 15332: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
15333: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 15334: foreach my $sparetype (@sparestypes) {
15335: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
15336: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
15337: }
15338: }
1.160.6.55 raeburn 15339: foreach my $item (@{$alltypes}) {
15340: next if ($item =~ /^_LC_ipchange/);
15341: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
15342: if ($hasrule eq 'homeserver') {
15343: map { $toupdate{$_} = 1; } (keys(%libraryservers));
15344: } else {
15345: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
15346: if ($servers{$hasrule}) {
15347: $toupdate{$hasrule} = 1;
15348: }
15349: }
15350: }
15351: }
15352: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
15353: $balancetext = $ruletitles{$rule};
15354: } else {
15355: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
15356: $balancetext = $ruletitles{'particular'}.' '.$receiver;
15357: if ($receiver) {
15358: $toupdate{$receiver};
15359: }
15360: }
15361: } else {
15362: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 15363: }
1.160.6.7 raeburn 15364: } else {
15365: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
15366: }
1.160.6.26 raeburn 15367: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 15368: }
15369: }
15370: }
15371: }
1.160.6.94 raeburn 15372: if ($changes{'curr'}{$balancer}{'cookie'}) {
15373: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
15374: $balancer).'</li>';
15375: }
1.160.6.106 raeburn 15376: }
15377: }
15378: if (keys(%toupdate)) {
15379: my %thismachine;
15380: my $updatedhere;
15381: my $cachetime = 60*60*24;
15382: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
15383: foreach my $lonhost (keys(%toupdate)) {
15384: if ($thismachine{$lonhost}) {
15385: unless ($updatedhere) {
15386: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
15387: $defaultshash{'loadbalancing'},
15388: $cachetime);
15389: $updatedhere = 1;
1.160.6.54 raeburn 15390: }
1.160.6.106 raeburn 15391: } else {
15392: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
15393: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.160.6.54 raeburn 15394: }
1.150 raeburn 15395: }
1.160.6.7 raeburn 15396: }
15397: if ($resulttext ne '') {
15398: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 15399: } else {
15400: $resulttext = $nochgmsg;
15401: }
15402: } else {
1.160.6.7 raeburn 15403: $resulttext = $nochgmsg;
1.150 raeburn 15404: }
15405: } else {
1.160.6.7 raeburn 15406: $resulttext = '<span class="LC_error">'.
15407: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 15408: }
15409: } else {
1.160.6.7 raeburn 15410: $resulttext = $nochgmsg;
1.150 raeburn 15411: }
15412: return $resulttext;
15413: }
15414:
1.48 raeburn 15415: sub recurse_check {
15416: my ($chkcats,$categories,$depth,$name) = @_;
15417: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
15418: my $chg = 0;
15419: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
15420: my $category = $chkcats->[$depth]{$name}[$j];
15421: my $item;
15422: if ($category eq '') {
15423: $chg ++;
15424: } else {
15425: my $deeper = $depth + 1;
15426: $item = &escape($category).':'.&escape($name).':'.$depth;
15427: if ($chg) {
15428: $categories->{$item} -= $chg;
15429: }
15430: &recurse_check($chkcats,$categories,$deeper,$category);
15431: $deeper --;
15432: }
15433: }
15434: }
15435: return;
15436: }
15437:
15438: sub recurse_cat_deletes {
15439: my ($item,$coursecategories,$deletions) = @_;
15440: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15441: my $subdepth = $depth + 1;
15442: if (ref($coursecategories) eq 'HASH') {
15443: foreach my $subitem (keys(%{$coursecategories})) {
15444: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
15445: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
15446: delete($coursecategories->{$subitem});
15447: $deletions->{$subitem} = 1;
15448: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 15449: }
1.48 raeburn 15450: }
15451: }
15452: return;
15453: }
15454:
1.125 raeburn 15455: sub active_dc_picker {
1.160.6.16 raeburn 15456: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 15457: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 15458: my @domcoord = keys(%domcoords);
15459: if (keys(%currhash)) {
15460: foreach my $dc (keys(%currhash)) {
15461: unless (exists($domcoords{$dc})) {
15462: push(@domcoord,$dc);
15463: }
15464: }
15465: }
15466: @domcoord = sort(@domcoord);
15467: my $numdcs = scalar(@domcoord);
15468: my $rows = 0;
15469: my $table;
1.125 raeburn 15470: if ($numdcs > 1) {
1.160.6.16 raeburn 15471: $table = '<table>';
15472: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 15473: my $rem = $i%($numinrow);
15474: if ($rem == 0) {
15475: if ($i > 0) {
1.160.6.16 raeburn 15476: $table .= '</tr>';
1.125 raeburn 15477: }
1.160.6.16 raeburn 15478: $table .= '<tr>';
15479: $rows ++;
1.125 raeburn 15480: }
1.160.6.16 raeburn 15481: my $check = '';
15482: if ($inputtype eq 'radio') {
15483: if (keys(%currhash) == 0) {
15484: if (!$i) {
15485: $check = ' checked="checked"';
15486: }
15487: } elsif (exists($currhash{$domcoord[$i]})) {
15488: $check = ' checked="checked"';
15489: }
15490: } else {
15491: if (exists($currhash{$domcoord[$i]})) {
15492: $check = ' checked="checked"';
1.125 raeburn 15493: }
15494: }
1.160.6.16 raeburn 15495: if ($i == @domcoord - 1) {
1.125 raeburn 15496: my $colsleft = $numinrow - $rem;
15497: if ($colsleft > 1) {
1.160.6.16 raeburn 15498: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 15499: } else {
1.160.6.16 raeburn 15500: $table .= '<td class="LC_left_item">';
1.125 raeburn 15501: }
15502: } else {
1.160.6.16 raeburn 15503: $table .= '<td class="LC_left_item">';
15504: }
15505: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
15506: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
15507: $table .= '<span class="LC_nobreak"><label>'.
15508: '<input type="'.$inputtype.'" name="'.$name.'"'.
15509: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
15510: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 15511: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 15512: }
1.160.6.33 raeburn 15513: $table .= '</label></span></td>';
1.125 raeburn 15514: }
1.160.6.16 raeburn 15515: $table .= '</tr></table>';
15516: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 15517: my ($dcname,$dcdom) = split(':',$domcoord[0]);
15518: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 15519: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 15520: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 15521: if ($user ne $dcname.':'.$dcdom) {
15522: $table .= ' ('.$dcname.':'.$dcdom.')';
15523: }
1.160.6.16 raeburn 15524: } else {
15525: my $check;
15526: if (exists($currhash{$domcoord[0]})) {
15527: $check = ' checked="checked"';
15528: }
1.160.6.50 raeburn 15529: $table = '<span class="LC_nobreak"><label>'.
15530: '<input type="checkbox" name="'.$name.'" '.
15531: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 15532: if ($user ne $dcname.':'.$dcdom) {
15533: $table .= ' ('.$dcname.':'.$dcdom.')';
15534: }
15535: $table .= '</label></span>';
1.160.6.16 raeburn 15536: $rows ++;
15537: }
1.125 raeburn 15538: }
1.160.6.16 raeburn 15539: return ($numdcs,$table,$rows);
1.125 raeburn 15540: }
15541:
1.137 raeburn 15542: sub usersession_titles {
15543: return &Apache::lonlocal::texthash(
15544: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
15545: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 15546: spares => 'Servers offloaded to, when busy',
1.137 raeburn 15547: version => 'LON-CAPA version requirement',
1.138 raeburn 15548: excludedomain => 'Allow all, but exclude specific domains',
15549: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 15550: primary => 'Primary (checked first)',
1.154 raeburn 15551: default => 'Default',
1.137 raeburn 15552: );
15553: }
15554:
1.152 raeburn 15555: sub id_for_thisdom {
15556: my (%servers) = @_;
15557: my %altids;
15558: foreach my $server (keys(%servers)) {
15559: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
15560: if ($serverhome ne $server) {
15561: $altids{$serverhome} = $server;
15562: }
15563: }
15564: return %altids;
15565: }
15566:
1.150 raeburn 15567: sub count_servers {
15568: my ($currbalancer,%servers) = @_;
15569: my (@spares,$numspares);
15570: foreach my $lonhost (sort(keys(%servers))) {
15571: next if ($currbalancer eq $lonhost);
15572: push(@spares,$lonhost);
15573: }
15574: if ($currbalancer) {
15575: $numspares = scalar(@spares);
15576: } else {
15577: $numspares = scalar(@spares) - 1;
15578: }
15579: return ($numspares,@spares);
15580: }
15581:
15582: sub lonbalance_targets_js {
1.160.6.7 raeburn 15583: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 15584: my $select = &mt('Select');
15585: my ($alltargets,$allishome,$allinsttypes,@alltypes);
15586: if (ref($servers) eq 'HASH') {
15587: $alltargets = join("','",sort(keys(%{$servers})));
15588: my @homedoms;
15589: foreach my $server (sort(keys(%{$servers}))) {
15590: if (&Apache::lonnet::host_domain($server) eq $dom) {
15591: push(@homedoms,'1');
15592: } else {
15593: push(@homedoms,'0');
15594: }
15595: }
15596: $allishome = join("','",@homedoms);
15597: }
15598: if (ref($types) eq 'ARRAY') {
15599: if (@{$types} > 0) {
15600: @alltypes = @{$types};
15601: }
15602: }
15603: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
15604: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 15605: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 15606: if (ref($settings) eq 'HASH') {
15607: %existing = %{$settings};
15608: }
15609: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 15610: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 15611: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 15612: return <<"END";
15613:
15614: <script type="text/javascript">
15615: // <![CDATA[
15616:
1.160.6.7 raeburn 15617: currBalancers = new Array('$balancers');
15618:
15619: function toggleTargets(balnum) {
15620: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
15621: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
15622: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
15623: var prevbalancer = prevhostitem.value;
15624: var baltotal = document.getElementById('loadbalancing_total').value;
15625: prevhostitem.value = balancer;
15626: if (prevbalancer != '') {
15627: var prevIdx = currBalancers.indexOf(prevbalancer);
15628: if (prevIdx != -1) {
15629: currBalancers.splice(prevIdx,1);
15630: }
15631: }
1.150 raeburn 15632: if (balancer == '') {
1.160.6.7 raeburn 15633: hideSpares(balnum);
1.150 raeburn 15634: } else {
1.160.6.7 raeburn 15635: var currIdx = currBalancers.indexOf(balancer);
15636: if (currIdx == -1) {
15637: currBalancers.push(balancer);
15638: }
1.150 raeburn 15639: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 15640: var ishomedom = homedoms[lonhostitem.selectedIndex];
15641: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 15642: }
1.160.6.7 raeburn 15643: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 15644: return;
15645: }
15646:
1.160.6.7 raeburn 15647: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 15648: var alltargets = new Array('$alltargets');
15649: var insttypes = new Array('$allinsttypes');
1.151 raeburn 15650: var offloadtypes = new Array('primary','default');
15651:
1.160.6.7 raeburn 15652: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
15653: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 15654:
1.151 raeburn 15655: for (var i=0; i<offloadtypes.length; i++) {
15656: var count = 0;
15657: for (var j=0; j<alltargets.length; j++) {
15658: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 15659: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
15660: item.value = alltargets[j];
15661: item.style.textAlign='left';
15662: item.style.textFace='normal';
15663: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
15664: if (currBalancers.indexOf(alltargets[j]) == -1) {
15665: item.disabled = '';
15666: } else {
15667: item.disabled = 'disabled';
15668: item.checked = false;
15669: }
1.151 raeburn 15670: count ++;
15671: }
1.150 raeburn 15672: }
15673: }
1.151 raeburn 15674: for (var k=0; k<insttypes.length; k++) {
15675: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 15676: if (ishomedom == 1) {
1.160.6.7 raeburn 15677: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
15678: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 15679: } else {
1.160.6.7 raeburn 15680: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
15681: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 15682: }
15683: } else {
1.160.6.7 raeburn 15684: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
15685: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 15686: }
1.151 raeburn 15687: if ((insttypes[k] != '_LC_external') &&
15688: ((insttypes[k] != '_LC_internetdom') ||
15689: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 15690: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
15691: item.options.length = 0;
15692: item.options[0] = new Option("","",true,true);
15693: var idx = 0;
1.151 raeburn 15694: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 15695: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
15696: idx ++;
15697: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 15698: }
15699: }
15700: }
15701: }
15702: return;
15703: }
15704:
1.160.6.7 raeburn 15705: function hideSpares(balnum) {
1.150 raeburn 15706: var alltargets = new Array('$alltargets');
15707: var insttypes = new Array('$allinsttypes');
15708: var offloadtypes = new Array('primary','default');
15709:
1.160.6.7 raeburn 15710: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
15711: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 15712:
15713: var total = alltargets.length - 1;
15714: for (var i=0; i<offloadtypes; i++) {
15715: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 15716: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
15717: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
15718: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 15719: }
1.150 raeburn 15720: }
15721: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 15722: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
15723: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 15724: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 15725: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
15726: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 15727: }
15728: }
15729: return;
15730: }
15731:
1.160.6.7 raeburn 15732: function checkOffloads(item,balnum,type) {
1.150 raeburn 15733: var alltargets = new Array('$alltargets');
15734: var offloadtypes = new Array('primary','default');
15735: if (item.checked) {
15736: var total = alltargets.length - 1;
15737: var other;
15738: if (type == offloadtypes[0]) {
1.151 raeburn 15739: other = offloadtypes[1];
1.150 raeburn 15740: } else {
1.151 raeburn 15741: other = offloadtypes[0];
1.150 raeburn 15742: }
15743: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 15744: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 15745: if (server == item.value) {
1.160.6.7 raeburn 15746: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
15747: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 15748: }
15749: }
15750: }
15751: }
15752: return;
15753: }
15754:
1.160.6.7 raeburn 15755: function singleServerToggle(balnum,type) {
15756: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 15757: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 15758: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
15759: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 15760:
15761: } else {
1.160.6.7 raeburn 15762: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
15763: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 15764: }
15765: return;
15766: }
15767:
1.160.6.7 raeburn 15768: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 15769: if (type == '_LC_external') {
1.160.6.26 raeburn 15770: return;
1.150 raeburn 15771: }
1.160.6.7 raeburn 15772: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 15773: for (var i=0; i<typesRules.length; i++) {
15774: if (formname.elements[typesRules[i]].checked) {
15775: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 15776: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
15777: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 15778: } else {
1.160.6.7 raeburn 15779: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
15780: }
15781: }
15782: }
15783: return;
15784: }
15785:
15786: function balancerDeleteChange(balnum) {
15787: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
15788: var baltotal = document.getElementById('loadbalancing_total').value;
15789: var addtarget;
15790: var removetarget;
15791: var action = 'delete';
15792: if (document.getElementById('loadbalancing_delete_'+balnum)) {
15793: var lonhost = hostitem.value;
15794: var currIdx = currBalancers.indexOf(lonhost);
15795: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
15796: if (currIdx != -1) {
15797: currBalancers.splice(currIdx,1);
15798: }
15799: addtarget = lonhost;
15800: } else {
15801: if (currIdx == -1) {
15802: currBalancers.push(lonhost);
15803: }
15804: removetarget = lonhost;
15805: action = 'undelete';
15806: }
15807: balancerChange(balnum,baltotal,action,addtarget,removetarget);
15808: }
15809: return;
15810: }
15811:
15812: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
15813: if (baltotal > 1) {
15814: var offloadtypes = new Array('primary','default');
15815: var alltargets = new Array('$alltargets');
15816: var insttypes = new Array('$allinsttypes');
15817: for (var i=0; i<baltotal; i++) {
15818: if (i != balnum) {
15819: for (var j=0; j<offloadtypes.length; j++) {
15820: var total = alltargets.length - 1;
15821: for (var k=0; k<total; k++) {
15822: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
15823: var server = serveritem.value;
15824: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
15825: if (server == addtarget) {
15826: serveritem.disabled = '';
15827: }
15828: }
15829: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
15830: if (server == removetarget) {
15831: serveritem.disabled = 'disabled';
15832: serveritem.checked = false;
15833: }
15834: }
15835: }
15836: }
15837: for (var j=0; j<insttypes.length; j++) {
15838: if (insttypes[j] != '_LC_external') {
15839: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
15840: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
15841: var currSel = singleserver.selectedIndex;
15842: var currVal = singleserver.options[currSel].value;
15843: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
15844: var numoptions = singleserver.options.length;
15845: var needsnew = 1;
15846: for (var k=0; k<numoptions; k++) {
15847: if (singleserver.options[k] == addtarget) {
15848: needsnew = 0;
15849: break;
15850: }
15851: }
15852: if (needsnew == 1) {
15853: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
15854: }
15855: }
15856: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
15857: singleserver.options.length = 0;
15858: if ((currVal) && (currVal != removetarget)) {
15859: singleserver.options[0] = new Option("","",false,false);
15860: } else {
15861: singleserver.options[0] = new Option("","",true,true);
15862: }
15863: var idx = 0;
15864: for (var m=0; m<alltargets.length; m++) {
15865: if (currBalancers.indexOf(alltargets[m]) == -1) {
15866: idx ++;
15867: if (currVal == alltargets[m]) {
15868: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
15869: } else {
15870: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
15871: }
15872: }
15873: }
15874: }
15875: }
15876: }
15877: }
1.150 raeburn 15878: }
15879: }
15880: }
15881: return;
15882: }
15883:
1.152 raeburn 15884: // ]]>
15885: </script>
15886:
15887: END
15888: }
15889:
15890: sub new_spares_js {
15891: my @sparestypes = ('primary','default');
15892: my $types = join("','",@sparestypes);
15893: my $select = &mt('Select');
15894: return <<"END";
15895:
15896: <script type="text/javascript">
15897: // <![CDATA[
15898:
15899: function updateNewSpares(formname,lonhost) {
15900: var types = new Array('$types');
15901: var include = new Array();
15902: var exclude = new Array();
15903: for (var i=0; i<types.length; i++) {
15904: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
15905: for (var j=0; j<spareboxes.length; j++) {
15906: if (formname.elements[spareboxes[j]].checked) {
15907: exclude.push(formname.elements[spareboxes[j]].value);
15908: } else {
15909: include.push(formname.elements[spareboxes[j]].value);
15910: }
15911: }
15912: }
15913: for (var i=0; i<types.length; i++) {
15914: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
15915: var selIdx = newSpare.selectedIndex;
15916: var currnew = newSpare.options[selIdx].value;
15917: var okSpares = new Array();
15918: for (var j=0; j<newSpare.options.length; j++) {
15919: var possible = newSpare.options[j].value;
15920: if (possible != '') {
15921: if (exclude.indexOf(possible) == -1) {
15922: okSpares.push(possible);
15923: } else {
15924: if (currnew == possible) {
15925: selIdx = 0;
15926: }
15927: }
15928: }
15929: }
15930: for (var k=0; k<include.length; k++) {
15931: if (okSpares.indexOf(include[k]) == -1) {
15932: okSpares.push(include[k]);
15933: }
15934: }
15935: okSpares.sort();
15936: newSpare.options.length = 0;
15937: if (selIdx == 0) {
15938: newSpare.options[0] = new Option("$select","",true,true);
15939: } else {
15940: newSpare.options[0] = new Option("$select","",false,false);
15941: }
15942: for (var m=0; m<okSpares.length; m++) {
15943: var idx = m+1;
15944: var selThis = 0;
15945: if (selIdx != 0) {
15946: if (okSpares[m] == currnew) {
15947: selThis = 1;
15948: }
15949: }
15950: if (selThis == 1) {
15951: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
15952: } else {
15953: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
15954: }
15955: }
15956: }
15957: return;
15958: }
15959:
15960: function checkNewSpares(lonhost,type) {
15961: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
15962: var chosen = newSpare.options[newSpare.selectedIndex].value;
15963: if (chosen != '') {
15964: var othertype;
15965: var othernewSpare;
15966: if (type == 'primary') {
15967: othernewSpare = document.getElementById('newspare_default_'+lonhost);
15968: }
15969: if (type == 'default') {
15970: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
15971: }
15972: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
15973: othernewSpare.selectedIndex = 0;
15974: }
15975: }
15976: return;
15977: }
15978:
15979: // ]]>
15980: </script>
15981:
15982: END
15983:
15984: }
15985:
15986: sub common_domprefs_js {
15987: return <<"END";
15988:
15989: <script type="text/javascript">
15990: // <![CDATA[
15991:
1.150 raeburn 15992: function getIndicesByName(formname,item) {
1.152 raeburn 15993: var group = new Array();
1.150 raeburn 15994: for (var i=0;i<formname.elements.length;i++) {
15995: if (formname.elements[i].name == item) {
1.152 raeburn 15996: group.push(formname.elements[i].id);
1.150 raeburn 15997: }
15998: }
1.152 raeburn 15999: return group;
1.150 raeburn 16000: }
16001:
16002: // ]]>
16003: </script>
16004:
16005: END
1.152 raeburn 16006:
1.150 raeburn 16007: }
16008:
1.160.6.5 raeburn 16009: sub recaptcha_js {
16010: my %lt = &captcha_phrases();
16011: return <<"END";
16012:
16013: <script type="text/javascript">
16014: // <![CDATA[
16015:
16016: function updateCaptcha(caller,context) {
16017: var privitem;
16018: var pubitem;
16019: var privtext;
16020: var pubtext;
1.160.6.69 raeburn 16021: var versionitem;
16022: var versiontext;
1.160.6.5 raeburn 16023: if (document.getElementById(context+'_recaptchapub')) {
16024: pubitem = document.getElementById(context+'_recaptchapub');
16025: } else {
16026: return;
16027: }
16028: if (document.getElementById(context+'_recaptchapriv')) {
16029: privitem = document.getElementById(context+'_recaptchapriv');
16030: } else {
16031: return;
16032: }
16033: if (document.getElementById(context+'_recaptchapubtxt')) {
16034: pubtext = document.getElementById(context+'_recaptchapubtxt');
16035: } else {
16036: return;
16037: }
16038: if (document.getElementById(context+'_recaptchaprivtxt')) {
16039: privtext = document.getElementById(context+'_recaptchaprivtxt');
16040: } else {
16041: return;
16042: }
1.160.6.69 raeburn 16043: if (document.getElementById(context+'_recaptchaversion')) {
16044: versionitem = document.getElementById(context+'_recaptchaversion');
16045: } else {
16046: return;
16047: }
16048: if (document.getElementById(context+'_recaptchavertxt')) {
16049: versiontext = document.getElementById(context+'_recaptchavertxt');
16050: } else {
16051: return;
16052: }
1.160.6.5 raeburn 16053: if (caller.checked) {
16054: if (caller.value == 'recaptcha') {
16055: pubitem.type = 'text';
16056: privitem.type = 'text';
16057: pubitem.size = '40';
16058: privitem.size = '40';
16059: pubtext.innerHTML = "$lt{'pub'}";
16060: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 16061: versionitem.type = 'text';
16062: versionitem.size = '3';
16063: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 16064: } else {
16065: pubitem.type = 'hidden';
16066: privitem.type = 'hidden';
1.160.6.69 raeburn 16067: versionitem.type = 'hidden';
1.160.6.5 raeburn 16068: pubtext.innerHTML = '';
16069: privtext.innerHTML = '';
1.160.6.69 raeburn 16070: versiontext.innerHTML = '';
1.160.6.5 raeburn 16071: }
16072: }
16073: return;
16074: }
16075:
16076: // ]]>
16077: </script>
16078:
16079: END
16080:
16081: }
16082:
1.160.6.40 raeburn 16083: sub toggle_display_js {
1.160.6.16 raeburn 16084: return <<"END";
16085:
16086: <script type="text/javascript">
16087: // <![CDATA[
16088:
1.160.6.40 raeburn 16089: function toggleDisplay(domForm,caller) {
16090: if (document.getElementById(caller)) {
16091: var divitem = document.getElementById(caller);
16092: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 16093: var checkval = 1;
16094: var dispval = 'block';
1.160.6.93 raeburn 16095: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 16096: if (caller == 'emailoptions') {
16097: optionsElement = domForm.cancreate_email;
16098: }
1.160.6.57 raeburn 16099: if (caller == 'studentsubmission') {
16100: optionsElement = domForm.postsubmit;
16101: }
1.160.6.64 raeburn 16102: if (caller == 'cloneinstcode') {
16103: optionsElement = domForm.canclone;
16104: checkval = 'instcode';
16105: }
1.160.6.93 raeburn 16106: if (selfcreateRegExp.test(caller)) {
16107: optionsElement = domForm.elements[caller];
16108: checkval = 'other';
16109: dispval = 'inline'
16110: }
1.160.6.40 raeburn 16111: if (optionsElement.length) {
1.160.6.16 raeburn 16112: var currval;
1.160.6.40 raeburn 16113: for (var i=0; i<optionsElement.length; i++) {
16114: if (optionsElement[i].checked) {
16115: currval = optionsElement[i].value;
1.160.6.16 raeburn 16116: }
16117: }
1.160.6.64 raeburn 16118: if (currval == checkval) {
16119: divitem.style.display = dispval;
1.160.6.16 raeburn 16120: } else {
1.160.6.40 raeburn 16121: divitem.style.display = 'none';
1.160.6.16 raeburn 16122: }
16123: }
16124: }
16125: return;
16126: }
16127:
16128: // ]]>
16129: </script>
16130:
16131: END
16132:
16133: }
16134:
1.160.6.5 raeburn 16135: sub captcha_phrases {
16136: return &Apache::lonlocal::texthash (
16137: priv => 'Private key',
16138: pub => 'Public key',
16139: original => 'original (CAPTCHA)',
16140: recaptcha => 'successor (ReCAPTCHA)',
16141: notused => 'unused',
1.160.6.69 raeburn 16142: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 16143: );
16144: }
16145:
1.160.6.24 raeburn 16146: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 16147: my ($dom,$cachekeys) = @_;
16148: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 16149: my %servers = &Apache::lonnet::internet_dom_servers($dom);
16150: my %thismachine;
16151: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.98 raeburn 16152: my @posscached = ('domainconfig','domdefaults','usersessions',
16153: 'directorysrch','passwdconf','cats');
1.160.6.61 raeburn 16154: if (keys(%servers)) {
1.160.6.24 raeburn 16155: foreach my $server (keys(%servers)) {
16156: next if ($thismachine{$server});
1.160.6.27 raeburn 16157: my @cached;
16158: foreach my $name (@posscached) {
16159: if ($cachekeys->{$name}) {
16160: push(@cached,&escape($name).':'.&escape($dom));
16161: }
16162: }
16163: if (@cached) {
16164: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
16165: }
1.160.6.24 raeburn 16166: }
16167: }
16168: return;
16169: }
16170:
1.3 raeburn 16171: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>